diff --git a/fine-bouncycastle/readme.md b/fine-bouncycastle/readme.md
index 0a3aa3155..7e179b705 100644
--- a/fine-bouncycastle/readme.md
+++ b/fine-bouncycastle/readme.md
@@ -1,2 +1,2 @@
-版本:1.64
+版本:1.67
源码:https://www.bouncycastle.org/latest_releases.html
\ No newline at end of file
diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1BitString.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1BitString.java
index bbaface4f..65eb93318 100644
--- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1BitString.java
+++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1BitString.java
@@ -203,7 +203,15 @@ public abstract class ASN1BitString
public byte[] getBytes()
{
- return derForm(data, padBits);
+ if (0 == data.length)
+ {
+ return data;
+ }
+
+ byte[] rv = Arrays.clone(data);
+ // DER requires pad bits be zero
+ rv[data.length - 1] &= (0xFF << padBits);
+ return rv;
}
public int getPadBits()
@@ -269,21 +277,6 @@ public abstract class ASN1BitString
return derA == derB;
}
- /**
- * @deprecated Will be hidden/removed.
- */
- protected static byte[] derForm(byte[] data, int padBits)
- {
- if (0 == data.length)
- {
- return data;
- }
- byte[] rv = Arrays.clone(data);
- // DER requires pad bits be zero
- rv[data.length - 1] &= (0xFF << padBits);
- return rv;
- }
-
static ASN1BitString fromInputStream(int length, InputStream stream)
throws IOException
{
diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1GeneralizedTime.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1GeneralizedTime.java
index c5d5c3bac..62bcc2cd9 100644
--- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1GeneralizedTime.java
+++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1GeneralizedTime.java
@@ -271,7 +271,7 @@ public class ASN1GeneralizedTime
}
}
catch (ParseException e)
- { e.printStackTrace();
+ {
// we'll do our best and ignore daylight savings
}
diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Generator.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Generator.java
index e457ff21f..7dbbbd656 100644
--- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Generator.java
+++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Generator.java
@@ -7,12 +7,14 @@ import java.io.OutputStream;
*/
public abstract class ASN1Generator
{
+ // TODO This is problematic if we want an isolating buffer for all ASN.1 writes
protected OutputStream _out;
/**
* Base constructor.
*
- * @param out the end output stream that object encodings are written to.
+ * @param out
+ * the end output stream that object encodings are written to.
*/
public ASN1Generator(OutputStream out)
{
diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1InputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1InputStream.java
index 2ba55d34a..ca9e8e0fe 100644
--- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1InputStream.java
+++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1InputStream.java
@@ -383,23 +383,20 @@ public class ASN1InputStream
throws IOException
{
int len = defIn.getRemaining();
- if (defIn.getRemaining() < tmpBuffers.length)
+ if (len >= tmpBuffers.length)
{
- byte[] buf = tmpBuffers[len];
-
- if (buf == null)
- {
- buf = tmpBuffers[len] = new byte[len];
- }
-
- Streams.readFully(defIn, buf);
-
- return buf;
+ return defIn.toByteArray();
}
- else
+
+ byte[] buf = tmpBuffers[len];
+ if (buf == null)
{
- return defIn.toByteArray();
+ buf = tmpBuffers[len] = new byte[len];
}
+
+ defIn.readAllIntoByteArray(buf);
+
+ return buf;
}
private static char[] getBMPCharBuffer(DefiniteLengthInputStream defIn)
diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Object.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Object.java
index cb01bcb01..ff604b800 100644
--- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Object.java
+++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Object.java
@@ -72,15 +72,6 @@ public abstract class ASN1Object
return this.toASN1Primitive().equals(other.toASN1Primitive());
}
- /**
- * @deprecated use toASN1Primitive()
- * @return the underlying primitive type.
- */
- public ASN1Primitive toASN1Object()
- {
- return this.toASN1Primitive();
- }
-
/**
* Return true if obj is a byte array and represents an object with the given tag value.
*
diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1OctetString.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1OctetString.java
index d74c6c6e0..ba1e9ea61 100644
--- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1OctetString.java
+++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1OctetString.java
@@ -133,7 +133,7 @@ public abstract class ASN1OctetString
*/
if (taggedObject.isExplicit())
{
- ASN1OctetString singleSegment = ASN1OctetString.getInstance(o);
+ ASN1OctetString singleSegment = getInstance(o);
if (taggedObject instanceof BERTaggedObject)
{
@@ -194,7 +194,7 @@ public abstract class ASN1OctetString
{
try
{
- return ASN1OctetString.getInstance(ASN1Primitive.fromByteArray((byte[])obj));
+ return getInstance(fromByteArray((byte[])obj));
}
catch (IOException e)
{
diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1OutputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1OutputStream.java
index c8269ca0f..9f114c83c 100644
--- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1OutputStream.java
+++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1OutputStream.java
@@ -264,16 +264,6 @@ public class ASN1OutputStream
}
}
- /**
- * @deprecated Will be removed.
- */
- protected void writeNull()
- throws IOException
- {
- write(BERTags.NULL);
- write(0x00);
- }
-
public void writeObject(ASN1Encodable obj) throws IOException
{
if (null == obj)
diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Sequence.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Sequence.java
index 68313a1ae..a0c5ae12b 100644
--- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Sequence.java
+++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Sequence.java
@@ -177,7 +177,7 @@ public abstract class ASN1Sequence
/**
* Create a SEQUENCE containing one object.
- * @param obj the object to be put in the SEQUENCE.
+ * @param element the object to be put in the SEQUENCE.
*/
protected ASN1Sequence(ASN1Encodable element)
{
@@ -205,7 +205,7 @@ public abstract class ASN1Sequence
/**
* Create a SEQUENCE containing an array of objects.
- * @param array the array of objects to be put in the SEQUENCE.
+ * @param elements the array of objects to be put in the SEQUENCE.
*/
protected ASN1Sequence(ASN1Encodable[] elements)
{
@@ -245,11 +245,11 @@ public abstract class ASN1Sequence
public Object nextElement()
{
- if (pos >= elements.length)
+ if (pos < elements.length)
{
- throw new NoSuchElementException("ASN1Sequence Enumeration");
+ return elements[pos++];
}
- return elements[pos++];
+ throw new NoSuchElementException();
}
};
}
diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Set.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Set.java
index 96b96b3c2..6b3902a64 100644
--- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Set.java
+++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1Set.java
@@ -312,11 +312,11 @@ public abstract class ASN1Set
public Object nextElement()
{
- if (pos >= elements.length)
+ if (pos < elements.length)
{
- throw new NoSuchElementException("ASN1Set Enumeration");
+ return elements[pos++];
}
- return elements[pos++];
+ throw new NoSuchElementException();
}
};
}
diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1TaggedObject.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1TaggedObject.java
index b2ae1a2c7..bcfb73ddc 100644
--- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1TaggedObject.java
+++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ASN1TaggedObject.java
@@ -123,14 +123,6 @@ public abstract class ASN1TaggedObject
return explicit;
}
- /**
- * @deprecated Will be removed (always returns false).
- */
- public boolean isEmpty()
- {
- return false;
- }
-
/**
* Return whatever was following the tag.
*
diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BERConstructedOctetString.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BERConstructedOctetString.java deleted file mode 100644 index be86b78ac..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BERConstructedOctetString.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Enumeration; -import java.util.Vector; - -/** - * @deprecated use BEROctetString - */ -public class BERConstructedOctetString - extends BEROctetString -{ - private static final int MAX_LENGTH = 1000; - - /** - * convert a vector of octet strings into a single byte string - */ - static private byte[] toBytes( - Vector octs) - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - - for (int i = 0; i != octs.size(); i++) - { - try - { - DEROctetString o = (DEROctetString)octs.elementAt(i); - - bOut.write(o.getOctets()); - } - catch (ClassCastException e) - { - throw new IllegalArgumentException(octs.elementAt(i).getClass().getName() + " found in input should only contain DEROctetString"); - } - catch (IOException e) - { - throw new IllegalArgumentException("exception converting octets " + e.toString()); - } - } - - return bOut.toByteArray(); - } - - private Vector octs; - - /** - * @param string the octets making up the octet string. - */ - public BERConstructedOctetString( - byte[] string) - { - super(string); - } - - public BERConstructedOctetString( - Vector octs) - { - super(toBytes(octs)); - - this.octs = octs; - } - - public BERConstructedOctetString( - ASN1Primitive obj) - { - super(toByteArray(obj)); - } - - private static byte[] toByteArray(ASN1Primitive obj) - { - try - { - return obj.getEncoded(); - } - catch (IOException e) - { - throw new IllegalArgumentException("Unable to encode object"); - } - } - - public BERConstructedOctetString( - ASN1Encodable obj) - { - this(obj.toASN1Primitive()); - } - - public byte[] getOctets() - { - return string; - } - - /** - * return the DER octets that make up this string. - */ - public Enumeration getObjects() - { - if (octs == null) - { - return generateOcts().elements(); - } - - return octs.elements(); - } - - private Vector generateOcts() - { - Vector vec = new Vector(); - for (int i = 0; i < string.length; i += MAX_LENGTH) - { - int end; - - if (i + MAX_LENGTH > string.length) - { - end = string.length; - } - else - { - end = i + MAX_LENGTH; - } - - byte[] nStr = new byte[end - i]; - - System.arraycopy(string, i, nStr, 0, nStr.length); - - vec.addElement(new DEROctetString(nStr)); - } - - return vec; - } - - public static BEROctetString fromSequence(ASN1Sequence seq) - { - Vector v = new Vector(); - Enumeration e = seq.getObjects(); - - while (e.hasMoreElements()) - { - v.addElement(e.nextElement()); - } - - return new BERConstructedOctetString(v); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BERGenerator.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BERGenerator.java index 4259a14a1..41d0e5bb6 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BERGenerator.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BERGenerator.java @@ -7,25 +7,23 @@ import java.io.OutputStream; * Base class for generators for indefinite-length structures. */ public class BERGenerator - extends ASN1Generator + extends + ASN1Generator { - private boolean _tagged = false; - private boolean _isExplicit; - private int _tagNo; + private boolean _tagged = false; + private boolean _isExplicit; + private int _tagNo; - protected BERGenerator( - OutputStream out) + protected BERGenerator(OutputStream out) { super(out); } - protected BERGenerator( - OutputStream out, - int tagNo, - boolean isExplicit) + protected BERGenerator(OutputStream out, int tagNo, boolean isExplicit) { super(out); - + + // TODO Check proper handling of implicit tagging _tagged = true; _isExplicit = isExplicit; _tagNo = tagNo; @@ -35,18 +33,14 @@ public class BERGenerator { return _out; } - - private void writeHdr( - int tag) - throws IOException + + private void writeHdr(int tag) throws IOException { _out.write(tag); _out.write(0x80); } - - protected void writeBERHeader( - int tag) - throws IOException + + protected void writeBERHeader(int tag) throws IOException { if (_tagged) { @@ -58,7 +52,7 @@ public class BERGenerator writeHdr(tag); } else - { + { if ((tag & BERTags.CONSTRUCTED) != 0) { writeHdr(tagNum | BERTags.CONSTRUCTED); @@ -75,12 +69,11 @@ public class BERGenerator } } - protected void writeBEREnd() - throws IOException + protected void writeBEREnd() throws IOException { _out.write(0x00); _out.write(0x00); - + if (_tagged && _isExplicit) // write extra end for tag header { _out.write(0x00); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BEROctetString.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BEROctetString.java index 5fd99fe88..8662a5b65 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BEROctetString.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BEROctetString.java @@ -3,7 +3,7 @@ package com.fr.third.org.bouncycastle.asn1; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Enumeration; -import java.util.Vector; +import java.util.NoSuchElementException; /** * ASN.1 OctetStrings, with indefinite length rules, and constructed form support. @@ -22,7 +22,7 @@ import java.util.Vector; public class BEROctetString extends ASN1OctetString { - private static final int DEFAULT_LENGTH = 1000; + private static final int DEFAULT_CHUNK_SIZE = 1000; private final int chunkSize; private final ASN1OctetString[] octs; @@ -39,13 +39,7 @@ public class BEROctetString { try { - DEROctetString o = (DEROctetString)octs[i]; - - bOut.write(o.getOctets()); - } - catch (ClassCastException e) - { - throw new IllegalArgumentException(octs[i].getClass().getName() + " found in input should only contain DEROctetString"); + bOut.write(octs[i].getOctets()); } catch (IOException e) { @@ -63,7 +57,7 @@ public class BEROctetString public BEROctetString( byte[] string) { - this(string, DEFAULT_LENGTH); + this(string, DEFAULT_CHUNK_SIZE); } /** @@ -75,7 +69,7 @@ public class BEROctetString public BEROctetString( ASN1OctetString[] octs) { - this(octs, DEFAULT_LENGTH); + this(octs, DEFAULT_CHUNK_SIZE); } /** @@ -111,15 +105,6 @@ public class BEROctetString this.chunkSize = chunkSize; } - /** - * Return a concatenated byte array of all the octets making up the constructed OCTET STRING - * @return the full OCTET STRING. - */ - public byte[] getOctets() - { - return string; - } - /** * Return the OCTET STRINGs that make up this string. * @@ -129,7 +114,28 @@ public class BEROctetString { if (octs == null) { - return generateOcts().elements(); + return new Enumeration() + { + int pos = 0; + + public boolean hasMoreElements() + { + return pos < string.length; + } + + public Object nextElement() + { + if (pos < string.length) + { + int length = Math.min(string.length - pos, chunkSize); + byte[] chunk = new byte[length]; + System.arraycopy(string, pos, chunk, 0, length); + pos += length; + return new DEROctetString(chunk); + } + throw new NoSuchElementException(); + } + }; } return new Enumeration() @@ -143,37 +149,15 @@ public class BEROctetString public Object nextElement() { - return octs[counter++]; + if (counter < octs.length) + { + return octs[counter++]; + } + throw new NoSuchElementException(); } }; } - private Vector generateOcts() - { - Vector vec = new Vector(); - for (int i = 0; i < string.length; i += chunkSize) - { - int end; - - if (i + chunkSize > string.length) - { - end = string.length; - } - else - { - end = i + chunkSize; - } - - byte[] nStr = new byte[end - i]; - - System.arraycopy(string, i, nStr, 0, nStr.length); - - vec.addElement(new DEROctetString(nStr)); - } - - return vec; - } - boolean isConstructed() { return true; @@ -191,15 +175,6 @@ public class BEROctetString return 2 + length + 2; } - /** - * @deprecated - */ - public void encode(ASN1OutputStream out) - throws IOException - { - out.writeObject(this); - } - void encode(ASN1OutputStream out, boolean withTag) throws IOException { out.writeEncodedIndef(withTag, BERTags.CONSTRUCTED | BERTags.OCTET_STRING, getObjects()); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BEROutputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BEROutputStream.java index acb28ae85..614a62dc3 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BEROutputStream.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/BEROutputStream.java @@ -5,10 +5,8 @@ import java.io.OutputStream; /** * A class which writes indefinite and definite length objects. Objects which specify DER will be * encoded accordingly, but DL or BER objects will be encoded as defined. - * - * @deprecated Will be removed from public API. */ -public class BEROutputStream +class BEROutputStream extends ASN1OutputStream { /** @@ -16,11 +14,8 @@ public class BEROutputStream * * @param os * target output stream. - * - * @deprecated Use {@link ASN1OutputStream#create(OutputStream, String)} with - * {@link ASN1Encoding#BER} instead. */ - public BEROutputStream(OutputStream os) + BEROutputStream(OutputStream os) { super(os); } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ConstructedOctetStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ConstructedOctetStream.java index cd0d17251..e42bc032a 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ConstructedOctetStream.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ConstructedOctetStream.java @@ -26,21 +26,14 @@ class ConstructedOctetStream return -1; } - ASN1Encodable asn1Obj = _parser.readObject(); - if (asn1Obj == null) + ASN1OctetStringParser next = getNextParser(); + if (next == null) { return -1; } - if (!(asn1Obj instanceof ASN1OctetStringParser)) - { - throw new IOException("unknown object encountered: " + asn1Obj.getClass()); - } - - ASN1OctetStringParser s = (ASN1OctetStringParser)asn1Obj; - _first = false; - _currentStream = s.getOctetStream(); + _currentStream = next.getOctetStream(); } int totalRead = 0; @@ -60,22 +53,14 @@ class ConstructedOctetStream } else { - ASN1Encodable asn1Obj = _parser.readObject(); - - if (asn1Obj == null) + ASN1OctetStringParser next = getNextParser(); + if (next == null) { _currentStream = null; return totalRead < 1 ? -1 : totalRead; } - if (!(asn1Obj instanceof ASN1OctetStringParser)) - { - throw new IOException("unknown object encountered: " + asn1Obj.getClass()); - } - - ASN1OctetStringParser aos = (ASN1OctetStringParser)asn1Obj; - - _currentStream = aos.getOctetStream(); + _currentStream = next.getOctetStream(); } } } @@ -90,22 +75,14 @@ class ConstructedOctetStream return -1; } - ASN1Encodable asn1Obj = _parser.readObject(); - - if (asn1Obj == null) + ASN1OctetStringParser next = getNextParser(); + if (next == null) { return -1; } - if (!(asn1Obj instanceof ASN1OctetStringParser)) - { - throw new IOException("unknown object encountered: " + asn1Obj.getClass()); - } - - ASN1OctetStringParser s = (ASN1OctetStringParser)asn1Obj; - _first = false; - _currentStream = s.getOctetStream(); + _currentStream = next.getOctetStream(); } for (;;) @@ -117,22 +94,30 @@ class ConstructedOctetStream return b; } - ASN1Encodable asn1Obj = _parser.readObject(); - - if (asn1Obj == null) + ASN1OctetStringParser next = getNextParser(); + if (next == null) { _currentStream = null; return -1; } - if (!(asn1Obj instanceof ASN1OctetStringParser)) - { - throw new IOException("unknown object encountered: " + asn1Obj.getClass()); - } + _currentStream = next.getOctetStream(); + } + } - ASN1OctetStringParser s = (ASN1OctetStringParser)asn1Obj; + private ASN1OctetStringParser getNextParser() throws IOException + { + ASN1Encodable asn1Obj = _parser.readObject(); + if (asn1Obj == null) + { + return null; + } - _currentStream = s.getOctetStream(); + if (asn1Obj instanceof ASN1OctetStringParser) + { + return (ASN1OctetStringParser)asn1Obj; } + + throw new IOException("unknown object encountered: " + asn1Obj.getClass()); } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERBMPString.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERBMPString.java index b6011f1db..15185c67f 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERBMPString.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERBMPString.java @@ -81,9 +81,21 @@ public class DERBMPString DERBMPString( byte[] string) { - char[] cs = new char[string.length / 2]; + if (string == null) + { + throw new NullPointerException("'string' cannot be null"); + } + + int byteLen = string.length; + if (0 != (byteLen & 1)) + { + throw new IllegalArgumentException("malformed BMPString encoding encountered"); + } + + int charLen = byteLen / 2; + char[] cs = new char[charLen]; - for (int i = 0; i != cs.length; i++) + for (int i = 0; i != charLen; i++) { cs[i] = (char)((string[2 * i] << 8) | (string[2 * i + 1] & 0xff)); } @@ -93,6 +105,11 @@ public class DERBMPString DERBMPString(char[] string) { + if (string == null) + { + throw new NullPointerException("'string' cannot be null"); + } + this.string = string; } @@ -103,6 +120,11 @@ public class DERBMPString public DERBMPString( String string) { + if (string == null) + { + throw new NullPointerException("'string' cannot be null"); + } + this.string = string.toCharArray(); } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEREncodableVector.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEREncodableVector.java deleted file mode 100644 index 0a54898b6..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEREncodableVector.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1; - -/** - * a general class for building up a vector of DER encodable objects - - * this will eventually be superseded by ASN1EncodableVector so you should - * use that class in preference. - */ -public class DEREncodableVector - extends ASN1EncodableVector -{ - /** - * @deprecated use ASN1EncodableVector instead. - */ - public DEREncodableVector() - { - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEREnumerated.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEREnumerated.java deleted file mode 100644 index ee466ca85..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEREnumerated.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1; - -import java.math.BigInteger; - -/** - * @deprecated Use ASN1Enumerated instead of this. - */ -public class DEREnumerated - extends ASN1Enumerated -{ - /** - * @param bytes the value of this enumerated as an encoded BigInteger (signed). - * @deprecated use ASN1Enumerated - */ - DEREnumerated(byte[] bytes) - { - super(bytes); - } - - /** - * @param value the value of this enumerated. - * @deprecated use ASN1Enumerated - */ - public DEREnumerated(BigInteger value) - { - super(value); - } - - /** - * @param value the value of this enumerated. - * @deprecated use ASN1Enumerated - */ - public DEREnumerated(int value) - { - super(value); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERInteger.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERInteger.java deleted file mode 100644 index 35d13092a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERInteger.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1; - -import java.math.BigInteger; - -/** - * @deprecated Use ASN1Integer instead of this, - */ -public class DERInteger - extends ASN1Integer -{ - /** - * Constructor from a byte array containing a signed representation of the number. - * - * @param bytes a byte array containing the signed number.A copy is made of the byte array. - */ - public DERInteger(byte[] bytes) - { - super(bytes, true); - } - - public DERInteger(BigInteger value) - { - super(value); - } - - public DERInteger(long value) - { - super(value); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERNull.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERNull.java index 0a5a934eb..a2a521ba6 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERNull.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERNull.java @@ -14,10 +14,7 @@ public class DERNull private static final byte[] zeroBytes = new byte[0]; - /** - * @deprecated use DERNull.INSTANCE - */ - public DERNull() + private DERNull() { } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERObjectIdentifier.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERObjectIdentifier.java deleted file mode 100644 index 2a5153cf4..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERObjectIdentifier.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1; - -/** - * - * @deprecated Use ASN1ObjectIdentifier instead of this, - */ -public class DERObjectIdentifier - extends ASN1ObjectIdentifier -{ - public DERObjectIdentifier(String identifier) - { - super(identifier); - } - - DERObjectIdentifier(byte[] bytes) - { - super(bytes); - } - - DERObjectIdentifier(ASN1ObjectIdentifier oid, String branch) - { - super(oid, branch); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEROutputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEROutputStream.java index 3951e0021..a7ce6f95b 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEROutputStream.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DEROutputStream.java @@ -5,17 +5,11 @@ import java.io.OutputStream; /** * Stream that outputs encoding based on distinguished encoding rules. - * - * @deprecated Will be removed from public API. */ -public class DEROutputStream +class DEROutputStream extends ASN1OutputStream { - /** - * @deprecated Use {@link ASN1OutputStream#create(OutputStream, String)} with - * {@link ASN1Encoding#DER} instead. - */ - public DEROutputStream(OutputStream os) + DEROutputStream(OutputStream os) { super(os); } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERSequenceParser.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERSequenceParser.java deleted file mode 100644 index 7b9acafe2..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERSequenceParser.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1; - -import java.io.IOException; - -/** - * @deprecated Use DLSequenceParser instead - */ -public class DERSequenceParser - implements ASN1SequenceParser -{ - private ASN1StreamParser _parser; - - DERSequenceParser(ASN1StreamParser parser) - { - this._parser = parser; - } - - /** - * Return the next object in the SEQUENCE. - * - * @return next object in SEQUENCE. - * @throws IOException if there is an issue loading the object. - */ - public ASN1Encodable readObject() - throws IOException - { - return _parser.readObject(); - } - - /** - * Return an in memory, encodable, representation of the SEQUENCE. - * - * @return a DERSequence. - * @throws IOException if there is an issue loading the data. - */ - public ASN1Primitive getLoadedObject() - throws IOException - { - return new DLSequence(_parser.readVector()); - } - - /** - * Return a DERSequence representing this parser and its contents. - * - * @return a DERSequence. - */ - public ASN1Primitive toASN1Primitive() - { - try - { - return getLoadedObject(); - } - catch (IOException e) - { - throw new IllegalStateException(e.getMessage()); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERSetParser.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERSetParser.java deleted file mode 100644 index 34b768833..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERSetParser.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1; - -import java.io.IOException; - -/** - * @deprecated Use DLSetParser instead - */ -public class DERSetParser - implements ASN1SetParser -{ - private ASN1StreamParser _parser; - - DERSetParser(ASN1StreamParser parser) - { - this._parser = parser; - } - - /** - * Return the next object in the SET. - * - * @return next object in SET. - * @throws IOException if there is an issue loading the object. - */ - public ASN1Encodable readObject() - throws IOException - { - return _parser.readObject(); - } - - /** - * Return an in memory, encodable, representation of the SET. - * - * @return a DERSet. - * @throws IOException if there is an issue loading the data. - */ - public ASN1Primitive getLoadedObject() - throws IOException - { - return new DLSet(_parser.readVector()); - } - - /** - * Return a DERSet representing this parser and its contents. - * - * @return a DERSet - */ - public ASN1Primitive toASN1Primitive() - { - try - { - return getLoadedObject(); - } - catch (IOException e) - { - throw new ASN1ParsingException(e.getMessage(), e); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERT61UTF8String.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERT61UTF8String.java deleted file mode 100644 index ad775e486..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERT61UTF8String.java +++ /dev/null @@ -1,153 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; - -/** - * DER T61String (also the teletex string) - a "modern" encapsulation that uses UTF-8. If at all possible, avoid this one! It's only for emergencies. - * Use UTF8String instead. - * @deprecated don't use this class, introduced in error, it will be removed. - */ -public class DERT61UTF8String - extends ASN1Primitive - implements ASN1String -{ - private byte[] string; - - /** - * return a T61 string from the passed in object. UTF-8 Encoding is assumed in this case. - * - * @param obj a DERT61UTF8String or an object that can be converted into one. - * @throws IllegalArgumentException if the object cannot be converted. - * @return a DERT61UTF8String instance, or null - */ - public static DERT61UTF8String getInstance( - Object obj) - { - if (obj instanceof DERT61String) - { - return new DERT61UTF8String(((DERT61String)obj).getOctets()); - } - - if (obj == null || obj instanceof DERT61UTF8String) - { - return (DERT61UTF8String)obj; - } - - if (obj instanceof byte[]) - { - try - { - return new DERT61UTF8String(((DERT61String)fromByteArray((byte[])obj)).getOctets()); - } - catch (Exception e) - { - throw new IllegalArgumentException("encoding error in getInstance: " + e.toString()); - } - } - - throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName()); - } - - /** - * return an T61 String from a tagged object. UTF-8 encoding is assumed in this case. - * - * @param obj the tagged object holding the object we want - * @param explicit true if the object is meant to be explicitly - * tagged false otherwise. - * @throws IllegalArgumentException if the tagged object cannot - * be converted. - * @return a DERT61UTF8String instance, or null - */ - public static DERT61UTF8String getInstance( - ASN1TaggedObject obj, - boolean explicit) - { - ASN1Primitive o = obj.getObject(); - - if (explicit || o instanceof DERT61String || o instanceof DERT61UTF8String) - { - return getInstance(o); - } - else - { - return new DERT61UTF8String(ASN1OctetString.getInstance(o).getOctets()); - } - } - - /** - * basic constructor - string encoded as a sequence of bytes. - */ - public DERT61UTF8String( - byte[] string) - { - this.string = string; - } - - /** - * basic constructor - with string UTF8 conversion assumed. - */ - public DERT61UTF8String( - String string) - { - this(Strings.toUTF8ByteArray(string)); - } - - /** - * Decode the encoded string and return it, UTF8 assumed. - * - * @return the decoded String - */ - public String getString() - { - return Strings.fromUTF8ByteArray(string); - } - - public String toString() - { - return getString(); - } - - boolean isConstructed() - { - return false; - } - - int encodedLength() - { - return 1 + StreamUtil.calculateBodyLength(string.length) + string.length; - } - - void encode(ASN1OutputStream out, boolean withTag) throws IOException - { - out.writeEncoded(withTag, BERTags.T61_STRING, string); - } - - /** - * Return the encoded string as a byte array. - * - * @return the actual bytes making up the encoded body of the T61 string. - */ - public byte[] getOctets() - { - return Arrays.clone(string); - } - - boolean asn1Equals( - ASN1Primitive o) - { - if (!(o instanceof DERT61UTF8String)) - { - return false; - } - - return Arrays.areEqual(string, ((DERT61UTF8String)o).string); - } - - public int hashCode() - { - return Arrays.hashCode(string); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERTags.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERTags.java deleted file mode 100644 index 12669f5c8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DERTags.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1; - -/** - * @deprecated use BERTags - */ -public interface DERTags - extends BERTags -{ -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLExternal.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLExternal.java index 201cec5f8..c9b31fd13 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLExternal.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLExternal.java @@ -82,7 +82,7 @@ public class DLExternal { baos.write(dataValueDescriptor.getEncoded(ASN1Encoding.DL)); } - DERTaggedObject obj = new DERTaggedObject(true, encoding, externalContent); + ASN1TaggedObject obj = new DLTaggedObject(true, encoding, externalContent); baos.write(obj.getEncoded(ASN1Encoding.DL)); out.writeEncoded(withTag, BERTags.CONSTRUCTED, BERTags.EXTERNAL, baos.toByteArray()); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLOutputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLOutputStream.java index d80b0e61e..c0a0d911f 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLOutputStream.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLOutputStream.java @@ -5,17 +5,11 @@ import java.io.OutputStream; /** * Stream that outputs encoding based on definite length. - * - * @deprecated Will be removed from public API. */ -public class DLOutputStream +class DLOutputStream extends ASN1OutputStream { - /** - * @deprecated Use {@link ASN1OutputStream#create(OutputStream, String)} with - * {@link ASN1Encoding#DL} instead. - */ - public DLOutputStream(OutputStream os) + DLOutputStream(OutputStream os) { super(os); } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLSequenceParser.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLSequenceParser.java index 52eaa8b2b..a57a61107 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLSequenceParser.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLSequenceParser.java @@ -1,12 +1,60 @@ package com.fr.third.org.bouncycastle.asn1; +import java.io.IOException; + /** * Parser class for DL SEQUENCEs. + * + * TODO The class is only publicly visible to support 'instanceof' checks; provide an alternative */ -public class DLSequenceParser extends DERSequenceParser +public class DLSequenceParser + implements ASN1SequenceParser { + private ASN1StreamParser _parser; + DLSequenceParser(ASN1StreamParser parser) { - super(parser); + this._parser = parser; + } + + /** + * Return the next object in the SEQUENCE. + * + * @return next object in SEQUENCE. + * @throws IOException if there is an issue loading the object. + */ + public ASN1Encodable readObject() + throws IOException + { + return _parser.readObject(); + } + + /** + * Return an in memory, encodable, representation of the SEQUENCE. + * + * @return a DLSequence. + * @throws IOException if there is an issue loading the data. + */ + public ASN1Primitive getLoadedObject() + throws IOException + { + return new DLSequence(_parser.readVector()); + } + + /** + * Return a DLSequence representing this parser and its contents. + * + * @return a DLSequence. + */ + public ASN1Primitive toASN1Primitive() + { + try + { + return getLoadedObject(); + } + catch (IOException e) + { + throw new IllegalStateException(e.getMessage()); + } } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLSetParser.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLSetParser.java index 121efef20..f54401393 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLSetParser.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DLSetParser.java @@ -1,12 +1,60 @@ package com.fr.third.org.bouncycastle.asn1; +import java.io.IOException; + /** * Parser class for DL SETs. + * + * TODO The class is only publicly visible to support 'instanceof' checks; provide an alternative */ -public class DLSetParser extends DERSetParser +public class DLSetParser + implements ASN1SetParser { + private ASN1StreamParser _parser; + DLSetParser(ASN1StreamParser parser) { - super(parser); + this._parser = parser; + } + + /** + * Return the next object in the SET. + * + * @return next object in SET. + * @throws IOException if there is an issue loading the object. + */ + public ASN1Encodable readObject() + throws IOException + { + return _parser.readObject(); + } + + /** + * Return an in memory, encodable, representation of the SET. + * + * @return a DLSet. + * @throws IOException if there is an issue loading the data. + */ + public ASN1Primitive getLoadedObject() + throws IOException + { + return new DLSet(_parser.readVector()); + } + + /** + * Return a DLSet representing this parser and its contents. + * + * @return a DLSet + */ + public ASN1Primitive toASN1Primitive() + { + try + { + return getLoadedObject(); + } + catch (IOException e) + { + throw new ASN1ParsingException(e.getMessage(), e); + } } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DefiniteLengthInputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DefiniteLengthInputStream.java index 96f7fa4a1..f6c38f15f 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DefiniteLengthInputStream.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/DefiniteLengthInputStream.java @@ -23,7 +23,7 @@ class DefiniteLengthInputStream int length, int limit) { - super(in, limit, length); + super(in, limit); if (length < 0) { @@ -91,6 +91,33 @@ class DefiniteLengthInputStream return numRead; } + void readAllIntoByteArray(byte[] buf) + throws IOException + { + if (_remaining != buf.length) + { + throw new IllegalArgumentException("buffer length not right for data"); + } + + if (_remaining == 0) + { + return; + } + + // make sure it's safe to do this! + int limit = getLimit(); + if (_remaining >= limit) + { + throw new IOException("corrupted stream - out of bounds length found: " + _remaining + " >= " + limit); + } + + if ((_remaining -= Streams.readFully(_in, buf)) != 0) + { + throw new EOFException("DEF length " + _originalLength + " object truncated by " + _remaining); + } + setParentEofDetect(true); + } + byte[] toByteArray() throws IOException { @@ -100,9 +127,10 @@ class DefiniteLengthInputStream } // make sure it's safe to do this! - if (_remaining >= this.getLimit()) + int limit = getLimit(); + if (_remaining >= limit) { - throw new IOException("corrupted stream - out of bounds length found: " + _remaining + " >= " + this.getLimit()); + throw new IOException("corrupted stream - out of bounds length found: " + _remaining + " >= " + limit); } byte[] bytes = new byte[_remaining]; diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/IndefiniteLengthInputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/IndefiniteLengthInputStream.java index 30f6757bd..1c3bfc70a 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/IndefiniteLengthInputStream.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/IndefiniteLengthInputStream.java @@ -17,7 +17,7 @@ class IndefiniteLengthInputStream int limit) throws IOException { - super(in, limit, limit); + super(in, limit); _b1 = in.read(); _b2 = in.read(); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/LazyConstructionEnumeration.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/LazyConstructionEnumeration.java index 217711285..77f5f389c 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/LazyConstructionEnumeration.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/LazyConstructionEnumeration.java @@ -2,6 +2,7 @@ package com.fr.third.org.bouncycastle.asn1; import java.io.IOException; import java.util.Enumeration; +import java.util.NoSuchElementException; class LazyConstructionEnumeration implements Enumeration @@ -22,11 +23,13 @@ class LazyConstructionEnumeration public Object nextElement() { - Object o = nextObj; - - nextObj = readObject(); - - return o; + if (nextObj != null) + { + Object o = nextObj; + nextObj = readObject(); + return o; + } + throw new NoSuchElementException(); } private Object readObject() diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/LimitedInputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/LimitedInputStream.java index 372cec878..d221e51d7 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/LimitedInputStream.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/LimitedInputStream.java @@ -10,16 +10,13 @@ abstract class LimitedInputStream { protected final InputStream _in; private int _limit; - private int _length; LimitedInputStream( InputStream in, - int limit, - int length) + int limit) { this._in = in; this._limit = limit; - this._length = length; } int getLimit() @@ -27,12 +24,6 @@ abstract class LimitedInputStream return _limit; } - int getRemaining() - { - // TODO: maybe one day this can become more accurate - return _length; - } - protected void setParentEofDetect(boolean on) { if (_in instanceof IndefiniteLengthInputStream) diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/anssi/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/anssi/package.html deleted file mode 100644 index f0ee6dc40..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/anssi/package.html +++ /dev/null @@ -1,5 +0,0 @@ - -
-Support classes for the French ANSSI EC curves. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/bc/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/bc/package.html deleted file mode 100644 index a8beb00aa..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/bc/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -ASN.1 classes specific to the Bouncy Castle APIs. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/bsi/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/bsi/package.html deleted file mode 100644 index be9bd80bb..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/bsi/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -ASN.1 classes specific to the Bundesamt für Sicherheit in der Informationstechnik (BSI) standards. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmc/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmc/package.html deleted file mode 100644 index 62fe6ceee..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmc/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for Certificate Management over CMS (CMC) - RFC 5272 and RFC 6402. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/CertOrEncCert.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/CertOrEncCert.java index 2496a5547..615433d07 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/CertOrEncCert.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/CertOrEncCert.java @@ -5,6 +5,7 @@ import com.fr.third.org.bouncycastle.asn1.ASN1Object; import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; import com.fr.third.org.bouncycastle.asn1.ASN1TaggedObject; import com.fr.third.org.bouncycastle.asn1.DERTaggedObject; +import com.fr.third.org.bouncycastle.asn1.crmf.EncryptedKey; import com.fr.third.org.bouncycastle.asn1.crmf.EncryptedValue; public class CertOrEncCert @@ -12,7 +13,7 @@ public class CertOrEncCert implements ASN1Choice { private CMPCertificate certificate; - private EncryptedValue encryptedCert; + private EncryptedKey encryptedKey; private CertOrEncCert(ASN1TaggedObject tagged) { @@ -22,7 +23,7 @@ public class CertOrEncCert } else if (tagged.getTagNo() == 1) { - encryptedCert = EncryptedValue.getInstance(tagged.getObject()); + encryptedKey = EncryptedKey.getInstance(tagged.getObject()); } else { @@ -62,7 +63,17 @@ public class CertOrEncCert throw new IllegalArgumentException("'encryptedCert' cannot be null"); } - this.encryptedCert = encryptedCert; + this.encryptedKey = new EncryptedKey(encryptedCert); + } + + public CertOrEncCert(EncryptedKey encryptedKey) + { + if (encryptedKey == null) + { + throw new IllegalArgumentException("'encryptedKey' cannot be null"); + } + + this.encryptedKey = encryptedKey; } public CMPCertificate getCertificate() @@ -70,16 +81,16 @@ public class CertOrEncCert return certificate; } - public EncryptedValue getEncryptedCert() + public EncryptedKey getEncryptedCert() { - return encryptedCert; + return encryptedKey; } /** ** CertOrEncCert ::= CHOICE { * certificate [0] CMPCertificate, - * encryptedCert [1] EncryptedValue + * encryptedCert [1] EncryptedKey * } ** @return a basic ASN.1 object representation. @@ -91,6 +102,6 @@ public class CertOrEncCert return new DERTaggedObject(true, 0, certificate); } - return new DERTaggedObject(true, 1, encryptedCert); + return new DERTaggedObject(true, 1, encryptedKey); } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/CertifiedKeyPair.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/CertifiedKeyPair.java index 2b6945752..e23d07977 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/CertifiedKeyPair.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/CertifiedKeyPair.java @@ -7,6 +7,7 @@ import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; import com.fr.third.org.bouncycastle.asn1.ASN1TaggedObject; import com.fr.third.org.bouncycastle.asn1.DERSequence; import com.fr.third.org.bouncycastle.asn1.DERTaggedObject; +import com.fr.third.org.bouncycastle.asn1.crmf.EncryptedKey; import com.fr.third.org.bouncycastle.asn1.crmf.EncryptedValue; import com.fr.third.org.bouncycastle.asn1.crmf.PKIPublicationInfo; @@ -14,7 +15,7 @@ import com.fr.third.org.bouncycastle.asn1.crmf.PKIPublicationInfo; *
* CertifiedKeyPair ::= SEQUENCE { * certOrEncCert CertOrEncCert, - * privateKey [0] EncryptedValue OPTIONAL, + * privateKey [0] EncryptedKey OPTIONAL, * -- see [CRMF] for comment on encoding * publicationInfo [1] PKIPublicationInfo OPTIONAL * } @@ -24,7 +25,7 @@ public class CertifiedKeyPair extends ASN1Object { private CertOrEncCert certOrEncCert; - private EncryptedValue privateKey; + private EncryptedKey privateKey; private PKIPublicationInfo publicationInfo; private CertifiedKeyPair(ASN1Sequence seq) @@ -38,7 +39,7 @@ public class CertifiedKeyPair ASN1TaggedObject tagged = ASN1TaggedObject.getInstance(seq.getObjectAt(1)); if (tagged.getTagNo() == 0) { - privateKey = EncryptedValue.getInstance(tagged.getObject()); + privateKey = EncryptedKey.getInstance(tagged.getObject()); } else { @@ -47,7 +48,7 @@ public class CertifiedKeyPair } else { - privateKey = EncryptedValue.getInstance(ASN1TaggedObject.getInstance(seq.getObjectAt(1)).getObject()); + privateKey = EncryptedKey.getInstance(ASN1TaggedObject.getInstance(seq.getObjectAt(1)).getObject()); publicationInfo = PKIPublicationInfo.getInstance(ASN1TaggedObject.getInstance(seq.getObjectAt(2)).getObject()); } } @@ -71,12 +72,12 @@ public class CertifiedKeyPair public CertifiedKeyPair( CertOrEncCert certOrEncCert) { - this(certOrEncCert, null, null); + this(certOrEncCert, (EncryptedKey)null, null); } public CertifiedKeyPair( CertOrEncCert certOrEncCert, - EncryptedValue privateKey, + EncryptedKey privateKey, PKIPublicationInfo publicationInfo) { if (certOrEncCert == null) @@ -89,12 +90,27 @@ public class CertifiedKeyPair this.publicationInfo = publicationInfo; } + public CertifiedKeyPair( + CertOrEncCert certOrEncCert, + EncryptedValue privateKey, + PKIPublicationInfo publicationInfo) + { + if (certOrEncCert == null) + { + throw new IllegalArgumentException("'certOrEncCert' cannot be null"); + } + + this.certOrEncCert = certOrEncCert; + this.privateKey = (privateKey != null) ? new EncryptedKey(privateKey) : (EncryptedKey)null; + this.publicationInfo = publicationInfo; + } + public CertOrEncCert getCertOrEncCert() { return certOrEncCert; } - public EncryptedValue getPrivateKey() + public EncryptedKey getPrivateKey() { return privateKey; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/PKIHeaderBuilder.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/PKIHeaderBuilder.java index 14a955ce7..ab8b3dd38 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/PKIHeaderBuilder.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/PKIHeaderBuilder.java @@ -76,7 +76,7 @@ public class PKIHeaderBuilder return setRecipKID(kid == null ? null : new DEROctetString(kid)); } - public PKIHeaderBuilder setRecipKID(DEROctetString kid) + public PKIHeaderBuilder setRecipKID(ASN1OctetString kid) { recipKID = kid; diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/package.html deleted file mode 100644 index d5ce6b957..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cmp/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding and supporting PKIX-CMP as described RFC 4210. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cms/ecc/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cms/ecc/package.html deleted file mode 100644 index 9d3302500..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cms/ecc/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for CMS ECC - RFC 5753/3278. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cms/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cms/package.html deleted file mode 100644 index c165a7a6e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cms/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding and supporting Cryptographic Message Syntax as described in PKCS#7 and RFC 3369 (formerly RFC 2630). - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/crmf/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/crmf/package.html deleted file mode 100644 index c8049240d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/crmf/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding and supporting PKIX-CRMF as described RFC 4211. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cryptopro/ECGOST3410NamedCurves.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cryptopro/ECGOST3410NamedCurves.java index 74574f75f..342a81883 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cryptopro/ECGOST3410NamedCurves.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cryptopro/ECGOST3410NamedCurves.java @@ -6,6 +6,8 @@ import java.util.Hashtable; import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; import com.fr.third.org.bouncycastle.asn1.rosstandart.RosstandartObjectIdentifiers; +import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; +import com.fr.third.org.bouncycastle.asn1.x9.X9ECPoint; import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; import com.fr.third.org.bouncycastle.math.ec.ECConstants; import com.fr.third.org.bouncycastle.math.ec.ECCurve; @@ -222,13 +224,21 @@ public class ECGOST3410NamedCurves * isn't present. * * @param oid an object identifier representing a named parameters, if present. + * + * @deprecated Use {@link #getByOIDX9(ASN1ObjectIdentifier)} instead. */ - public static ECDomainParameters getByOID( - ASN1ObjectIdentifier oid) + public static ECDomainParameters getByOID(ASN1ObjectIdentifier oid) { return (ECDomainParameters)params.get(oid); } + public static X9ECParameters getByOIDX9(ASN1ObjectIdentifier oid) + { + ECDomainParameters ec = (ECDomainParameters)params.get(oid); + return ec == null ? null : new X9ECParameters(ec.getCurve(), new X9ECPoint(ec.getG(), false), ec.getN(), + ec.getH(), ec.getSeed()); + } + /** * returns an enumeration containing the name strings for parameters * contained in this structure. @@ -238,17 +248,19 @@ public class ECGOST3410NamedCurves return names.elements(); } - public static ECDomainParameters getByName( - String name) + /** + * @deprecated Use {@link #getByNameX9(String)} instead. + */ + public static ECDomainParameters getByName(String name) { ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)objIds.get(name); + return oid == null ? null : (ECDomainParameters)params.get(oid); + } - if (oid != null) - { - return (ECDomainParameters)params.get(oid); - } - - return null; + public static X9ECParameters getByNameX9(String name) + { + ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)objIds.get(name); + return oid == null ? null : getByOIDX9(oid); } /** diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cryptopro/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cryptopro/package.html deleted file mode 100644 index 2b0af9e08..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/cryptopro/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for CRYPTO-PRO related objects - such as GOST identifiers. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/dvcs/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/dvcs/package.html deleted file mode 100644 index a94192222..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/dvcs/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding and processing Data Validation and Certification Server (DVCS) protocols as described in RFC 3029. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/eac/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/eac/package.html deleted file mode 100644 index 360d598bc..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/eac/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -ASN.1 classes specific to the Bundesamt für Sicherheit in der Informationstechnik (BSI) Technical Guideline Advanced Security Mechanisms for Machine Readable Travel Documents. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/esf/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/esf/package.html deleted file mode 100644 index de2736754..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/esf/package.html +++ /dev/null @@ -1,6 +0,0 @@ - - -Support classes useful for encoding and supporting [ESF] RFC3126 -Electronic Signature Formats for long term electronic signatures. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ess/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ess/package.html deleted file mode 100644 index 21854b368..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ess/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding and supporting Enhanced Security Services for S/MIME as described RFC 2634 and RFC 5035. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/est/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/est/package.html deleted file mode 100644 index 19b82dc6d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/est/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for Enrollment over Secure Transport (EST) - RFC 7030. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/gm/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/gm/package.html deleted file mode 100644 index 54a633d67..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/gm/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for Chinese Standard (GM) standard curves and algorithms. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/gnu/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/gnu/package.html deleted file mode 100644 index cdb9f59d9..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/gnu/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -ASN.1 classes specific to the GNU APIs and applications. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/iana/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/iana/package.html deleted file mode 100644 index bb60b438a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/iana/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -ASN.1 classes specific to the Internet Assigned Numbers Authority (IANA). - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/icao/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/icao/package.html deleted file mode 100644 index f2301dbe0..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/icao/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -ICAO ASN.1 classes for electronic passport. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isara/IsaraObjectIdentifiers.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isara/IsaraObjectIdentifiers.java new file mode 100644 index 000000000..ed2cd9ded --- /dev/null +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isara/IsaraObjectIdentifiers.java @@ -0,0 +1,22 @@ +package com.fr.third.org.bouncycastle.asn1.isara; + +import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; + +public interface IsaraObjectIdentifiers +{ + /* + id-alg-xmss OBJECT IDENTIFIER ::= { itu-t(0) + identified-organization(4) etsi(0) reserved(127) + etsi-identified-organization(0) isara(15) algorithms(1) + asymmetric(1) xmss(13) 0 } + */ + static ASN1ObjectIdentifier id_alg_xmss = new ASN1ObjectIdentifier("0.4.0.127.0.15.1.1.13.0"); + + /* + id-alg-xmssmt OBJECT IDENTIFIER ::= { itu-t(0) + identified-organization(4) etsi(0) reserved(127) + etsi-identified-organization(0) isara(15) algorithms(1) + asymmetric(1) xmssmt(14) 0 } + */ + static ASN1ObjectIdentifier id_alg_xmssmt = new ASN1ObjectIdentifier("0.4.0.127.0.15.1.1.14.0"); +} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/ocsp/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/ocsp/package.html deleted file mode 100644 index cd95ca33c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/ocsp/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for the ISIS-MTT profile for OCSP. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/package.html deleted file mode 100644 index 14ab39018..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for the ISIS-MTT Project. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/x509/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/x509/package.html deleted file mode 100644 index fa411ec7e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/isismtt/x509/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for the ISIS-MTT X.509 Certificate Extensions. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/iso/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/iso/package.html deleted file mode 100644 index dfd52993f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/iso/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for various ISO Standards. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/kisa/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/kisa/package.html deleted file mode 100644 index 48b5afdf1..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/kisa/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for the Korea Information Security Agency (KISA) standard - SEED algorithm. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/microsoft/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/microsoft/package.html deleted file mode 100644 index 35d124868..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/microsoft/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support for Microsoft specific ASN.1 classes and object identifiers. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/misc/MiscObjectIdentifiers.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/misc/MiscObjectIdentifiers.java index 3eb4814f6..8019c7682 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/misc/MiscObjectIdentifiers.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/misc/MiscObjectIdentifiers.java @@ -101,6 +101,12 @@ public interface MiscObjectIdentifiers */ ASN1ObjectIdentifier cast5CBC = entrust.branch("66.10"); + // + // HMAC-SHA1 hMAC-SHA1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) + // dod(6) internet(1) security(5) mechanisms(5) 8 1 2 } + // + ASN1ObjectIdentifier hMAC_SHA1 = new ASN1ObjectIdentifier("1.3.6.1.5.5.8.1.2"); + // // Ascom // @@ -135,4 +141,11 @@ public interface MiscObjectIdentifiers // // Scrypt ASN1ObjectIdentifier id_scrypt = new ASN1ObjectIdentifier("1.3.6.1.4.1.11591.4.11"); + + // Composite key/signature oid - prototyping + // + // id-alg-composite OBJECT IDENTIFIER ::= { + // iso(1) identified-organization(3) dod(6) internet(1) private(4) + // enterprise(1) OpenCA(18227) Algorithms(2) id-alg-composite(1) } + ASN1ObjectIdentifier id_alg_composite = new ASN1ObjectIdentifier("1.3.6.1.4.1.18227.2.1"); } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/misc/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/misc/package.html deleted file mode 100644 index e3bda6408..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/misc/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Miscellaneous object identifiers and objects. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/mozilla/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/mozilla/package.html deleted file mode 100644 index 40776b018..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/mozilla/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding objects used by mozilla. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/KMACwithSHAKE128_params.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/KMACwithSHAKE128_params.java new file mode 100644 index 000000000..83349a718 --- /dev/null +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/KMACwithSHAKE128_params.java @@ -0,0 +1,114 @@ +package com.fr.third.org.bouncycastle.asn1.nist; + +import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; +import com.fr.third.org.bouncycastle.asn1.ASN1Integer; +import com.fr.third.org.bouncycastle.asn1.ASN1Object; +import com.fr.third.org.bouncycastle.asn1.ASN1OctetString; +import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; +import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; +import com.fr.third.org.bouncycastle.asn1.DEROctetString; +import com.fr.third.org.bouncycastle.asn1.DERSequence; +import com.fr.third.org.bouncycastle.util.Arrays; + +/** + *+ * KMACwithSHAKE128-params ::= SEQUENCE { + * kMACOutputLength INTEGER DEFAULT 256, -- Output length in bits + * customizationString OCTET STRING DEFAULT ''H + * } + *+ */ +public class KMACwithSHAKE128_params + extends ASN1Object +{ + private static final byte[] EMPTY_STRING = new byte[0]; + private static final int DEF_LENGTH = 256; + + private final int outputLength; + private final byte[] customizationString; + + public KMACwithSHAKE128_params(int outputLength) + { + this.outputLength = outputLength; + this.customizationString = EMPTY_STRING; + } + + public KMACwithSHAKE128_params(int outputLength, byte[] customizationString) + { + this.outputLength = outputLength; + this.customizationString = Arrays.clone(customizationString); + } + + public static KMACwithSHAKE128_params getInstance(Object o) + { + if (o instanceof KMACwithSHAKE128_params) + { + return (KMACwithSHAKE128_params)o; + } + else if (o != null) + { + return new KMACwithSHAKE128_params(ASN1Sequence.getInstance(o)); + } + + return null; + } + + private KMACwithSHAKE128_params(ASN1Sequence seq) + { + if (seq.size() > 2) + { + throw new IllegalArgumentException("sequence size greater than 2"); + } + + if (seq.size() == 2) + { + this.outputLength = ASN1Integer.getInstance(seq.getObjectAt(0)).intValueExact(); + this.customizationString = Arrays.clone(ASN1OctetString.getInstance(seq.getObjectAt(1)).getOctets()); + } + else if (seq.size() == 1) + { + if (seq.getObjectAt(0) instanceof ASN1Integer) + { + this.outputLength = ASN1Integer.getInstance(seq.getObjectAt(0)).intValueExact(); + this.customizationString = EMPTY_STRING; + } + else + { + this.outputLength = DEF_LENGTH; + this.customizationString = Arrays.clone(ASN1OctetString.getInstance(seq.getObjectAt(0)).getOctets()); + } + } + else + { + this.outputLength = DEF_LENGTH; + this.customizationString = EMPTY_STRING; + } + } + + public int getOutputLength() + { + return outputLength; + } + + public byte[] getCustomizationString() + { + return Arrays.clone(customizationString); + } + + public ASN1Primitive toASN1Primitive() + { + ASN1EncodableVector v = new ASN1EncodableVector(); + + if (outputLength != DEF_LENGTH) + { + v.add(new ASN1Integer(outputLength)); + } + + if (customizationString.length != 0) + { + v.add(new DEROctetString(getCustomizationString())); + } + + return new DERSequence(v); + } +} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/KMACwithSHAKE256_params.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/KMACwithSHAKE256_params.java new file mode 100644 index 000000000..ae5cee77e --- /dev/null +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/KMACwithSHAKE256_params.java @@ -0,0 +1,114 @@ +package com.fr.third.org.bouncycastle.asn1.nist; + +import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; +import com.fr.third.org.bouncycastle.asn1.ASN1Integer; +import com.fr.third.org.bouncycastle.asn1.ASN1Object; +import com.fr.third.org.bouncycastle.asn1.ASN1OctetString; +import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; +import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; +import com.fr.third.org.bouncycastle.asn1.DEROctetString; +import com.fr.third.org.bouncycastle.asn1.DERSequence; +import com.fr.third.org.bouncycastle.util.Arrays; + +/** + *+ * KMACwithSHAKE256-params ::= SEQUENCE { + * kMACOutputLength INTEGER DEFAULT 512, -- Output length in bits + * customizationString OCTET STRING DEFAULT ''H + * } + *+ */ +public class KMACwithSHAKE256_params + extends ASN1Object +{ + private static final byte[] EMPTY_STRING = new byte[0]; + private static final int DEF_LENGTH = 512; + + private final int outputLength; + private final byte[] customizationString; + + public KMACwithSHAKE256_params(int outputLength) + { + this.outputLength = outputLength; + this.customizationString = EMPTY_STRING; + } + + public KMACwithSHAKE256_params(int outputLength, byte[] customizationString) + { + this.outputLength = outputLength; + this.customizationString = Arrays.clone(customizationString); + } + + public static KMACwithSHAKE256_params getInstance(Object o) + { + if (o instanceof KMACwithSHAKE256_params) + { + return (KMACwithSHAKE256_params)o; + } + else if (o != null) + { + return new KMACwithSHAKE256_params(ASN1Sequence.getInstance(o)); + } + + return null; + } + + private KMACwithSHAKE256_params(ASN1Sequence seq) + { + if (seq.size() > 2) + { + throw new IllegalArgumentException("sequence size greater than 2"); + } + + if (seq.size() == 2) + { + this.outputLength = ASN1Integer.getInstance(seq.getObjectAt(0)).intValueExact(); + this.customizationString = Arrays.clone(ASN1OctetString.getInstance(seq.getObjectAt(1)).getOctets()); + } + else if (seq.size() == 1) + { + if (seq.getObjectAt(0) instanceof ASN1Integer) + { + this.outputLength = ASN1Integer.getInstance(seq.getObjectAt(0)).intValueExact(); + this.customizationString = EMPTY_STRING; + } + else + { + this.outputLength = DEF_LENGTH; + this.customizationString = Arrays.clone(ASN1OctetString.getInstance(seq.getObjectAt(0)).getOctets()); + } + } + else + { + this.outputLength = DEF_LENGTH; + this.customizationString = EMPTY_STRING; + } + } + + public int getOutputLength() + { + return outputLength; + } + + public byte[] getCustomizationString() + { + return Arrays.clone(customizationString); + } + + public ASN1Primitive toASN1Primitive() + { + ASN1EncodableVector v = new ASN1EncodableVector(); + + if (outputLength != DEF_LENGTH) + { + v.add(new ASN1Integer(outputLength)); + } + + if (customizationString.length != 0) + { + v.add(new DEROctetString(getCustomizationString())); + } + + return new DERSequence(v); + } +} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/NISTObjectIdentifiers.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/NISTObjectIdentifiers.java index e07bd90c8..21de38cff 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/NISTObjectIdentifiers.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/NISTObjectIdentifiers.java @@ -51,6 +51,14 @@ public interface NISTObjectIdentifiers static final ASN1ObjectIdentifier id_hmacWithSHA3_384 = hashAlgs.branch("15"); /** 2.16.840.1.101.3.4.2.16 */ static final ASN1ObjectIdentifier id_hmacWithSHA3_512 = hashAlgs.branch("16"); + /** 2.16.840.1.101.3.4.2.17 */ + static final ASN1ObjectIdentifier id_shake128_len = hashAlgs.branch("17"); + /** 2.16.840.1.101.3.4.2.18 */ + static final ASN1ObjectIdentifier id_shake256_len = hashAlgs.branch("18"); + /** 2.16.840.1.101.3.4.2.19 */ + static final ASN1ObjectIdentifier id_KmacWithSHAKE128 = hashAlgs.branch("19"); + /** 2.16.840.1.101.3.4.2.20 */ + static final ASN1ObjectIdentifier id_KmacWithSHAKE256 = hashAlgs.branch("20"); /** 2.16.840.1.101.3.4.1 */ static final ASN1ObjectIdentifier aes = nistAlgorithm.branch("1"); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/package.html deleted file mode 100644 index 1cdca7695..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nist/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for NIST related objects. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nsri/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nsri/package.html deleted file mode 100644 index bd43ca003..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/nsri/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes algorithms from the Korean National Security Research Institute. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ntt/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ntt/package.html deleted file mode 100644 index 4b9d05dde..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ntt/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -ASN.1 classes relevant to the standards produced by Nippon Telegraph and Telephone. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ocsp/OCSPResponseStatus.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ocsp/OCSPResponseStatus.java index 3960e603c..61e9733a0 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ocsp/OCSPResponseStatus.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ocsp/OCSPResponseStatus.java @@ -78,6 +78,11 @@ public class OCSPResponseStatus return null; } + public int getIntValue() + { + return value.intValueExact(); + } + public BigInteger getValue() { return value.getValue(); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ocsp/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ocsp/package.html deleted file mode 100644 index 22c560d2c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ocsp/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding and supporting OCSP objects. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/oiw/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/oiw/package.html deleted file mode 100644 index 44eb2fe84..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/oiw/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Objects and OID for the support of ISO OIW. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/package.html deleted file mode 100644 index 1ac16a553..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -A library for parsing and writing ASN.1 objects. Support is provided for DER and BER encoding. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/CertBag.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/CertBag.java index f633a247c..6bc98059f 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/CertBag.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/CertBag.java @@ -19,7 +19,7 @@ public class CertBag private CertBag( ASN1Sequence seq) { - this.certId = (ASN1ObjectIdentifier)seq.getObjectAt(0); + this.certId = ASN1ObjectIdentifier.getInstance(seq.getObjectAt(0)); this.certValue = ASN1TaggedObject.getInstance(seq.getObjectAt(1)).getObject(); } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java index 15a0f518f..bb32dfc4e 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java @@ -253,6 +253,14 @@ public interface PKCSObjectIdentifiers */ ASN1ObjectIdentifier id_rsa_KEM = id_alg.branch("14"); + + /** + * id-alg-hss-lms-hashsig OBJECT IDENTIFIER ::= { iso(1) + * member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs9(9) + * smime(16) alg(3) 17 } + */ + public static final ASN1ObjectIdentifier id_alg_hss_lms_hashsig = id_alg.branch("17"); + /** ** id-alg-AEADChaCha20Poly1305 OBJECT IDENTIFIER ::= @@ -264,6 +272,30 @@ public interface PKCSObjectIdentifiers */ ASN1ObjectIdentifier id_alg_AEADChaCha20Poly1305 = id_alg.branch("18"); + /** + *+ * * @param secondDigest the content digest - * @param signingTime the signing time + * @param signingTime the signing time * @return the byte array representation of the authenticatedAttributes ready to be signed - */ + */ public byte[] getAuthenticatedAttributeBytes(byte secondDigest[], Calendar signingTime, byte[] ocsp) { try { return getAuthenticatedAttributeSet(secondDigest, signingTime, ocsp).getEncoded("DER"); - } - catch (Exception e) { + } catch (Exception e) { throw new ExceptionConverter(e); } } - + private DERSet getAuthenticatedAttributeSet(byte secondDigest[], Calendar signingTime, byte[] ocsp) { try { ASN1EncodableVector attribute = new ASN1EncodableVector(); ASN1EncodableVector v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(ID_CONTENT_TYPE)); - v.add(new DERSet(new DERObjectIdentifier(ID_PKCS7_DATA))); + v.add(new ASN1ObjectIdentifier(ID_CONTENT_TYPE)); + v.add(new DERSet(new ASN1ObjectIdentifier(ID_PKCS7_DATA))); attribute.add(new DERSequence(v)); v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(ID_SIGNING_TIME)); + v.add(new ASN1ObjectIdentifier(ID_SIGNING_TIME)); v.add(new DERSet(new DERUTCTime(signingTime.getTime()))); attribute.add(new DERSequence(v)); v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(ID_MESSAGE_DIGEST)); + v.add(new ASN1ObjectIdentifier(ID_MESSAGE_DIGEST)); v.add(new DERSet(new DEROctetString(secondDigest))); attribute.add(new DERSequence(v)); if (ocsp != null) { v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(ID_ADBE_REVOCATION)); + v.add(new ASN1ObjectIdentifier(ID_ADBE_REVOCATION)); DEROctetString doctet = new DEROctetString(ocsp); ASN1EncodableVector vo1 = new ASN1EncodableVector(); ASN1EncodableVector v2 = new ASN1EncodableVector(); v2.add(OCSPObjectIdentifiers.id_pkix_ocsp_basic); v2.add(doctet); - DEREnumerated den = new DEREnumerated(0); + ASN1Enumerated den = new ASN1Enumerated(0); ASN1EncodableVector v3 = new ASN1EncodableVector(); v3.add(den); v3.add(new DERTaggedObject(true, 0, new DERSequence(v2))); vo1.add(new DERSequence(v3)); v.add(new DERSet(new DERSequence(new DERTaggedObject(true, 1, new DERSequence(vo1))))); attribute.add(new DERSequence(v)); - } - else if (!crls.isEmpty()) { + } else if (!crls.isEmpty()) { v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(ID_ADBE_REVOCATION)); + v.add(new ASN1ObjectIdentifier(ID_ADBE_REVOCATION)); ASN1EncodableVector v2 = new ASN1EncodableVector(); - for (Iterator i = crls.iterator();i.hasNext();) { - ASN1InputStream t = new ASN1InputStream(new ByteArrayInputStream(((X509CRL)i.next()).getEncoded())); + for (Iterator i = crls.iterator(); i.hasNext(); ) { + ASN1InputStream t = new ASN1InputStream(new ByteArrayInputStream(((X509CRL) i.next()).getEncoded())); v2.add(t.readObject()); } v.add(new DERSet(new DERSequence(new DERTaggedObject(true, 0, new DERSequence(v2))))); attribute.add(new DERSequence(v)); } return new DERSet(attribute); - } - catch (Exception e) { + } catch (Exception e) { throw new ExceptionConverter(e); } } - + /** * Getter for property reason. + * * @return Value of property reason. */ public String getReason() { return this.reason; } - + /** * Setter for property reason. + * * @param reason New value of property reason. */ public void setReason(String reason) { this.reason = reason; } - + /** * Getter for property location. + * * @return Value of property location. */ public String getLocation() { return this.location; } - + /** * Setter for property location. + * * @param location New value of property location. */ public void setLocation(String location) { this.location = location; } - + /** * Getter for property signDate. + * * @return Value of property signDate. */ public Calendar getSignDate() { return this.signDate; } - + /** * Setter for property signDate. + * * @param signDate New value of property signDate. */ public void setSignDate(Calendar signDate) { this.signDate = signDate; } - + /** * Getter for property sigName. + * * @return Value of property sigName. */ public String getSignName() { return this.signName; } - + /** * Setter for property sigName. + * * @param signName New value of property sigName. */ public void setSignName(String signName) { this.signName = signName; } - + /** * a class that holds an X509 name */ @@ -1467,74 +1475,90 @@ public class PdfPKCS7 { /** * country code - StringType(SIZE(2)) */ - public static final DERObjectIdentifier C = new DERObjectIdentifier("2.5.4.6"); + public static final ASN1ObjectIdentifier C = new ASN1ObjectIdentifier("2.5.4.6"); /** * organization - StringType(SIZE(1..64)) */ - public static final DERObjectIdentifier O = new DERObjectIdentifier("2.5.4.10"); + public static final ASN1ObjectIdentifier O = new ASN1ObjectIdentifier("2.5.4.10"); /** * organizational unit name - StringType(SIZE(1..64)) */ - public static final DERObjectIdentifier OU = new DERObjectIdentifier("2.5.4.11"); + public static final ASN1ObjectIdentifier OU = new ASN1ObjectIdentifier("2.5.4.11"); /** * Title */ - public static final DERObjectIdentifier T = new DERObjectIdentifier("2.5.4.12"); + public static final ASN1ObjectIdentifier T = new ASN1ObjectIdentifier("2.5.4.12"); /** * common name - StringType(SIZE(1..64)) */ - public static final DERObjectIdentifier CN = new DERObjectIdentifier("2.5.4.3"); + public static final ASN1ObjectIdentifier CN = new ASN1ObjectIdentifier("2.5.4.3"); /** * device serial number name - StringType(SIZE(1..64)) */ - public static final DERObjectIdentifier SN = new DERObjectIdentifier("2.5.4.5"); + public static final ASN1ObjectIdentifier SN = new ASN1ObjectIdentifier("2.5.4.5"); /** * locality name - StringType(SIZE(1..64)) */ - public static final DERObjectIdentifier L = new DERObjectIdentifier("2.5.4.7"); + public static final ASN1ObjectIdentifier L = new ASN1ObjectIdentifier("2.5.4.7"); /** * state, or province name - StringType(SIZE(1..64)) */ - public static final DERObjectIdentifier ST = new DERObjectIdentifier("2.5.4.8"); - - /** Naming attribute of type X520name */ - public static final DERObjectIdentifier SURNAME = new DERObjectIdentifier("2.5.4.4"); - /** Naming attribute of type X520name */ - public static final DERObjectIdentifier GIVENNAME = new DERObjectIdentifier("2.5.4.42"); - /** Naming attribute of type X520name */ - public static final DERObjectIdentifier INITIALS = new DERObjectIdentifier("2.5.4.43"); - /** Naming attribute of type X520name */ - public static final DERObjectIdentifier GENERATION = new DERObjectIdentifier("2.5.4.44"); - /** Naming attribute of type X520name */ - public static final DERObjectIdentifier UNIQUE_IDENTIFIER = new DERObjectIdentifier("2.5.4.45"); + public static final ASN1ObjectIdentifier ST = new ASN1ObjectIdentifier("2.5.4.8"); + + /** + * Naming attribute of type X520name + */ + public static final ASN1ObjectIdentifier SURNAME = new ASN1ObjectIdentifier("2.5.4.4"); + /** + * Naming attribute of type X520name + */ + public static final ASN1ObjectIdentifier GIVENNAME = new ASN1ObjectIdentifier("2.5.4.42"); + /** + * Naming attribute of type X520name + */ + public static final ASN1ObjectIdentifier INITIALS = new ASN1ObjectIdentifier("2.5.4.43"); + /** + * Naming attribute of type X520name + */ + public static final ASN1ObjectIdentifier GENERATION = new ASN1ObjectIdentifier("2.5.4.44"); + /** + * Naming attribute of type X520name + */ + public static final ASN1ObjectIdentifier UNIQUE_IDENTIFIER = new ASN1ObjectIdentifier("2.5.4.45"); /** * Email address (RSA PKCS#9 extension) - IA5String. *+ * id-alg-hkdf-with-sha256 OBJECT IDENTIFIER ::= { iso(1) member-body(2) + * us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 28 } + *+ */ + ASN1ObjectIdentifier id_alg_hkdf_with_sha256 = id_alg.branch("28"); + + /** + *+ * id-alg-hkdf-with-sha384 OBJECT IDENTIFIER ::= { iso(1) member-body(2) + * us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 29 } + *+ */ + ASN1ObjectIdentifier id_alg_hkdf_with_sha384 = id_alg.branch("29"); + + /** + *+ * id-alg-hkdf-with-sha512 OBJECT IDENTIFIER ::= { iso(1) member-body(2) + * us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 30 } + *+ */ + ASN1ObjectIdentifier id_alg_hkdf_with_sha512 = id_alg.branch("30"); + // // id-cti OBJECT IDENTIFIER ::= {iso(1) member-body(2) usa(840) // rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) cti(6)} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/PrivateKeyInfo.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/PrivateKeyInfo.java index 424054c82..22dcadcc5 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/PrivateKeyInfo.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/PrivateKeyInfo.java @@ -1,7 +1,6 @@ package com.fr.third.org.bouncycastle.asn1.pkcs; import java.io.IOException; -import java.math.BigInteger; import java.util.Enumeration; import com.fr.third.org.bouncycastle.asn1.ASN1BitString; @@ -176,6 +175,11 @@ public class PrivateKeyInfo } } + public ASN1Integer getVersion() + { + return version; + } + public ASN1Set getAttributes() { return attributes; @@ -186,6 +190,11 @@ public class PrivateKeyInfo return privateKeyAlgorithm; } + public ASN1OctetString getPrivateKey() + { + return new DEROctetString(privateKey.getOctets()); + } + public ASN1Encodable parsePrivateKey() throws IOException { diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/package.html deleted file mode 100644 index ab800f446..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/pkcs/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding and supporting the various RSA PKCS documents. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/rosstandart/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/rosstandart/package.html deleted file mode 100644 index 9d1b84200..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/rosstandart/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes algorithms from the Russian Federal Agency on Technical Regulating and Metrology - Rosstandart. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/sec/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/sec/package.html deleted file mode 100644 index 5e34dec46..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/sec/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Classes for support of the SEC standard for Elliptic Curve. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/smime/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/smime/package.html deleted file mode 100644 index d527abad5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/smime/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding and supporting S/MIME. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/teletrust/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/teletrust/package.html deleted file mode 100644 index 86606c39d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/teletrust/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for TeleTrust related objects. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ASN1IntegerTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ASN1IntegerTest.java deleted file mode 100644 index 49ca27489..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ASN1IntegerTest.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.asn1.ASN1Enumerated; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.util.BigIntegers; -import com.fr.third.org.bouncycastle.util.Properties; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class ASN1IntegerTest - extends SimpleTest -{ - private static final byte[] suspectKey = Base64.decode( - "MIGJAoGBAHNc+iExm94LUrJdPSJ4QJ9tDRuvaNmGVHpJ4X7a5zKI02v+2E7RotuiR2MHDJfVJkb9LUs2kb3XBlyENhtMLsbeH+3Muy3" + - "hGDlh/mLJSh1s4c5jDKBRYOHom7Uc8wP0P2+zBCA+OEdikNDFBaP5PbR2Xq9okG2kPh35M2quAiMTAgMBAAE="); - - public String getName() - { - return "ASN1Integer"; - } - - public void performTest() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); - - ASN1Sequence.getInstance(suspectKey); - - testValidEncodingSingleByte(); - testValidEncodingMultiByte(); - testInvalidEncoding_00(); - testInvalidEncoding_ff(); - testInvalidEncoding_00_32bits(); - testInvalidEncoding_ff_32bits(); - //testLooseInvalidValidEncoding_FF_32B(); - //testLooseInvalidValidEncoding_zero_32B(); - testLooseValidEncoding_zero_32BAligned(); - testLooseValidEncoding_FF_32BAligned(); - testLooseValidEncoding_FF_32BAligned_1not0(); - testLooseValidEncoding_FF_32BAligned_2not0(); - testOversizedEncoding(); - - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); - - new ASN1Integer(Hex.decode("ffda47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b0e")); - - new ASN1Enumerated(Hex.decode("005a47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b0e")); - - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - - try - { - new ASN1Integer(Hex.decode("ffda47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b")); - - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("malformed integer", e.getMessage()); - } - - isTrue(!Properties.setThreadOverride("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", true)); - - new ASN1Integer(Hex.decode("ffda47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b")); - - isTrue(Properties.removeThreadOverride("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer")); - - try - { - ASN1Sequence.getInstance(suspectKey); - - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("test 1", "failed to construct sequence from byte[]: corrupted stream detected", e.getMessage()); - } - - try - { - new ASN1Integer(Hex.decode("ffda47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b0e")); - - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("malformed integer", e.getMessage()); - } - - try - { - new ASN1Enumerated(Hex.decode("ffda47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b0e")); - - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("malformed enumerated", e.getMessage()); - } - - try - { - new ASN1Enumerated(Hex.decode("005a47bfc776bcd269da4832626ac332adfca6dd835e8ecd83cd1ebe7d709b0e")); - - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("malformed enumerated", e.getMessage()); - } - } - - /** - * Ensure existing single byte behavior. - */ - public void testValidEncodingSingleByte() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - // - // Without property, single byte. - // - byte[] rawInt = Hex.decode("10"); - ASN1Integer i = new ASN1Integer(rawInt); - isEquals(i.getValue().intValue(), 16); - isEquals(i.intValueExact(), 16); - - // - // With property set. - // - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); - - rawInt = Hex.decode("10"); - i = new ASN1Integer(rawInt); - isEquals(i.getValue().intValue(), 16); - isEquals(i.intValueExact(), 16); - } - - public void testValidEncodingMultiByte() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - // - // Without property, single byte. - // - byte[] rawInt = Hex.decode("10FF"); - ASN1Integer i = new ASN1Integer(rawInt); - isEquals(i.getValue().intValue(), 4351); - isEquals(i.intValueExact(), 4351); - - // - // With property set. - // - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); - - rawInt = Hex.decode("10FF"); - i = new ASN1Integer(rawInt); - isEquals(i.getValue().intValue(), 4351); - isEquals(i.intValueExact(), 4351); - } - - public void testInvalidEncoding_00() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - try - { - byte[] rawInt = Hex.decode("0010FF"); - new ASN1Integer(rawInt); - fail("Expecting illegal argument exception."); - } - catch (IllegalArgumentException e) - { - isEquals("malformed integer", e.getMessage()); - } - } - - public void testInvalidEncoding_ff() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - try - { - byte[] rawInt = Hex.decode("FF81FF"); - new ASN1Integer(rawInt); - fail("Expecting illegal argument exception."); - } - catch (IllegalArgumentException e) - { - isEquals("malformed integer", e.getMessage()); - } - } - - public void testInvalidEncoding_00_32bits() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - // - // Check what would pass loose validation fails outside of loose validation. - // - try - { - byte[] rawInt = Hex.decode("0000000010FF"); - new ASN1Integer(rawInt); - fail("Expecting illegal argument exception."); - } - catch (IllegalArgumentException e) - { - isEquals("malformed integer", e.getMessage()); - } - } - - public void testInvalidEncoding_ff_32bits() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - // - // Check what would pass loose validation fails outside of loose validation. - // - try - { - byte[] rawInt = Hex.decode("FFFFFFFF01FF"); - new ASN1Integer(rawInt); - fail("Expecting illegal argument exception."); - } - catch (IllegalArgumentException e) - { - isEquals("malformed integer", e.getMessage()); - } - } - - /* - Unfortunately it turns out that integers stored without sign bits that are assumed to be - unsigned.. this means a string of FF may occur and then the user will call getPositiveValue(). - Sigh.. - public void testLooseInvalidValidEncoding_zero_32B() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - // - // Should still fail as loose validation only permits 3 leading 0x00 bytes. - // - try - { - System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); - byte[] rawInt = Hex.decode("0000000010FF"); - ASN1Integer i = new ASN1Integer(rawInt); - fail("Expecting illegal argument exception."); - } - catch (IllegalArgumentException e) - { - isEquals("malformed integer", e.getMessage()); - } - } - - public void testLooseInvalidValidEncoding_FF_32B() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - // - // Should still fail as loose validation only permits 3 leading 0xFF bytes. - // - try - { - System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); - byte[] rawInt = Hex.decode("FFFFFFFF10FF"); - ASN1Integer i = new ASN1Integer(rawInt); - fail("Expecting illegal argument exception."); - } - catch (IllegalArgumentException e) - { - isEquals("malformed integer", e.getMessage()); - } - } - */ - - public void testLooseValidEncoding_zero_32BAligned() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - // - // Should pass as loose validation permits 3 leading 0x00 bytes. - // - - System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); - byte[] rawInt = Hex.decode("00000010FF000000"); - ASN1Integer i = new ASN1Integer(rawInt); - isEquals(72997666816L, BigIntegers.longValueExact(i.getValue())); - } - - public void testLooseValidEncoding_FF_32BAligned() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - // - // Should pass as loose validation permits 3 - - System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); - byte[] rawInt = Hex.decode("FFFFFF10FF000000"); - ASN1Integer i = new ASN1Integer(rawInt); - isEquals(-1026513960960L, BigIntegers.longValueExact(i.getValue())); - } - - public void testLooseValidEncoding_FF_32BAligned_1not0() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - // - // Should pass as loose validation permits 3 leading 0xFF bytes. - // - - System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); - byte[] rawInt = Hex.decode("FFFEFF10FF000000"); - ASN1Integer i = new ASN1Integer(rawInt); - isEquals(-282501490671616L, BigIntegers.longValueExact(i.getValue())); - } - - public void testLooseValidEncoding_FF_32BAligned_2not0() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - // - // Should pass as loose validation permits 3 leading 0xFF bytes. - // - - System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); - byte[] rawInt = Hex.decode("FFFFFE10FF000000"); - ASN1Integer i = new ASN1Integer(rawInt); - isEquals(-2126025588736L, BigIntegers.longValueExact(i.getValue())); - } - - public void testOversizedEncoding() - throws Exception - { - System.setProperty("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "false"); - // - // Should pass as loose validation permits 3 leading 0xFF bytes. - // - - System.getProperties().put("com.fr.third.org.bouncycastle.asn1.allow_unsafe_integer", "true"); - byte[] rawInt = Hex.decode("FFFFFFFE10FF000000000000"); - ASN1Integer i = new ASN1Integer(rawInt); - isEquals(new BigInteger(Hex.decode("FFFFFFFE10FF000000000000")), i.getValue()); - - rawInt = Hex.decode("FFFFFFFFFE10FF000000000000"); - try - { - new ASN1Integer(rawInt); - } - catch (IllegalArgumentException e) - { - isEquals("malformed integer", e.getMessage()); - } - } - - public static void main( - String[] args) - { - runTest(new ASN1IntegerTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ASN1UnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ASN1UnitTest.java deleted file mode 100644 index 168c0798a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ASN1UnitTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -import java.math.BigInteger; - -public abstract class ASN1UnitTest - extends SimpleTest -{ - protected void checkMandatoryField(String name, ASN1Encodable expected, ASN1Encodable present) - { - if (!expected.equals(present)) - { - fail(name + " field doesn't match."); - } - } - - protected void checkMandatoryField(String name, String expected, String present) - { - if (!expected.equals(present)) - { - fail(name + " field doesn't match."); - } - } - - protected void checkMandatoryField(String name, byte[] expected, byte[] present) - { - if (!areEqual(expected, present)) - { - fail(name + " field doesn't match."); - } - } - - protected void checkMandatoryField(String name, int expected, int present) - { - if (expected != present) - { - fail(name + " field doesn't match."); - } - } - - protected void checkOptionalField(String name, ASN1Encodable expected, ASN1Encodable present) - { - if (expected != null) - { - if (!expected.equals(present)) - { - fail(name + " field doesn't match."); - } - } - else if (present != null) - { - fail(name + " field found when none expected."); - } - } - - protected void checkOptionalField(String name, String expected, String present) - { - if (expected != null) - { - if (!expected.equals(present)) - { - fail(name + " field doesn't match."); - } - } - else if (present != null) - { - fail(name + " field found when none expected."); - } - } - - protected void checkOptionalField(String name, BigInteger expected, BigInteger present) - { - if (expected != null) - { - if (!expected.equals(present)) - { - fail(name + " field doesn't match."); - } - } - else if (present != null) - { - fail(name + " field found when none expected."); - } - } - - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdditionalInformationSyntaxUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdditionalInformationSyntaxUnitTest.java deleted file mode 100644 index 53b35e52d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdditionalInformationSyntaxUnitTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1String; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.AdditionalInformationSyntax; -import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; - -public class AdditionalInformationSyntaxUnitTest - extends ASN1UnitTest -{ - public String getName() - { - return "AdditionalInformationSyntax"; - } - - public void performTest() - throws Exception - { - AdditionalInformationSyntax syntax = new AdditionalInformationSyntax("hello world"); - - checkConstruction(syntax, new DirectoryString("hello world")); - - try - { - AdditionalInformationSyntax.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - AdditionalInformationSyntax syntax, - DirectoryString information) - throws IOException - { - checkValues(syntax, information); - - syntax = AdditionalInformationSyntax.getInstance(syntax); - - checkValues(syntax, information); - - ASN1InputStream aIn = new ASN1InputStream(syntax.toASN1Primitive().getEncoded()); - - ASN1String info = (ASN1String)aIn.readObject(); - - syntax = AdditionalInformationSyntax.getInstance(info); - - checkValues(syntax, information); - } - - private void checkValues( - AdditionalInformationSyntax syntax, - DirectoryString information) - { - checkMandatoryField("information", information, syntax.getInformation()); - } - - public static void main( - String[] args) - { - runTest(new AdditionalInformationSyntaxUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdmissionSyntaxUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdmissionSyntaxUnitTest.java deleted file mode 100644 index a79ca5012..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdmissionSyntaxUnitTest.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.AdmissionSyntax; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.Admissions; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.NamingAuthority; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.ProfessionInfo; -import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; - -public class AdmissionSyntaxUnitTest - extends ASN1UnitTest -{ - public String getName() - { - return "AdmissionSyntax"; - } - - public void performTest() - throws Exception - { - GeneralName name = new GeneralName(new X500Name("CN=hello world")); - ASN1Sequence admissions = new DERSequence( - new Admissions(name, - new NamingAuthority(new ASN1ObjectIdentifier("1.2.3"), "url", new DirectoryString("fred")), - new ProfessionInfo[0])); - AdmissionSyntax syntax = new AdmissionSyntax(name, admissions); - - checkConstruction(syntax, name, admissions); - - syntax = AdmissionSyntax.getInstance(null); - - if (syntax != null) - { - fail("null getInstance() failed."); - } - - try - { - AdmissionSyntax.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - AdmissionSyntax syntax, - GeneralName authority, - ASN1Sequence admissions) - throws IOException - { - checkValues(syntax, authority, admissions); - - syntax = AdmissionSyntax.getInstance(syntax); - - checkValues(syntax, authority, admissions); - - ASN1InputStream aIn = new ASN1InputStream(syntax.toASN1Primitive().getEncoded()); - - ASN1Sequence info = (ASN1Sequence)aIn.readObject(); - - syntax = AdmissionSyntax.getInstance(info); - - checkValues(syntax, authority, admissions); - } - - private void checkValues( - AdmissionSyntax syntax, - GeneralName authority, - ASN1Sequence admissions) - { - checkMandatoryField("admissionAuthority", authority, syntax.getAdmissionAuthority()); - - Admissions[] adm = syntax.getContentsOfAdmissions(); - - if (adm.length != 1 || !adm[0].equals(admissions.getObjectAt(0))) - { - fail("admissions check failed"); - } - } - - public static void main( - String[] args) - { - runTest(new AdmissionSyntaxUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdmissionsUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdmissionsUnitTest.java deleted file mode 100644 index cc17b56b2..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AdmissionsUnitTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.Admissions; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.NamingAuthority; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.ProfessionInfo; -import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; - -public class AdmissionsUnitTest - extends ASN1UnitTest -{ - public String getName() - { - return "Admissions"; - } - - public void performTest() - throws Exception - { - GeneralName name = new GeneralName(new X500Name("CN=hello world")); - NamingAuthority auth = new NamingAuthority(new ASN1ObjectIdentifier("1.2.3"), "url", new DirectoryString("fred")); - Admissions admissions = new Admissions(name, auth, new ProfessionInfo[0]); - - checkConstruction(admissions, name, auth); - - admissions = Admissions.getInstance(null); - - if (admissions != null) - { - fail("null getInstance() failed."); - } - - try - { - Admissions.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - Admissions admissions, - GeneralName name, - NamingAuthority auth) - throws IOException - { - checkValues(admissions, name, auth); - - admissions = Admissions.getInstance(admissions); - - checkValues(admissions, name, auth); - - ASN1InputStream aIn = new ASN1InputStream(admissions.toASN1Primitive().getEncoded()); - - ASN1Sequence info = (ASN1Sequence)aIn.readObject(); - - admissions = Admissions.getInstance(info); - - checkValues(admissions, name, auth); - } - - private void checkValues( - Admissions admissions, - GeneralName name, - NamingAuthority auth) - { - checkMandatoryField("admissionAuthority", name, admissions.getAdmissionAuthority()); - checkMandatoryField("namingAuthority", auth, admissions.getNamingAuthority()); - } - - public static void main( - String[] args) - { - runTest(new AdmissionsUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AttributeTableUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AttributeTableUnitTest.java deleted file mode 100644 index f16f25e6a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/AttributeTableUnitTest.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.DERSet; -import com.fr.third.org.bouncycastle.asn1.cms.Attribute; -import com.fr.third.org.bouncycastle.asn1.cms.AttributeTable; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class AttributeTableUnitTest - extends SimpleTest -{ - private static final ASN1ObjectIdentifier type1 = new ASN1ObjectIdentifier("1.1.1"); - private static final ASN1ObjectIdentifier type2 = new ASN1ObjectIdentifier("1.1.2"); - private static final ASN1ObjectIdentifier type3 = new ASN1ObjectIdentifier("1.1.3"); - - public String getName() - { - return "AttributeTable"; - } - - public void performTest() - throws Exception - { - ASN1EncodableVector v = new ASN1EncodableVector(); - - v.add(new Attribute(type1, new DERSet(type1))); - v.add(new Attribute(type2, new DERSet(type2))); - - AttributeTable table = new AttributeTable(v); - - Attribute a = table.get(type1); - if (a == null) - { - fail("type1 attribute not found."); - } - if (!a.getAttrValues().equals(new DERSet(type1))) - { - fail("wrong value retrieved for type1!"); - } - - a = table.get(type2); - if (a == null) - { - fail("type2 attribute not found."); - } - if (!a.getAttrValues().equals(new DERSet(type2))) - { - fail("wrong value retrieved for type2!"); - } - - a = table.get(type3); - if (a != null) - { - fail("type3 attribute found when none expected."); - } - - ASN1EncodableVector vec = table.getAll(type1); - if (vec.size() != 1) - { - fail("wrong vector size for type1."); - } - - vec = table.getAll(type3); - if (vec.size() != 0) - { - fail("wrong vector size for type3."); - } - - vec = table.toASN1EncodableVector(); - if (vec.size() != 2) - { - fail("wrong vector size for single."); - } - - Hashtable t = table.toHashtable(); - - if (t.size() != 2) - { - fail("hashtable wrong size."); - } - - // multiple - - v = new ASN1EncodableVector(); - - v.add(new Attribute(type1, new DERSet(type1))); - v.add(new Attribute(type1, new DERSet(type2))); - v.add(new Attribute(type1, new DERSet(type3))); - v.add(new Attribute(type2, new DERSet(type2))); - - table = new AttributeTable(v); - - a = table.get(type1); - if (!a.getAttrValues().equals(new DERSet(type1))) - { - fail("wrong value retrieved for type1 multi get!"); - } - - vec = table.getAll(type1); - if (vec.size() != 3) - { - fail("wrong vector size for multiple type1."); - } - - a = (Attribute)vec.get(0); - if (!a.getAttrValues().equals(new DERSet(type1))) - { - fail("wrong value retrieved for type1(0)!"); - } - - a = (Attribute)vec.get(1); - if (!a.getAttrValues().equals(new DERSet(type2))) - { - fail("wrong value retrieved for type1(1)!"); - } - - a = (Attribute)vec.get(2); - if (!a.getAttrValues().equals(new DERSet(type3))) - { - fail("wrong value retrieved for type1(2)!"); - } - - vec = table.getAll(type2); - if (vec.size() != 1) - { - fail("wrong vector size for multiple type2."); - } - - vec = table.toASN1EncodableVector(); - if (vec.size() != 4) - { - fail("wrong vector size for multiple."); - } - } - - public static void main( - String[] args) - { - runTest(new AttributeTableUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BiometricDataUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BiometricDataUnitTest.java deleted file mode 100644 index c06712f0e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BiometricDataUnitTest.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1OctetString; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.DERIA5String; -import com.fr.third.org.bouncycastle.asn1.DERNull; -import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.asn1.x509.qualified.BiometricData; -import com.fr.third.org.bouncycastle.asn1.x509.qualified.TypeOfBiometricData; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class BiometricDataUnitTest - extends SimpleTest -{ - public String getName() - { - return "BiometricData"; - } - - private byte[] generateHash() - { - SecureRandom rand = new SecureRandom(); - byte[] bytes = new byte[20]; - - rand.nextBytes(bytes); - - return bytes; - } - - public void performTest() - throws Exception - { - TypeOfBiometricData dataType = new TypeOfBiometricData(TypeOfBiometricData.HANDWRITTEN_SIGNATURE); - AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, DERNull.INSTANCE); - ASN1OctetString dataHash = new DEROctetString(generateHash()); - BiometricData bd = new BiometricData(dataType, hashAlgorithm, dataHash); - - checkConstruction(bd, dataType, hashAlgorithm, dataHash, null); - - DERIA5String dataUri = new DERIA5String("http://test"); - - bd = new BiometricData(dataType, hashAlgorithm, dataHash, dataUri); - - checkConstruction(bd, dataType, hashAlgorithm, dataHash, dataUri); - - bd = BiometricData.getInstance(null); - - if (bd != null) - { - fail("null getInstance() failed."); - } - - try - { - BiometricData.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - BiometricData bd, - TypeOfBiometricData dataType, - AlgorithmIdentifier hashAlgorithm, - ASN1OctetString dataHash, - DERIA5String dataUri) - throws Exception - { - checkValues(bd, dataType, hashAlgorithm, dataHash, dataUri); - - bd = BiometricData.getInstance(bd); - - checkValues(bd, dataType, hashAlgorithm, dataHash, dataUri); - - ASN1InputStream aIn = new ASN1InputStream(bd.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - bd = BiometricData.getInstance(seq); - - checkValues(bd, dataType, hashAlgorithm, dataHash, dataUri); - } - - private void checkValues( - BiometricData bd, - TypeOfBiometricData dataType, - AlgorithmIdentifier algID, - ASN1OctetString dataHash, - DERIA5String sourceDataURI) - { - if (!bd.getTypeOfBiometricData().equals(dataType)) - { - fail("types don't match."); - } - - if (!bd.getHashAlgorithm().equals(algID)) - { - fail("hash algorithms don't match."); - } - - if (!bd.getBiometricDataHash().equals(dataHash)) - { - fail("hash algorithms don't match."); - } - - if (sourceDataURI != null) - { - if (!bd.getSourceDataUri().equals(sourceDataURI)) - { - fail("data uris don't match."); - } - } - else if (bd.getSourceDataUri() != null) - { - fail("data uri found when none expected."); - } - } - - public static void main( - String[] args) - { - runTest(new BiometricDataUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BitStringConstantTester.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BitStringConstantTester.java deleted file mode 100644 index 260e44f1d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BitStringConstantTester.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -public class BitStringConstantTester -{ - private static final int[] bits = - { - 1 << 7, 1 << 6, 1 << 5, 1 << 4, 1 << 3, 1 << 2, 1 << 1, 1 << 0, - 1 << 15, 1 << 14, 1 << 13, 1 << 12, 1 << 11, 1 << 10, 1 << 9, 1 << 8, - 1 << 23, 1 << 22, 1 << 21, 1 << 20, 1 << 19, 1 << 18, 1 << 17, 1 << 16, - 1 << 31, 1 << 30, 1 << 29, 1 << 28, 1 << 27, 1 << 26, 1 << 25, 1 << 24 - }; - - public static void testFlagValueCorrect( - int bitNo, - int value) - { - if (bits[bitNo] != value) - { - throw new IllegalArgumentException("bit value " + bitNo + " wrong"); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BitStringTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BitStringTest.java deleted file mode 100644 index 1143c95ec..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BitStringTest.java +++ /dev/null @@ -1,185 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1BitString; -import com.fr.third.org.bouncycastle.asn1.ASN1Encoding; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.DERBitString; -import com.fr.third.org.bouncycastle.asn1.DLBitString; -import com.fr.third.org.bouncycastle.asn1.x509.KeyUsage; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -public class BitStringTest - extends SimpleTest -{ - private void testZeroLengthStrings() - throws Exception - { - // basic construction - DERBitString s1 = new DERBitString(new byte[0], 0); - - // check getBytes() - s1.getBytes(); - - // check encoding/decoding - DERBitString derBit = (DERBitString)ASN1Primitive.fromByteArray(s1.getEncoded()); - - if (!Arrays.areEqual(s1.getEncoded(), Hex.decode("030100"))) - { - fail("zero encoding wrong"); - } - - try - { - new DERBitString(null, 1); - fail("exception not thrown"); - } - catch (NullPointerException e) - { - if (!"'data' cannot be null".equals(e.getMessage())) - { - fail("Unexpected exception: " + e.getMessage()); - } - } - - try - { - new DERBitString(new byte[0], 1); - fail("exception not thrown"); - } - catch (IllegalArgumentException e) - { - if (!"zero length data with non-zero pad bits".equals(e.getMessage())) - { - fail("Unexpected exception"); - } - } - - try - { - new DERBitString(new byte[1], 8); - fail("exception not thrown"); - } - catch (IllegalArgumentException e) - { - if (!"pad bits cannot be greater than 7 or less than 0".equals(e.getMessage())) - { - fail("Unexpected exception"); - } - } - - DERBitString s2 = new DERBitString(0); - if (!Arrays.areEqual(s1.getEncoded(), s2.getEncoded())) - { - fail("zero encoding wrong"); - } - } - - private void testRandomPadBits() - throws Exception - { - byte[] test = Hex.decode("030206c0"); - - byte[] test1 = Hex.decode("030206f0"); - byte[] test2 = Hex.decode("030206c1"); - byte[] test3 = Hex.decode("030206c7"); - byte[] test4 = Hex.decode("030206d1"); - - encodingCheck(test, test1); - encodingCheck(test, test2); - encodingCheck(test, test3); - encodingCheck(test, test4); - } - - private void encodingCheck(byte[] derData, byte[] dlData) - throws IOException - { - if (Arrays.areEqual(derData, ASN1Primitive.fromByteArray(dlData).getEncoded())) - { - fail("failed DL check"); - } - ASN1BitString dl = DLBitString.getInstance(dlData); - - isTrue("DL test failed", dl instanceof DLBitString); - if (!Arrays.areEqual(derData, ASN1Primitive.fromByteArray(dlData).getEncoded(ASN1Encoding.DER))) - { - fail("failed DER check"); - } - try - { - DERBitString.getInstance(dlData); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - // ignore - } - ASN1BitString der = DERBitString.getInstance(derData); - isTrue("DER test failed", der instanceof DERBitString); - } - - public void performTest() - throws Exception - { - KeyUsage k = new KeyUsage(KeyUsage.digitalSignature); - if ((k.getBytes()[0] != (byte)KeyUsage.digitalSignature) || (k.getPadBits() != 7)) - { - fail("failed digitalSignature"); - } - - k = new KeyUsage(KeyUsage.nonRepudiation); - if ((k.getBytes()[0] != (byte)KeyUsage.nonRepudiation) || (k.getPadBits() != 6)) - { - fail("failed nonRepudiation"); - } - - k = new KeyUsage(KeyUsage.keyEncipherment); - if ((k.getBytes()[0] != (byte)KeyUsage.keyEncipherment) || (k.getPadBits() != 5)) - { - fail("failed keyEncipherment"); - } - - k = new KeyUsage(KeyUsage.cRLSign); - if ((k.getBytes()[0] != (byte)KeyUsage.cRLSign) || (k.getPadBits() != 1)) - { - fail("failed cRLSign"); - } - - k = new KeyUsage(KeyUsage.decipherOnly); - if ((k.getBytes()[1] != (byte)(KeyUsage.decipherOnly >> 8)) || (k.getPadBits() != 7)) - { - fail("failed decipherOnly"); - } - - // test for zero length bit string - try - { - ASN1Primitive.fromByteArray(new DERBitString(new byte[0], 0).getEncoded()); - } - catch (IOException e) - { - fail(e.toString()); - } - - testRandomPadBits(); - testZeroLengthStrings(); - } - - public String getName() - { - return "BitString"; - } - - public static void main( - String[] args) - { - BitStringTest test = new BitStringTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartIDTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartIDTest.java deleted file mode 100644 index 075cba782..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartIDTest.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - - -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class BodyPartIDTest - extends SimpleTest -{ - - - public void performTest() - throws Exception - { - // Test correct encode / decode - - - { - // Test encode and decode from Long and from other instance of BodyPartID - BodyPartID bpd = new BodyPartID(10L); - byte[] b = bpd.getEncoded(); - BodyPartID resBpd = BodyPartID.getInstance(b); - isEquals("Correct / Encode byte array", resBpd.getID(), bpd.getID()); - - BodyPartID rootPartID = new BodyPartID(12L); - bpd = BodyPartID.getInstance(rootPartID); - b = bpd.getEncoded(); - resBpd = BodyPartID.getInstance(b); - isEquals("Correct / Encode byte array", resBpd.getID(), rootPartID.getID()); - } - - - { - // Test lower limit, should not throw exception - try - { - new BodyPartID(0); - } - catch (Throwable t) - { - fail("Unexpected exception: " + t.getMessage(), t); - } - - // Test below lower range - try - { - new BodyPartID(-1); - fail("Expecting IllegalArgumentException because of outside lower range"); - } - catch (Throwable e) - { - if (!(e instanceof IllegalArgumentException)) - { - fail("Expecting only IllegalArgumentException, got:" + e.getMessage(), e); - } - } - } - - { - // Test upper limit, should not throw exception. - try - { - new BodyPartID(4294967295L); - } - catch (Throwable t) - { - fail("Unexpected exception: " + t.getMessage(), t); - } - - // Test above upper range - try - { - new BodyPartID(4294967296L); - fail("Expecting IllegalArgumentException because of outside upper range"); - } - catch (Throwable e) - { - if (!(e instanceof IllegalArgumentException)) - { - fail("Expecting only IllegalArgumentException, got:" + e.getMessage(), e); - } - } - } - } - - public String getName() - { - return "BodyPartIDTest"; - } - - public static void main(String[] args) - throws Exception - { - runTest(new BodyPartIDTest()); - } -} - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartListTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartListTest.java deleted file mode 100644 index 699843d10..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartListTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.util.Random; - -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartList; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -/** - * Test the creation of BodyPartListTest and encoding and decoding. - */ -public class BodyPartListTest - extends SimpleTest -{ - - public void performTest() - throws Exception - { - Random rand = new Random(); - { - BodyPartID[] bpid = new BodyPartID[Math.abs(rand.nextInt()) % 20]; - for (int t = 0; t < bpid.length; t++) - { - bpid[t] = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); - } - BodyPartList bpl = new BodyPartList(bpid); - DERSequence _bpl = (DERSequence)bpl.toASN1Primitive(); - byte[] b = bpl.getEncoded(); - - // - // Decode and compare results. - // - - BodyPartList resList = BodyPartList.getInstance(b); - DERSequence _resList = (DERSequence)resList.toASN1Primitive(); - - isEquals(_bpl.size(), _resList.size()); - - for (int j = 0; j < _bpl.size(); j++) - { - isEquals(_resList.getObjectAt(j), _bpl.getObjectAt(j)); - } - } - { - // - // Compare when same thing instantiated via different constructors. - // - - BodyPartID bpid = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); - BodyPartList bpidList = new BodyPartList(bpid); // Single entry constructor. - BodyPartList resList = new BodyPartList(new BodyPartID[]{bpid}); // Array constructor. - - DERSequence _bpidList = (DERSequence)bpidList.toASN1Primitive(); - DERSequence _resList = (DERSequence)resList.toASN1Primitive(); - - isEquals(_bpidList, _resList); - } - } - - public String getName() - { - return "BodyPartListTest"; - } - - public static void main(String[] args) - { - runTest(new BodyPartListTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartPathTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartPathTest.java deleted file mode 100644 index 9468f3275..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartPathTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - - -import java.util.Random; - -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartPath; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class BodyPartPathTest - extends SimpleTest -{ - - public void performTest() - throws Exception - { - Random rand = new Random(); - { - BodyPartID[] bpid = new BodyPartID[Math.abs(rand.nextInt()) % 20]; - for (int t = 0; t < bpid.length; t++) - { - bpid[t] = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); - } - BodyPartPath bpp = new BodyPartPath(bpid); - DERSequence _bpp = (DERSequence)bpp.toASN1Primitive(); - byte[] b = bpp.getEncoded(); - - // - // Decode and compare results. - // - - BodyPartPath resList = BodyPartPath.getInstance(b); - DERSequence _resList = (DERSequence)resList.toASN1Primitive(); - - isEquals(_bpp.size(), _resList.size()); - - for (int j = 0; j < _bpp.size(); j++) - { - isEquals(_resList.getObjectAt(j), _bpp.getObjectAt(j)); - } - } - { - // - // Compare when same thing instantiated via different constructors. - // - - BodyPartID bpid = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); - BodyPartPath bpidList = new BodyPartPath(bpid); // Single entry constructor. - BodyPartPath resList = new BodyPartPath(new BodyPartID[]{bpid}); // Array constructor. - - DERSequence _bpidList = (DERSequence)bpidList.toASN1Primitive(); - DERSequence _resList = (DERSequence)resList.toASN1Primitive(); - - isEquals(_bpidList, _resList); - } - } - - public String getName() - { - return "BodyPartPathTest"; - } - - public static void main(String[] args) - { - runTest(new BodyPartPathTest()); - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartReferenceTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartReferenceTest.java deleted file mode 100644 index cfa26542a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/BodyPartReferenceTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.util.Random; - -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartPath; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartReference; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class BodyPartReferenceTest - extends SimpleTest -{ - - public String getName() - { - return "BodyPartReferenceTest"; - } - - public void performTest() - throws Exception - { - Random rand = new Random(); - BodyPartReference ch0 = null; - BodyPartReference ch1 = null; - { - // Choice 1 - BodyPartID id = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); - - ch0 = new BodyPartReference(id); - byte[] b = ch0.getEncoded(); - - BodyPartReference brRes = BodyPartReference.getInstance(b); - isEquals(brRes, ch0); - } - - { - // Choice 2 - - BodyPartID[] bpid = new BodyPartID[Math.abs(rand.nextInt()) % 20]; - for (int t = 0; t < bpid.length; t++) - { - bpid[t] = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); - } - - ch1 = new BodyPartReference(new BodyPartPath(bpid)); - byte[] b = ch1.getEncoded(); - - BodyPartReference brRes = BodyPartReference.getInstance(b); - isEquals(brRes, ch1); - } - - - { - // Test choice alternatives are not equal. - BodyPartID id = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L)); - - ch0 = new BodyPartReference(id); - ch1 = new BodyPartReference(new BodyPartPath(id)); - - try - { - isEquals(ch0, ch1); - fail("Must not be equal."); - } - catch (Throwable t) - { - // Ignored - } - } - - } - - public static void main(String[] args) - { - runTest(new BodyPartReferenceTest()); - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCCertificationRequestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCCertificationRequestTest.java deleted file mode 100644 index b5717db6d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCCertificationRequestTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encoding; -import com.fr.third.org.bouncycastle.asn1.cmc.CertificationRequest; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class CMCCertificationRequestTest - extends SimpleTest -{ - byte[] req1 = Base64.decode( - "MIHoMIGTAgEAMC4xDjAMBgNVBAMTBVRlc3QyMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNF" - + "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALlEt31Tzt2MlcOljvacJgzQVhmlMoqAOgqJ9Pgd3Gux" - + "Z7/WcIlgW4QCB7WZT21O1YoghwBhPDMcNGrHei9kHQkCAwEAAaAAMA0GCSqGSIb3DQEBBQUAA0EA" - + "NDEI4ecNtJ3uHwGGlitNFq9WxcoZ0djbQJ5hABMotav6gtqlrwKXY2evaIrsNwkJtNdwwH18aQDU" - + "KCjOuBL38Q=="); - - byte[] req2 = Base64.decode( - "MIIB6TCCAVICAQAwgagxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRQwEgYDVQQH" - + "EwtTYW50YSBDbGFyYTEMMAoGA1UEChMDQUJCMVEwTwYDVQQLHEhQAAAAAAAAAG8AAAAAAAAAdwAA" - + "AAAAAABlAAAAAAAAAHIAAAAAAAAAIAAAAAAAAABUAAAAAAAAABxIAAAAAAAARAAAAAAAAAAxDTAL" - + "BgNVBAMTBGJsdWUwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANETRZ+6occCOrFxNhfKIp4C" - + "mMkxwhBNb7TnnahpbM9O0r4hrBPcfYuL7u9YX/jN0YNUP+/CiT39HhSe/bikaBPDEyNsl988I8vX" - + "piEdgxYq/+LTgGHbjRsRYCkPtmzwBbuBldNF8bV7pu0v4UScSsExmGqqDlX1TbPU8KkPU1iTAgMB" - + "AAGgADANBgkqhkiG9w0BAQQFAAOBgQAFbrs9qUwh93CtETk7DeUD5HcdCnxauo1bck44snSV6MZV" - + "OCIGaYu1501kmhEvAtVVRr6SEHwimfQDDIjnrWwYsEr/DT6tkTZAbfRd3qUu3iKjT0H0vlUZp0hJ" - + "66mINtBM84uZFBfoXiWY8M3FuAnGmvy6ah/dYtJorTxLKiGkew=="); - - public String getName() - { - return "CMCCertificationRequestTest"; - } - - public void certReqTest( - String testName, - byte[] req) - throws Exception - { - CertificationRequest r = CertificationRequest.getInstance(req); - - byte[] bytes = r.getEncoded(ASN1Encoding.DER); - - if (bytes.length != req.length) - { - fail(testName + " failed length test"); - } - - for (int i = 0; i != req.length; i++) - { - if (bytes[i] != req[i]) - { - fail(testName + " failed comparison test"); - } - } - } - - public void performTest() - throws Exception - { - certReqTest("req1", req1); - certReqTest("req2", req2); - - CertificationRequest a = CertificationRequest.getInstance(req1); - CertificationRequest b = new CertificationRequest(a.getSubject(), a.getSubjectPublicKeyAlgorithm(), a.getSubjectPublicKey(), a.getAttributes(), a.getSignatureAlgorithm(), a.getSignature()); - - isTrue(Arrays.areEqual(a.getEncoded(), b.getEncoded())); - } - - - public static void main( - String[] args) - { - runTest(new CMCCertificationRequestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCFailInfoTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCFailInfoTest.java deleted file mode 100644 index 6a8bf930d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCFailInfoTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.cmc.CMCFailInfo; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class CMCFailInfoTest - extends SimpleTest -{ - - // From Page 68, CMC: Structures RFC 5272 - private static Object[][] types = new Object[][]{ - {"badAlg", new Long(0L) }, - {"badMessageCheck", new Long(1L) }, - {"badRequest", new Long(2L) }, - {"badTime", new Long(3L) }, - {"badCertId", new Long(4L) }, - {"unsupportedExt", new Long(5L) }, - {"mustArchiveKeys", new Long(6L) }, - {"badIdentity", new Long(7L) }, - {"popRequired", new Long(8L) }, - {"popFailed", new Long(9L) }, - {"noKeyReuse", new Long(10L) }, - {"internalCAError", new Long(11L) }, - {"tryLater", new Long(12L) }, - {"authDataFail", new Long(13L)} - }; - private static Map typesMap = new HashMap(); - - static - { - for (int t = 0; t < types.length; t++) - { - typesMap.put(types[t][1], types[t][0]); - } - } - - - public void performTest() - throws Exception - { - - // - // Check that range has changed and this test has not been updated or vice versa. - // It is intended to act as a double check on the addition of CMCFailInfo presets by - // requiring this test to be updated equally to ensure it will pass. - // - - Field rangeField = CMCFailInfo.class.getDeclaredField("range"); - rangeField.setAccessible(true); - - Map range = (Map)rangeField.get(null); - - isEquals("Range in CMCFailInfo does not match test data.",range.size(), types.length); - - for (Iterator rangeKeys = range.keySet().iterator(); rangeKeys.hasNext(); ) - { Object j = rangeKeys.next(); - if (!typesMap.containsKey(new Long(((ASN1Integer)j).getValue().longValue()))) { - fail("The 'range' map in CMCFailInfo contains a value not in the test ('typesMap') map, value was: "+j.toString()); - } - } - - - for (Iterator typeKeys = typesMap.keySet().iterator(); typeKeys.hasNext(); ) - { Object j = typeKeys.next(); - if (!range.containsKey(new ASN1Integer(((Long)j).longValue()))) { - fail("The 'typesMap' map in CMCFailInfoTest contains a value not in the CMCFailInfo ('range') map, value was: "+j.toString()); - } - } - - - // - // Test encoding / decoding - // - - byte[] b = CMCFailInfo.authDataFail.getEncoded(); - CMCFailInfo r = CMCFailInfo.getInstance(b); - isEquals(r,CMCFailInfo.authDataFail); - - } - - public String getName() - { - return "CMCFailInfoTest"; - } - - public static void main(String[] args) - { - runTest(new CMCFailInfoTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCPublicationInfoTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCPublicationInfoTest.java deleted file mode 100644 index 274b2cbfa..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/CMCPublicationInfoTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.DERNull; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.cmc.CMCPublicationInfo; -import com.fr.third.org.bouncycastle.asn1.crmf.PKIPublicationInfo; -import com.fr.third.org.bouncycastle.asn1.crmf.SinglePubInfo; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class CMCPublicationInfoTest - extends SimpleTest -{ - - public void performTest() - throws Exception - { - SecureRandom secureRandom = new SecureRandom(); - - // - // Test encode and decode. - // - - // Not a real AlgorithmIdentifier - AlgorithmIdentifier testIA = new AlgorithmIdentifier(new ASN1ObjectIdentifier("1.1.2.3"), DERNull.INSTANCE); - byte[][] hashes = new byte[5][64]; - for(int i =0; i- * RSA's PKCS5 Page. - *
- * The vectors are Base 64 encoded and encrypted using the password "password" - * (without quotes). They should all yield the same PrivateKeyInfo object. - */ -public class EncryptedPrivateKeyInfoTest - extends SimpleTest -{ - static byte[] sample1 = Base64.decode( - "MIIBozA9BgkqhkiG9w0BBQ0wMDAbBgkqhkiG9w0BBQwwDgQIfWBDXwLp4K4CAggA" - + "MBEGBSsOAwIHBAiaCF/AvOgQ6QSCAWDWX4BdAzCRNSQSANSuNsT5X8mWYO27mr3Y" - + "9c9LoBVXGNmYWKA77MI4967f7SmjNcgXj3xNE/jmnVz6hhsjS8E5VPT3kfyVkpdZ" - + "0lr5e9Yk2m3JWpPU7++v5zBkZmC4V/MwV/XuIs6U+vykgzMgpxQg0oZKS9zgmiZo" - + "f/4dOCL0UtCDnyOSvqT7mCVIcMDIEKu8QbVlgZYBop08l60EuEU3gARUo8WsYQmO" - + "Dz/ldx0Z+znIT0SXVuOwc+RVItC5T/Qx+aijmmpt+9l14nmaGBrEkmuhmtdvU/4v" - + "aptewGRgmjOfD6cqK+zs0O5NrrJ3P/6ZSxXj91CQgrThGfOv72bUncXEMNtc8pks" - + "2jpHFjGMdKufnadAD7XuMgzkkaklEXZ4f5tU6heIIwr51g0GBEGF96gYPFnjnSQM" - + "75JE02Clo+DfcfXpcybPTwwFg2jd6JTTOfkdf6OdSlA/1XNK43FA"); - - static byte[] sample2 = Base64.decode( - "MIIBpjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIeFeOWl1jywYCAggA" - + "MBQGCCqGSIb3DQMHBAjUJ5eGBhQGtQSCAWBrHrRgqO8UUMLcWzZEtpk1l3mjxiF/" - + "koCMkHsFwowgyWhEbgIkTgbSViK54LVK8PskekcGNLph+rB6bGZ7pPbL5pbXASJ8" - + "+MkQcG3FZdlS4Ek9tTJDApj3O1UubZGFG4uvTlJJFbF1BOJ3MkY3XQ9Gl1qwv7j5" - + "6e103Da7Cq9+oIDKmznza78XXQYrUsPo8mJGjUxPskEYlzwvHjKubRnYm/K6RKhi" - + "5f4zX4BQ/Dt3H812ZjRXrsjAJP0KrD/jyD/jCT7zNBVPH1izBds+RwizyQAHwfNJ" - + "BFR78TH4cgzB619X47FDVOnT0LqQNVd0O3cSwnPrXE9XR3tPayE+iOB15llFSmi8" - + "z0ByOXldEpkezCn92Umk++suzIVj1qfsK+bv2phZWJPbLEIWPDRHUbYf76q5ArAr" - + "u4xtxT/hoK3krEs/IN3d70qjlUJ36SEw1UaZ82PWhakQbdtu39ZraMJB"); - - static byte[] sample3 = Base64.decode( - "MIIBrjBIBgkqhkiG9w0BBQ0wOzAeBgkqhkiG9w0BBQwwEQQIrHyQPBZqWLUCAggA" - + "AgEQMBkGCCqGSIb3DQMCMA0CAToECEhbh7YZKiPSBIIBYCT1zp6o5jpFlIkgwPop" - + "7bW1+8ACr4exqzkeb3WflQ8cWJ4cURxzVdvxUnXeW1VJdaQZtjS/QHs5GhPTG/0f" - + "wtvnaPfwrIJ3FeGaZfcg2CrYhalOFmEb4xrE4KyoEQmUN8tb/Cg94uzd16BOPw21" - + "RDnE8bnPdIGY7TyL95kbkqH23mK53pi7h+xWIgduW+atIqDyyt55f7WMZcvDvlj6" - + "VpN/V0h+qxBHL274WA4dj6GYgeyUFpi60HdGCK7By2TBy8h1ZvKGjmB9h8jZvkx1" - + "MkbRumXxyFsowTZawyYvO8Um6lbfEDP9zIEUq0IV8RqH2MRyblsPNSikyYhxX/cz" - + "tdDxRKhilySbSBg5Kr8OfcwKp9bpinN96nmG4xr3Tch1bnVvqJzOQ5+Vva2WwVvH" - + "2JkWvYm5WaANg4Q6bRxu9vz7DuhbJjQdZbxFezIAgrJdSe92B00jO/0Kny1WjiVO" - + "6DA="); - - public String getName() - { - return "EncryptedPrivateKeyInfoTest"; - } - - private void test( - int id, - byte[] sample) - { - ByteArrayInputStream bIn = new ByteArrayInputStream(sample); - ASN1InputStream aIn = new ASN1InputStream(bIn); - EncryptedPrivateKeyInfo info = null; - - try - { - info = EncryptedPrivateKeyInfo.getInstance(aIn.readObject()); - } - catch (Exception e) - { - fail("test " + id + " failed construction - exception " + e.toString(), e); - } - - byte[] bytes = null; - try - { - bytes = info.getEncoded(ASN1Encoding.DER); - } - catch (Exception e) - { - fail("test " + id + " failed writing - exception " + e.toString(), e); - } - - if (bytes.length != sample.length) - { - try - { - bIn = new ByteArrayInputStream(bytes); - aIn = new ASN1InputStream(bIn); - - ASN1Primitive obj = aIn.readObject(); - - fail("test " + id + " length mismatch - expected " + sample.length + Strings.lineSeparator() + ASN1Dump.dumpAsString(info) + " got " + bytes.length + Strings.lineSeparator() + ASN1Dump.dumpAsString(obj)); - } - catch (Exception e) - { - fail("test " + id + " length mismatch - exception " + e.toString()); - } - } - - for (int i = 0; i != bytes.length; i++) - { - if (bytes[i] != sample[i]) - { - fail("test " + id + " data mismatch"); - } - } - } - - public void performTest() - { - test(0, sample1); - test(1, sample2); - test(2, sample3); - } - - - public static void main( - String[] args) - { - runTest(new EncryptedPrivateKeyInfoTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/EqualsAndHashCodeTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/EqualsAndHashCodeTest.java deleted file mode 100644 index c079cba50..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/EqualsAndHashCodeTest.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.util.Date; - -import com.fr.third.org.bouncycastle.asn1.ASN1Boolean; -import com.fr.third.org.bouncycastle.asn1.ASN1Enumerated; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1OutputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.BERConstructedOctetString; -import com.fr.third.org.bouncycastle.asn1.BERSequence; -import com.fr.third.org.bouncycastle.asn1.BERSet; -import com.fr.third.org.bouncycastle.asn1.BERTaggedObject; -import com.fr.third.org.bouncycastle.asn1.DERApplicationSpecific; -import com.fr.third.org.bouncycastle.asn1.DERBMPString; -import com.fr.third.org.bouncycastle.asn1.DERBitString; -import com.fr.third.org.bouncycastle.asn1.DERGeneralString; -import com.fr.third.org.bouncycastle.asn1.DERGeneralizedTime; -import com.fr.third.org.bouncycastle.asn1.DERGraphicString; -import com.fr.third.org.bouncycastle.asn1.DERIA5String; -import com.fr.third.org.bouncycastle.asn1.DERNull; -import com.fr.third.org.bouncycastle.asn1.DERNumericString; -import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.DERPrintableString; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERSet; -import com.fr.third.org.bouncycastle.asn1.DERT61String; -import com.fr.third.org.bouncycastle.asn1.DERTaggedObject; -import com.fr.third.org.bouncycastle.asn1.DERUTCTime; -import com.fr.third.org.bouncycastle.asn1.DERUTF8String; -import com.fr.third.org.bouncycastle.asn1.DERUniversalString; -import com.fr.third.org.bouncycastle.asn1.DERVideotexString; -import com.fr.third.org.bouncycastle.asn1.DERVisibleString; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -public class EqualsAndHashCodeTest - implements Test -{ - public TestResult perform() - { - byte[] data = { 0, 1, 0, 1, 0, 0, 1 }; - - ASN1Primitive values[] = { - new BERConstructedOctetString(data), - new BERSequence(new DERPrintableString("hello world")), - new BERSet(new DERPrintableString("hello world")), - new BERTaggedObject(0, new DERPrintableString("hello world")), - new DERApplicationSpecific(0, data), - new DERBitString(data), - new DERBMPString("hello world"), - ASN1Boolean.getInstance(true), - ASN1Boolean.getInstance(false), - new ASN1Enumerated(100), - new DERGeneralizedTime("20070315173729Z"), - new DERGeneralString("hello world"), - new DERIA5String("hello"), - new ASN1Integer(1000), - new DERNull(), - new DERNumericString("123456"), - new ASN1ObjectIdentifier("1.1.1.10000.1"), - new DEROctetString(data), - new DERPrintableString("hello world"), - new DERSequence(new DERPrintableString("hello world")), - new DERSet(new DERPrintableString("hello world")), - new DERT61String("hello world"), - new DERTaggedObject(0, new DERPrintableString("hello world")), - new DERUniversalString(data), - new DERUTCTime(new Date()), - new DERUTF8String("hello world"), - new DERVisibleString("hello world") , - new DERGraphicString(Hex.decode("deadbeef")), - new DERVideotexString(Strings.toByteArray("Hello World")) - }; - - try - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - ASN1OutputStream aOut = ASN1OutputStream.create(bOut); - - for (int i = 0; i != values.length; i++) - { - aOut.writeObject(values[i]); - } - - ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray()); - ASN1InputStream aIn = new ASN1InputStream(bIn); - - for (int i = 0; i != values.length; i++) - { - ASN1Primitive o = aIn.readObject(); - if (!o.equals(values[i])) - { - return new SimpleTestResult(false, getName() + ": Failed equality test for " + o.getClass()); - } - - if (o.hashCode() != values[i].hashCode()) - { - return new SimpleTestResult(false, getName() + ": Failed hashCode test for " + o.getClass()); - } - } - } - catch (Exception e) - { - return new SimpleTestResult(false, getName() + ": Failed - exception " + e.toString(), e); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public String getName() - { - return "EqualsAndHashCode"; - } - - public static void main( - String[] args) - { - EqualsAndHashCodeTest test = new EqualsAndHashCodeTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ExtendedFailInfoTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ExtendedFailInfoTest.java deleted file mode 100644 index 7597da4f7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ExtendedFailInfoTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.cmc.ExtendedFailInfo; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class ExtendedFailInfoTest - extends SimpleTest -{ - - public static void main(String[] args) - { - runTest(new ExtendedFailInfoTest()); - } - - public String getName() - { - return "ExtendedFailInfo"; - } - - public void performTest() - throws Exception - { - // OID not real - ExtendedFailInfo extendedFailInfo = new ExtendedFailInfo( - new ASN1ObjectIdentifier("1.2.3.2"), - new ASN1Integer(10L)); - byte[] b = extendedFailInfo.getEncoded(); - ExtendedFailInfo extendedFailInfoResult = ExtendedFailInfo.getInstance(b); - - isEquals("failInfoOID", extendedFailInfo.getFailInfoOID(), extendedFailInfoResult.getFailInfoOID()); - isEquals("failInfoValue", extendedFailInfo.getFailInfoValue(), extendedFailInfoResult.getFailInfoValue()); - - try - { - ExtendedFailInfo.getInstance(new DERSequence(new ASN1Integer(10L))); - fail("Sequence must be 2 elements."); - } - catch (Throwable t) - { - isEquals("Wrong exception type",t.getClass(), IllegalArgumentException.class); - } - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ExtensionReqTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ExtensionReqTest.java deleted file mode 100644 index cff240c90..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ExtensionReqTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1Boolean; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.cmc.ExtensionReq; -import com.fr.third.org.bouncycastle.asn1.x509.Extension; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class ExtensionReqTest - extends SimpleTest -{ - public String getName() - { - return "ExtensionReqTest"; - } - - public void performTest() - throws Exception - { - ExtensionReq extensionReq = new ExtensionReq( - new Extension( - new ASN1ObjectIdentifier("1.2.4"), ASN1Boolean.FALSE, new DEROctetString("abcdef".getBytes()) - )); - byte[] b = extensionReq.getEncoded(); - - ExtensionReq extensionReqResult = ExtensionReq.getInstance(b); - - isEquals("Extensions", extensionReq.getExtensions()[0], extensionReqResult.getExtensions()[0]); - - } - - public static void main(String[] args) - { - runTest(new ExtensionReqTest()); - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GeneralNameTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GeneralNameTest.java deleted file mode 100644 index 27eb0ddfe..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GeneralNameTest.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralNames; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralNamesBuilder; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class GeneralNameTest - extends SimpleTest -{ - private static final byte[] ipv4 = Hex.decode("87040a090800"); - private static final byte[] ipv4WithMask1 = Hex.decode("87080a090800ffffff00"); - private static final byte[] ipv4WithMask2 = Hex.decode("87080a090800ffff8000"); - private static final byte[] ipv4WithMask3 = Hex.decode("87080a090800ffffc000"); - - private static final byte[] ipv6a = Hex.decode("871020010db885a308d313198a2e03707334"); - private static final byte[] ipv6b = Hex.decode("871020010db885a3000013198a2e03707334"); - private static final byte[] ipv6c = Hex.decode("871000000000000000000000000000000001"); - private static final byte[] ipv6d = Hex.decode("871020010db885a3000000008a2e03707334"); - private static final byte[] ipv6e = Hex.decode("871020010db885a3000000008a2e0a090800"); - private static final byte[] ipv6f = Hex.decode("872020010db885a3000000008a2e0a090800ffffffffffff00000000000000000000"); - private static final byte[] ipv6g = Hex.decode("872020010db885a3000000008a2e0a090800ffffffffffffffffffffffffffffffff"); - private static final byte[] ipv6h = Hex.decode("872020010db885a300000000000000000000ffffffffffff00000000000000000000"); - private static final byte[] ipv6i = Hex.decode("872020010db885a300000000000000000000fffffffffffe00000000000000000000"); - private static final byte[] ipv6j = Hex.decode("872020010db885a300000000000000000000ffffffffffff80000000000000000000"); - - public String getName() - { - return "GeneralName"; - } - - public void performTest() - throws Exception - { - GeneralName nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0"); - if (!Arrays.areEqual(nm.getEncoded(), ipv4)) - { - fail("ipv4 encoding failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0/255.255.255.0"); - if (!Arrays.areEqual(nm.getEncoded(), ipv4WithMask1)) - { - fail("ipv4 with netmask 1 encoding failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0/24"); - if (!Arrays.areEqual(nm.getEncoded(), ipv4WithMask1)) - { - fail("ipv4 with netmask 2 encoding failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0/255.255.128.0"); - if (!Arrays.areEqual(nm.getEncoded(), ipv4WithMask2)) - { - fail("ipv4 with netmask 3a encoding failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0/17"); - if (!Arrays.areEqual(nm.getEncoded(), ipv4WithMask2)) - { - fail("ipv4 with netmask 3b encoding failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0/255.255.192.0"); - if (!Arrays.areEqual(nm.getEncoded(), ipv4WithMask3)) - { - fail("ipv4 with netmask 3a encoding failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0/18"); - if (!Arrays.areEqual(nm.getEncoded(), ipv4WithMask3)) - { - fail("ipv4 with netmask 3b encoding failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3:08d3:1319:8a2e:0370:7334"); - if (!Arrays.areEqual(nm.getEncoded(), ipv6a)) - { - fail("ipv6 with netmask encoding failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::1319:8a2e:0370:7334"); - if (!Arrays.areEqual(nm.getEncoded(), ipv6b)) - { - fail("ipv6b encoding failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "::1"); - if (!Arrays.areEqual(nm.getEncoded(), ipv6c)) - { - fail("ipv6c failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::8a2e:0370:7334"); - if (!Arrays.areEqual(nm.getEncoded(), ipv6d)) - { - fail("ipv6d failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::8a2e:10.9.8.0"); - if (!Arrays.areEqual(nm.getEncoded(), ipv6e)) - { - fail("ipv6e failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::8a2e:10.9.8.0/ffff:ffff:ffff::0000"); - if (!Arrays.areEqual(nm.getEncoded(), ipv6f)) - { - fail("ipv6f failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::8a2e:10.9.8.0/128"); - if (!Arrays.areEqual(nm.getEncoded(), ipv6g)) - { - fail("ipv6g failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::/48"); - if (!Arrays.areEqual(nm.getEncoded(), ipv6h)) - { - fail("ipv6h failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::/47"); - if (!Arrays.areEqual(nm.getEncoded(), ipv6i)) - { - fail("ipv6i failed"); - } - - nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::/49"); - if (!Arrays.areEqual(nm.getEncoded(), ipv6j)) - { - fail("ipv6j failed"); - } - - GeneralNamesBuilder genNamesBuilder = new GeneralNamesBuilder(); - - GeneralName name1 = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::8a2e:0370:7334"); - - genNamesBuilder.addName(name1); - - if (!genNamesBuilder.build().equals(new GeneralNames(name1))) - { - fail("single build failed"); - } - - GeneralName nm1 = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::/48"); - GeneralName nm2 = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::/47"); - GeneralName nm3 = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::/49"); - - genNamesBuilder = new GeneralNamesBuilder(); - - genNamesBuilder.addName(name1); - - genNamesBuilder.addNames(new GeneralNames(new GeneralName[]{nm1, nm2})); - - genNamesBuilder.addName(nm3); - - if (!genNamesBuilder.build().equals(new GeneralNames(new GeneralName[] { name1, nm1, nm2, nm3 }))) - { - fail("multi build failed"); - } - } - - public static void main( - String[] args) - { - runTest(new GeneralNameTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GeneralizedTimeTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GeneralizedTimeTest.java deleted file mode 100644 index 6791a8dad..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GeneralizedTimeTest.java +++ /dev/null @@ -1,269 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.SimpleTimeZone; -import java.util.TimeZone; - -import com.fr.third.org.bouncycastle.asn1.ASN1GeneralizedTime; -import com.fr.third.org.bouncycastle.asn1.DERGeneralizedTime; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * X.690 test example - */ -public class GeneralizedTimeTest - extends SimpleTest -{ - String[] input = - { - "20020122122220", - "20020122122220Z", - "20020122122220-1000", - "20020122122220+00", - "20020122122220.1", - "20020122122220.1Z", - "20020122122220.1-1000", - "20020122122220.1+00", - "20020122122220.01", - "20020122122220.01Z", - "20020122122220.01-1000", - "20020122122220.01+00", - "20020122122220.001", - "20020122122220.001Z", - "20020122122220.001-1000", - "20020122122220.001+00", - "20020122122220.0001", - "20020122122220.0001Z", - "20020122122220.0001-1000", - "20020122122220.0001+00", - "20020122122220.0001+1000" - }; - - String[] output = { - "20020122122220", - "20020122122220GMT+00:00", - "20020122122220GMT-10:00", - "20020122122220GMT+00:00", - "20020122122220.1", - "20020122122220.1GMT+00:00", - "20020122122220.1GMT-10:00", - "20020122122220.1GMT+00:00", - "20020122122220.01", - "20020122122220.01GMT+00:00", - "20020122122220.01GMT-10:00", - "20020122122220.01GMT+00:00", - "20020122122220.001", - "20020122122220.001GMT+00:00", - "20020122122220.001GMT-10:00", - "20020122122220.001GMT+00:00", - "20020122122220.0001", - "20020122122220.0001GMT+00:00", - "20020122122220.0001GMT-10:00", - "20020122122220.0001GMT+00:00", - "20020122122220.0001GMT+10:00" }; - - String[] zOutput = { - "20020122122220Z", - "20020122122220Z", - "20020122222220Z", - "20020122122220Z", - "20020122122220Z", - "20020122122220Z", - "20020122222220Z", - "20020122122220Z", - "20020122122220Z", - "20020122122220Z", - "20020122222220Z", - "20020122122220Z", - "20020122122220Z", - "20020122122220Z", - "20020122222220Z", - "20020122122220Z", - "20020122122220Z", - "20020122122220Z", - "20020122222220Z", - "20020122122220Z", - "20020122022220Z" - }; - - String[] mzOutput = { - "20020122122220.000Z", - "20020122122220.000Z", - "20020122222220.000Z", - "20020122122220.000Z", - "20020122122220.100Z", - "20020122122220.100Z", - "20020122222220.100Z", - "20020122122220.100Z", - "20020122122220.010Z", - "20020122122220.010Z", - "20020122222220.010Z", - "20020122122220.010Z", - "20020122122220.001Z", - "20020122122220.001Z", - "20020122222220.001Z", - "20020122122220.001Z", - "20020122122220.000Z", - "20020122122220.000Z", - "20020122222220.000Z", - "20020122122220.000Z", - "20020122022220.000Z" - }; - - String[] derMzOutput = { - "20020122122220Z", - "20020122122220Z", - "20020122222220Z", - "20020122122220Z", - "20020122122220.1Z", - "20020122122220.1Z", - "20020122222220.1Z", - "20020122122220.1Z", - "20020122122220.01Z", - "20020122122220.01Z", - "20020122222220.01Z", - "20020122122220.01Z", - "20020122122220.001Z", - "20020122122220.001Z", - "20020122222220.001Z", - "20020122122220.001Z", - "20020122122220Z", - "20020122122220Z", - "20020122222220Z", - "20020122122220Z", - "20020122022220Z" - }; - - String[] truncOutput = { - "200201221222Z", - "2002012212Z" - }; - - String[] derTruncOutput = { - "20020122122200Z", - "20020122120000Z" - }; - - public String getName() - { - return "GeneralizedTime"; - } - - public void performTest() - throws Exception - { - SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'"); - - dateF.setTimeZone(new SimpleTimeZone(0,"Z")); - - for (int i = 0; i != input.length; i++) - { - ASN1GeneralizedTime t = new ASN1GeneralizedTime(input[i]); - if (output[i].indexOf('G') > 0) // don't check local time the same way - { - if (!t.getTime().equals(output[i])) - { - fail("failed GMT conversion test got " + t.getTime() + " expected " + output[i]); - } - if (!dateF.format(t.getDate()).equals(zOutput[i])) - { - fail("failed date conversion test"); - } - } - else - { - String offset = calculateGMTOffset(t.getDate()); - if (!t.getTime().equals(output[i] + offset)) - { - fail("failed conversion test got " + t.getTime() + " expected " + output[i] + offset); - } - } - } - - dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'"); - - dateF.setTimeZone(new SimpleTimeZone(0,"Z")); - - for (int i = 0; i != input.length; i++) - { - ASN1GeneralizedTime t = new ASN1GeneralizedTime(input[i]); - - if (!dateF.format(t.getDate()).equals(mzOutput[i])) - { - fail("failed long date conversion test"); - } - } - - for (int i = 0; i != mzOutput.length; i++) - { - ASN1GeneralizedTime t = new DERGeneralizedTime(mzOutput[i]); - - if (!areEqual(t.getEncoded(), new ASN1GeneralizedTime(derMzOutput[i]).getEncoded())) - { - fail("der encoding wrong"); - } - } - - for (int i = 0; i != truncOutput.length; i++) - { - DERGeneralizedTime t = new DERGeneralizedTime(truncOutput[i]); - - if (!areEqual(t.getEncoded(), new ASN1GeneralizedTime(derTruncOutput[i]).getEncoded())) - { - fail("trunc der encoding wrong"); - } - } - - // check an actual GMT string comes back untampered - ASN1GeneralizedTime time = new ASN1GeneralizedTime("20190704031318GMT+00:00"); - - isTrue("20190704031318GMT+00:00".equals(time.getTime())); - - try - { - new DERGeneralizedTime(new byte[0]); - } - catch (IllegalArgumentException e) - { - isTrue(e.getMessage().equals("GeneralizedTime string too short")); - } - } - - private String calculateGMTOffset(Date date) - { - String sign = "+"; - TimeZone timeZone = TimeZone.getDefault(); - int offset = timeZone.getRawOffset(); - if (offset < 0) - { - sign = "-"; - offset = -offset; - } - int hours = offset / (60 * 60 * 1000); - int minutes = (offset - (hours * 60 * 60 * 1000)) / (60 * 1000); - - if (timeZone.useDaylightTime() && timeZone.inDaylightTime(date)) - { - hours += sign.equals("+") ? 1 : -1; - } - - return "GMT" + sign + convert(hours) + ":" + convert(minutes); - } - - private String convert(int time) - { - if (time < 10) - { - return "0" + time; - } - - return Integer.toString(time); - } - - public static void main( - String[] args) - { - runTest(new GeneralizedTimeTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GenerationTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GenerationTest.java deleted file mode 100644 index ef60dc670..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GenerationTest.java +++ /dev/null @@ -1,406 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; -import java.math.BigInteger; -import java.text.ParseException; -import java.util.Date; - -import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; -import com.fr.third.org.bouncycastle.asn1.ASN1GeneralizedTime; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.DERNull; -import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.oiw.ElGamalParameter; -import com.fr.third.org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.pkcs.RSAPublicKey; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.asn1.x509.AuthorityKeyIdentifier; -import com.fr.third.org.bouncycastle.asn1.x509.CRLReason; -import com.fr.third.org.bouncycastle.asn1.x509.Extension; -import com.fr.third.org.bouncycastle.asn1.x509.Extensions; -import com.fr.third.org.bouncycastle.asn1.x509.ExtensionsGenerator; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralNames; -import com.fr.third.org.bouncycastle.asn1.x509.IssuingDistributionPoint; -import com.fr.third.org.bouncycastle.asn1.x509.KeyUsage; -import com.fr.third.org.bouncycastle.asn1.x509.SubjectKeyIdentifier; -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.asn1.x509.TBSCertList; -import com.fr.third.org.bouncycastle.asn1.x509.TBSCertificate; -import com.fr.third.org.bouncycastle.asn1.x509.Time; -import com.fr.third.org.bouncycastle.asn1.x509.V1TBSCertificateGenerator; -import com.fr.third.org.bouncycastle.asn1.x509.V2TBSCertListGenerator; -import com.fr.third.org.bouncycastle.asn1.x509.V3TBSCertificateGenerator; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class GenerationTest - extends SimpleTest -{ - private byte[] v1Cert = Base64.decode( - "MIGtAgEBMA0GCSqGSIb3DQEBBAUAMCUxCzAJBgNVBAMMAkFVMRYwFAYDVQQKDA1Cb" - + "3VuY3kgQ2FzdGxlMB4XDTcwMDEwMTAwMDAwMVoXDTcwMDEwMTAwMDAxMlowNjELMA" - + "kGA1UEAwwCQVUxFjAUBgNVBAoMDUJvdW5jeSBDYXN0bGUxDzANBgNVBAsMBlRlc3Q" - + "gMTAaMA0GCSqGSIb3DQEBAQUAAwkAMAYCAQECAQI="); - - private byte[] v3Cert = Base64.decode( - "MIIBSKADAgECAgECMA0GCSqGSIb3DQEBBAUAMCUxCzAJBgNVBAMMAkFVMRYwFAYD" - + "VQQKDA1Cb3VuY3kgQ2FzdGxlMB4XDTcwMDEwMTAwMDAwMVoXDTcwMDEwMTAwMDAw" - + "MlowNjELMAkGA1UEAwwCQVUxFjAUBgNVBAoMDUJvdW5jeSBDYXN0bGUxDzANBgNV" - + "BAsMBlRlc3QgMjAYMBAGBisOBwIBATAGAgEBAgECAwQAAgEDo4GVMIGSMGEGA1Ud" - + "IwEB/wRXMFWAFDZPdpHPzKi7o8EJokkQU2uqCHRRoTqkODA2MQswCQYDVQQDDAJB" - + "VTEWMBQGA1UECgwNQm91bmN5IENhc3RsZTEPMA0GA1UECwwGVGVzdCAyggECMCAG" - + "A1UdDgEB/wQWBBQ2T3aRz8you6PBCaJJEFNrqgh0UTALBgNVHQ8EBAMCBBA="); - - private byte[] v3CertNullSubject = Base64.decode( - "MIHGoAMCAQICAQIwDQYJKoZIhvcNAQEEBQAwJTELMAkGA1UEAwwCQVUxFjAUBgNVB" - + "AoMDUJvdW5jeSBDYXN0bGUwHhcNNzAwMTAxMDAwMDAxWhcNNzAwMTAxMDAwMDAyWj" - + "AAMBgwEAYGKw4HAgEBMAYCAQECAQIDBAACAQOjSjBIMEYGA1UdEQEB/wQ8MDqkODA" - + "2MQswCQYDVQQDDAJBVTEWMBQGA1UECgwNQm91bmN5IENhc3RsZTEPMA0GA1UECwwG" - + "VGVzdCAy"); - - private byte[] v2CertList = Base64.decode( - "MIIBQwIBATANBgkqhkiG9w0BAQUFADAlMQswCQYDVQQDDAJBVTEWMBQGA1UECgwN" + - "Qm91bmN5IENhc3RsZRcNNzAwMTAxMDAwMDAwWhcNNzAwMTAxMDAwMDAyWjAiMCAC" + - "AQEXDTcwMDEwMTAwMDAwMVowDDAKBgNVHRUEAwoBCqCBxTCBwjBhBgNVHSMBAf8E" + - "VzBVgBQ2T3aRz8you6PBCaJJEFNrqgh0UaE6pDgwNjELMAkGA1UEAwwCQVUxFjAU" + - "BgNVBAoMDUJvdW5jeSBDYXN0bGUxDzANBgNVBAsMBlRlc3QgMoIBAjBDBgNVHRIE" + - "PDA6pDgwNjELMAkGA1UEAwwCQVUxFjAUBgNVBAoMDUJvdW5jeSBDYXN0bGUxDzAN" + - "BgNVBAsMBlRlc3QgMzAKBgNVHRQEAwIBATAMBgNVHRwBAf8EAjAA"); - - private void tbsV1CertGen() - throws IOException - { - V1TBSCertificateGenerator gen = new V1TBSCertificateGenerator(); - Date startDate = new Date(1000); - Date endDate = new Date(12000); - - gen.setSerialNumber(new ASN1Integer(1)); - - gen.setStartDate(new Time(startDate)); - gen.setEndDate(new Time(endDate)); - - gen.setIssuer(new X500Name("CN=AU,O=Bouncy Castle")); - gen.setSubject(new X500Name("CN=AU,O=Bouncy Castle,OU=Test 1")); - - gen.setSignature(new AlgorithmIdentifier(PKCSObjectIdentifiers.md5WithRSAEncryption, DERNull.INSTANCE)); - - SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), - new RSAPublicKey(BigInteger.valueOf(1), BigInteger.valueOf(2))); - - gen.setSubjectPublicKeyInfo(info); - - TBSCertificate tbs = gen.generateTBSCertificate(); - - byte[] encoding = tbs.getEncoded(); - if (!Arrays.areEqual(encoding, v1Cert)) - { - fail("failed v1 cert generation"); - } - - // - // read back test - // - ASN1Primitive o = ASN1Primitive.fromByteArray(v1Cert); - - encoding = o.getEncoded(); - if (!Arrays.areEqual(encoding, v1Cert)) - { - fail("failed v1 cert read back test"); - } - } - - private AuthorityKeyIdentifier createAuthorityKeyId( - SubjectPublicKeyInfo info, - X500Name name, - int sNumber) - { - GeneralName genName = new GeneralName(name); - ASN1EncodableVector v = new ASN1EncodableVector(); - - v.add(genName); - - return new AuthorityKeyIdentifier( - info, GeneralNames.getInstance(new DERSequence(v)), BigInteger.valueOf(sNumber)); - } - - private void tbsV3CertGen() - throws IOException - { - V3TBSCertificateGenerator gen = new V3TBSCertificateGenerator(); - Date startDate = new Date(1000); - Date endDate = new Date(2000); - - gen.setSerialNumber(new ASN1Integer(2)); - - gen.setStartDate(new Time(startDate)); - gen.setEndDate(new Time(endDate)); - - gen.setIssuer(new X500Name("CN=AU,O=Bouncy Castle")); - gen.setSubject(new X500Name("CN=AU,O=Bouncy Castle,OU=Test 2")); - - gen.setSignature(new AlgorithmIdentifier(PKCSObjectIdentifiers.md5WithRSAEncryption, DERNull.INSTANCE)); - - SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(BigInteger.valueOf(1), BigInteger.valueOf(2))), new ASN1Integer(3)); - - gen.setSubjectPublicKeyInfo(info); - - // - // add extensions - // - Extensions ex = new Extensions(new Extension[] { - new Extension(Extension.authorityKeyIdentifier, true, new DEROctetString(createAuthorityKeyId(info, new X500Name("CN=AU,O=Bouncy Castle,OU=Test 2"), 2))), - new Extension(Extension.subjectKeyIdentifier, true, new DEROctetString(new SubjectKeyIdentifier(getDigest(info)))), - new Extension(Extension.keyUsage, false, new DEROctetString(new KeyUsage(KeyUsage.dataEncipherment))) - }); - - gen.setExtensions(ex); - - TBSCertificate tbs = gen.generateTBSCertificate(); - - byte[] encoding = tbs.getEncoded(); - if (!Arrays.areEqual(encoding, v3Cert)) - { - fail("failed v3 cert generation"); - } - - // - // read back test - // - ASN1Primitive o = ASN1Primitive.fromByteArray(v3Cert); - - encoding = o.getEncoded(); - if (!Arrays.areEqual(encoding, v3Cert)) - { - fail("failed v3 cert read back test"); - } - } - - private void tbsV3CertGenWithNullSubject() - throws IOException - { - V3TBSCertificateGenerator gen = new V3TBSCertificateGenerator(); - Date startDate = new Date(1000); - Date endDate = new Date(2000); - - gen.setSerialNumber(new ASN1Integer(2)); - - gen.setStartDate(new Time(startDate)); - gen.setEndDate(new Time(endDate)); - - gen.setIssuer(new X500Name("CN=AU,O=Bouncy Castle")); - - gen.setSignature(new AlgorithmIdentifier(PKCSObjectIdentifiers.md5WithRSAEncryption, DERNull.INSTANCE)); - - SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(BigInteger.valueOf(1), BigInteger.valueOf(2))), new ASN1Integer(3)); - - gen.setSubjectPublicKeyInfo(info); - - try - { - gen.generateTBSCertificate(); - fail("null subject not caught!"); - } - catch (IllegalStateException e) - { - if (!e.getMessage().equals("not all mandatory fields set in V3 TBScertificate generator")) - { - fail("unexpected exception", e); - } - } - - // - // add extensions - // - - Extensions ex = new Extensions(new Extension(Extension.subjectAlternativeName, true, - new DEROctetString(new GeneralNames(new GeneralName(new X500Name("CN=AU,O=Bouncy Castle,OU=Test 2")))))); - - gen.setExtensions(ex); - - TBSCertificate tbs = gen.generateTBSCertificate(); - - byte[] encoding = tbs.getEncoded(); - if (!Arrays.areEqual(encoding, v3CertNullSubject)) - { - fail("failed v3 null sub cert generation"); - } - - // - // read back test - // - ASN1Primitive o = ASN1Primitive.fromByteArray(v3CertNullSubject); - - encoding = o.getEncoded(); - if (!Arrays.areEqual(encoding, v3CertNullSubject)) - { - fail("failed v3 null sub cert read back test"); - } - } - - private void tbsV2CertListGen() - throws IOException - { - V2TBSCertListGenerator gen = new V2TBSCertListGenerator(); - - gen.setIssuer(new X500Name("CN=AU,O=Bouncy Castle")); - - gen.addCRLEntry(new ASN1Integer(1), new Time(new Date(1000)), CRLReason.aACompromise); - - gen.setNextUpdate(new Time(new Date(2000))); - - gen.setThisUpdate(new Time(new Date(500))); - - gen.setSignature(new AlgorithmIdentifier(PKCSObjectIdentifiers.sha1WithRSAEncryption, DERNull.INSTANCE)); - - // - // extensions - // - SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(BigInteger.valueOf(1), BigInteger.valueOf(2))), new ASN1Integer(3)); - - ExtensionsGenerator extGen = new ExtensionsGenerator(); - - extGen.addExtension(Extension.authorityKeyIdentifier, true, createAuthorityKeyId(info, new X500Name("CN=AU,O=Bouncy Castle,OU=Test 2"), 2)); - extGen.addExtension(Extension.issuerAlternativeName, false, new GeneralNames(new GeneralName(new X500Name("CN=AU,O=Bouncy Castle,OU=Test 3")))); - extGen.addExtension(Extension.cRLNumber, false, new ASN1Integer(1)); - extGen.addExtension(Extension.issuingDistributionPoint, true, IssuingDistributionPoint.getInstance(new DERSequence())); - - isTrue(extGen.hasExtension(Extension.cRLNumber)); - isTrue(!extGen.hasExtension(Extension.freshestCRL)); - - isEquals(new Extension(Extension.cRLNumber, false, new ASN1Integer(1).getEncoded()), extGen.getExtension(Extension.cRLNumber)); - - Extensions ex = extGen.generate(); - - gen.setExtensions(ex); - - TBSCertList tbs = gen.generateTBSCertList(); - - byte[] encoding = tbs.getEncoded(); - if (!Arrays.areEqual(encoding, v2CertList)) - { - System.out.println(new String(Base64.encode(encoding))); - fail("failed v2 cert list generation"); - } - - // extGen - check replacement. - extGen.replaceExtension(Extension.cRLNumber, false, new ASN1Integer(2)); - - isEquals(new Extension(Extension.cRLNumber, false, new ASN1Integer(2).getEncoded()), extGen.getExtension(Extension.cRLNumber)); - - // extGen - check remove. - extGen.removeExtension(Extension.cRLNumber); - - isTrue(!extGen.hasExtension(Extension.cRLNumber)); - - // check we can still generate - ex = extGen.generate(); - - // - // read back test - // - ASN1Primitive o = ASN1Primitive.fromByteArray(v2CertList); - - encoding = o.getEncoded(); - if (!Arrays.areEqual(encoding, v2CertList)) - { - fail("failed v2 cert list read back test"); - } - - // - // check we can add a custom reason - // - gen.addCRLEntry(new ASN1Integer(1), new Time(new Date(1000)), CRLReason.aACompromise); - - // - // check invalidity date - gen.addCRLEntry(new ASN1Integer(2), new Time(new Date(1000)), CRLReason.affiliationChanged, new ASN1GeneralizedTime(new Date(2000))); - - TBSCertList crl = gen.generateTBSCertList(); - - TBSCertList.CRLEntry[] entries = crl.getRevokedCertificates(); - for (int i = 0; i != entries.length; i++) - { - TBSCertList.CRLEntry entry = entries[i]; - - if (entry.getUserCertificate().equals(new ASN1Integer(1))) - { - Extensions extensions = entry.getExtensions(); - Extension ext = extensions.getExtension(Extension.reasonCode); - - CRLReason r = CRLReason.getInstance(ext.getParsedValue()); - - if (r.getValue().intValue() != CRLReason.aACompromise) - { - fail("reason code mismatch"); - } - } - else if (entry.getUserCertificate().equals(new ASN1Integer(2))) - { - Extensions extensions = entry.getExtensions(); - Extension ext = extensions.getExtension(Extension.reasonCode); - - CRLReason r = CRLReason.getInstance(ext.getParsedValue()); - - if (r.getValue().intValue() != CRLReason.affiliationChanged) - { - fail("reason code mismatch"); - } - - ext = extensions.getExtension(Extension.invalidityDate); - - ASN1GeneralizedTime t = ASN1GeneralizedTime.getInstance(ext.getParsedValue()); - - try - { - if (!t.getDate().equals(new Date(2000))) - { - fail("invalidity date mismatch"); - } - } - catch (ParseException e) - { - fail("can't parse date", e); - } - } - } - } - - public void performTest() - throws Exception - { - tbsV1CertGen(); - tbsV3CertGen(); - tbsV3CertGenWithNullSubject(); - tbsV2CertListGen(); - } - - public String getName() - { - return "Generation"; - } - - private static byte[] getDigest(SubjectPublicKeyInfo spki) - { - Digest digest = new SHA1Digest(); - byte[] resBuf = new byte[digest.getDigestSize()]; - - byte[] bytes = spki.getPublicKeyData().getBytes(); - digest.update(bytes, 0, bytes.length); - digest.doFinal(resBuf, 0); - return resBuf; - } - - public static void main( - String[] args) - { - runTest(new GenerationTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GetCRLTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GetCRLTest.java deleted file mode 100644 index 9156ce4d2..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GetCRLTest.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.util.Date; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.asn1.ASN1GeneralizedTime; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.cmc.GetCRL; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x500.X500NameBuilder; -import com.fr.third.org.bouncycastle.asn1.x500.style.BCStyle; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; -import com.fr.third.org.bouncycastle.asn1.x509.ReasonFlags; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class GetCRLTest - extends SimpleTest -{ - - public static void main(String[] args) - { - runTest(new GetCRLTest()); - } - - public String getName() - { - return "GetCRLTest"; - } - - public void performTest() - throws Exception - { - - { - X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE); - builder.addRDN(BCStyle.C, "AU"); - X500Name name = new X500Name(builder.build().toString()); - - GetCRL crl = new GetCRL( - name, - new GeneralName(GeneralName.rfc822Name, "/"), - new ASN1GeneralizedTime(new Date()), - new ReasonFlags(ReasonFlags.affiliationChanged) - ); - - byte[] b = crl.getEncoded(); - - GetCRL crlResp = GetCRL.getInstance(b); - - isEquals("IssuerName", crl.getIssuerName(), crlResp.getIssuerName()); - isEquals("cRLName", crl.getcRLName(), crlResp.getcRLName()); - isEquals("time", crl.getTime(), crlResp.getTime()); - isEquals("reasons", crl.getReasons(), crlResp.getReasons()); - - try - { - GetCRL.getInstance(new DERSequence(new ASN1Encodable[0])); - fail("Must not accept sequence less than 1"); - } - catch (Throwable t) - { - isEquals("", t.getClass(), IllegalArgumentException.class); - } - - try - { - GetCRL.getInstance(new DERSequence(new ASN1Encodable[5])); - fail("Must not accept sequence larger than 5"); - } - catch (Throwable t) - { - isEquals("", t.getClass(), IllegalArgumentException.class); - } - } - - { // Permutate on options test all possible combinations. - - X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE); - builder.addRDN(BCStyle.C, "AU"); - X500Name name = new X500Name(builder.build().toString()); - GeneralName generalName = null; - ASN1GeneralizedTime generalizedTime = null; - ReasonFlags flags = null; - - for (int t = 0; t < 8; t++) - { - if ((t & 1) == 1) - { - generalName = new GeneralName(GeneralName.rfc822Name, "/"); - } - if ((t & 2) == 2) - { - generalizedTime = new ASN1GeneralizedTime(new Date()); - } - - if ((t & 4) == 4) - { - flags = new ReasonFlags(ReasonFlags.affiliationChanged); - } - - - GetCRL crl = new GetCRL( - name, - generalName, - generalizedTime, - flags - ); - - byte[] b = crl.getEncoded(); - - GetCRL crlResp = GetCRL.getInstance(b); - - isEquals("IssuerName", crl.getIssuerName(), crlResp.getIssuerName()); - isEquals("cRLName", crl.getcRLName(), crlResp.getcRLName()); - isEquals("time", crl.getTime(), crlResp.getTime()); - isEquals("reasons", crl.getReasons(), crlResp.getReasons()); - - } - } - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GetCertTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GetCertTest.java deleted file mode 100644 index b5844813a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/GetCertTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.cmc.GetCert; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class GetCertTest extends SimpleTest -{ - public static void main(String[] args) { - runTest(new GetCertTest()); - } - - public String getName() - { - return "GetCertTest"; - } - - public void performTest() - throws Exception - { - GetCert gs = new GetCert(new GeneralName(GeneralName.dNSName,"fish"),new BigInteger("109")); - byte[] b = gs.getEncoded(); - GetCert gsResp = GetCert.getInstance(b); - - isEquals("Issuer Name",gs.getIssuerName(), gsResp.getIssuerName()); - isEquals("Serial Number",gs.getSerialNumber(), gsResp.getSerialNumber()); - - try { - GetCert.getInstance(new DERSequence(new ASN1Integer(1L))); - fail("Sequence must be length of 2"); - } catch (Throwable t) { - isEquals("Wrong exception",t.getClass(), IllegalArgumentException.class); - } - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/IdentityProofV2Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/IdentityProofV2Test.java deleted file mode 100644 index 2fd1a4efa..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/IdentityProofV2Test.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.cmc.IdentityProofV2; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class IdentityProofV2Test - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new IdentityProofV2Test()); - } - - public String getName() - { - return "IdentityProofV2"; - } - - public void performTest() - throws Exception - { - IdentityProofV2 proofV2 = new IdentityProofV2( - new AlgorithmIdentifier(PKCSObjectIdentifiers.encryptionAlgorithm, new ASN1Integer(10L)), - new AlgorithmIdentifier(PKCSObjectIdentifiers.bagtypes, new ASN1Integer(10L)), - "Cats".getBytes() - ); - - byte[] b = proofV2.getEncoded(); - IdentityProofV2 proofV2Res = IdentityProofV2.getInstance(b); - - isEquals("proofAldID", proofV2.getProofAlgID(), proofV2Res.getProofAlgID()); - isEquals("macAlgId", proofV2.getMacAlgId(), proofV2Res.getMacAlgId()); - isTrue("witness", areEqual(proofV2.getWitness(), proofV2Res.getWitness())); - - - try - { - IdentityProofV2.getInstance(new DERSequence(new ASN1Encodable[0])); - fail("Sequence must be length of 3"); - } - catch (Throwable t) - { - isEquals("Exception incorrect", t.getClass(), IllegalArgumentException.class); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/InputStreamTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/InputStreamTest.java deleted file mode 100644 index 0274bb4cd..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/InputStreamTest.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class InputStreamTest - extends SimpleTest -{ - private static final byte[] outOfBoundsLength = new byte[]{(byte)0x30, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff}; - private static final byte[] negativeLength = new byte[]{(byte)0x30, (byte)0x84, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff}; - private static final byte[] outsideLimitLength = new byte[]{(byte)0x30, (byte)0x83, (byte)0x0f, (byte)0xff, (byte)0xff}; - - private static final byte[] classCast1 = Base64.decode("p1AkHmYAvfOEIrL4ESfrNg=="); - private static final byte[] classCast2 = Base64.decode("JICNbaBUTTq7uxj5mg=="); - private static final byte[] classCast3 = Base64.decode("JAKzADNCxhrrBSVS"); - private static final byte[] memoryError1 = Base64.decode("vm66gOiEe+FV/NvujMwSkUp5Lffw5caQlaRU5sdMPC70IGWmyK2/"); - private static final byte[] memoryError2 = Base64.decode("vm4ogOSEfVGsS3w+KTzb2A0ALYR8VBOQqQeuRwnsPC4AAGWEDLjd"); - - public String getName() - { - return "InputStream"; - } - - public void performTest() - throws Exception - { - ASN1InputStream aIn = new ASN1InputStream(outOfBoundsLength); - - try - { - aIn.readObject(); - fail("out of bounds length not detected."); - } - catch (IOException e) - { - if (!e.getMessage().startsWith("DER length more than 4 bytes")) - { - fail("wrong exception: " + e.getMessage()); - } - } - - aIn = new ASN1InputStream(negativeLength); - - try - { - aIn.readObject(); - fail("negative length not detected."); - } - catch (IOException e) - { - if (!e.getMessage().equals("corrupted stream - negative length found")) - { - fail("wrong exception: " + e.getMessage()); - } - } - - aIn = new ASN1InputStream(outsideLimitLength); - - try - { - aIn.readObject(); - fail("outside limit length not detected."); - } - catch (IOException e) - { - if (!e.getMessage().equals("corrupted stream - out of bounds length found: 1048575 >= 5")) - { - fail("wrong exception: " + e.getMessage()); - } - } - - testWithByteArray(classCast1, "unknown object encountered: class com.fr.third.org.bouncycastle.asn1.DLApplicationSpecific"); - testWithByteArray(classCast2, "unknown object encountered: class com.fr.third.org.bouncycastle.asn1.BERTaggedObjectParser"); - testWithByteArray(classCast3, "unknown object encountered in constructed OCTET STRING: class com.fr.third.org.bouncycastle.asn1.DLTaggedObject"); - - testWithByteArray(memoryError1, "corrupted stream - out of bounds length found: 2078365180 >= 39"); - testWithByteArray(memoryError2, "corrupted stream - out of bounds length found: 2102504523 >= 39"); - } - - private void testWithByteArray(byte[] data, String message) - { - try - { - ASN1InputStream input = new ASN1InputStream(data); - - ASN1Primitive p; - while ((p = input.readObject()) != null) - { - ASN1Sequence asn1 = ASN1Sequence.getInstance(p); - for (int i = 0; i < asn1.size(); i++) - { - asn1.getObjectAt(i); - } - } - } - catch (java.io.IOException e) - { - isEquals(e.getMessage(), message, e.getMessage()); - } - } - - public static void main( - String[] args) - { - runTest(new InputStreamTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/Iso4217CurrencyCodeUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/Iso4217CurrencyCodeUnitTest.java deleted file mode 100644 index 27a03252a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/Iso4217CurrencyCodeUnitTest.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.x509.qualified.Iso4217CurrencyCode; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class Iso4217CurrencyCodeUnitTest - extends SimpleTest -{ - private static final String ALPHABETIC_CURRENCY_CODE = "AUD"; - private static final int NUMERIC_CURRENCY_CODE = 1; - - public String getName() - { - return "Iso4217CurrencyCode"; - } - - public void performTest() - throws Exception - { - // - // alphabetic - // - Iso4217CurrencyCode cc = new Iso4217CurrencyCode(ALPHABETIC_CURRENCY_CODE); - - checkNumeric(cc, ALPHABETIC_CURRENCY_CODE); - - cc = Iso4217CurrencyCode.getInstance(cc); - - checkNumeric(cc, ALPHABETIC_CURRENCY_CODE); - - ASN1Primitive obj = cc.toASN1Primitive(); - - cc = Iso4217CurrencyCode.getInstance(obj); - - checkNumeric(cc, ALPHABETIC_CURRENCY_CODE); - - // - // numeric - // - cc = new Iso4217CurrencyCode(NUMERIC_CURRENCY_CODE); - - checkNumeric(cc, NUMERIC_CURRENCY_CODE); - - cc = Iso4217CurrencyCode.getInstance(cc); - - checkNumeric(cc, NUMERIC_CURRENCY_CODE); - - obj = cc.toASN1Primitive(); - - cc = Iso4217CurrencyCode.getInstance(obj); - - checkNumeric(cc, NUMERIC_CURRENCY_CODE); - - cc = Iso4217CurrencyCode.getInstance(null); - - if (cc != null) - { - fail("null getInstance() failed."); - } - - try - { - Iso4217CurrencyCode.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - new Iso4217CurrencyCode("ABCD"); - - fail("constructor failed to detect out of range currencycode."); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - new Iso4217CurrencyCode(0); - - fail("constructor failed to detect out of range small numeric code."); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - new Iso4217CurrencyCode(1000); - - fail("constructor failed to detect out of range large numeric code."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkNumeric( - Iso4217CurrencyCode cc, - String code) - { - if (!cc.isAlphabetic()) - { - fail("non-alphabetic code found when one expected."); - } - - if (!cc.getAlphabetic().equals(code)) - { - fail("string codes don't match."); - } - } - - private void checkNumeric( - Iso4217CurrencyCode cc, - int code) - { - if (cc.isAlphabetic()) - { - fail("alphabetic code found when one not expected."); - } - - if (cc.getNumeric() != code) - { - fail("numeric codes don't match."); - } - } - - public static void main( - String[] args) - { - runTest(new Iso4217CurrencyCodeUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/IssuingDistributionPointUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/IssuingDistributionPointUnitTest.java deleted file mode 100644 index 57d3a40ab..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/IssuingDistributionPointUnitTest.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x509.DistributionPointName; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralNames; -import com.fr.third.org.bouncycastle.asn1.x509.IssuingDistributionPoint; -import com.fr.third.org.bouncycastle.asn1.x509.ReasonFlags; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class IssuingDistributionPointUnitTest - extends SimpleTest -{ - public String getName() - { - return "IssuingDistributionPoint"; - } - - public void performTest() - throws Exception - { - DistributionPointName name = new DistributionPointName( - new GeneralNames(new GeneralName(new X500Name("cn=test")))); - ReasonFlags reasonFlags = new ReasonFlags(ReasonFlags.cACompromise); - - checkPoint(6, name, true, true, reasonFlags, true, true); - - checkPoint(2, name, false, false, reasonFlags, false, false); - - checkPoint(0, null, false, false, null, false, false); - - try - { - IssuingDistributionPoint.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkPoint( - int size, - DistributionPointName distributionPoint, - boolean onlyContainsUserCerts, - boolean onlyContainsCACerts, - ReasonFlags onlySomeReasons, - boolean indirectCRL, - boolean onlyContainsAttributeCerts) - throws IOException - { - IssuingDistributionPoint point = new IssuingDistributionPoint(distributionPoint, onlyContainsUserCerts, onlyContainsCACerts, onlySomeReasons, indirectCRL, onlyContainsAttributeCerts); - - checkValues(point, distributionPoint, onlyContainsUserCerts, onlyContainsCACerts, onlySomeReasons, indirectCRL, onlyContainsAttributeCerts); - - ASN1Sequence seq = ASN1Sequence.getInstance(ASN1Primitive.fromByteArray(point.getEncoded())); - - if (seq.size() != size) - { - fail("size mismatch"); - } - - point = IssuingDistributionPoint.getInstance(seq); - - checkValues(point, distributionPoint, onlyContainsUserCerts, onlyContainsCACerts, onlySomeReasons, indirectCRL, onlyContainsAttributeCerts); - } - - private void checkValues(IssuingDistributionPoint point, DistributionPointName distributionPoint, boolean onlyContainsUserCerts, boolean onlyContainsCACerts, ReasonFlags onlySomeReasons, boolean indirectCRL, boolean onlyContainsAttributeCerts) - { - if (point.onlyContainsUserCerts() != onlyContainsUserCerts) - { - fail("mismatch on onlyContainsUserCerts"); - } - - if (point.onlyContainsCACerts() != onlyContainsCACerts) - { - fail("mismatch on onlyContainsCACerts"); - } - - if (point.isIndirectCRL() != indirectCRL) - { - fail("mismatch on indirectCRL"); - } - - if (point.onlyContainsAttributeCerts() != onlyContainsAttributeCerts) - { - fail("mismatch on onlyContainsAttributeCerts"); - } - - if (!isEquiv(onlySomeReasons, point.getOnlySomeReasons())) - { - fail("mismatch on onlySomeReasons"); - } - - if (!isEquiv(distributionPoint, point.getDistributionPoint())) - { - fail("mismatch on distributionPoint"); - } - } - - private boolean isEquiv(Object o1, Object o2) - { - if (o1 == null) - { - return o2 == null; - } - - return o1.equals(o2); - } - - public static void main( - String[] args) - { - runTest(new IssuingDistributionPointUnitTest()); - } -} \ No newline at end of file diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/KeyUsageTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/KeyUsageTest.java deleted file mode 100644 index 270c52383..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/KeyUsageTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.x509.KeyUsage; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class KeyUsageTest - extends SimpleTest -{ - public String getName() - { - return "KeyUsage"; - } - - public void performTest() - throws IOException - { - BitStringConstantTester.testFlagValueCorrect(0, KeyUsage.digitalSignature); - BitStringConstantTester.testFlagValueCorrect(1, KeyUsage.nonRepudiation); - BitStringConstantTester.testFlagValueCorrect(2, KeyUsage.keyEncipherment); - BitStringConstantTester.testFlagValueCorrect(3, KeyUsage.dataEncipherment); - BitStringConstantTester.testFlagValueCorrect(4, KeyUsage.keyAgreement); - BitStringConstantTester.testFlagValueCorrect(5, KeyUsage.keyCertSign); - BitStringConstantTester.testFlagValueCorrect(6, KeyUsage.cRLSign); - BitStringConstantTester.testFlagValueCorrect(7, KeyUsage.encipherOnly); - BitStringConstantTester.testFlagValueCorrect(8, KeyUsage.decipherOnly); - - if (!new KeyUsage(KeyUsage.keyCertSign).hasUsages(KeyUsage.keyCertSign)) - { - fail("usages bit test failed 1"); - } - - if (new KeyUsage(KeyUsage.cRLSign).hasUsages(KeyUsage.keyCertSign)) - { - fail("usages bit test failed 2"); - } - - if (!new KeyUsage(KeyUsage.cRLSign | KeyUsage.decipherOnly).hasUsages(KeyUsage.cRLSign | KeyUsage.decipherOnly)) - { - fail("usages bit test failed 3"); - } - - if (new KeyUsage(KeyUsage.cRLSign | KeyUsage.decipherOnly).hasUsages(KeyUsage.cRLSign | KeyUsage.decipherOnly | KeyUsage.keyCertSign)) - { - fail("usages bit test failed 4"); - } - } - - public static void main( - String[] args) - { - runTest(new KeyUsageTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/LDSSecurityObjectUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/LDSSecurityObjectUnitTest.java deleted file mode 100644 index d4d8e7a78..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/LDSSecurityObjectUnitTest.java +++ /dev/null @@ -1,216 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; -import java.util.Random; - -import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.icao.DataGroupHash; -import com.fr.third.org.bouncycastle.asn1.icao.LDSSecurityObject; -import com.fr.third.org.bouncycastle.asn1.icao.LDSVersionInfo; -import com.fr.third.org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class LDSSecurityObjectUnitTest - extends SimpleTest -{ - public String getName() - { - return "LDSSecurityObject"; - } - - private byte[] generateHash() - { - Random rand = new Random(); - byte[] bytes = new byte[20]; - - for (int i = 0; i != bytes.length; i++) - { - bytes[i] = (byte)rand.nextInt(); - } - - return bytes; - } - - public void performTest() - throws Exception - { - AlgorithmIdentifier algoId = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1); - DataGroupHash[] datas = new DataGroupHash[2]; - - datas[0] = new DataGroupHash(1, new DEROctetString(generateHash())); - datas[1] = new DataGroupHash(2, new DEROctetString(generateHash())); - - LDSSecurityObject so = new LDSSecurityObject(algoId, datas); - - checkConstruction(so, algoId, datas); - - LDSVersionInfo versionInfo = new LDSVersionInfo("Hello", "world"); - - so = new LDSSecurityObject(algoId, datas, versionInfo); - - checkConstruction(so, algoId, datas, versionInfo); - - try - { - LDSSecurityObject.getInstance(null); - } - catch (Exception e) - { - fail("getInstance() failed to handle null."); - } - - try - { - LDSSecurityObject.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - ASN1EncodableVector v = new ASN1EncodableVector(); - - LDSSecurityObject.getInstance(new DERSequence(v)); - - fail("constructor failed to detect empty sequence."); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - new LDSSecurityObject(algoId, new DataGroupHash[1]); - - fail("constructor failed to detect small DataGroupHash array."); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - new LDSSecurityObject(algoId, new DataGroupHash[LDSSecurityObject.ub_DataGroups + 1]); - - fail("constructor failed to out of bounds DataGroupHash array."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - LDSSecurityObject so, - AlgorithmIdentifier digestAlgorithmIdentifier, - DataGroupHash[] datagroupHash) - throws IOException - { - checkStatement(so, digestAlgorithmIdentifier, datagroupHash, null); - - so = LDSSecurityObject.getInstance(so); - - checkStatement(so, digestAlgorithmIdentifier, datagroupHash, null); - - ASN1InputStream aIn = new ASN1InputStream(so.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - so = LDSSecurityObject.getInstance(seq); - - checkStatement(so, digestAlgorithmIdentifier, datagroupHash, null); - } - - private void checkConstruction( - LDSSecurityObject so, - AlgorithmIdentifier digestAlgorithmIdentifier, - DataGroupHash[] datagroupHash, - LDSVersionInfo versionInfo) - throws IOException - { - if (so.getVersion() != 1) - { - fail("version number not 1"); - } - - checkStatement(so, digestAlgorithmIdentifier, datagroupHash, versionInfo); - - so = LDSSecurityObject.getInstance(so); - - checkStatement(so, digestAlgorithmIdentifier, datagroupHash, versionInfo); - - ASN1InputStream aIn = new ASN1InputStream(so.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - so = LDSSecurityObject.getInstance(seq); - - checkStatement(so, digestAlgorithmIdentifier, datagroupHash, versionInfo); - } - - private void checkStatement( - LDSSecurityObject so, - AlgorithmIdentifier digestAlgorithmIdentifier, - DataGroupHash[] datagroupHash, - LDSVersionInfo versionInfo) - { - if (digestAlgorithmIdentifier != null) - { - if (!so.getDigestAlgorithmIdentifier().equals(digestAlgorithmIdentifier)) - { - fail("ids don't match."); - } - } - else if (so.getDigestAlgorithmIdentifier() != null) - { - fail("digest algorithm Id found when none expected."); - } - - if (datagroupHash != null) - { - DataGroupHash[] datas = so.getDatagroupHash(); - - for (int i = 0; i != datas.length; i++) - { - if (!datagroupHash[i].equals(datas[i])) - { - fail("name registration authorities don't match."); - } - } - } - else if (so.getDatagroupHash() != null) - { - fail("data hash groups found when none expected."); - } - - if (versionInfo != null) - { - if (!versionInfo.equals(so.getVersionInfo())) - { - fail("versionInfo doesn't match"); - } - } - else if (so.getVersionInfo() != null) - { - fail("version info found when none expected."); - } - } - - public static void main( - String[] args) - { - runTest(new LDSSecurityObjectUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/LinkedCertificateTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/LinkedCertificateTest.java deleted file mode 100644 index 5ff2c55d6..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/LinkedCertificateTest.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.bc.LinkedCertificate; -import com.fr.third.org.bouncycastle.asn1.nist.NISTObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.asn1.x509.DigestInfo; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralNames; - -public class LinkedCertificateTest - extends ASN1UnitTest -{ - public String getName() - { - return "LinkedCertificate"; - } - - public void performTest() - throws Exception - { - DigestInfo digInfo = new DigestInfo( - new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256), new byte[32]); - GeneralName certLocation = new GeneralName(GeneralName.uniformResourceIdentifier, "https://www.bouncycastle.org/certs"); - X500Name certIssuer = null; - GeneralNames cACerts = null; - - LinkedCertificate linked = new LinkedCertificate(digInfo, certLocation); - - checkConstruction(linked, digInfo, certLocation, certIssuer, cACerts); - - certIssuer = new X500Name("CN=Test"); - cACerts = new GeneralNames(new GeneralName(new X500Name("CN=CA Test"))); - - linked = new LinkedCertificate(digInfo, certLocation, certIssuer, cACerts); - - checkConstruction(linked, digInfo, certLocation, certIssuer, cACerts); - - linked = LinkedCertificate.getInstance(null); - - if (linked != null) - { - fail("null getInstance() failed."); - } - - try - { - LinkedCertificate.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - LinkedCertificate linked, - DigestInfo digestInfo, GeneralName certLocation, X500Name certIssuer, GeneralNames caCerts) - throws IOException - { - checkValues(linked, digestInfo, certLocation, certIssuer, caCerts); - - linked = LinkedCertificate.getInstance(linked); - - checkValues(linked, digestInfo, certLocation, certIssuer, caCerts); - - ASN1InputStream aIn = new ASN1InputStream(linked.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - linked = LinkedCertificate.getInstance(seq); - - checkValues(linked, digestInfo, certLocation, certIssuer, caCerts); - } - - private void checkValues( - LinkedCertificate linked, - DigestInfo digestInfo, GeneralName certLocation, X500Name certIssuer, GeneralNames caCerts) - { - checkMandatoryField("digest", digestInfo, linked.getDigest()); - checkMandatoryField("certLocatin", certLocation, linked.getCertLocation()); - checkOptionalField("certIssuer", certIssuer, linked.getCertIssuer()); - checkOptionalField("caCerts", caCerts, linked.getCACerts()); - } - - public static void main( - String[] args) - { - runTest(new LinkedCertificateTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/LocaleTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/LocaleTest.java deleted file mode 100644 index dc3c2a7a1..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/LocaleTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.text.DateFormat; -import java.util.Date; -import java.util.Locale; - -import com.fr.third.org.bouncycastle.asn1.DERGeneralizedTime; -import com.fr.third.org.bouncycastle.asn1.DERUTCTime; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class LocaleTest - extends SimpleTest -{ - public String getName() - { - return "LocaleTest"; - } - - private void doTestLocale(Locale l) - throws Exception - { - long time = 1538063166000L; - String timeString = "180927154606GMT+00:00"; - String longTimeString = "20180927154606Z"; - - Locale.setDefault(l); - - isTrue("a", time == new DERUTCTime(timeString).getAdjustedDate().getTime()); - isTrue("b", time == new DERGeneralizedTime(longTimeString).getDate().getTime()); - - isTrue("c", time == new DERUTCTime(new Date(time)).getAdjustedDate().getTime()); - isTrue("d", time == new DERGeneralizedTime(new Date(time)).getDate().getTime()); - - Date d = new Date(); - - isTrue("e", (d.getTime() - (d.getTime() % 1000)) == new DERUTCTime(d).getAdjustedDate().getTime()); - isTrue("f", (d.getTime() - (d.getTime() % 1000)) == new DERGeneralizedTime(d).getDate().getTime()); - } - - public void performTest() - throws Exception - { - Locale defLocale = Locale.getDefault(); - - Locale list[] = DateFormat.getAvailableLocales(); - for (int i = 0; i != list.length; i++) - { - if (!list[i].getCountry().equals("TH") // skip Thailand as it appears the JVM is now a day out on this one. - && !list[i].getCountry().equals("JP")) // and it appears the change in era is causing issues here. - { - doTestLocale(list[i]); - } - } - - Locale.setDefault(defLocale); - } - - public static void main( - String[] args) - { - runTest(new LocaleTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/LraPopWitnessTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/LraPopWitnessTest.java deleted file mode 100644 index 6a1ce3e74..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/LraPopWitnessTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.asn1.cmc.LraPopWitness; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class LraPopWitnessTest - extends SimpleTest -{ - - public static void main(String[] args) - { - runTest(new LraPopWitnessTest()); - } - - public String getName() - { - return "LraPopWitnessTest"; - } - - public void performTest() - throws Exception - { - LraPopWitness popWitness = new LraPopWitness(new BodyPartID(10L), new DERSequence(new ASN1Integer(20L))); - byte[] b = popWitness.getEncoded(); - LraPopWitness popWitnessResult = LraPopWitness.getInstance(b); - - isTrue("BodyIds", Arrays.areEqual(popWitness.getBodyIds(), popWitnessResult.getBodyIds())); - isEquals("PkiDataBody", popWitness.getPkiDataBodyid(), popWitnessResult.getPkiDataBodyid()); - - try { - LraPopWitness.getInstance(new DERSequence()); - fail("Sequence length must be 2"); - } catch (Throwable t) { - isEquals("Exception class",t.getClass(), IllegalArgumentException.class); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/MiscTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/MiscTest.java deleted file mode 100644 index 980c1d0b8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/MiscTest.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.asn1.ASN1Enumerated; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1OutputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.BERSequence; -import com.fr.third.org.bouncycastle.asn1.DERBitString; -import com.fr.third.org.bouncycastle.asn1.DERIA5String; -import com.fr.third.org.bouncycastle.asn1.misc.CAST5CBCParameters; -import com.fr.third.org.bouncycastle.asn1.misc.IDEACBCPar; -import com.fr.third.org.bouncycastle.asn1.misc.NetscapeCertType; -import com.fr.third.org.bouncycastle.asn1.misc.NetscapeRevocationURL; -import com.fr.third.org.bouncycastle.asn1.misc.VerisignCzagExtension; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class MiscTest - extends SimpleTest -{ - public void shouldFailOnExtraData() - throws Exception - { - // basic construction - DERBitString s1 = new DERBitString(new byte[0], 0); - - ASN1Primitive.fromByteArray(s1.getEncoded()); - - ASN1Primitive.fromByteArray(new BERSequence(s1).getEncoded()); - - try - { - ASN1Primitive obj = ASN1Primitive.fromByteArray(Arrays.concatenate(s1.getEncoded(), new byte[1])); - fail("no exception"); - } - catch (IOException e) - { - if (!"Extra data detected in stream".equals(e.getMessage())) - { - fail("wrong exception"); - } - } - } - - public void derIntegerTest() - throws Exception - { - try - { - new ASN1Integer(new byte[] { 0, 0, 0, 1}); - } - catch (IllegalArgumentException e) - { - isTrue("wrong exc", "malformed integer".equals(e.getMessage())); - } - - try - { - new ASN1Integer(new byte[] {(byte)0xff, (byte)0x80, 0, 1}); - } - catch (IllegalArgumentException e) - { - isTrue("wrong exc", "malformed integer".equals(e.getMessage())); - } - - try - { - new ASN1Enumerated(new byte[] { 0, 0, 0, 1}); - } - catch (IllegalArgumentException e) - { - isTrue("wrong exc", "malformed enumerated".equals(e.getMessage())); - } - - try - { - new ASN1Enumerated(new byte[] {(byte)0xff, (byte)0x80, 0, 1}); - } - catch (IllegalArgumentException e) - { - isTrue("wrong exc", "malformed enumerated".equals(e.getMessage())); - } - } - - public void performTest() - throws Exception - { - byte[] testIv = { 1, 2, 3, 4, 5, 6, 7, 8 }; - - ASN1Encodable[] values = { - new CAST5CBCParameters(testIv, 128), - new NetscapeCertType(NetscapeCertType.smime), - new VerisignCzagExtension(new DERIA5String("hello")), - new IDEACBCPar(testIv), - new NetscapeRevocationURL(new DERIA5String("http://test")) - }; - - byte[] data = Base64.decode("MA4ECAECAwQFBgcIAgIAgAMCBSAWBWhlbGxvMAoECAECAwQFBgcIFgtodHRwOi8vdGVzdA=="); - - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - ASN1OutputStream aOut = ASN1OutputStream.create(bOut); - - for (int i = 0; i != values.length; i++) - { - aOut.writeObject(values[i].toASN1Primitive()); - } - - if (!areEqual(bOut.toByteArray(), data)) - { - fail("Failed data check"); - } - - ASN1InputStream aIn = new ASN1InputStream(data); - - for (int i = 0; i != values.length; i++) - { - ASN1Primitive o = aIn.readObject(); - if (!values[i].equals(o)) - { - fail("Failed equality test for " + o); - } - - if (o.hashCode() != values[i].hashCode()) - { - fail("Failed hashCode test for " + o); - } - } - - shouldFailOnExtraData(); - derIntegerTest(); - } - - public String getName() - { - return "Misc"; - } - - public static void main( - String[] args) - { - runTest(new MiscTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ModCertTemplateTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ModCertTemplateTest.java deleted file mode 100644 index 2522719dc..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ModCertTemplateTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERTaggedObject; -import com.fr.third.org.bouncycastle.asn1.DLSequence; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartList; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartPath; -import com.fr.third.org.bouncycastle.asn1.cmc.ModCertTemplate; -import com.fr.third.org.bouncycastle.asn1.crmf.CertTemplate; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class ModCertTemplateTest - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new ModCertTemplateTest()); - } - - public String getName() - { - return "ModCertTemplateTest"; - } - - public void performTest() - throws Exception - { - - BodyPartPath pkiDataReference = new BodyPartPath(new BodyPartID(10L)); - BodyPartList certReferences = new BodyPartList(new BodyPartID(12L)); - boolean replace = false; - CertTemplate certTemplate = CertTemplate.getInstance(new DLSequence(new DERTaggedObject(false, 1, new ASN1Integer(34L)))); - { - ModCertTemplate modCertTemplate = new ModCertTemplate( - pkiDataReference, - certReferences, - replace, - certTemplate - ); - - byte[] b = modCertTemplate.getEncoded(); - - ModCertTemplate modCertTemplateResult = ModCertTemplate.getInstance(b); - - isEquals("pkiDataReference", modCertTemplate.getPkiDataReference(), modCertTemplateResult.getPkiDataReference()); - isEquals("certReference", modCertTemplate.getCertReferences(), modCertTemplateResult.getCertReferences()); - isEquals("replacingFields", modCertTemplate.isReplacingFields(), modCertTemplateResult.isReplacingFields()); - isEquals("certTemplate", modCertTemplate.getCertTemplate().getSerialNumber(), modCertTemplateResult.getCertTemplate().getSerialNumber()); - } - - - { - // Test default 'result' - ModCertTemplate mct = ModCertTemplate.getInstance(new DERSequence(new ASN1Encodable[]{ - pkiDataReference, - certReferences, - certTemplate - })); - - isEquals("pkiDataReference", mct.getPkiDataReference(), pkiDataReference); - isEquals("certReference", mct.getCertReferences(), certReferences); - isEquals("DEFAULT TRUE on replacingFields", mct.isReplacingFields(), true); - isEquals("certTemplate", mct.getCertTemplate().getSerialNumber(), certTemplate.getSerialNumber()); - } - - - try - { - ModCertTemplate.getInstance(new DERSequence()); - fail("Sequence must be 3 or 4."); - } - catch (Throwable t) - { - isEquals(t.getClass(), IllegalArgumentException.class); - } - - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/MonetaryLimitUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/MonetaryLimitUnitTest.java deleted file mode 100644 index 3d8b20b75..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/MonetaryLimitUnitTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.MonetaryLimit; - -public class MonetaryLimitUnitTest - extends ASN1UnitTest -{ - public String getName() - { - return "MonetaryLimit"; - } - - public void performTest() - throws Exception - { - String currency = "AUD"; - int amount = 1; - int exponent = 2; - - MonetaryLimit limit = new MonetaryLimit(currency, amount, exponent); - - checkConstruction(limit, currency, amount, exponent); - - limit = MonetaryLimit.getInstance(null); - - if (limit != null) - { - fail("null getInstance() failed."); - } - - try - { - MonetaryLimit.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - MonetaryLimit limit, - String currency, - int amount, - int exponent) - throws IOException - { - checkValues(limit, currency, amount, exponent); - - limit = MonetaryLimit.getInstance(limit); - - checkValues(limit, currency, amount, exponent); - - ASN1InputStream aIn = new ASN1InputStream(limit.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - limit = MonetaryLimit.getInstance(seq); - - checkValues(limit, currency, amount, exponent); - } - - private void checkValues( - MonetaryLimit limit, - String currency, - int amount, - int exponent) - { - checkMandatoryField("currency", currency, limit.getCurrency()); - checkMandatoryField("amount", amount, limit.getAmount().intValue()); - checkMandatoryField("exponent", exponent, limit.getExponent().intValue()); - } - - public static void main( - String[] args) - { - runTest(new MonetaryLimitUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/MonetaryValueUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/MonetaryValueUnitTest.java deleted file mode 100644 index c26197d60..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/MonetaryValueUnitTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.x509.qualified.Iso4217CurrencyCode; -import com.fr.third.org.bouncycastle.asn1.x509.qualified.MonetaryValue; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class MonetaryValueUnitTest - extends SimpleTest -{ - private static final int TEST_AMOUNT = 100; - private static final int ZERO_EXPONENT = 0; - - private static final String CURRENCY_CODE = "AUD"; - - public String getName() - { - return "MonetaryValue"; - } - - public void performTest() - throws Exception - { - MonetaryValue mv = new MonetaryValue(new Iso4217CurrencyCode(CURRENCY_CODE), TEST_AMOUNT, ZERO_EXPONENT); - - checkValues(mv, TEST_AMOUNT, ZERO_EXPONENT); - - mv = MonetaryValue.getInstance(mv); - - checkValues(mv, TEST_AMOUNT, ZERO_EXPONENT); - - ASN1InputStream aIn = new ASN1InputStream(mv.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - mv = MonetaryValue.getInstance(seq); - - checkValues(mv, TEST_AMOUNT, ZERO_EXPONENT); - - mv = MonetaryValue.getInstance(null); - - if (mv != null) - { - fail("null getInstance() failed."); - } - - try - { - MonetaryValue.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkValues( - MonetaryValue mv, - int amount, - int exponent) - { - if (mv.getAmount().intValue() != amount) - { - fail("amounts don't match."); - } - - if (mv.getExponent().intValue() != exponent) - { - fail("exponents don't match."); - } - - Iso4217CurrencyCode cc = mv.getCurrency(); - - if (!cc.getAlphabetic().equals(CURRENCY_CODE)) - { - fail("currency code wrong"); - } - } - - public static void main( - String[] args) - { - runTest(new MonetaryValueUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/NameOrPseudonymUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/NameOrPseudonymUnitTest.java deleted file mode 100644 index 700197202..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/NameOrPseudonymUnitTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.ASN1String; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; -import com.fr.third.org.bouncycastle.asn1.x509.sigi.NameOrPseudonym; - -public class NameOrPseudonymUnitTest - extends ASN1UnitTest -{ - public String getName() - { - return "NameOrPseudonym"; - } - - public void performTest() - throws Exception - { - String pseudonym = "pseudonym"; - DirectoryString surname = new DirectoryString("surname"); - ASN1Sequence givenName = new DERSequence(new DirectoryString("givenName")); - - NameOrPseudonym id = new NameOrPseudonym(pseudonym); - - checkConstruction(id, pseudonym, null, null); - - id = new NameOrPseudonym(surname, givenName); - - checkConstruction(id, null, surname, givenName); - - id = NameOrPseudonym.getInstance(null); - - if (id != null) - { - fail("null getInstance() failed."); - } - - try - { - NameOrPseudonym.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - NameOrPseudonym id, - String pseudonym, - DirectoryString surname, - ASN1Sequence givenName) - throws IOException - { - checkValues(id, pseudonym, surname, givenName); - - id = NameOrPseudonym.getInstance(id); - - checkValues(id, pseudonym, surname, givenName); - - ASN1InputStream aIn = new ASN1InputStream(id.toASN1Primitive().getEncoded()); - - if (surname != null) - { - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - id = NameOrPseudonym.getInstance(seq); - } - else - { - ASN1String s = (ASN1String)aIn.readObject(); - - id = NameOrPseudonym.getInstance(s); - } - - checkValues(id, pseudonym, surname, givenName); - } - - private void checkValues( - NameOrPseudonym id, - String pseudonym, - DirectoryString surname, - ASN1Sequence givenName) - { - - if (surname != null) - { - checkMandatoryField("surname", surname, id.getSurname()); - checkMandatoryField("givenName", givenName, new DERSequence(id.getGivenName()[0])); - } - else - { - checkOptionalField("pseudonym", new DirectoryString(pseudonym), id.getPseudonym()); - } - } - - public static void main( - String[] args) - { - runTest(new NameOrPseudonymUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/NamingAuthorityUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/NamingAuthorityUnitTest.java deleted file mode 100644 index c06d61a8f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/NamingAuthorityUnitTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.NamingAuthority; -import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; - -public class NamingAuthorityUnitTest - extends ASN1UnitTest -{ - public String getName() - { - return "NamingAuthority"; - } - - public void performTest() - throws Exception - { - ASN1ObjectIdentifier namingAuthorityID = new ASN1ObjectIdentifier("1.2.3"); - String namingAuthorityURL = "url"; - DirectoryString namingAuthorityText = new DirectoryString("text"); - - NamingAuthority auth = new NamingAuthority(namingAuthorityID, namingAuthorityURL, namingAuthorityText); - - checkConstruction(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText); - - auth = new NamingAuthority(null, namingAuthorityURL, namingAuthorityText); - - checkConstruction(auth, null, namingAuthorityURL, namingAuthorityText); - - auth = new NamingAuthority(namingAuthorityID, null, namingAuthorityText); - - checkConstruction(auth, namingAuthorityID, null, namingAuthorityText); - - auth = new NamingAuthority(namingAuthorityID, namingAuthorityURL, null); - - checkConstruction(auth, namingAuthorityID, namingAuthorityURL, null); - - auth = NamingAuthority.getInstance(null); - - if (auth != null) - { - fail("null getInstance() failed."); - } - - try - { - NamingAuthority.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - NamingAuthority auth, - ASN1ObjectIdentifier namingAuthorityID, - String namingAuthorityURL, - DirectoryString namingAuthorityText) - throws IOException - { - checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText); - - auth = NamingAuthority.getInstance(auth); - - checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText); - - ASN1InputStream aIn = new ASN1InputStream(auth.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - auth = NamingAuthority.getInstance(seq); - - checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText); - } - - private void checkValues( - NamingAuthority auth, - ASN1ObjectIdentifier namingAuthorityId, - String namingAuthorityURL, - DirectoryString namingAuthorityText) - { - checkOptionalField("namingAuthorityId", namingAuthorityId, auth.getNamingAuthorityId()); - checkOptionalField("namingAuthorityURL", namingAuthorityURL, auth.getNamingAuthorityUrl()); - checkOptionalField("namingAuthorityText", namingAuthorityText, auth.getNamingAuthorityText()); - } - - public static void main( - String[] args) - { - runTest(new NamingAuthorityUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/NetscapeCertTypeTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/NetscapeCertTypeTest.java deleted file mode 100644 index b0ccd2808..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/NetscapeCertTypeTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.misc.NetscapeCertType; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class NetscapeCertTypeTest - extends SimpleTest -{ - public String getName() - { - return "NetscapeCertType"; - } - - public void performTest() - throws IOException - { - BitStringConstantTester.testFlagValueCorrect(0, NetscapeCertType.sslClient); - BitStringConstantTester.testFlagValueCorrect(1, NetscapeCertType.sslServer); - BitStringConstantTester.testFlagValueCorrect(2, NetscapeCertType.smime); - BitStringConstantTester.testFlagValueCorrect(3, NetscapeCertType.objectSigning); - BitStringConstantTester.testFlagValueCorrect(4, NetscapeCertType.reserved); - BitStringConstantTester.testFlagValueCorrect(5, NetscapeCertType.sslCA); - BitStringConstantTester.testFlagValueCorrect(6, NetscapeCertType.smimeCA); - BitStringConstantTester.testFlagValueCorrect(7, NetscapeCertType.objectSigningCA); - } - - public static void main( - String[] args) - { - runTest(new NetscapeCertTypeTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OCSPTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OCSPTest.java deleted file mode 100644 index a43cd80b1..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OCSPTest.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.ByteArrayInputStream; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.ocsp.BasicOCSPResponse; -import com.fr.third.org.bouncycastle.asn1.ocsp.OCSPRequest; -import com.fr.third.org.bouncycastle.asn1.ocsp.OCSPResponse; -import com.fr.third.org.bouncycastle.asn1.ocsp.ResponseBytes; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; - -public class OCSPTest - implements Test -{ - private byte[] unsignedReq = Base64.decode( - "MEIwQDA+MDwwOjAJBgUrDgMCGgUABBRDb9GODnq7lRhSkEqw4XX24huERwQUkY4j" - + "a6eKuDlkVP9hRgkEvIWqHPECAQE="); - - private byte[] signedReq = Base64.decode( - "MIIC9jBAMD4wPDA6MAkGBSsOAwIaBQAEFENv0Y4OeruVGFKQSrDhdfbiG4RHBBTc" - + "Mr1fP+mZAxbF2ZdehWxn6mtAngIBAaCCArAwggKsMA0GCSqGSIb3DQEBBQUAA4GB" - + "AAzHBm4nL5AcRQB3Jkz7ScNeZF+GbRZ0p4kBDTnqi3IeESuso12yJhpqqyijdnj5" - + "gd4/GsSAgdluLHyYZ6wgozV7G9MDXCnFnG4PBUW05HaVX81JYAp+amVyU0NOgNrG" - + "90npVBsHb0o+UlkxNgMiEbSkp/TeGb6YURsYKhmwp7BgoIICFTCCAhEwggINMIIB" - + "dqADAgECAgEBMA0GCSqGSIb3DQEBBAUAMCUxFjAUBgNVBAoTDUJvdW5jeSBDYXN0" - + "bGUxCzAJBgNVBAYTAkFVMB4XDTA0MTAyNDEzNDc0M1oXDTA1MDIwMTEzNDc0M1ow" - + "JTEWMBQGA1UEChMNQm91bmN5IENhc3RsZTELMAkGA1UEBhMCQVUwgZ8wDQYJKoZI" - + "hvcNAQEBBQADgY0AMIGJAoGBAJBmLeIzthMHUeTkOeJ76iBxcMHY31o/i3a9VT12" - + "y2FcS/ejJmeUCMTdtwl5alOwXY66vF4DyT1VU/nJG3mHpSoqq7qrMXOIFGcXg1Wf" - + "oJRrQgTOLdQ6bod7i9ME/EjEJy70orh0nVS7NGcu0R5TjcbLde2J5zxjb/W9wqfy" - + "RovJAgMBAAGjTTBLMB0GA1UdDgQWBBTcMr1fP+mZAxbF2ZdehWxn6mtAnjAfBgNV" - + "HSMEGDAWgBTcMr1fP+mZAxbF2ZdehWxn6mtAnjAJBgNVHRMEAjAAMA0GCSqGSIb3" - + "DQEBBAUAA4GBAF/4EH1KkNrNxocJPIp7lThmG1KIVYESIadowMowrbok46ESofRF" - + "OIPku07W+e1Y1Y1KXLIiPMG3IGwrBrn04iLsbbBUiN37BcC/VyT4xKJ2MYscGjKL" - + "ua/9bU0lOyeTRAwqb8towWRd5lLYAI3RQ7dhStUTFp3Vqd803PJ/cpR6"); - - private byte[] response = Base64.decode( - "MIIFnAoBAKCCBZUwggWRBgkrBgEFBQcwAQEEggWCMIIFfjCCARehgZ8wgZwx" - + "CzAJBgNVBAYTAklOMRcwFQYDVQQIEw5BbmRocmEgcHJhZGVzaDESMBAGA1UE" - + "BxMJSHlkZXJhYmFkMQwwCgYDVQQKEwNUQ1MxDDAKBgNVBAsTA0FUQzEeMBwG" - + "A1UEAxMVVENTLUNBIE9DU1AgUmVzcG9uZGVyMSQwIgYJKoZIhvcNAQkBFhVv" - + "Y3NwQHRjcy1jYS50Y3MuY28uaW4YDzIwMDMwNDAyMTIzNDU4WjBiMGAwOjAJ" - + "BgUrDgMCGgUABBRs07IuoCWNmcEl1oHwIak1BPnX8QQUtGyl/iL9WJ1VxjxF" - + "j0hAwJ/s1AcCAQKhERgPMjAwMjA4MjkwNzA5MjZaGA8yMDAzMDQwMjEyMzQ1" - + "OFowDQYJKoZIhvcNAQEFBQADgYEAfbN0TCRFKdhsmvOdUoiJ+qvygGBzDxD/" - + "VWhXYA+16AphHLIWNABR3CgHB3zWtdy2j7DJmQ/R7qKj7dUhWLSqclAiPgFt" - + "QQ1YvSJAYfEIdyHkxv4NP0LSogxrumANcDyC9yt/W9yHjD2ICPBIqCsZLuLk" - + "OHYi5DlwWe9Zm9VFwCGgggPMMIIDyDCCA8QwggKsoAMCAQICAQYwDQYJKoZI" - + "hvcNAQEFBQAwgZQxFDASBgNVBAMTC1RDUy1DQSBPQ1NQMSYwJAYJKoZIhvcN" - + "AQkBFhd0Y3MtY2FAdGNzLWNhLnRjcy5jby5pbjEMMAoGA1UEChMDVENTMQww" - + "CgYDVQQLEwNBVEMxEjAQBgNVBAcTCUh5ZGVyYWJhZDEXMBUGA1UECBMOQW5k" - + "aHJhIHByYWRlc2gxCzAJBgNVBAYTAklOMB4XDTAyMDgyOTA3MTE0M1oXDTAz" - + "MDgyOTA3MTE0M1owgZwxCzAJBgNVBAYTAklOMRcwFQYDVQQIEw5BbmRocmEg" - + "cHJhZGVzaDESMBAGA1UEBxMJSHlkZXJhYmFkMQwwCgYDVQQKEwNUQ1MxDDAK" - + "BgNVBAsTA0FUQzEeMBwGA1UEAxMVVENTLUNBIE9DU1AgUmVzcG9uZGVyMSQw" - + "IgYJKoZIhvcNAQkBFhVvY3NwQHRjcy1jYS50Y3MuY28uaW4wgZ8wDQYJKoZI" - + "hvcNAQEBBQADgY0AMIGJAoGBAM+XWW4caMRv46D7L6Bv8iwtKgmQu0SAybmF" - + "RJiz12qXzdvTLt8C75OdgmUomxp0+gW/4XlTPUqOMQWv463aZRv9Ust4f8MH" - + "EJh4ekP/NS9+d8vEO3P40ntQkmSMcFmtA9E1koUtQ3MSJlcs441JjbgUaVnm" - + "jDmmniQnZY4bU3tVAgMBAAGjgZowgZcwDAYDVR0TAQH/BAIwADALBgNVHQ8E" - + "BAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwkwNgYIKwYBBQUHAQEEKjAoMCYG" - + "CCsGAQUFBzABhhpodHRwOi8vMTcyLjE5LjQwLjExMDo3NzAwLzAtBgNVHR8E" - + "JjAkMCKgIKAehhxodHRwOi8vMTcyLjE5LjQwLjExMC9jcmwuY3JsMA0GCSqG" - + "SIb3DQEBBQUAA4IBAQB6FovM3B4VDDZ15o12gnADZsIk9fTAczLlcrmXLNN4" - + "PgmqgnwF0Ymj3bD5SavDOXxbA65AZJ7rBNAguLUo+xVkgxmoBH7R2sBxjTCc" - + "r07NEadxM3HQkt0aX5XYEl8eRoifwqYAI9h0ziZfTNes8elNfb3DoPPjqq6V" - + "mMg0f0iMS4W8LjNPorjRB+kIosa1deAGPhq0eJ8yr0/s2QR2/WFD5P4aXc8I" - + "KWleklnIImS3zqiPrq6tl2Bm8DZj7vXlTOwmraSQxUwzCKwYob1yGvNOUQTq" - + "pG6jxn7jgDawHU1+WjWQe4Q34/pWeGLysxTraMa+Ug9kPe+jy/qRX2xwvKBZ"); - - private boolean isSameAs( - byte[] a, - byte[] b) - { - if (a.length != b.length) - { - return false; - } - - for (int i = 0; i != a.length; i++) - { - if (a[i] != b[i]) - { - return false; - } - } - - return true; - } - - private TestResult unsignedRequest() - { - try - { - ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(unsignedReq)); - OCSPRequest req = OCSPRequest.getInstance(aIn.readObject()); - - if (!isSameAs(req.getEncoded(), unsignedReq)) - { - return new SimpleTestResult(false, getName() + ": OCSP unsigned request failed to re-encode"); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - catch (Exception e) - { - return new SimpleTestResult(false, getName() + ": failed unsigned exception - " + e.toString(), e); - } - } - - private TestResult signedRequest() - { - try - { - ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(signedReq)); - OCSPRequest req = OCSPRequest.getInstance(aIn.readObject()); - - if (!isSameAs(req.getEncoded(), signedReq)) - { - return new SimpleTestResult(false, getName() + ": OCSP signed request failed to re-encode"); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - catch (Exception e) - { - return new SimpleTestResult(false, getName() + ": failed signed exception - " + e.toString(), e); - } - } - - private TestResult response() - { - try - { - ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(response)); - OCSPResponse resp = OCSPResponse.getInstance(aIn.readObject()); - ResponseBytes rBytes = ResponseBytes.getInstance(resp.getResponseBytes()); - - aIn = new ASN1InputStream(new ByteArrayInputStream(rBytes.getResponse().getOctets())); - - BasicOCSPResponse bResp = BasicOCSPResponse.getInstance(aIn.readObject()); - - resp = new OCSPResponse(resp.getResponseStatus(), new ResponseBytes(rBytes.getResponseType(), new DEROctetString(bResp.getEncoded()))); - - if (!isSameAs(resp.getEncoded(), response)) - { - return new SimpleTestResult(false, getName() + ": OCSP response failed to re-encode"); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - catch (Exception e) - { - return new SimpleTestResult(false, getName() + ": failed response exception - " + e.toString(), e); - } - } - - public TestResult perform() - { - TestResult res = unsignedRequest(); - - if (!res.isSuccessful()) - { - return res; - } - - res = signedRequest(); - if (!res.isSuccessful()) - { - return res; - } - - return response(); - } - - public String getName() - { - return "OCSP"; - } - - public static void main( - String[] args) - { - OCSPTest test = new OCSPTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OIDTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OIDTest.java deleted file mode 100644 index 02ac10bc8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OIDTest.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encoding; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1OutputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -/** - * X.690 test example - */ -public class OIDTest - extends SimpleTest -{ - byte[] req1 = Hex.decode("0603813403"); - byte[] req2 = Hex.decode("06082A36FFFFFFDD6311"); - - public String getName() - { - return "OID"; - } - - private void recodeCheck( - String oid, - byte[] enc) - throws IOException - { - ByteArrayInputStream bIn = new ByteArrayInputStream(enc); - ASN1InputStream aIn = new ASN1InputStream(bIn); - - ASN1ObjectIdentifier o = new ASN1ObjectIdentifier(oid); - ASN1ObjectIdentifier encO = (ASN1ObjectIdentifier)aIn.readObject(); - - if (!o.equals(encO)) - { - fail("oid ID didn't match", o, encO); - } - - byte[] bytes = o.getEncoded(ASN1Encoding.DER); - - if (bytes.length != enc.length) - { - fail("failed length test"); - } - - for (int i = 0; i != enc.length; i++) - { - if (bytes[i] != enc[i]) - { - fail("failed comparison test", new String(Hex.encode(enc)), new String(Hex.encode(bytes))); - } - } - } - - private void validOidCheck( - String oid) - throws IOException - { - ASN1ObjectIdentifier o = new ASN1ObjectIdentifier(oid); - o = (ASN1ObjectIdentifier)ASN1Primitive.fromByteArray(o.getEncoded()); - if (!o.getId().equals(oid)) - { - fail("failed oid check for " + oid); - } - } - - private void invalidOidCheck( - String oid) - { - try - { - new ASN1ObjectIdentifier(oid); - fail("failed to catch bad oid: " + oid); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void branchCheck(String stem, String branch) - { - String expected = stem + "." + branch; - String actual = new ASN1ObjectIdentifier(stem).branch(branch).getId(); - - if (!expected.equals(actual)) - { - fail("failed 'branch' check for " + stem + "/" + branch); - } - } - - private void onCheck(String stem, String test, boolean expected) - { - if (expected != new ASN1ObjectIdentifier(test).on(new ASN1ObjectIdentifier(stem))) - { - fail("failed 'on' check for " + stem + "/" + test); - } - } - - public void performTest() - throws IOException - { - recodeCheck("2.100.3", req1); - recodeCheck("1.2.54.34359733987.17", req2); - - validOidCheck(PKCSObjectIdentifiers.pkcs_9_at_contentType.getId()); - validOidCheck("0.1"); - validOidCheck("1.0"); - validOidCheck("1.0.2"); - validOidCheck("1.0.20"); - validOidCheck("1.0.200"); - validOidCheck("1.1.127.32512.8323072.2130706432.545460846592.139637976727552.35747322042253312.9151314442816847872"); - validOidCheck("1.2.123.12345678901.1.1.1"); - validOidCheck("2.25.196556539987194312349856245628873852187.1"); - - invalidOidCheck("0"); - invalidOidCheck("1"); - invalidOidCheck("2"); - invalidOidCheck("3.1"); - invalidOidCheck("0.01"); - invalidOidCheck("00.1"); - invalidOidCheck("1.00.2"); - invalidOidCheck("1.0.02"); - invalidOidCheck("1.2.00"); - invalidOidCheck("..1"); - invalidOidCheck("192.168.1.1"); - invalidOidCheck(".123452"); - invalidOidCheck("1."); - invalidOidCheck("1.345.23.34..234"); - invalidOidCheck("1.345.23.34.234."); - invalidOidCheck(".12.345.77.234"); - invalidOidCheck(".12.345.77.234."); - invalidOidCheck("1.2.3.4.A.5"); - invalidOidCheck("1,2"); - - branchCheck("1.1", "2.2"); - - onCheck("1.1", "1.1", false); - onCheck("1.1", "1.2", false); - onCheck("1.1", "1.2.1", false); - onCheck("1.1", "2.1", false); - onCheck("1.1", "1.11", false); - onCheck("1.12", "1.1.2", false); - onCheck("1.1", "1.1.1", true); - onCheck("1.1", "1.1.2", true); - } - - public static void main( - String[] args) - { - runTest(new OIDTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ObjectIdentifierTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ObjectIdentifierTest.java deleted file mode 100644 index e87db7821..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ObjectIdentifierTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -public class ObjectIdentifierTest - extends SimpleTest -{ - public String getName() - { - return "ObjectIdentifier"; - } - - public void performTest() - throws Exception - { - // exercise the object cache - for (int i = 0; i < 100; i++) - { - for (int j = 0; j < 100; j++) - { - final ASN1ObjectIdentifier oid1 = new ASN1ObjectIdentifier("1.1." + i + "." + j); - final byte[] encoded1 = oid1.getEncoded(); - final ASN1ObjectIdentifier oid2 = ASN1ObjectIdentifier.getInstance(encoded1); - if (oid1 == oid2) - { - fail("Shouldn't be the same: " + oid1 + " " + oid2); - } - if (!oid1.equals(oid2)) - { - fail("Should be equal: " + oid1 + " " + oid2); - } - final ASN1ObjectIdentifier oid3 = oid2.intern(); - if (oid2 != oid3) - { - fail("Should be the same: " + oid2 + " " + oid3); - } - if (!oid2.equals(oid3)) - { - fail("Should be equal: " + oid2 + " " + oid3); - } - final byte[] encoded2 = oid3.getEncoded(); - final ASN1ObjectIdentifier oid4 = ASN1ObjectIdentifier.getInstance(encoded2); - if (oid3 != oid4) - { - fail("Should be taken from cache: " + oid3 + " " + oid4); - } - if (!oid3.equals(oid4)) - { - fail("Should be equal: " + oid3 + " " + oid4); - } - } - } - - // make sure we're not leaking memory - for (int i = 0; i < 100; i++) - { - for (int j = 0; j < 100; j++) - { - final ASN1ObjectIdentifier oid1 = new ASN1ObjectIdentifier("1.1.2." + i + "." + j); - final byte[] encoded1 = oid1.getEncoded(); - final ASN1ObjectIdentifier oid2 = ASN1ObjectIdentifier.getInstance(encoded1); - final ASN1ObjectIdentifier oid3 = ASN1ObjectIdentifier.getInstance(encoded1); - if (oid1 == oid2) - { - fail("Shouldn't be the same: " + oid1 + " " + oid2); - } - if (oid2 == oid3) - { - fail("Shouldn't be the same: " + oid2 + " " + oid3); - } - } - } - } - - public static void main( - String[] args) - { - ObjectIdentifierTest test = new ObjectIdentifierTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OtherCertIDUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OtherCertIDUnitTest.java deleted file mode 100644 index 17bad7ece..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OtherCertIDUnitTest.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.ess.OtherCertID; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralNames; -import com.fr.third.org.bouncycastle.asn1.x509.IssuerSerial; - -public class OtherCertIDUnitTest - extends ASN1UnitTest -{ - public String getName() - { - return "OtherCertID"; - } - - public void performTest() - throws Exception - { - AlgorithmIdentifier algId = new AlgorithmIdentifier(new ASN1ObjectIdentifier("1.2.2.3")); - byte[] digest = new byte[20]; - IssuerSerial issuerSerial = new IssuerSerial(new GeneralNames(new GeneralName(new X500Name("CN=test"))), new ASN1Integer(1)); - - OtherCertID certID = new OtherCertID(algId, digest); - - checkConstruction(certID, algId, digest, null); - - certID = new OtherCertID(algId, digest, issuerSerial); - - checkConstruction(certID, algId, digest, issuerSerial); - - certID = OtherCertID.getInstance(null); - - if (certID != null) - { - fail("null getInstance() failed."); - } - - try - { - OtherCertID.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - OtherCertID certID, - AlgorithmIdentifier algId, - byte[] digest, - IssuerSerial issuerSerial) - throws IOException - { - checkValues(certID, algId, digest, issuerSerial); - - certID = OtherCertID.getInstance(certID); - - checkValues(certID, algId, digest, issuerSerial); - - ASN1InputStream aIn = new ASN1InputStream(certID.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - certID = OtherCertID.getInstance(seq); - - checkValues(certID, algId, digest, issuerSerial); - } - - private void checkValues( - OtherCertID certID, - AlgorithmIdentifier algId, - byte[] digest, - IssuerSerial issuerSerial) - { - checkMandatoryField("algorithmHash", algId, certID.getAlgorithmHash()); - checkMandatoryField("certHash", digest, certID.getCertHash()); - - checkOptionalField("issuerSerial", issuerSerial, certID.getIssuerSerial()); - } - - public static void main( - String[] args) - { - runTest(new OtherCertIDUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OtherMsgTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OtherMsgTest.java deleted file mode 100644 index 16b3d3d64..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OtherMsgTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERUTF8String; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.asn1.cmc.OtherMsg; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class OtherMsgTest - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new OtherMsgTest()); - } - - public String getName() - { - return "OtherMsgTest"; - } - - public void performTest() - throws Exception - { - OtherMsg otherMsg = new OtherMsg(new BodyPartID(10L), PKCSObjectIdentifiers.id_aa, new DERUTF8String("Cats")); - byte[] b = otherMsg.getEncoded(); - OtherMsg otherMsgResult = OtherMsg.getInstance(b); - - isEquals("bodyPartID", otherMsg.getBodyPartID(), otherMsgResult.getBodyPartID()); - isEquals("otherMsgType", otherMsg.getOtherMsgType(), otherMsgResult.getOtherMsgType()); - isEquals("otherMsgValue", otherMsg.getOtherMsgValue(), otherMsgResult.getOtherMsgValue()); - - try { - OtherMsg.getInstance(new DERSequence()); - fail("Sequence should be 3 elements long."); - } catch (Throwable t) { - isEquals("Sequence size",t.getClass(), IllegalArgumentException.class); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OtherSigningCertificateUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OtherSigningCertificateUnitTest.java deleted file mode 100644 index d213c2881..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OtherSigningCertificateUnitTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.ess.OtherCertID; -import com.fr.third.org.bouncycastle.asn1.ess.OtherSigningCertificate; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; - -public class OtherSigningCertificateUnitTest - extends ASN1UnitTest -{ - public String getName() - { - return "OtherSigningCertificate"; - } - - public void performTest() - throws Exception - { - AlgorithmIdentifier algId = new AlgorithmIdentifier(new ASN1ObjectIdentifier("1.2.2.3")); - byte[] digest = new byte[20]; - OtherCertID otherCertID = new OtherCertID(algId, digest); - - OtherSigningCertificate otherCert = new OtherSigningCertificate(otherCertID); - - checkConstruction(otherCert, otherCertID); - - otherCert = OtherSigningCertificate.getInstance(null); - - if (otherCert != null) - { - fail("null getInstance() failed."); - } - - try - { - OtherCertID.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - OtherSigningCertificate otherCert, - OtherCertID otherCertID) - throws IOException - { - checkValues(otherCert, otherCertID); - - otherCert = OtherSigningCertificate.getInstance(otherCert); - - checkValues(otherCert, otherCertID); - - ASN1InputStream aIn = new ASN1InputStream(otherCert.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - otherCert = OtherSigningCertificate.getInstance(seq); - - checkValues(otherCert, otherCertID); - } - - private void checkValues( - OtherSigningCertificate otherCert, - OtherCertID otherCertID) - { - if (otherCert.getCerts().length != 1) - { - fail("getCerts() length wrong"); - } - checkMandatoryField("getCerts()[0]", otherCertID, otherCert.getCerts()[0]); - } - - public static void main( - String[] args) - { - runTest(new OtherSigningCertificateUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OtherStatusInfoTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OtherStatusInfoTest.java deleted file mode 100644 index e6355cc53..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/OtherStatusInfoTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.util.Date; - -import com.fr.third.org.bouncycastle.asn1.ASN1GeneralizedTime; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.cmc.CMCFailInfo; -import com.fr.third.org.bouncycastle.asn1.cmc.ExtendedFailInfo; -import com.fr.third.org.bouncycastle.asn1.cmc.OtherStatusInfo; -import com.fr.third.org.bouncycastle.asn1.cmc.PendInfo; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class OtherStatusInfoTest - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new OtherStatusInfoTest()); - } - - public String getName() - { - return "OtherStatusInfoTest"; - } - - public void performTest() - throws Exception - { - { - OtherStatusInfo ose = OtherStatusInfo.getInstance(CMCFailInfo.badCertId.toASN1Primitive()); - byte[] b = ose.getEncoded(); - OtherStatusInfo oseResult = OtherStatusInfo.getInstance(b); - - isEquals("isFailInfo", oseResult.isFailInfo(), true); - isEquals("isPendInfo", oseResult.isPendingInfo(), false); - isEquals("isExtendedFailInfo", oseResult.isExtendedFailInfo(), false); - - isEquals(ose, oseResult); - } - - { - OtherStatusInfo ose = OtherStatusInfo.getInstance(new PendInfo("Fish".getBytes(), new ASN1GeneralizedTime(new Date()))); - byte[] b = ose.getEncoded(); - OtherStatusInfo oseResult = OtherStatusInfo.getInstance(b); - - isEquals("isFailInfo", oseResult.isFailInfo(), false); - isEquals("isPendInfo", oseResult.isPendingInfo(), true); - isEquals("isExtendedFailInfo", oseResult.isExtendedFailInfo(), false); - - isEquals(ose, oseResult); - } - - { - OtherStatusInfo ose = OtherStatusInfo.getInstance( - new ExtendedFailInfo(PKCSObjectIdentifiers.canNotDecryptAny, new ASN1Integer(10L))); - byte[] b = ose.getEncoded(); - OtherStatusInfo oseResult = OtherStatusInfo.getInstance(b); - - isEquals("isFailInfo", oseResult.isFailInfo(), false); - isEquals("isPendInfo", oseResult.isPendingInfo(), false); - isEquals("isExtendedFailInfo", oseResult.isExtendedFailInfo(), true); - - isEquals(ose, oseResult); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKCS10Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKCS10Test.java deleted file mode 100644 index 285525167..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKCS10Test.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.ByteArrayInputStream; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encoding; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.pkcs.CertificationRequest; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -public class PKCS10Test - implements Test -{ - byte[] req1 = Base64.decode( - "MIHoMIGTAgEAMC4xDjAMBgNVBAMTBVRlc3QyMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNF" - + "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALlEt31Tzt2MlcOljvacJgzQVhmlMoqAOgqJ9Pgd3Gux" - + "Z7/WcIlgW4QCB7WZT21O1YoghwBhPDMcNGrHei9kHQkCAwEAAaAAMA0GCSqGSIb3DQEBBQUAA0EA" - + "NDEI4ecNtJ3uHwGGlitNFq9WxcoZ0djbQJ5hABMotav6gtqlrwKXY2evaIrsNwkJtNdwwH18aQDU" - + "KCjOuBL38Q=="); - - byte[] req2 = Base64.decode( - "MIIB6TCCAVICAQAwgagxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRQwEgYDVQQH" - + "EwtTYW50YSBDbGFyYTEMMAoGA1UEChMDQUJCMVEwTwYDVQQLHEhQAAAAAAAAAG8AAAAAAAAAdwAA" - + "AAAAAABlAAAAAAAAAHIAAAAAAAAAIAAAAAAAAABUAAAAAAAAABxIAAAAAAAARAAAAAAAAAAxDTAL" - + "BgNVBAMTBGJsdWUwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANETRZ+6occCOrFxNhfKIp4C" - + "mMkxwhBNb7TnnahpbM9O0r4hrBPcfYuL7u9YX/jN0YNUP+/CiT39HhSe/bikaBPDEyNsl988I8vX" - + "piEdgxYq/+LTgGHbjRsRYCkPtmzwBbuBldNF8bV7pu0v4UScSsExmGqqDlX1TbPU8KkPU1iTAgMB" - + "AAGgADANBgkqhkiG9w0BAQQFAAOBgQAFbrs9qUwh93CtETk7DeUD5HcdCnxauo1bck44snSV6MZV" - + "OCIGaYu1501kmhEvAtVVRr6SEHwimfQDDIjnrWwYsEr/DT6tkTZAbfRd3qUu3iKjT0H0vlUZp0hJ" - + "66mINtBM84uZFBfoXiWY8M3FuAnGmvy6ah/dYtJorTxLKiGkew=="); - - public String getName() - { - return "PKCS10"; - } - - public TestResult pkcs10Test( - String testName, - byte[] req) - { - try - { - ByteArrayInputStream bIn = new ByteArrayInputStream(req); - ASN1InputStream aIn = new ASN1InputStream(bIn); - - CertificationRequest r = new CertificationRequest((ASN1Sequence)aIn.readObject()); - - byte[] bytes = r.getEncoded(ASN1Encoding.DER); - - if (bytes.length != req.length) - { - return new SimpleTestResult(false, getName() + ": " + testName + " failed length test"); - } - - for (int i = 0; i != req.length; i++) - { - if (bytes[i] != req[i]) - { - return new SimpleTestResult(false, getName() + ": " + testName + " failed comparison test"); - } - } - } - catch (Exception e) - { - return new SimpleTestResult(false, getName() + ": Exception - " + testName + " " + e.toString()); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public TestResult perform() - { - TestResult res = pkcs10Test("basic CR", req1); - - if (!res.isSuccessful()) - { - return res; - } - - return pkcs10Test("Universal CR", req2); - } - - public static void main( - String[] args) - { - Test test = new PKCS10Test(); - - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKCS12Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKCS12Test.java deleted file mode 100644 index 84df8172b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKCS12Test.java +++ /dev/null @@ -1,214 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.ByteArrayInputStream; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1OctetString; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.BEROctetString; -import com.fr.third.org.bouncycastle.asn1.DLSequence; -import com.fr.third.org.bouncycastle.asn1.pkcs.AuthenticatedSafe; -import com.fr.third.org.bouncycastle.asn1.pkcs.ContentInfo; -import com.fr.third.org.bouncycastle.asn1.pkcs.EncryptedData; -import com.fr.third.org.bouncycastle.asn1.pkcs.EncryptedPrivateKeyInfo; -import com.fr.third.org.bouncycastle.asn1.pkcs.MacData; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.pkcs.Pfx; -import com.fr.third.org.bouncycastle.asn1.pkcs.SafeBag; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.asn1.x509.DigestInfo; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class PKCS12Test - extends SimpleTest -{ - byte[] pkcs12 = Base64.decode( - "MIACAQMwgAYJKoZIhvcNAQcBoIAkgASCA+gwgDCABgkqhkiG9w0BBwGggCSA" - + "BIIDRDCCA0AwggM8BgsqhkiG9w0BDAoBAqCCArEwggKtMCcGCiqGSIb3DQEM" - + "AQMwGQQUFlnNVpQoEHc+J3UEGxARipkHu5kCAWQEggKAAH9tmy40lly6QDoc" - + "1TfmY9y2qysD+lrgk+dnxP04RfoJfycTRDeaz2sPLImZtio9nsqCFqtzU/sl" - + "eWigbH34BpKU1sC0Gq1cyik0GO65sW95S6YjKtGcGOBfQCPk1oQjfiqnfU3G" - + "oeOaG3COQJukMFj8unv55u0xbX1hwO8SsZmr9RjPzLrVaeY6BP5+CCzOKBaj" - + "GxneIDqnQW7/kBIVWK7M+JXGdgQyiKhD6NvXL/zD8oKEne0nIX7IokQuWEn6" - + "8Sglv5OSclsSdvHTk57bCuV5lVzoIzczA4J/LZWdrtITeVefBLQSalBzpRde" - + "rSTMj485z2x5ChizhjE627/KQ5vkKQkQVqXYYXVyeTvKZRpL7vz13C4DUCwN" - + "im1XvNSCNebXS1yHJRtcONDhGJN3UsrVjHr+2kCfE5SCEeSU/dqgNLuLa1tk" - + "5+jwZFNj/HjO88wlOwPCol1uuJjDpaEW7dxu5qsVSfZhEXWHs8rZAMttFMzi" - + "yxsEkZe8kqngRbNJOY6KpppYedsMWDusUJGfIHo+8zymiw3gv/z+lmFOlDGt" - + "CKMk9Es/MgfjpbfhbTVYHOBKS6Qyrz7LdTuBMI8XdsZMuN+Uf73690ggLmKW" - + "IELUg8h1RX0ra2n6jOc/1rnebAifMhiMkL1ABQvqOobfOrG/9h9XcXoi64Qr" - + "htc3T7yMAHafBX5KUcNkbcn6kssYhpvd8bPADoLBnbx3GxGh/uziB0zKQEI0" - + "GnaY4SL7aR4C5xNNi41lYtsR6ohKyfPEGslhrhd4axx0cKxC2sHgVl0k+r8B" - + "8Vu44XHbW8LqdspjOHN9qg2erES1Dvgj05SfHDup+V6a3ogJo2YKXOiu3DF4" - + "MFEGCSqGSIb3DQEJFDFEHkIARABhAHYAaQBkACAARwAuACAASABvAG8AawAn" - + "AHMAIABWAGUAcgBpAFMAaQBnAG4ALAAgAEkAbgBjAC4AIABJAEQwIwYJKoZI" - + "hvcNAQkVMRYEFKEcMJ798oZLFkH0OnpbUBnrTLgWAAAAAAAAMIAGCSqGSIb3" - + "DQEHBqCAMIACAQAwgAYJKoZIhvcNAQcBMCcGCiqGSIb3DQEMAQYwGQQUTErH" - + "kWZ8nBXZYWO53FH4yqRZZsECAWSggASCDGCreuCr6/azcOv5w04bN3jkg4G2" - + "dsvTPAjL8bichaEOQCykhuNPt1dv3FsjUsdFC550K0+Y48RyBIID6JTiN9Gj" - + "K+a5aLPaXgTRdY74Toof1hYtZ4DIcVyq25LezVQHoe/++pAgEpWjqHTxVDIv" - + "YFAgT2oDB+2vkeXM61XnNWOjwCY3pXpk/VGjyN4USkD7Q/Y6tPjQOywvQE7c" - + "Ab1z62k9iMia7Yk/qmh+zJu4SSneo0/RLLdMZOlGZv89MResVG038TC8MTA9" - + "Uf+wDRcS20d7XDbTaBAgju8TpFIw5/lbDi0feUVlk6L+jkT1ktaTc1Pwtxn7" - + "psXMFW6HAWB4exOi09297R9BCOQX6vcetK/iA/3jIC6NuTdizYof0DWetdGy" - + "haIkMiEnERYE3unJocH4fq585Rw6mE+BYssPVPkVWZZInF3l69bKduuxsQt+" - + "pcApgBVsTjsU+1FOiUxuW2wWKi70RcQprPv5Ef1A5FRNxPFp+7IzLNlE4qCo" - + "wvC6NTpeuRw3aGsXSfqHmSddrHugNPmghNgG5lv1Ef7A8MUuyp8fyjAgxCDk" - + "4Hpb8PCHGj5t//Fr6Cd0MygJMIFQmv4kUd2LVHxQ9A9WFNCqTz/nBe+ZRLJL" - + "NghTv6gGpjGJiBnXYv6Sod2fs+5J2GIvex4qbdh6gzZIU2YTAwpj6Aca3SjA" - + "X8+m8AXt2SC3Z6T5+m8SxyiNp2P511paV/TZKtLWXQGKeEX1JXhQkaM6Q5W/" - + "IhSgC8/gppk1gbIraBqrW8bEnGBnC03wi0OnMz3ohM4CVHyaW3dQquT2+u6F" - + "8VeGXAYHU022NkrpPl/VlfNNEAyisU2+oJqpPZkqL6FsDWF3k6Fq2jXBLL+/" - + "a0WA82jIpgjNeXze/cgoHtU023V9E9Qcu+5nPBYdCTR4sRxvHLANii0W8lPv" - + "tvU5XO1UsEjHDfKL4E1bhGzGpb/OU5yg/98EN95r/xdFL5G+XVyHeR0UtkcB" - + "IuvyBdhkwoprCjkcgLZe8FPIBNw84HRe7Ye6f2gDW/F5uej6rBehJS1VFvCh" - + "DXzkajGmK40Gc2APS1/1vZqPu68polgw9dT84rem36PLEOq4KuU7n4QE0g7T" - + "YR2G8+4FNgQTjjg/qw3lX+sj6yLn1lYt1dOVvkiM8i8tdZg/3pCKKAW1uV7a" - + "astlBxVSkFfn1BrFTc2oFGkTrlUg90a+parOfGHTfDiaHX8ouEg63fk0+Xdi" - + "FCarXsqHNPDbpmWLKw8TAmdeneGipyScntJJk4ajy+jROQBgGew3ofOmfkqm" - + "oJFNwUvKOXN2ucViLZgsdK/7YgV1OR7oiTh8knQNPk3d5fRYSMFf9GJTjQRV" - + "y2CLdICAVzvrUXf9k7miWYkjIp2/HGD7pOH018sX9MrpfJKqvdPFOssZiFd0" - + "I2FUbgcEggPotvnT0XoabEiurTm8EPPpw66NKmK/H1kQL0hEtdIazPxfLmm/" - + "ZUDokwa7d4bE3BwFh0weQfEvMzJu6Y5E7ir2MqD33XaGMOGys1nst1SPPyDB" - + "WpOWD9w7Ng3yU1JVzqFWuVXaXDYbfnlG7AGevKF5PYNZj/RIQBBf5Xle9hTd" - + "c9CtxPkrsJwA8DeAwKl2WIfbXGzAYLSnXoYUcoTkWn/O81BlUFgAXv80gLe8" - + "NUrH7bhsnyGaPY953NyDk8IWUYrsn/sXvxTy5B0/7/WGMh3CSZrLX3p7TcFY" - + "yBrL6SRas4q9rrcwuhBq0tUUbbgWi92nhZl4bOGmx7ehHnwuUId2HWXyVGoB" - + "qToee/2E4PZFxSZwKCY6dahswFq5QGDrQKN2/qpOLZcJib6SvSGyEZl2pqr0" - + "lqk7tVPzBkN/4uP0qrcbZCDbGW6IXwu3RGMRehqj/HEJcs92lZKfVrk/U07X" - + "MBAiQHqV+kLw7kStECR/MGJG1c0xhqqBrf0W74+LpJiv/Q9iFNdWbXvE/cAk" - + "G7+OTUABd2kI88uA43T0UoRuPOi5KnLuD3AG+7IuyGyP69Xncd4u0srMg2fn" - + "DiLLZUy6vWmxwRFsSMCEfQNLtZaggukoPIihQvbX3mQS9izwLs6D89WtEcZ5" - + "6DVbIlUqUinnNKsT8vW1DZo5FMJkUxB666YIPVmkQbbJOEUU89dZg5Gw0og6" - + "rn4irEr4xHFdx+S7iqJXhzs9THg/9e4/k8KQ136z7LALOqDookcSdBzW6H8c" - + "STjs4qKQyNimsLB90mEuIEApzhseAaLFl+kgORGJv/2a+uoukZchMsJ98MVo" - + "sEPS1oBXJl2m9AshkWfON2GDeJatgcw6CyC1mSx++Gg602ZKUZZUaWxkz1Sw" - + "zTj3nhiJe+SZsdfxhsojNq7zfxqgY/Rq7BwvphU3StjnxvkB4rTkbmbiGOBO" - + "cvTFg4yOtQGRcifk2/XH/bgYiPqQrYSXpO3WRASV005RaSGufcpTtj3YlHGe" - + "8FUgZfDtfiGezhNET9KO3/Q0i34bGEpoIb/9uOWH4ZHULIlfdSm1ynV50nE4" - + "mJTXccrF6BE80KZI5GWGhqXdfPFaHTK1S20+XCw7bRJCGeiwVxvGfB+C0SZ4" - + "ndtqx165dKG5JwFukcygiIZN6foh0/PhwzmFxmPtZuPQt9dtuIQ35Y7PSDsy" - + "IH2Ot0Hh0YIN99lHJ6n9HomSjpwcgDXGssEuevbpz27u/MI/Uhq4Gfx0k5RF" - + "0pcRYtk1dYSx44a+8WgqZLF8DUNtyjSE/H8P5iGa6tqOl7kNyeeEkfoTtKst" - + "asGFwL4Qxxus4GC7repyVi7IJgSCA+iopiqKQJ2IqUHvoIEuD//sZooDx0Je" - + "oFRO5VakkTO6WHd8JpOOEU2f6Zjg++HdIl0QK7xcUaRH075LzEfqgn1vyw6J" - + "N6ex8D76sf/nAy01NvDPij48Z50XDwXu4kJGJvv0AJwId8BpjziBF0j3K/DI" - + "YOOpd6nW4EvdivCgaCnxqlIU/u1OP4BwpO+AUjJh6RKlKviGihQpi103DFhR" - + "yXNDhh55pqgCCCuNeEB+ovRt7UxzlGAVRSxJh1Zbjp/+iQun0E32RlSR4Diz" - + "p5vDk8NBZpIiKRqI+8GWZc3G1igp7dvViTLw4OdWMKwhccV5+3Ll/W72aNVm" - + "azYUoYOVn+OYS1NJkER0tjFOCozRGm5hfkxGlP+02wbH5uu/AQoJMqWIxT6l" - + "46IWC24lmAnDCXuM+gWmwUvyXLwuBdejVK8iG1Lnfg1qztoLpYRbBROgRdpt" - + "2cbPRm+9seqrth3eJbtmxCvuh3bZ3pR2e0/r5Tob/fDcOc5Kp+j4ndXWkwpa" - + "OuH1yxam7zNJR+mcYp1Wiujia5qIeY1QCAEY5QgAWaSHtjlEprwUuootA2Xm" - + "V7D8Vsr9BValhm9zMKj6IzsPmM+HZJWlhHcoucuAmPK6Lnys3Kv/mbkSgNOq" - + "fJDY901veFfKeqiCbAm6hZjNWoQDNJKFhjXUALrcOv9VCFPA3bMW3Xul/sB4" - + "Mq595e+x/1HkNOgZorBv97C6X7ENVDaAFcyZvrRU/ZeDnvFhisfxS4EJhzxl" - + "cWWnQhzD+ur1FTTlkmUFzgoB/rW+i3XigiHOuRRnkcoMy1uV17rwH8eELHJu" - + "Yni5vu2QUaD4jNEhliE2XCsn8Sm6bcXnfzBa7FXC39QvAcdJHzqcD6iIwjIz" - + "hKLu+/XoWFMFFNsgV78AwzPAn6TRya8LLCYPoIZkEP4qBoeZtUZ8PIS/Y7M9" - + "QStMwa/NI9SPswb3iScTGvor/obUEQS4QM6mVxFMpQWfwJfyU6jingX4EHRE" - + "mqvZ3ehzU8ZLOdKzRKuk022YDT7hwEQ+VL0Fg0Ld9oexqT96nQpUTHZtDRMV" - + "iTuJoUYTneDs2c9tsY4mWBqamZQSfTegj4sLMZagkuSUp/SpPM2zSGuD3nY6" - + "u3553gIM9jYhvLBEXwjGudVCwMd3bqo/4EhnKb2PcwUzdaMkipQlNteHZjBT" - + "1ici63xjJva+di0qTV+W9cyYyHwg1927X2qcMh06BhbHlcXQKbgmbL18KJEt" - + "K+GGhGNkP7mtPyHHgBb6vref/z8p7oxT2CG+oBuN/z+xQoYfe9c4IC3e/kNN" - + "DIoyYvPyEzAdfMS2aL8qDxzc5GH9UE9kcusJ/2dNEFTzBH2GK1CItL3IACv/" - + "LwX1SkI0w7oIQTL127CSnuTrUUkvJ/+rOYScQTMD/ntZPdLdu2ffszg3SzhN" - + "ELgojK8ss1OBlruWRHw/fP736Nx8MNsuOvXMnO8lruz+uyuEhF3BLv96oTcg" - + "XVHdWhPmOoqNdBQdRgAAAAAAAAAAAAAAAAAAAAAAADA8MCEwCQYFKw4DAhoF" - + "AAQUJMZn7MEKv4vW/+voCVyHBa6B0EMEFJOzH/BEjRtNNsZWlo/4L840aE5r" - + "AgFkAAA="); - - public void performTest() - throws Exception - { - ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(pkcs12)); - ASN1Sequence obj = (ASN1Sequence)aIn.readObject(); - Pfx bag = Pfx.getInstance(obj); - ContentInfo info = bag.getAuthSafe(); - MacData mData = bag.getMacData(); - DigestInfo dInfo = mData.getMac(); - AlgorithmIdentifier algId = dInfo.getAlgorithmId(); - byte[] salt = mData.getSalt(); - int itCount = mData.getIterationCount().intValue(); - - aIn = new ASN1InputStream(new ByteArrayInputStream(((ASN1OctetString)info.getContent()).getOctets())); - - AuthenticatedSafe authSafe = AuthenticatedSafe.getInstance(aIn.readObject()); - ContentInfo[] c = authSafe.getContentInfo(); - - // - // private key section - // - if (!c[0].getContentType().equals(PKCSObjectIdentifiers.data)) - { - fail("failed comparison data test"); - } - - aIn = new ASN1InputStream(new ByteArrayInputStream(((ASN1OctetString)c[0].getContent()).getOctets())); - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - SafeBag b = SafeBag.getInstance(seq.getObjectAt(0)); - if (!b.getBagId().equals(PKCSObjectIdentifiers.pkcs8ShroudedKeyBag)) - { - fail("failed comparison shroudedKeyBag test"); - } - - EncryptedPrivateKeyInfo encInfo = EncryptedPrivateKeyInfo.getInstance(b.getBagValue()); - - encInfo = new EncryptedPrivateKeyInfo(encInfo.getEncryptionAlgorithm(), encInfo.getEncryptedData()); - - b = new SafeBag(PKCSObjectIdentifiers.pkcs8ShroudedKeyBag, encInfo.toASN1Primitive(), b.getBagAttributes()); - - byte[] contentOctets = new DLSequence(b).getEncoded(); - - c[0] = new ContentInfo(PKCSObjectIdentifiers.data, new BEROctetString(contentOctets)); - - // - // certificates - // - if (!c[1].getContentType().equals(PKCSObjectIdentifiers.encryptedData)) - { - fail("failed comparison encryptedData test"); - } - - EncryptedData eData = EncryptedData.getInstance(c[1].getContent()); - - c[1] = new ContentInfo(PKCSObjectIdentifiers.encryptedData, eData); - - // - // create an octet stream represent the BER encoding of authSafe - // - authSafe = new AuthenticatedSafe(c); - - contentOctets = authSafe.getEncoded(); - - info = new ContentInfo(PKCSObjectIdentifiers.data, new BEROctetString(contentOctets)); - - mData = new MacData(new DigestInfo(algId, dInfo.getDigest()), salt, itCount); - - bag = new Pfx(info, mData); - - // - // comparison test - // - byte[] pfxEncoding = bag.getEncoded(); - if (!Arrays.areEqual(pfxEncoding, pkcs12)) - { - fail("failed comparison test"); - } - } - - public String getName() - { - return "PKCS12"; - } - - public static void main( - String[] args) - { - runTest(new PKCS12Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKIDataTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKIDataTest.java deleted file mode 100644 index 8bef695b5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKIDataTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERSet; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.asn1.cmc.CertificationRequest; -import com.fr.third.org.bouncycastle.asn1.cmc.OtherMsg; -import com.fr.third.org.bouncycastle.asn1.cmc.PKIData; -import com.fr.third.org.bouncycastle.asn1.cmc.TaggedAttribute; -import com.fr.third.org.bouncycastle.asn1.cmc.TaggedCertificationRequest; -import com.fr.third.org.bouncycastle.asn1.cmc.TaggedContentInfo; -import com.fr.third.org.bouncycastle.asn1.cmc.TaggedRequest; -import com.fr.third.org.bouncycastle.asn1.cms.ContentInfo; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class PKIDataTest - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new PKIDataTest()); - } - - public String getName() - { - return "PKIDataTest"; - } - - public void performTest() - throws Exception - { - - byte[] req1 = Base64.decode( - "MIHoMIGTAgEAMC4xDjAMBgNVBAMTBVRlc3QyMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNF" - + "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALlEt31Tzt2MlcOljvacJgzQVhmlMoqAOgqJ9Pgd3Gux" - + "Z7/WcIlgW4QCB7WZT21O1YoghwBhPDMcNGrHei9kHQkCAwEAAaAAMA0GCSqGSIb3DQEBBQUAA0EA" - + "NDEI4ecNtJ3uHwGGlitNFq9WxcoZ0djbQJ5hABMotav6gtqlrwKXY2evaIrsNwkJtNdwwH18aQDU" - + "KCjOuBL38Q=="); - - - PKIData pkiData = new PKIData( - new TaggedAttribute[]{new TaggedAttribute(new BodyPartID(10L), PKCSObjectIdentifiers.id_aa, new DERSet())}, - new TaggedRequest[]{new TaggedRequest(new TaggedCertificationRequest(new BodyPartID(10L), CertificationRequest.getInstance(req1)))}, - new TaggedContentInfo[]{new TaggedContentInfo(new BodyPartID(10L), new ContentInfo(PKCSObjectIdentifiers.id_aa_ets_commitmentType, new ASN1Integer(10L)))}, - new OtherMsg[]{new OtherMsg(new BodyPartID(10L), PKCSObjectIdentifiers.pkcs_9, new ASN1Integer(10L))}); - - - byte[] b = pkiData.getEncoded(); - - PKIData pkiDataResult = PKIData.getInstance(b); - - isTrue("controlSequence", Arrays.areEqual(pkiData.getControlSequence(), pkiDataResult.getControlSequence())); - isTrue("reqSequence", Arrays.areEqual(pkiData.getReqSequence(), pkiDataResult.getReqSequence())); - isTrue("cmsSequence", Arrays.areEqual(pkiData.getCmsSequence(), pkiDataResult.getCmsSequence())); - isTrue("otherMsgSequence", Arrays.areEqual(pkiData.getOtherMsgSequence(), pkiDataResult.getOtherMsgSequence())); - - try - { - PKIData.getInstance(new DERSequence()); - fail("Sequence must be 4."); - } - catch (Throwable t) - { - isEquals("Exception type", t.getClass(), IllegalArgumentException.class); - } - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKIFailureInfoTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKIFailureInfoTest.java deleted file mode 100644 index 8e7a7f1c5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKIFailureInfoTest.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encoding; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.DERBitString; -import com.fr.third.org.bouncycastle.asn1.cmp.PKIFailureInfo; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -/** - * PKIFailureInfoTest - */ -public class PKIFailureInfoTest - extends SimpleTest -{ - // A correct hex encoded BAD_DATA_FORMAT PKIFailureInfo - private static final byte[] CORRECT_FAILURE_INFO = Base64.decode("AwIANQ=="); - - public String getName() - { - return "PKIFailureInfo"; - } - - private void testEncoding() - throws IOException - { - DERBitString bitString = (DERBitString)new ASN1InputStream(CORRECT_FAILURE_INFO).readObject(); - PKIFailureInfo correct = new PKIFailureInfo(bitString); - - PKIFailureInfo bug = new PKIFailureInfo(PKIFailureInfo.badRequest | PKIFailureInfo.badTime |PKIFailureInfo.badDataFormat | PKIFailureInfo.incorrectData); - - if (!areEqual(correct.getEncoded(ASN1Encoding.DER),bug.getEncoded(ASN1Encoding.DER))) - { - fail("encoding doesn't match"); - } - } - - public void performTest() - throws IOException - { - BitStringConstantTester.testFlagValueCorrect(0, PKIFailureInfo.badAlg); - BitStringConstantTester.testFlagValueCorrect(1, PKIFailureInfo.badMessageCheck); - BitStringConstantTester.testFlagValueCorrect(2, PKIFailureInfo.badRequest); - BitStringConstantTester.testFlagValueCorrect(3, PKIFailureInfo.badTime); - BitStringConstantTester.testFlagValueCorrect(4, PKIFailureInfo.badCertId); - BitStringConstantTester.testFlagValueCorrect(5, PKIFailureInfo.badDataFormat); - BitStringConstantTester.testFlagValueCorrect(6, PKIFailureInfo.wrongAuthority); - BitStringConstantTester.testFlagValueCorrect(7, PKIFailureInfo.incorrectData); - BitStringConstantTester.testFlagValueCorrect(8, PKIFailureInfo.missingTimeStamp); - BitStringConstantTester.testFlagValueCorrect(9, PKIFailureInfo.badPOP); - BitStringConstantTester.testFlagValueCorrect(10, PKIFailureInfo.certRevoked); - BitStringConstantTester.testFlagValueCorrect(11, PKIFailureInfo.certConfirmed); - BitStringConstantTester.testFlagValueCorrect(12, PKIFailureInfo.wrongIntegrity); - BitStringConstantTester.testFlagValueCorrect(13, PKIFailureInfo.badRecipientNonce); - BitStringConstantTester.testFlagValueCorrect(14, PKIFailureInfo.timeNotAvailable); - BitStringConstantTester.testFlagValueCorrect(15, PKIFailureInfo.unacceptedPolicy); - BitStringConstantTester.testFlagValueCorrect(16, PKIFailureInfo.unacceptedExtension); - BitStringConstantTester.testFlagValueCorrect(17, PKIFailureInfo.addInfoNotAvailable); - BitStringConstantTester.testFlagValueCorrect(18, PKIFailureInfo.badSenderNonce); - BitStringConstantTester.testFlagValueCorrect(19, PKIFailureInfo.badCertTemplate); - BitStringConstantTester.testFlagValueCorrect(20, PKIFailureInfo.signerNotTrusted); - BitStringConstantTester.testFlagValueCorrect(21, PKIFailureInfo.transactionIdInUse); - BitStringConstantTester.testFlagValueCorrect(22, PKIFailureInfo.unsupportedVersion); - BitStringConstantTester.testFlagValueCorrect(23, PKIFailureInfo.notAuthorized); - BitStringConstantTester.testFlagValueCorrect(24, PKIFailureInfo.systemUnavail); - BitStringConstantTester.testFlagValueCorrect(25, PKIFailureInfo.systemFailure); - BitStringConstantTester.testFlagValueCorrect(26, PKIFailureInfo.duplicateCertReq); - - testEncoding(); - } - - public static void main( - String[] args) - { - runTest(new PKIFailureInfoTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKIPublicationInfoTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKIPublicationInfoTest.java deleted file mode 100644 index 255c64311..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKIPublicationInfoTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.crmf.PKIPublicationInfo; -import com.fr.third.org.bouncycastle.asn1.crmf.SinglePubInfo; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class PKIPublicationInfoTest - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new PKIPublicationInfoTest()); - } - - public String getName() - { - return "PKIPublicationInfoTest"; - } - - public void performTest() - throws Exception - { - PKIPublicationInfo pkiPubInfo = new PKIPublicationInfo(PKIPublicationInfo.dontPublish); - - isEquals(PKIPublicationInfo.dontPublish, pkiPubInfo.getAction()); - - encEqualTest(pkiPubInfo); - - pkiPubInfo = new PKIPublicationInfo(PKIPublicationInfo.dontPublish.getValue()); - - isEquals(PKIPublicationInfo.dontPublish, pkiPubInfo.getAction()); - - encEqualTest(pkiPubInfo); - - SinglePubInfo singlePubInfo1 = new SinglePubInfo(SinglePubInfo.x500, new GeneralName(new X500Name("CN=TEST"))); - pkiPubInfo = new PKIPublicationInfo(singlePubInfo1); - - isEquals(PKIPublicationInfo.pleasePublish, pkiPubInfo.getAction()); - isEquals(1, pkiPubInfo.getPubInfos().length); - isEquals(singlePubInfo1, pkiPubInfo.getPubInfos()[0]); - - encEqualTest(pkiPubInfo); - - SinglePubInfo singlePubInfo2 = new SinglePubInfo(SinglePubInfo.x500, new GeneralName(new X500Name("CN=BLOOT"))); - - pkiPubInfo = new PKIPublicationInfo(new SinglePubInfo[] { singlePubInfo1, singlePubInfo2 }); - - isEquals(PKIPublicationInfo.pleasePublish, pkiPubInfo.getAction()); - isEquals(2, pkiPubInfo.getPubInfos().length); - isEquals(singlePubInfo1, pkiPubInfo.getPubInfos()[0]); - isEquals(singlePubInfo2, pkiPubInfo.getPubInfos()[1]); - - encEqualTest(pkiPubInfo); - - pkiPubInfo = new PKIPublicationInfo((SinglePubInfo)null); - - isEquals(PKIPublicationInfo.pleasePublish, pkiPubInfo.getAction()); - isTrue(null == pkiPubInfo.getPubInfos()); - - encEqualTest(pkiPubInfo); - - pkiPubInfo = new PKIPublicationInfo((SinglePubInfo[])null); - - isEquals(PKIPublicationInfo.pleasePublish, pkiPubInfo.getAction()); - isTrue(null == pkiPubInfo.getPubInfos()); - - encEqualTest(pkiPubInfo); - } - - private void encEqualTest(PKIPublicationInfo pubInfo) - throws IOException - { - byte[] b = pubInfo.getEncoded(); - - PKIPublicationInfo pubInfoResult = PKIPublicationInfo.getInstance(b); - - isEquals(pubInfo, pubInfoResult); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKIResponseTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKIResponseTest.java deleted file mode 100644 index bccf86311..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PKIResponseTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERSet; -import com.fr.third.org.bouncycastle.asn1.DERUTF8String; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.asn1.cmc.OtherMsg; -import com.fr.third.org.bouncycastle.asn1.cmc.PKIResponse; -import com.fr.third.org.bouncycastle.asn1.cmc.TaggedAttribute; -import com.fr.third.org.bouncycastle.asn1.cmc.TaggedContentInfo; -import com.fr.third.org.bouncycastle.asn1.cms.ContentInfo; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class PKIResponseTest - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new PKIResponseTest()); - } - - public String getName() - { - return "PKIResponseTest"; - } - - public void performTest() - throws Exception - { - PKIResponse pkiResponse = PKIResponse.getInstance(new DERSequence(new ASN1Encodable[]{ - new DERSequence(new TaggedAttribute(new BodyPartID(10L), PKCSObjectIdentifiers.bagtypes, new DERSet())), - new DERSequence(new TaggedContentInfo(new BodyPartID(12L), new ContentInfo(PKCSObjectIdentifiers.id_aa, new ASN1Integer(10L)))), - new DERSequence(new OtherMsg(new BodyPartID(12), PKCSObjectIdentifiers.id_aa_msgSigDigest, new DERUTF8String("foo"))) - })); - - byte[] b = pkiResponse.getEncoded(); - - PKIResponse pkiResponseResult = PKIResponse.getInstance(b); - - isEquals(pkiResponse, pkiResponseResult); - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ParsingTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ParsingTest.java deleted file mode 100644 index 6594abb05..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ParsingTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1StreamParser; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class ParsingTest - extends SimpleTest -{ - String[] streams = { - "oRNphCO0F+jcMQKC1uMO8qFBPikDDYmtfVGeB45xvbfj1qu696YGjdW2igRnePYM/KkQtADG7gMHIhqBRcl7dBtkejNeolOklPNA3NgsACTiVN9JFUsYq0a5842+TU+U2/6Kt/D0kvz0WmwWFRPHWEWVM9PYOWabGsh28Iucc6s7eEqmr8NEzWUx/jM3dmjpFYVpSpxt2KbbT+yUO0EqFQyy8hQ7JvKRgv1AoWQfPjMsfjkKgxnA8DjenmwXaZnDaKEvQIKQl46L1Yyu3boN082SQliSJMJVgNuNNLFIt5QSUdG1ant5O6f9Yr0niAkAoqGzmqz+LZE1S7RrGHWiQ3DowE9NzviBuaAoI4WdCn1ClMwb9fdEmBMU4C7DJSgs3qaJzPUuaAT9vU3GhZqZ0wcTV5DHxSRzGLqg9JEJRi4qyeuG3Qkg3YBtathl+FiLJ7mVoO3dFIccRuuqp2MpMhfuP1DxHLNLNiUZEhLMQ0CLTGabUISBuyQudVFlKBZIpcLD0k7fKpMPuywrYiDrTinMc2ZP3fOGevoR5fnZ6kZAE5oMTtMNokzBuctGqVapblXNrVMLYbriT538oYz5", - "KEKVhHxtyUR9D3v5K4IJbVQLAMiVKoK9z7wFWUjzvLFNLg9C/r8zKfBa3YgZrt0Nq64+MxBePMbiNLCnfditc2qUcQZUHnvNnhwT6uGK37JmXg7MvQiKwvi31EIYt6ghqBZVs1iaqc0ep7wuQ16uwSQMlaDdXc9Qf1L0dGO/6eLyREz+p4UR4NOXK+GooQLfMxYL40zJlYcwNyR0rigvIr84WP2IMS2hZjqXtyS6HMM4yUv70hkIorjr7+JC4GtU1MyWuPuNSAGen0AZTaEEXd5sMbqXMqWg3jeM4mzRH1Kb3WdAChO5vMJZPBj9jZZKgXzmxkUh5GlIhUdYgztoNceBzQ3PIc7slCDUw9I2PjB87xsfy7jA5tFtFADs2EUyxUTMCuhilP664jSHgwbrr80k9Xc4sU+MCwCq2nQmcZYcPgKb4M31VJMlKwnZF3JUU2Jtqgg4gbErw58YoBwSkEcMJ2Juhiyx9U36MzxHs9OcTURfpsilMy+mDL8arCDx1knM1KkAHCLjWuJI+p1PvuIypgCwVc+MtGfd7wW8iR1JPJLBiuoZyNJ+xx9htd/HVB+rLtB57H8Gz8W+R00f", - "Ol9I/rXMwbLpxTY97v70B+HCl2+cojz2574x/cC56A7KGVF13La8RdzOOvSkl338ct9T/blEFa6QwNz3GmF+MoPdH9lncwz+tqixIqGU02Bp5swH0qjbp/Yjaeq91eR6B+9fl+KKrpglBr8S1BrI4Ey5v3AxxJdCWP8Gd+6Sp15/HMYanwlHBpCsW4+Kq8sGJoJXUXpQ/GBUJKs+WjX1zE6PsvF7/B8cByuqE3NJt7x4Oa+qZtF8qNc0CFDNj31Yhdt7JkAoD30IAd+ue9OhImQMCWwFwySRIRJXU3865K2dBR+VhLuI2aKzLh7MlgVKJk6b2P/ZIkc86ksR1sOUiHrs9EdoYuIssAgMc8QGzn4VN8lxopdzQYVG6pbXGS/VQlHkGdyLd+OHt4srz/NTUWiOquVTRxa6GgtlBFfIXikPTb+iT2pZKyKUlBvpgo0BY9vVUadsteHAI5qrFZBrL5ecK/Qtl9hf/M8qEjyjt2aCXe9B96Hg2QR5A53qW2PJW5VzS0AeB3g+zJSPCTpygrBs20q5Xrna0ux2l17r6HT9Q/AXIOkwPZUXXn0d02igS4D6Hxrg3Fhdp+OTXL8G", - "o3eXWpwAGmUkxHEKm/pGkDb1ZQQctCQ06lltZjeMXDp9AkowmA0KXjPQCQwyWE/nqEvk2g/58AxNU0TWSujo5uU0h4/hdMZ7Mrj33NSskWvDpKe7lE5tUjPi74Rmc5RRS+1T/EQobpNxoic3+tTO7NBbZfJtcUYeZ3jqxL+3YQL3PrGe/Zpno9TnQW8mWbbhKhDRtKY4p3Pgk9hPSpJCM9xYo3EMAOAIiH2P6RKH6uX/gSaUY2b6DE/TT0V6v/jdSmYM4+cnYiTyJCi5txI35jfCqIlVCXJd7klirvUMg9SXBhGR25AgQ5Z8yjd7lbB8FvD8JQAXZrp6xiHxbLIW7G11fWEo7RGLFtALI6H38Ud0vKjsEN7N5AibJcxS2A/CWk9R00sTHRBHFUP8o5mz8nE7FeCiwJPs/+tCt04nGb9wxBFMsmWcPEDfIzphCaO6U/D/tQHlA846gbKoikv/6LI0ussSR/i85XBclNcvzTctxylSbCR02lZ+go6fe5rmMouiel/0Tndz8t1YpQGilVeOQ3mqAFyAJk3dgfTNKZuOhNzVIZ5GWScKQ5ZtNcWrg6siR+6YwKvLiRb/TJZk", - "PwRUnW4yU8PI7ggbI1BIO9fcTup8optkqCirodyHCiqsPOMZ4g28bJ2+kpfQRujWGlKFYQzA1ZT32s9hdci+fvXPX0KAjcUgcxsGzMABFbEm04BwDF2WLgg9s4/x71r5JrgME1S08I3mCo4N0eFHWDeLJL1b5YNNo6tfO5V2WpIE867N9zdAgvp1gijVjUNWqEB3A/NLb3reLMu2hYgqRFTCVBfcFclD46k0XEfUJqwWdQhOz92WNl/3g53bjKX1hDZgjLIzK6m+SU6+J/h4NidrS7E0gOBevZW8gRYdKMVqNWxzUfxv6kgG+kIeF9JqMcO6jdh/Zu/0tpZoHFeCweZ1jT1eEtltFu1FcTTPc1UT0pT+ZNVgefrBONoGnvn8+dBjPese6F2TmRCExJq9taKlIh/kHdkbpaa7vwrBpYRgVGfARPyM9SSCaE7pVBDuwkFeYiGU4tamm5Gq10ojRQgetJ3UOg/PGTJcxo97GBiG5zAST9NdHdgK3eI4FAbWpGwmWxNpPWOst0a7zuGKAzYU+1IQh8XA3IgJ2vy3+w0JihU6G+12LUzsL2aQtpG7d1PqLhwOqHq3Qqv3SDsB", - "ZIAKizvGzbvqvqOlxOeVgHGHV9TfKNjjqyzbCj8tggv2yp7kkq1D3yRlC349tuul3zN9g4u83Ctio9Gg3HiLzMULxoOImF/hKRDhJpPLbLm0jSq1fyF+N7/YvyLeFhGoPhYEBUihDcxo1NIcWy66aBt3EuOlTyDQWrDe0Za3mrTrrl10uLHVKcQMgeD+UMgjQqmHzQJR8wdNjHPKHWVvZEdiwI031nV2giHJHXv08Jvf4vmw4dAlH2drCl6cBgg33jy7ohK8IiXz6eCw6iY9Ri8YaMzxOhgE2BOHzEz5ZC2hilL4xO/ambTER4bhb4+9VTUIehHP18FcXm8TKPQRMqyKP2fMlzWW3/uelYfPP5SHlyLAULa1KjDCkLIDunEKZDpv2ljGB6JPrTlNwFsvlZcihfOAwjbr2jW3MwP704OA8xzd/dynBU47unIZEu0LAvQ3TUz3PLga0GGO1LZGtg0Foo9zFG2wuVCdgYHmozOQ+8I3gRguW1CjGy7ZCTBuN1GZ510ERhae+bRQtldHsLeiHTghnkU1xEX1+W0iEf3csDYrgpuq3NaBYRGirovDiPBYFHmru0AMclhFnpcX", - "uG0wQ55kMlfZtJFAqTl0bnYW/oy9NFOi0e4FqAYwsvMxGO4JtGzXgkVwEUAC0AUDItRUjxBl+TkoPTYaprgn0M/NQvKPpXJ+yzI7Ssi+F2alLR0T6eF/4rQ32AVjnANJaghXZm0ZKduckbhSxk5lilJVJRuzXKchZRtlPluvlj448bq+iThktsEQoNP8NMpi7n/EVxovp+dow4Q6t7msSRP4cGXtyYoWKbf/7e5XzBKOZZ1/f3s86uJke4dcKIaljpJfBrtuFxZC6NYXzX6PkoDoBgqQ8RBrxsX54S9cBDAPxxmkq8zviAOW3oqPMULGGmQzHBiRwE8oeDFoMnzF5aR/lkbNuTLOxhbIkosgLWlDNVEFYx9bVhdLzO7VwaAK829dimlPOo5loKB7Pd2G7ekRKXwu7wNvJBq8KRkhtLKbKoS8D6TaRWUMb9VBJ1CMy4mrw+YwTmAKURQ6Dko9J/RgzRg5Y/sUlwdMYS9HOnvKiTVu5I/ha35wwkhIPVm+FCn05tstntZaXXXu4xExHeugAKNBhkcc/SQt+GFdxXDd+R4C2LfKxGDSyZKVTFYojHTdZUo8Gx6SZLY6b2SZ", - "sH0kIwIq1THAfTLfqUKJfG1YauCQKPc9/mk3l39yK6zgxSpCH2IjZIwhhJtGm3F+8PTneT725OuyR617nxqrgqMGkkZkyY4DA5CjsikpBo5mo8TspX1g+vtXXtxymJMTMo8JwX3nSH4gSb3vPia+gwOW2TcJmxVdp3ITPA4gJpMfqoMBqRM+eDWO6QXW5ijVL4+wnp40u5bU4fQLVzpg25+QGLqBHD6PZTQaN6F9Vy5XpsAGDlncCklVuX3Lkp3Xb9cTiNa/4ii04uwZqx0juszjwFAMPPb6u56crvN1x4FXfXzabWECHbdQLlKazowvU9bEnqG2i4H44Ae+v8Iw8HK5mbZ6ercLTD9oPgs7Ogal037l2WwLApUz/fmD5fV8SxHh+vKDpfOzv6xcQxynS82jAJw9AdUwE/4ndGzzHPIu2M81gbAgZQ02EurMMU62hYgiXeridrtyh+H5R+CiwQdEyX7/op6WVihsYj2O3O/1hgjhGQRFD6sGwnko50jgWRxaMMfJGNlyGoT8WT5k931jU7547u7Ovr7XP/t8r3G7ceCiCcYjQgdwXdvIStzPvvV7Yy02isZjiJF8TLJQ", - "tycxf1mOz1yLE6cT/ZlCxMeTxlEEHFeIdw0+nF/40Tsw4vLco+4kR2A6cVml611CSpN6l/RMKk2LnAkprrbJ/Uam902WBnQ+I6Vsl6GkFFq7362bdixojqMFVKYytXLCT8I78f6s8M6a3jSALQloD6Ftvn+cc+cctO3weaaaPgAlrz+f2MFs8bqpnLQYbbY/JS9IAYJFH+yVtLz7eKcedEp9JMlJ3/43szU2fDN9ZMxBoQnxEmF3WZv6GF0WRc8VhTblXRgk4mlz6Fu3IXvwW/rbn+VCYYIk/XaVLrxFAnnw6mBozAF7vmV0OrIYBlSDU8rMb+F7AvE7pwErO9TJtCE8IUvQf8TsJYRoYv21/X57pzcBedtqVeU3DnTlmESHxG6H1uJbadSFLWSxKS4svfp8T9FWqX5815yD/UplAKEIeorLTAlPIC2ASKDU6SQW260biNAfY8FYQCWa8btaTwFuY8NMwSHzyqgU0aoPKnagi/4hOIWNO5rZ8Xcnzx+ELtEl33hQnzc4OUlT5eeVYQWkz2IWVQ6Re4JWF3L4OXzNZWgefKGMzZU6IHoBeCgfi+popLRJpaOx0dcvwGjk", - "oDsoFvUA+sGOoMyZY6w1UhY3NBkeoozzjEkDSRN1golyXJ1dC5CtYNEjvAJYKj+sqNwg9mBlYyybYpnI3GSP125zMeBHPCoy5CoNOkJW4OH/oLyjVeQbFNic/b2Jcz6lTguYhep8hq9EM2XuFV8T1rm5+4ucI7fH1UiOqRZyuHBAJ0Cna5kv6D3efsa9rd+swybiMIUjmPWpyxzNOOihCYuf4JqRh/D5eZKm6x0Zj2uRhTAYYxI7Q3czd0R9490ufG8VbF8ASBMireMONNNAA/OZCpxJh6xnIANBqV6YDeysws3NBWY2QuNumvg5Kr3/g+VMzJHi4wGuJjraKWi9+ylMfelHF5h/h+pAQVxCotq8JU3OTnMUW4rQp2a8BR5S+mZqPSPlb87tDG9r0+yqb1uO4UIo71C7Xxwoq4M0tXjk6mSmtP/sm+Lh14qfUzKRhTHVdz91TK104mbTJNXbK+jGPD/2BJO9fiaXY8IYanpfDLBfJo06VYbm6HehRZTwnDHnN50j7ki4aMS3COZvffjRInXD8dS5h9zmtKNpoqg//lPg4gpS+4Th2sJ3SGtBV0Ne89r7AfZMAVa26PMK", - "MIDLuZTrtZnEBOB6l14iSEyokAg5Wf5JviumhfPeL7WSFTHfOodU2hrvhyvM6oAlRHY1blTj7mw+Tcf9Tmc+/FHT6PGu0NT5UAqaqChX0gS9jizgAE2Yfhd4X/DoeQySMAixKuhu8TbvDxb54jeW9+7LVkmlntJ/0SkMgsT+WQ31OfpwDmEGDczYc+Ol14aJS+EW+rnGv9d38bo/cy+EnpNh8iV2rGGoC8fDzFHKU4gqGFSZF/tnD2OfCne0Vjr/GD6kyp2MVcHig19DBg2toGRkHnuY5kLkwOanztXA80IaAmv8e6s62U8CE8ozUZeDBcvBigEkSGx79Vsyiks8+9Kq9xLHLeS5kRT6zSl8whe8U1fIfrgic34KPlozcQVahwCru1XWyQ+9uevih8x4zMftkJ3JBZhPrnlgtx9McntH/Ss9fdUEkNwWpDnq8Xby8/5gMMMwQ13XDB73vqqteDiltMq8i7LRez4iIHfSBBfIkZIzMZAblQXaSm029iBcAAUes7wcGHUl7KOpRy18jNtI3+h7e1Ri6sT2vJYQaove0nzZ5xAjpBKnbJX+lpGVlI00fC2YSTfyNqFA0jkL", - "MG4QbKLbQR3enPn6Z/kEUtHrzWBIqYKR7Gvs5QHLPF6417p1O58suZq38Bb8dO5udtgOqNEVAPGmOuidYygWWfWOP5ReggTUk5XlrkvRxCU0MHWbkSKkJ+T4nLjozreqTJ0io41sFVrpxuOugAvXJ6QtMmixSABUaNgU9SkkWf9pOEiJI8dfND51HxJCbXHwsMCMBp5FbaMZmlWPwirRdAox4wbLk9ZLmoWUcorUjdaWhKvT/LnjMgPmwnwwKpN/4MOnRDdAPdzXX3aWHdkzpfsQnqt3UJsTsSaJlzeUja5C5L4CXGyt99qmfcwB8OB9TL4EYTIl3maD/gUWBfckOsji8x2E2c2iuKKrcmMmcChYr4wCjtTjEeVKOAZ2m9mU2MKc2z2hDw3AuZxsY6aOtdAjnrwl5QXGRg9I5LVl5SI5RwnLwk90pJzDGuSSCtSmzh9DUZ4WpfN+1393aTGRqCMOsB4KxbXjspUbVMFJbnXXlsSNWaoFTpHjK6b6Ghi2/re7KJpoKElM3nGs3qvxdvGTKu7LKr/sgKDL6uQLRKoyk8AHSIGX9c8ZUTk7Sq9jV9p4QfV1WFVpaBxSsEmw", - "MR0BACgWKis9/AKwG9/ARgGWJn1aM3nU8YXzWG+b7aeRUkVCjl4WxeL38E3FAMLW4UcyLzxeb+CskOqhPPTglmxhK7jQcrNILsWcZvdZfApYIvk5uKqA5FKuUuL48uvD0aKGRENe/VEUFlkQru5YX4Xnp+ZThrJJlgn7ANat/qAdP6ULEcLaOQlLYcGRh5ttsJTRT4+cZQggTJjWt+9idUQ66HfC6zQ1qHcMuochy7GHiUmNXAs0AgwOF9Jwet/Qh74KGMtmppJ9gkEqiYECFQA2gVgKc1AufHJS6S6Re72FfH/UkL41L2hvlwktkD5/hZrUZ1R+RG12Eip2zKgus4g/aGl0V8B/JvkcnFUsZJ6uxs24arOBDJOuzzxky5F5B/hwVGPEdcfHunqndUcx26/KCK72hOljlqTXl8yEbXlcMqVFNByZLr7TnGzGGUlO7kuHPW/ItZUJvrHokpsLLrb3ZhEZ8pTQd75gFcf0Ve8CYzEtk2ISHtNJQV6Iz4AZHWssU6F6YWM/OlJz5JGTtPHfGMJXgl4oxbBjeenS3JQ0X7vWXYMwPe3U1dat6m5hrRC1KzI6e6w+gPDtF8GQ", - "DH2WX6XoIseX6lHIey3seUr3DAz82fyk0jL7xc5IDTrDfqS64QBhHDpqHETF/81MrPXsM3IANBfjDOl9g/gua8wWPpPNxuWZMNh0GLcAr6PJ939TCbjE3soZHF2wiA82nZEO8jIZosDVRWFUfJS6Y3nrJz63SExqB6OUdBfvSfz1Y1M/90ofBxkfeuS85deMdn+1rZdsnZJYwz2Z6lCDvYjUTfrSwfVFJBP8Y2BXr8WClUYkfGG4eNG7IPNBRuMmhrhHj5y9z+5Jor+EbbTi5F5Jvdu2/bDM7s32XsaMNLYuVtNYONrbQ+3QZ746/yKZM4hDREvxyGLgDx3Apz7pyvwKm0//iTCY3yJLxZifGLh2uc28cFBln7IH1x8oui4Xq9vF+Z2EH4Ow48Ln5pzggBKMGy4dsfW6266TNYd/Z3SZUi28sxondqhGCSGUo7ZVPAOoYDcYKvjdI/cJ688PHliyZSYBYVmR5HBxZ57sqWwgZQ7zVvwv4CHHysvb92sPrXijHxBIkwpNuK56UMyQCcywlTRLDCMAMNAEGi4fWbDQIoPfn+NixMhEieg3Zh7GXPwHxW8morlgBW5aF76P", - "AwClK6Tq9R2DYGf8RAHu9dEttLeOfUVmS4WPwX0NehsnyM7y7n2sgGnXsiva3yFqK1hKZICkVukvHF7/bpgEEm/jRwcAhQUoG+c1qVde38eHJXj58YOBGTveruc+021or9/tHBtenmYPO6+arLQtONi43NKm7+I6ugkgQlp6iBr4haa0XMDTzMX9c8Qm/O+MrVo3qESYKkVtoSSK7SGZTBaRWNF/dOM0NQxeMP+XTVOuroqE23ZNsubBTEZnd4vUilFb/iKnhyT9XnIo7gM/Yz7HLVU5yc3yIj2sFUE+DcwpvcNO5EnPhj3bHsJvf3N4r72+5my2KjoR3KAJE1Imabd54o4xZ/9UaR93qLkVuXMkLRCCU/zlZDtfbJDsRR0C5rSYd2k6IPlNcl7PgmUpsNPUyoDYqvhuRUZxgoUAfKbogzJX8FU/QpllsKVtt68ucBi0bqC5pVKu23j79nDvYQsSlYY3JwJQaM5M558J5qpP1yEF2p4kSRphnB9UR29wWgch5eWZ4a02LlHVM5Msl6W5PdmHt+eFARBRv6edIyYDFzxm4WZroH5F/GxBhM0KObgawkxa5VWsYm0VhhXb", - "KACwq8rZuOLHuNnZJA07WzI7kppCwptbcYU2B7t86QcZrnadCtxoM5QNcl9rsbMA26iWCPV3VlDAmLSWcxtMoSKWuo4edJpk8K915xkFU5U6I/901vx5hqAECQDy/Q+QDWmWTXDoVHqFV9wvIj3wCJPpJL/Ewpl0NZd+68jjOjUhjIdNebLrWNK2nhTPiIjFjkcVqEgashpOmnbHT+2MV/CHoixmUEiuRI1B0dvSf7FHGRgbXGBubisuu60g8XTens5zyRo4Qn/LTxIu2aj4LTtyLonV3sXr+y35A1zq5mCrE1f1nOINVzwYYY76iJGIaBkZuMU3366FPIbYkmXwla6RQU1FA0Y7n05qczw7Ie5TveRTByKFtUqW8OAb9vH+H2ezJ4CXE3AGbu/nTj64KClO/zL499GA+97g+X6tTN6xOJdNknlqw6ZnFNtCL8+A3hL4OyOgWD0IGC+xFvcKjDUaaJenCtQvprCJaFrvoOS+yYmixnFqglnPYL/64/Lca8NmDVpPzlHI8HNwUDzKiXTw3q7GnQZWmUYzu1vLIEi6/hyqrULRN1vLdd/8HCMNQFj4ot61UftHtOG8MCKa", - "rUABPQ3SEWE5rY16pM+o+7EObLNM1jEa5YCMQM/aen0PWajWNax3Pyo6TZL8aGDXZF0yWqDM3b2m6UHOr6yqsUSrD+0jXPT48QN1VdBmh+AFRK+UcaYO383a0nvtv0c9uHt4yfceXLPGWrNjW+uTnS/lKpCdpE4GfLF1SFHIUcMxT+3At7hwDHNkLXllEXqbgDP8LyQSlYwT5jQUDCOzwc8CSxAryUOj6fN+iLKAiw4haPV/WZDG+JOmDMG2azo8SoBMi3y6Z2Le2fz2dMuvn5DUvCUvazrUmWYx4NEdSzc9GfBc6cXkduMqCs+lT2Ik2GHO0WjhrEB6j5NULOaCtbrislM85P6QutN4Pj9l18pcD6vZCcDTOwMj/BznclH342jeMn7rBgpW1YSzbNGP6KC4NeNW1H2xqNtuyhcJvasx4dwhzO18A36H6HtkiQyJNnfnVHh1oviO6mi3atmnh9B/55ugXM1Wf/6Kv8kJyaKtK8cWo+jCAR0/P/EsPtzToJM9Yk2+qxaPFd3k7T2KXvCQ9D1jLeECxL59L+WDvdBtxOEBD7W0a/Mn/9LuQPOiwARKJSTU+blJ6ezTeo83", - "poA1hF4zRh7HF0xVglYoLFqkUR7Pru/qYFnfMKBPuEOOGdgO3MMcAvIZ+w+Ug4THr/6+Vux0TN3wdOB+beObOboLgNE2zaD65lyMFbaulzrEnWjUgIg63CdpQJ2ESaimHGg/GmsipUCndRJ37TbUtn8W112SehsAgrsjiBcuJhw61i4bVfAZEcycq4Y/FlEDxtzoH8WzDoESNbl+r5agLcHGr37BFi81IXS8TLihC1T8b7d6tLb6lpXT+9IR4xAyZTw1IFMDZZEzVmHgYE/Et20/WhkX/oGghkWSpCxR0kynDplk+BEK2oyGKnl+rf4vymhsse2iQ/C99PhaodZjDfuGVSwPLoU0AYyAKaEwmgHPOFbDlrAmNk4iBp+IZYm9guZM2hcQ4GeA5WQyZzw4C1yMywWbdjtL9ZhpClmmPZ28nmwNORAat7tXPJoBBdXFB0gNT/wU7UYIKU5GnAiDIFJ0o8ijnuAMat3AsBki2vxwdypuBq5M6OF9DVA0HRUjOA0l4JHjK8Y282mz3U34PDPQvwCT342uD9cO3uXoSr3T2FnDmsVHz4Q9zYpSjioLmZk9ZTnQWgN5V5Oyat6m" - }; - - public String getName() - { - return "ParsingTest"; - } - - public void performTest() - throws Exception - { - inputStreamTest(); - parserTest(); - } - - private void parserTest() - { - for (int i = 0; i != streams.length; i++) - { - ASN1StreamParser aIn = new ASN1StreamParser(Base64.decode(streams[i])); - - try - { - Object obj; - - while ((obj = aIn.readObject()) != null) - { - - } - - fail("bad stream parsed successfully!"); - } - catch (IOException e) - { - // ignore - } - } - } - - private void inputStreamTest() - { - for (int i = 0; i != streams.length; i++) - { - ASN1InputStream aIn = new ASN1InputStream(Base64.decode(streams[i])); - - try - { - Object obj; - - while ((obj = aIn.readObject()) != null) - { - - } - - fail("bad stream parsed successfully!"); - } - catch (IOException e) - { - // ignore - } - } - } - - public static void main( - String[] args) - { - runTest(new ParsingTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PendInfoTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PendInfoTest.java deleted file mode 100644 index c36435f0a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PendInfoTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.util.Date; - -import com.fr.third.org.bouncycastle.asn1.ASN1GeneralizedTime; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.cmc.PendInfo; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class PendInfoTest - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new PendInfoTest()); - } - - public String getName() - { - return "PendInfoTest"; - } - - public void performTest() - throws Exception - { - PendInfo info = new PendInfo("".getBytes(), new ASN1GeneralizedTime(new Date())); - byte[] b = info.getEncoded(); - PendInfo infoResult = PendInfo.getInstance(b); - - isTrue("pendToken", areEqual(info.getPendToken(), infoResult.getPendToken())); - isEquals("pendTime", info.getPendTime(), infoResult.getPendTime()); - - try - { - PendInfo.getInstance(new DERSequence()); - fail("Sequence length not 2"); - } - catch (Throwable t) - { - isEquals("Exception type", t.getClass(), IllegalArgumentException.class); - } - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PersonalDataUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PersonalDataUnitTest.java deleted file mode 100644 index c23f62c16..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PersonalDataUnitTest.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.asn1.ASN1GeneralizedTime; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; -import com.fr.third.org.bouncycastle.asn1.x509.sigi.NameOrPseudonym; -import com.fr.third.org.bouncycastle.asn1.x509.sigi.PersonalData; - -public class PersonalDataUnitTest - extends ASN1UnitTest -{ - public String getName() - { - return "PersonalData"; - } - - public void performTest() - throws Exception - { - NameOrPseudonym nameOrPseudonym = new NameOrPseudonym("pseudonym"); - BigInteger nameDistinguisher = BigInteger.valueOf(10); - ASN1GeneralizedTime dateOfBirth= new ASN1GeneralizedTime("20070315173729Z"); - DirectoryString placeOfBirth = new DirectoryString("placeOfBirth"); - String gender = "M"; - DirectoryString postalAddress = new DirectoryString("address"); - - PersonalData data = new PersonalData(nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, postalAddress); - - checkConstruction(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, postalAddress); - - data = new PersonalData(nameOrPseudonym, null, dateOfBirth, placeOfBirth, gender, postalAddress); - - checkConstruction(data, nameOrPseudonym, null, dateOfBirth, placeOfBirth, gender, postalAddress); - - data = new PersonalData(nameOrPseudonym, nameDistinguisher, null, placeOfBirth, gender, postalAddress); - - checkConstruction(data, nameOrPseudonym, nameDistinguisher, null, placeOfBirth, gender, postalAddress); - - data = new PersonalData(nameOrPseudonym, nameDistinguisher, dateOfBirth, null, gender, postalAddress); - - checkConstruction(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, null, gender, postalAddress); - - data = new PersonalData(nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, null, postalAddress); - - checkConstruction(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, null, postalAddress); - - data = new PersonalData(nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, null); - - checkConstruction(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, null); - - data = PersonalData.getInstance(null); - - if (data != null) - { - fail("null getInstance() failed."); - } - - try - { - PersonalData.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - PersonalData data, - NameOrPseudonym nameOrPseudonym, - BigInteger nameDistinguisher, - ASN1GeneralizedTime dateOfBirth, - DirectoryString placeOfBirth, - String gender, - DirectoryString postalAddress) - throws IOException - { - checkValues(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, postalAddress); - - data = PersonalData.getInstance(data); - - checkValues(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, postalAddress); - - ASN1InputStream aIn = new ASN1InputStream(data.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - data = PersonalData.getInstance(seq); - - checkValues(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, postalAddress); - } - - private void checkValues( - PersonalData data, - NameOrPseudonym nameOrPseudonym, - BigInteger nameDistinguisher, - ASN1GeneralizedTime dateOfBirth, - DirectoryString placeOfBirth, - String gender, - DirectoryString postalAddress) - { - checkMandatoryField("nameOrPseudonym", nameOrPseudonym, data.getNameOrPseudonym()); - checkOptionalField("nameDistinguisher", nameDistinguisher, data.getNameDistinguisher()); - checkOptionalField("dateOfBirth", dateOfBirth, data.getDateOfBirth()); - checkOptionalField("placeOfBirth", placeOfBirth, data.getPlaceOfBirth()); - checkOptionalField("gender", gender, data.getGender()); - checkOptionalField("postalAddress", postalAddress, data.getPostalAddress()); - } - - public static void main( - String[] args) - { - runTest(new PersonalDataUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PolicyConstraintsTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PolicyConstraintsTest.java deleted file mode 100644 index 7850e2c45..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PolicyConstraintsTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERTaggedObject; -import com.fr.third.org.bouncycastle.asn1.x509.PolicyConstraints; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class PolicyConstraintsTest - extends SimpleTest -{ - public String getName() - { - return "PolicyConstraints"; - } - - public void performTest() - throws Exception - { - PolicyConstraints constraints = new PolicyConstraints(BigInteger.valueOf(1), BigInteger.valueOf(2)); - - PolicyConstraints c = PolicyConstraints.getInstance(constraints.getEncoded()); - - isTrue("1 requireExplicitPolicyMapping", c.getRequireExplicitPolicyMapping().equals(BigInteger.valueOf(1))); - isTrue("2 inhibitPolicyMapping", c.getInhibitPolicyMapping().equals(BigInteger.valueOf(2))); - - constraints = new PolicyConstraints(BigInteger.valueOf(3), null); - - c = PolicyConstraints.getInstance(constraints.getEncoded()); - - isTrue("3 requireExplicitPolicyMapping", c.getRequireExplicitPolicyMapping().equals(BigInteger.valueOf(3))); - isTrue("4 inhibitPolicyMapping", c.getInhibitPolicyMapping() == null); - - - constraints = new PolicyConstraints(null, BigInteger.valueOf(4)); - - c = PolicyConstraints.getInstance(constraints.getEncoded()); - - isTrue("5 inhibitPolicyMapping", c.getInhibitPolicyMapping().equals(BigInteger.valueOf(4))); - isTrue("6 requireExplicitPolicyMapping", c.getRequireExplicitPolicyMapping() == null); - - isTrue("encoding test", Arrays.areEqual( - new PolicyConstraints(BigInteger.valueOf(1), null).getEncoded(), - new DERSequence(new DERTaggedObject(false, 0, new ASN1Integer(1))).getEncoded())); - } - - public static void main( - String[] args) - { - runTest(new PolicyConstraintsTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PollReqContentTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PollReqContentTest.java deleted file mode 100644 index 00e185c12..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PollReqContentTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.cmp.PollReqContent; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class PollReqContentTest - extends SimpleTest -{ - public String getName() - { - return "PollReqContentTest"; - } - - public void performTest() - throws Exception - { - BigInteger one = BigInteger.valueOf(1), two = BigInteger.valueOf(2); - BigInteger[] ids = new BigInteger[] { one, two }; - - PollReqContent c = new PollReqContent(ids); - - ASN1Integer[][] vs = c.getCertReqIds(); - - isTrue(vs.length == 2); - for (int i = 0; i != vs.length; i++) - { - isTrue(vs[i].length == 1); - isTrue(vs[i][0].getValue().equals(ids[i])); - } - - BigInteger[] values = c.getCertReqIdValues(); - - isTrue(values.length == 2); - for (int i = 0; i != values.length; i++) - { - isTrue(values[i].equals(ids[i])); - } - - c = new PollReqContent(two); - vs = c.getCertReqIds(); - - isTrue(vs.length == 1); - - isTrue(vs[0].length == 1); - isTrue(vs[0][0].getValue().equals(two)); - } - - public static void main(String[] args) - { - runTest(new PollReqContentTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PopLinkWitnessV2Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PopLinkWitnessV2Test.java deleted file mode 100644 index 3dd7b9586..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PopLinkWitnessV2Test.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.cmc.PopLinkWitnessV2; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class PopLinkWitnessV2Test - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new PopLinkWitnessV2Test()); - } - - public String getName() - { - return "PopLinkWitnessV2Test"; - } - - public void performTest() - throws Exception - { - // Object identifiers real but not correct in this context. - PopLinkWitnessV2 popLinkWitnessV2 = new PopLinkWitnessV2( - new AlgorithmIdentifier(PKCSObjectIdentifiers.bagtypes, new ASN1Integer(10L)), - new AlgorithmIdentifier(PKCSObjectIdentifiers.crlTypes, new ASN1Integer(12L)), - "cats".getBytes() - ); - - byte[] b = popLinkWitnessV2.getEncoded(); - PopLinkWitnessV2 popLinkWitnessV2Result = PopLinkWitnessV2.getInstance(b); - - isEquals(popLinkWitnessV2, popLinkWitnessV2Result); - - try - { - PopLinkWitnessV2.getInstance(new DERSequence()); - fail("Length must be 3"); - } - catch (Throwable t) - { - isEquals(t.getClass(), IllegalArgumentException.class); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PrivateKeyInfoTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PrivateKeyInfoTest.java deleted file mode 100644 index ba1ff2cc7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PrivateKeyInfoTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.pkcs.PrivateKeyInfo; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class PrivateKeyInfoTest - extends SimpleTest -{ - private static final byte[] priv = Base64.decode( - "MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC"); - - private static final byte[] privWithPub = Base64.decode( - "MHICAQEwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC" + - "oB8wHQYKKoZIhvcNAQkJFDEPDA1DdXJkbGUgQ2hhaXJzgSEAGb9ECWmEzf6FQbrB" + - "Z9w7lshQhqowtrbLDFw4rXAxZuE="); - - - public String getName() - { - return "PrivateKeyInfoTest"; - } - - public void performTest() - throws Exception - { - PrivateKeyInfo privInfo1 = PrivateKeyInfo.getInstance(priv); - - isTrue(!privInfo1.hasPublicKey()); - - PrivateKeyInfo privInfo2 = new PrivateKeyInfo(privInfo1.getPrivateKeyAlgorithm(), privInfo1.parsePrivateKey()); - - isTrue("enc 1 failed", areEqual(priv, privInfo2.getEncoded())); - - privInfo1 = PrivateKeyInfo.getInstance(privWithPub); - - isTrue(privInfo1.hasPublicKey()); - - privInfo2 = new PrivateKeyInfo(privInfo1.getPrivateKeyAlgorithm(), privInfo1.parsePrivateKey(), privInfo1.getAttributes(), privInfo1.getPublicKeyData().getOctets()); - - isTrue("enc 2 failed", areEqual(privWithPub, privInfo2.getEncoded())); - } - - public static void main( - String[] args) - { - runTest(new PrivateKeyInfoTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ProcurationSyntaxUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ProcurationSyntaxUnitTest.java deleted file mode 100644 index 442771e1a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ProcurationSyntaxUnitTest.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.ProcurationSyntax; -import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralNames; -import com.fr.third.org.bouncycastle.asn1.x509.IssuerSerial; - -public class ProcurationSyntaxUnitTest - extends ASN1UnitTest -{ - public String getName() - { - return "ProcurationSyntax"; - } - - public void performTest() - throws Exception - { - String country = "AU"; - DirectoryString typeOfSubstitution = new DirectoryString("substitution"); - GeneralName thirdPerson = new GeneralName(new X500Name("CN=thirdPerson")); - IssuerSerial certRef = new IssuerSerial(new GeneralNames(new GeneralName(new X500Name("CN=test"))), new ASN1Integer(1)); - - ProcurationSyntax procuration = new ProcurationSyntax(country, typeOfSubstitution, thirdPerson); - - checkConstruction(procuration, country, typeOfSubstitution, thirdPerson, null); - - procuration = new ProcurationSyntax(country, typeOfSubstitution, certRef); - - checkConstruction(procuration, country, typeOfSubstitution, null, certRef); - - procuration = new ProcurationSyntax(null, typeOfSubstitution, certRef); - - checkConstruction(procuration, null, typeOfSubstitution, null, certRef); - - procuration = new ProcurationSyntax(country, null, certRef); - - checkConstruction(procuration, country, null, null, certRef); - - procuration = ProcurationSyntax.getInstance(null); - - if (procuration != null) - { - fail("null getInstance() failed."); - } - - try - { - ProcurationSyntax.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - ProcurationSyntax procuration, - String country, - DirectoryString typeOfSubstitution, - GeneralName thirdPerson, - IssuerSerial certRef) - throws IOException - { - checkValues(procuration, country, typeOfSubstitution, thirdPerson, certRef); - - procuration = ProcurationSyntax.getInstance(procuration); - - checkValues(procuration, country, typeOfSubstitution, thirdPerson, certRef); - - ASN1InputStream aIn = new ASN1InputStream(procuration.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - procuration = ProcurationSyntax.getInstance(seq); - - checkValues(procuration, country, typeOfSubstitution, thirdPerson, certRef); - } - - private void checkValues( - ProcurationSyntax procuration, - String country, - DirectoryString typeOfSubstitution, - GeneralName thirdPerson, - IssuerSerial certRef) - { - checkOptionalField("country", country, procuration.getCountry()); - checkOptionalField("typeOfSubstitution", typeOfSubstitution, procuration.getTypeOfSubstitution()); - checkOptionalField("thirdPerson", thirdPerson, procuration.getThirdPerson()); - checkOptionalField("certRef", certRef, procuration.getCertRef()); - } - - public static void main( - String[] args) - { - runTest(new ProcurationSyntaxUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ProfessionInfoUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ProfessionInfoUnitTest.java deleted file mode 100644 index 3c514c0b6..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ProfessionInfoUnitTest.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.NamingAuthority; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.ProcurationSyntax; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.ProfessionInfo; -import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; - -public class ProfessionInfoUnitTest - extends ASN1UnitTest -{ - public String getName() - { - return "ProfessionInfo"; - } - - public void performTest() - throws Exception - { - NamingAuthority auth = new NamingAuthority(new ASN1ObjectIdentifier("1.2.3"), "url", new DirectoryString("fred")); - DirectoryString[] professionItems = { new DirectoryString("substitution") }; - ASN1ObjectIdentifier[] professionOids = { new ASN1ObjectIdentifier("1.2.3") }; - String registrationNumber = "12345"; - DEROctetString addProfInfo = new DEROctetString(new byte[20]); - - ProfessionInfo info = new ProfessionInfo(auth, professionItems, professionOids, registrationNumber, addProfInfo); - - checkConstruction(info, auth, professionItems, professionOids, registrationNumber, addProfInfo); - - info = new ProfessionInfo(null, professionItems, professionOids, registrationNumber, addProfInfo); - - checkConstruction(info, null, professionItems, professionOids, registrationNumber, addProfInfo); - - info = new ProfessionInfo(auth, professionItems, null, registrationNumber, addProfInfo); - - checkConstruction(info, auth, professionItems, null, registrationNumber, addProfInfo); - - info = new ProfessionInfo(auth, professionItems, professionOids, null, addProfInfo); - - checkConstruction(info, auth, professionItems, professionOids, null, addProfInfo); - - info = new ProfessionInfo(auth, professionItems, professionOids, registrationNumber, null); - - checkConstruction(info, auth, professionItems, professionOids, registrationNumber, null); - - info = ProfessionInfo.getInstance(null); - - if (info != null) - { - fail("null getInstance() failed."); - } - - try - { - ProcurationSyntax.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - ProfessionInfo profInfo, - NamingAuthority auth, - DirectoryString[] professionItems, - ASN1ObjectIdentifier[] professionOids, - String registrationNumber, - DEROctetString addProfInfo) - throws IOException - { - checkValues(profInfo, auth, professionItems, professionOids, registrationNumber, addProfInfo); - - profInfo = ProfessionInfo.getInstance(profInfo); - - checkValues(profInfo, auth, professionItems, professionOids, registrationNumber, addProfInfo); - - ASN1InputStream aIn = new ASN1InputStream(profInfo.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - profInfo = ProfessionInfo.getInstance(seq); - - checkValues(profInfo, auth, professionItems, professionOids, registrationNumber, addProfInfo); - } - - private void checkValues( - ProfessionInfo profInfo, - NamingAuthority auth, - DirectoryString[] professionItems, - ASN1ObjectIdentifier[] professionOids, - String registrationNumber, - DEROctetString addProfInfo) - { - checkOptionalField("auth", auth, profInfo.getNamingAuthority()); - checkMandatoryField("professionItems", professionItems[0], profInfo.getProfessionItems()[0]); - if (professionOids != null) - { - checkOptionalField("professionOids", professionOids[0], profInfo.getProfessionOIDs()[0]); - } - checkOptionalField("registrationNumber", registrationNumber, profInfo.getRegistrationNumber()); - checkOptionalField("addProfessionInfo", addProfInfo, profInfo.getAddProfessionInfo()); - } - - public static void main( - String[] args) - { - runTest(new ProfessionInfoUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PublishTrustAnchorsTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PublishTrustAnchorsTest.java deleted file mode 100644 index 67adf2252..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/PublishTrustAnchorsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.cmc.PublishTrustAnchors; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class PublishTrustAnchorsTest - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new PublishTrustAnchorsTest()); - } - - public String getName() - { - return "PublishTrustAnchorsTest"; - } - - public void performTest() - throws Exception - { - PublishTrustAnchors publishTrustAnchors = new PublishTrustAnchors( - new BigInteger("10"), new AlgorithmIdentifier(PKCSObjectIdentifiers.crlTypes, - new ASN1Integer(5L)), new byte[][]{"cats".getBytes()}); - - byte[] b = publishTrustAnchors.getEncoded(); - - PublishTrustAnchors publishTrustAnchorsResult = PublishTrustAnchors.getInstance(b); - - isEquals("seqNumber", publishTrustAnchors.getSeqNumber(), publishTrustAnchorsResult.getSeqNumber()); - isEquals("hashAlgorithm", publishTrustAnchors.getHashAlgorithm(), publishTrustAnchorsResult.getHashAlgorithm()); - isTrue("anchorHashes", areEqual(publishTrustAnchors.getAnchorHashes(), publishTrustAnchorsResult.getAnchorHashes())); - - try - { - PublishTrustAnchors.getInstance(new DERSequence()); - fail("Sequence must be 3"); - } - catch (Throwable t) - { - isEquals("Expect IllegalArgumentException", t.getClass(), IllegalArgumentException.class); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/QCStatementUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/QCStatementUnitTest.java deleted file mode 100644 index b285fa9e6..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/QCStatementUnitTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.x509.qualified.QCStatement; -import com.fr.third.org.bouncycastle.asn1.x509.qualified.RFC3739QCObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.x509.qualified.SemanticsInformation; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class QCStatementUnitTest - extends SimpleTest -{ - public String getName() - { - return "QCStatement"; - } - - public void performTest() - throws Exception - { - QCStatement mv = new QCStatement(RFC3739QCObjectIdentifiers.id_qcs_pkixQCSyntax_v1); - - checkConstruction(mv, RFC3739QCObjectIdentifiers.id_qcs_pkixQCSyntax_v1, null); - - ASN1Encodable info = new SemanticsInformation(new ASN1ObjectIdentifier("1.2")); - - mv = new QCStatement(RFC3739QCObjectIdentifiers.id_qcs_pkixQCSyntax_v1, info); - - checkConstruction(mv, RFC3739QCObjectIdentifiers.id_qcs_pkixQCSyntax_v1, info); - - mv = QCStatement.getInstance(null); - - if (mv != null) - { - fail("null getInstance() failed."); - } - - try - { - QCStatement.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - QCStatement mv, - ASN1ObjectIdentifier statementId, - ASN1Encodable statementInfo) - throws IOException - { - checkStatement(mv, statementId, statementInfo); - - mv = QCStatement.getInstance(mv); - - checkStatement(mv, statementId, statementInfo); - - ASN1InputStream aIn = new ASN1InputStream(mv.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - mv = QCStatement.getInstance(seq); - - checkStatement(mv, statementId, statementInfo); - } - - private void checkStatement( - QCStatement qcs, - ASN1ObjectIdentifier statementId, - ASN1Encodable statementInfo) - throws IOException - { - if (!qcs.getStatementId().equals(statementId)) - { - fail("statementIds don't match."); - } - - if (statementInfo != null) - { - if (!qcs.getStatementInfo().equals(statementInfo)) - { - fail("statementInfos don't match."); - } - } - else if (qcs.getStatementInfo() != null) - { - fail("statementInfo found when none expected."); - } - } - - public static void main( - String[] args) - { - runTest(new QCStatementUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RFC4519Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RFC4519Test.java deleted file mode 100644 index e21176f3d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RFC4519Test.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x500.X500NameStyle; -import com.fr.third.org.bouncycastle.asn1.x500.style.RFC4519Style; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class RFC4519Test - extends SimpleTest -{ - static String[] attributeTypes = - { - "businessCategory", - "c", - "cn", - "dc", - "description", - "destinationIndicator", - "distinguishedName", - "dnQualifier", - "enhancedSearchGuide", - "facsimileTelephoneNumber", - "generationQualifier", - "givenName", - "houseIdentifier", - "initials", - "internationalISDNNumber", - "l", - "member", - "name", - "o", - "ou", - "owner", - "physicalDeliveryOfficeName", - "postalAddress", - "postalCode", - "postOfficeBox", - "preferredDeliveryMethod", - "registeredAddress", - "roleOccupant", - "searchGuide", - "seeAlso", - "serialNumber", - "sn", - "st", - "street", - "telephoneNumber", - "teletexTerminalIdentifier", - "telexNumber", - "title", - "uid", - "uniqueMember", - "userPassword", - "x121Address", - "x500UniqueIdentifier" - }; - - static ASN1ObjectIdentifier[] attributeTypeOIDs = - { - new ASN1ObjectIdentifier("2.5.4.15"), - new ASN1ObjectIdentifier("2.5.4.6"), - new ASN1ObjectIdentifier("2.5.4.3"), - new ASN1ObjectIdentifier("0.9.2342.19200300.100.1.25"), - new ASN1ObjectIdentifier("2.5.4.13"), - new ASN1ObjectIdentifier("2.5.4.27"), - new ASN1ObjectIdentifier("2.5.4.49"), - new ASN1ObjectIdentifier("2.5.4.46"), - new ASN1ObjectIdentifier("2.5.4.47"), - new ASN1ObjectIdentifier("2.5.4.23"), - new ASN1ObjectIdentifier("2.5.4.44"), - new ASN1ObjectIdentifier("2.5.4.42"), - new ASN1ObjectIdentifier("2.5.4.51"), - new ASN1ObjectIdentifier("2.5.4.43"), - new ASN1ObjectIdentifier("2.5.4.25"), - new ASN1ObjectIdentifier("2.5.4.7"), - new ASN1ObjectIdentifier("2.5.4.31"), - new ASN1ObjectIdentifier("2.5.4.41"), - new ASN1ObjectIdentifier("2.5.4.10"), - new ASN1ObjectIdentifier("2.5.4.11"), - new ASN1ObjectIdentifier("2.5.4.32"), - new ASN1ObjectIdentifier("2.5.4.19"), - new ASN1ObjectIdentifier("2.5.4.16"), - new ASN1ObjectIdentifier("2.5.4.17"), - new ASN1ObjectIdentifier("2.5.4.18"), - new ASN1ObjectIdentifier("2.5.4.28"), - new ASN1ObjectIdentifier("2.5.4.26"), - new ASN1ObjectIdentifier("2.5.4.33"), - new ASN1ObjectIdentifier("2.5.4.14"), - new ASN1ObjectIdentifier("2.5.4.34"), - new ASN1ObjectIdentifier("2.5.4.5"), - new ASN1ObjectIdentifier("2.5.4.4"), - new ASN1ObjectIdentifier("2.5.4.8"), - new ASN1ObjectIdentifier("2.5.4.9"), - new ASN1ObjectIdentifier("2.5.4.20"), - new ASN1ObjectIdentifier("2.5.4.22"), - new ASN1ObjectIdentifier("2.5.4.21"), - new ASN1ObjectIdentifier("2.5.4.12"), - new ASN1ObjectIdentifier("0.9.2342.19200300.100.1.1"), - new ASN1ObjectIdentifier("2.5.4.50"), - new ASN1ObjectIdentifier("2.5.4.35"), - new ASN1ObjectIdentifier("2.5.4.24"), - new ASN1ObjectIdentifier("2.5.4.45") - }; - - public String getName() - { - return "RFC4519Test"; - } - - public void performTest() - throws Exception - { - X500NameStyle style = RFC4519Style.INSTANCE; - - for (int i = 0; i != attributeTypes.length; i++) - { - if (!attributeTypeOIDs[i].equals(style.attrNameToOID(attributeTypes[i]))) - { - fail("mismatch for " + attributeTypes[i]); - } - } - - byte[] enc = Hex.decode("305e310b300906035504061302415531283026060355040a0c1f546865204c6567696f6e206f662074686520426f756e637920436173746c653125301006035504070c094d656c626f75726e653011060355040b0c0a4173636f742056616c65"); - - X500Name n = X500Name.getInstance(style, X500Name.getInstance(enc)); - - if (!n.toString().equals("l=Melbourne+ou=Ascot Vale,o=The Legion of the Bouncy Castle,c=AU")) - { - fail("Failed composite to string test got: " + n.toString()); - } - - n = new X500Name(style, "l=Melbourne+ou=Ascot Vale,o=The Legion of the Bouncy Castle,c=AU"); - - if (!Arrays.areEqual(n.getEncoded(), enc)) - { - fail("re-encoding test after parse failed"); - } - } - - - public static void main( - String[] args) - { - runTest(new RFC4519Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ReasonFlagsTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ReasonFlagsTest.java deleted file mode 100644 index e300f7ad7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/ReasonFlagsTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.x509.ReasonFlags; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class ReasonFlagsTest - extends SimpleTest -{ - public String getName() - { - return "ReasonFlags"; - } - - public void performTest() - throws IOException - { - BitStringConstantTester.testFlagValueCorrect(0, ReasonFlags.unused); - BitStringConstantTester.testFlagValueCorrect(1, ReasonFlags.keyCompromise); - BitStringConstantTester.testFlagValueCorrect(2, ReasonFlags.cACompromise); - BitStringConstantTester.testFlagValueCorrect(3, ReasonFlags.affiliationChanged); - BitStringConstantTester.testFlagValueCorrect(4, ReasonFlags.superseded); - BitStringConstantTester.testFlagValueCorrect(5, ReasonFlags.cessationOfOperation); - BitStringConstantTester.testFlagValueCorrect(6, ReasonFlags.certificateHold); - BitStringConstantTester.testFlagValueCorrect(7, ReasonFlags.privilegeWithdrawn); - BitStringConstantTester.testFlagValueCorrect(8, ReasonFlags.aACompromise); - } - - public static void main( - String[] args) - { - runTest(new ReasonFlagsTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RegressionTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RegressionTest.java deleted file mode 100644 index 33f0e6d08..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RegressionTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.Test; - -public class RegressionTest -{ - public static Test[] tests = { - new InputStreamTest(), - new EqualsAndHashCodeTest(), - new TagTest(), - new SetTest(), - new ASN1IntegerTest(), - new DERUTF8StringTest(), - new CertificateTest(), - new GenerationTest(), - new CMSTest(), - new OCSPTest(), - new OIDTest(), - new PKCS10Test(), - new PKCS12Test(), - new X509NameTest(), - new X500NameTest(), - new X509ExtensionsTest(), - new GeneralizedTimeTest(), - new BitStringTest(), - new MiscTest(), - new SMIMETest(), - new X9Test(), - new MonetaryValueUnitTest(), - new BiometricDataUnitTest(), - new Iso4217CurrencyCodeUnitTest(), - new SemanticsInformationUnitTest(), - new QCStatementUnitTest(), - new TypeOfBiometricDataUnitTest(), - new SignerLocationUnitTest(), - new CommitmentTypeQualifierUnitTest(), - new CommitmentTypeIndicationUnitTest(), - new EncryptedPrivateKeyInfoTest(), - new DataGroupHashUnitTest(), - new LDSSecurityObjectUnitTest(), - new CscaMasterListTest(), - new AttributeTableUnitTest(), - new ReasonFlagsTest(), - new NetscapeCertTypeTest(), - new PKIFailureInfoTest(), - new KeyUsageTest(), - new StringTest(), - new UTCTimeTest(), - new RequestedCertificateUnitTest(), - new OtherCertIDUnitTest(), - new OtherSigningCertificateUnitTest(), - new ContentHintsUnitTest(), - new CertHashUnitTest(), - new AdditionalInformationSyntaxUnitTest(), - new AdmissionSyntaxUnitTest(), - new AdmissionsUnitTest(), - new DeclarationOfMajorityUnitTest(), - new ProcurationSyntaxUnitTest(), - new ProfessionInfoUnitTest(), - new RestrictionUnitTest(), - new NamingAuthorityUnitTest(), - new MonetaryLimitUnitTest(), - new NameOrPseudonymUnitTest(), - new PersonalDataUnitTest(), - new DERApplicationSpecificTest(), - new IssuingDistributionPointUnitTest(), - new TargetInformationTest(), - new SubjectKeyIdentifierTest(), - new ESSCertIDv2UnitTest(), - new ParsingTest(), - new GeneralNameTest(), - new ObjectIdentifierTest(), - new RFC4519Test(), - new PolicyConstraintsTest(), - new PollReqContentTest(), - new DhSigStaticTest(), - new PKIPublicationInfoTest(), - new CertifiedKeyPairTest(), - new PrivateKeyInfoTest(), - new LocaleTest(), - new LinkedCertificateTest() - }; - - public static void main(String[] args) - { - SimpleTest.runTests(tests); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RequestedCertificateUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RequestedCertificateUnitTest.java deleted file mode 100644 index 77bf64419..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RequestedCertificateUnitTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.isismtt.ocsp.RequestedCertificate; -import com.fr.third.org.bouncycastle.asn1.x509.Certificate; -import com.fr.third.org.bouncycastle.util.encoders.Base64; - -public class RequestedCertificateUnitTest - extends ASN1UnitTest -{ - byte[] certBytes = Base64.decode( - "MIIBWzCCAQYCARgwDQYJKoZIhvcNAQEEBQAwODELMAkGA1UEBhMCQVUxDDAKBgNV" - + "BAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3JzYSB0ZXN0IENBMB4XDTk1MDYxOTIz" - + "MzMxMloXDTk1MDcxNzIzMzMxMlowOjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FM" - + "RDEdMBsGA1UEAxMUU1NMZWF5L3JzYSB0ZXN0IGNlcnQwXDANBgkqhkiG9w0BAQEF" - + "AANLADBIAkEAqtt6qS5GTxVxGZYWa0/4u+IwHf7p2LNZbcPBp9/OfIcYAXBQn8hO" - + "/Re1uwLKXdCjIoaGs4DLdG88rkzfyK5dPQIDAQABMAwGCCqGSIb3DQIFBQADQQAE" - + "Wc7EcF8po2/ZO6kNCwK/ICH6DobgLekA5lSLr5EvuioZniZp5lFzAw4+YzPQ7XKJ" - + "zl9HYIMxATFyqSiD9jsx"); - - public String getName() - { - return "RequestedCertificate"; - } - - public void performTest() - throws Exception - { - int type = 1; - byte[] certOctets = new byte[20]; - Certificate cert = Certificate.getInstance(certBytes); - - RequestedCertificate requested = new RequestedCertificate(type, certOctets); - - checkConstruction(requested, type, certOctets, null); - - requested = new RequestedCertificate(cert); - - checkConstruction(requested, RequestedCertificate.certificate, null, cert); - - requested = RequestedCertificate.getInstance(null); - - if (requested != null) - { - fail("null getInstance() failed."); - } - - try - { - RequestedCertificate.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - RequestedCertificate requested, - int type, - byte[] certOctets, - Certificate cert) - throws IOException - { - checkValues(requested, type, certOctets, cert); - - requested = RequestedCertificate.getInstance(requested); - - checkValues(requested, type, certOctets, cert); - - ASN1InputStream aIn = new ASN1InputStream(requested.toASN1Primitive().getEncoded()); - - Object obj = aIn.readObject(); - - requested = RequestedCertificate.getInstance(obj); - - checkValues(requested, type, certOctets, cert); - } - - private void checkValues( - RequestedCertificate requested, - int type, - byte[] certOctets, - Certificate cert) - throws IOException - { - checkMandatoryField("certType", type, requested.getType()); - - if (requested.getType() == RequestedCertificate.certificate) - { - checkMandatoryField("certificate", cert.getEncoded(), requested.getCertificateBytes()); - } - else - { - checkMandatoryField("certificateOctets", certOctets, requested.getCertificateBytes()); - } - } - - public static void main( - String[] args) - { - runTest(new RequestedCertificateUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RestrictionUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RestrictionUnitTest.java deleted file mode 100644 index c870d14ac..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RestrictionUnitTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1String; -import com.fr.third.org.bouncycastle.asn1.isismtt.x509.Restriction; -import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; - -public class RestrictionUnitTest - extends ASN1UnitTest -{ - public String getName() - { - return "Restriction"; - } - - public void performTest() - throws Exception - { - DirectoryString res = new DirectoryString("test"); - Restriction restriction = new Restriction(res.getString()); - - checkConstruction(restriction, res); - - try - { - Restriction.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - Restriction restriction, - DirectoryString res) - throws IOException - { - checkValues(restriction, res); - - restriction = Restriction.getInstance(restriction); - - checkValues(restriction, res); - - ASN1InputStream aIn = new ASN1InputStream(restriction.toASN1Primitive().getEncoded()); - - ASN1String str = (ASN1String)aIn.readObject(); - - restriction = Restriction.getInstance(str); - - checkValues(restriction, res); - } - - private void checkValues( - Restriction restriction, - DirectoryString res) - { - checkMandatoryField("restriction", res, restriction.getRestriction()); - } - - public static void main( - String[] args) - { - runTest(new RestrictionUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RevokeRequestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RevokeRequestTest.java deleted file mode 100644 index 554cd66fa..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/RevokeRequestTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.util.Date; - -import com.fr.third.org.bouncycastle.asn1.ASN1Enumerated; -import com.fr.third.org.bouncycastle.asn1.ASN1GeneralizedTime; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1OctetString; -import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERUTF8String; -import com.fr.third.org.bouncycastle.asn1.cmc.RevokeRequest; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x500.X500NameBuilder; -import com.fr.third.org.bouncycastle.asn1.x500.style.BCStyle; -import com.fr.third.org.bouncycastle.asn1.x509.CRLReason; -import com.fr.third.org.bouncycastle.util.Pack; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class RevokeRequestTest - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new RevokeRequestTest()); - } - - public String getName() - { - return "RevokeRequestTest"; - } - - public void performTest() - throws Exception - { - - - X500NameBuilder builder = new X500NameBuilder(); - builder.addRDN(BCStyle.OU, "Bouncycastle"); - - X500Name name = builder.build(); - - for (int t = 0; t < 8; t++) - { - ASN1GeneralizedTime invalidityDate = null; - ASN1OctetString passphrase = null; - DERUTF8String comment = null; - - if ((t & 1) == 1) - { - invalidityDate = new ASN1GeneralizedTime(new Date()); - } - if ((t & 2) == 2) - { - passphrase = new DEROctetString(Pack.longToBigEndian(System.currentTimeMillis())); - } - if ((t & 4) == 4) - { - comment = new DERUTF8String("T" + Long.toOctalString(System.currentTimeMillis())); - } - - RevokeRequest rr = new RevokeRequest( - name, - new ASN1Integer(12L), - CRLReason.getInstance(new ASN1Enumerated(CRLReason.certificateHold)), - invalidityDate, - passphrase, - comment); - byte[] b = rr.getEncoded(); - RevokeRequest rrResp = RevokeRequest.getInstance(b); - - isEquals("issuerName", rr.getName(), rrResp.getName()); - isEquals("serialNumber", rr.getSerialNumber(), rrResp.getSerialNumber()); - isEquals("reason", rr.getReason(), rrResp.getReason()); - isEquals("invalidityDate", rr.getInvalidityDate(), rrResp.getInvalidityDate()); - isTrue("passphrase", areEqual(rr.getPassPhrase(), rrResp.getPassPhrase())); - isEquals("comment", rr.getComment(), rrResp.getComment()); - - } - - try - { - RevokeRequest.getInstance(new DERSequence()); - fail("Sequence is less that 3"); - } - catch (Throwable t) - { - isEquals("Exception type", t.getClass(), IllegalArgumentException.class); - } - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SMIMETest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SMIMETest.java deleted file mode 100644 index 20bf3fafc..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SMIMETest.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.ByteArrayInputStream; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.DERGeneralizedTime; -import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.cms.RecipientKeyIdentifier; -import com.fr.third.org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute; -import com.fr.third.org.bouncycastle.asn1.smime.SMIMECapability; -import com.fr.third.org.bouncycastle.asn1.smime.SMIMECapabilityVector; -import com.fr.third.org.bouncycastle.asn1.smime.SMIMEEncryptionKeyPreferenceAttribute; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -public class SMIMETest - implements Test -{ - byte[] attrBytes = Base64.decode("MDQGCSqGSIb3DQEJDzEnMCUwCgYIKoZIhvcNAwcwDgYIKoZIhvcNAwICAgCAMAcGBSsOAwIH"); - byte[] prefBytes = Base64.decode("MCwGCyqGSIb3DQEJEAILMR2hGwQIAAAAAAAAAAAYDzIwMDcwMzE1MTczNzI5Wg=="); - - private boolean isSameAs( - byte[] a, - byte[] b) - { - if (a.length != b.length) - { - return false; - } - - for (int i = 0; i != a.length; i++) - { - if (a[i] != b[i]) - { - return false; - } - } - - return true; - } - - public TestResult perform() - { - SMIMECapabilityVector caps = new SMIMECapabilityVector(); - - caps.addCapability(SMIMECapability.dES_EDE3_CBC); - caps.addCapability(SMIMECapability.rC2_CBC, 128); - caps.addCapability(SMIMECapability.dES_CBC); - - SMIMECapabilitiesAttribute attr = new SMIMECapabilitiesAttribute(caps); - - SMIMEEncryptionKeyPreferenceAttribute pref = new SMIMEEncryptionKeyPreferenceAttribute( - new RecipientKeyIdentifier(new DEROctetString(new byte[8]), new DERGeneralizedTime("20070315173729Z"), null)); - - try - { - if (!isSameAs(attr.getEncoded(), attrBytes)) - { - return new SimpleTestResult(false, getName() + ": Failed attr data check"); - } - - ByteArrayInputStream bIn = new ByteArrayInputStream(attrBytes); - ASN1InputStream aIn = new ASN1InputStream(bIn); - - ASN1Primitive o = aIn.readObject(); - if (!attr.equals(o)) - { - return new SimpleTestResult(false, getName() + ": Failed equality test for attr"); - } - - if (!isSameAs(pref.getEncoded(), prefBytes)) - { - return new SimpleTestResult(false, getName() + ": Failed attr data check"); - } - - bIn = new ByteArrayInputStream(prefBytes); - aIn = new ASN1InputStream(bIn); - - o = aIn.readObject(); - if (!pref.equals(o)) - { - return new SimpleTestResult(false, getName() + ": Failed equality test for pref"); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - catch (Exception e) - { - return new SimpleTestResult(false, getName() + ": Failed - exception " + e.toString(), e); - } - } - - public String getName() - { - return "SMIME"; - } - - public static void main( - String[] args) - { - SMIMETest test = new SMIMETest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SemanticsInformationUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SemanticsInformationUnitTest.java deleted file mode 100644 index 3efa5c06a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SemanticsInformationUnitTest.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; -import com.fr.third.org.bouncycastle.asn1.x509.qualified.SemanticsInformation; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class SemanticsInformationUnitTest - extends SimpleTest -{ - public String getName() - { - return "SemanticsInformation"; - } - - public void performTest() - throws Exception - { - ASN1ObjectIdentifier statementId = new ASN1ObjectIdentifier("1.1"); - SemanticsInformation mv = new SemanticsInformation(statementId); - - checkConstruction(mv, statementId, null); - - GeneralName[] names = new GeneralName[2]; - - names[0] = new GeneralName(GeneralName.rfc822Name, "test@test.org"); - names[1] = new GeneralName(new X500Name("cn=test")); - - mv = new SemanticsInformation(statementId, names); - - checkConstruction(mv, statementId, names); - - mv = new SemanticsInformation(names); - - checkConstruction(mv, null, names); - - mv = SemanticsInformation.getInstance(null); - - if (mv != null) - { - fail("null getInstance() failed."); - } - - try - { - SemanticsInformation.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - ASN1EncodableVector v = new ASN1EncodableVector(); - - SemanticsInformation.getInstance(new DERSequence(v)); - - fail("constructor failed to detect empty sequence."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - SemanticsInformation mv, - ASN1ObjectIdentifier semanticsIdentifier, - GeneralName[] names) - throws Exception - { - checkStatement(mv, semanticsIdentifier, names); - - mv = SemanticsInformation.getInstance(mv); - - checkStatement(mv, semanticsIdentifier, names); - - ASN1InputStream aIn = new ASN1InputStream(mv.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - mv = SemanticsInformation.getInstance(seq); - - checkStatement(mv, semanticsIdentifier, names); - } - - private void checkStatement( - SemanticsInformation si, - ASN1ObjectIdentifier id, - GeneralName[] names) - { - if (id != null) - { - if (!si.getSemanticsIdentifier().equals(id)) - { - fail("ids don't match."); - } - } - else if (si.getSemanticsIdentifier() != null) - { - fail("statementId found when none expected."); - } - - if (names != null) - { - GeneralName[] siNames = si.getNameRegistrationAuthorities(); - - for (int i = 0; i != siNames.length; i++) - { - if (!names[i].equals(siNames[i])) - { - fail("name registration authorities don't match."); - } - } - } - else if (si.getNameRegistrationAuthorities() != null) - { - fail("name registration authorities found when none expected."); - } - } - - public static void main( - String[] args) - { - runTest(new SemanticsInformationUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SetTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SetTest.java deleted file mode 100644 index 6d836cf77..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SetTest.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1Boolean; -import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1Set; -import com.fr.third.org.bouncycastle.asn1.ASN1TaggedObject; -import com.fr.third.org.bouncycastle.asn1.BERSet; -import com.fr.third.org.bouncycastle.asn1.DERBitString; -import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERSet; -import com.fr.third.org.bouncycastle.asn1.DERTaggedObject; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Set sorting test example - */ -public class SetTest - extends SimpleTest -{ - - public String getName() - { - return "Set"; - } - - private void checkedSortedSet(int attempt, ASN1Set s) - { - if (s.getObjectAt(0) instanceof ASN1Boolean - && s.getObjectAt(1) instanceof ASN1Integer - && s.getObjectAt(2) instanceof DERBitString - && s.getObjectAt(3) instanceof DEROctetString) - { - return; - } - - fail("sorting failed on attempt: " + attempt); - } - - public void performTest() - { - ASN1EncodableVector v = new ASN1EncodableVector(); - byte[] data = new byte[10]; - - v.add(new DEROctetString(data)); - v.add(new DERBitString(data)); - v.add(new ASN1Integer(100)); - v.add(ASN1Boolean.getInstance(true)); - - checkedSortedSet(0, new DERSet(v)); - - v = new ASN1EncodableVector(); - v.add(new ASN1Integer(100)); - v.add(ASN1Boolean.getInstance(true)); - v.add(new DEROctetString(data)); - v.add(new DERBitString(data)); - - checkedSortedSet(1, new DERSet(v)); - - v = new ASN1EncodableVector(); - v.add(ASN1Boolean.getInstance(true)); - v.add(new DEROctetString(data)); - v.add(new DERBitString(data)); - v.add(new ASN1Integer(100)); - - - checkedSortedSet(2, new DERSet(v)); - - v = new ASN1EncodableVector(); - v.add(new DERBitString(data)); - v.add(new DEROctetString(data)); - v.add(new ASN1Integer(100)); - v.add(ASN1Boolean.getInstance(true)); - - checkedSortedSet(3, new DERSet(v)); - - v = new ASN1EncodableVector(); - v.add(new DEROctetString(data)); - v.add(new DERBitString(data)); - v.add(new ASN1Integer(100)); - v.add(ASN1Boolean.getInstance(true)); - - ASN1Set s = new BERSet(v); - - if (!(s.getObjectAt(0) instanceof DEROctetString)) - { - fail("BER set sort order changed."); - } - - // create an implicitly tagged "set" without sorting - ASN1TaggedObject tag = new DERTaggedObject(false, 1, new DERSequence(v)); - s = ASN1Set.getInstance(tag, false); - - if (s.getObjectAt(0) instanceof ASN1Boolean) - { - fail("sorted when shouldn't be."); - } - - // equality test - v = new ASN1EncodableVector(); - - v.add(ASN1Boolean.getInstance(true)); - v.add(ASN1Boolean.getInstance(true)); - v.add(ASN1Boolean.getInstance(true)); - - s = new DERSet(v); - } - - public static void main( - String[] args) - { - runTest(new SetTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SignerLocationUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SignerLocationUnitTest.java deleted file mode 100644 index 17f7ad46b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SignerLocationUnitTest.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERTaggedObject; -import com.fr.third.org.bouncycastle.asn1.DERUTF8String; -import com.fr.third.org.bouncycastle.asn1.esf.SignerLocation; -import com.fr.third.org.bouncycastle.asn1.x500.DirectoryString; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class SignerLocationUnitTest - extends SimpleTest -{ - public String getName() - { - return "SignerLocation"; - } - - public void performTest() - throws Exception - { - DERUTF8String countryName = new DERUTF8String("Australia"); - - SignerLocation sl = new SignerLocation(countryName, null, null); - - checkConstruction(sl, DirectoryString.getInstance(countryName), null, null); - - DERUTF8String localityName = new DERUTF8String("Melbourne"); - - sl = new SignerLocation(null, localityName, null); - - checkConstruction(sl, null, DirectoryString.getInstance(localityName), null); - - sl = new SignerLocation(countryName, localityName, null); - - checkConstruction(sl, DirectoryString.getInstance(countryName), DirectoryString.getInstance(localityName), null); - - ASN1EncodableVector v = new ASN1EncodableVector(); - - v.add(new DERUTF8String("line 1")); - v.add(new DERUTF8String("line 2")); - - ASN1Sequence postalAddress = new DERSequence(v); - - sl = new SignerLocation(null, null, postalAddress); - - checkConstruction(sl, null, null, postalAddress); - - sl = new SignerLocation(countryName, null, postalAddress); - - checkConstruction(sl, DirectoryString.getInstance(countryName), null, postalAddress); - - sl = new SignerLocation(countryName, localityName, postalAddress); - - checkConstruction(sl, DirectoryString.getInstance(countryName), DirectoryString.getInstance(localityName), postalAddress); - - sl = SignerLocation.getInstance(null); - - if (sl != null) - { - fail("null getInstance() failed."); - } - - try - { - SignerLocation.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - - // - // out of range postal address - // - v = new ASN1EncodableVector(); - - v.add(new DERUTF8String("line 1")); - v.add(new DERUTF8String("line 2")); - v.add(new DERUTF8String("line 3")); - v.add(new DERUTF8String("line 4")); - v.add(new DERUTF8String("line 5")); - v.add(new DERUTF8String("line 6")); - v.add(new DERUTF8String("line 7")); - - postalAddress = new DERSequence(v); - - try - { - new SignerLocation(null, null, postalAddress); - - fail("constructor failed to detect bad postalAddress."); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - SignerLocation.getInstance(new DERSequence(new DERTaggedObject(2, postalAddress))); - - fail("sequence constructor failed to detect bad postalAddress."); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - SignerLocation.getInstance(new DERSequence(new DERTaggedObject(5, postalAddress))); - - fail("sequence constructor failed to detect bad tag."); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - private void checkConstruction( - SignerLocation sl, - DirectoryString countryName, - DirectoryString localityName, - ASN1Sequence postalAddress) - throws IOException - { - checkValues(sl, countryName, localityName, postalAddress); - - sl = SignerLocation.getInstance(sl); - - checkValues(sl, countryName, localityName, postalAddress); - - ASN1InputStream aIn = new ASN1InputStream(sl.toASN1Primitive().getEncoded()); - - ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); - - sl = SignerLocation.getInstance(seq); - - checkValues(sl, countryName, localityName, postalAddress); - } - - private void checkValues( - SignerLocation sl, - DirectoryString countryName, - DirectoryString localityName, - ASN1Sequence postalAddress) - { - if (countryName != null) - { - if (!countryName.equals(sl.getCountryName())) - { - fail("countryNames don't match."); - } - } - else if (sl.getCountryName() != null) - { - fail("countryName found when none expected."); - } - - if (localityName != null) - { - if (!localityName.equals(sl.getLocalityName())) - { - fail("localityNames don't match."); - } - } - else if (sl.getLocalityName() != null) - { - fail("localityName found when none expected."); - } - - if (postalAddress != null) - { - if (!postalAddress.equals(sl.getPostalAddress())) - { - fail("postalAddresses don't match."); - } - } - else if (sl.getPostalAddress() != null) - { - fail("postalAddress found when none expected."); - } - } - - public static void main( - String[] args) - { - runTest(new SignerLocationUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/StringTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/StringTest.java deleted file mode 100644 index 0432ea1e8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/StringTest.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.ASN1String; -import com.fr.third.org.bouncycastle.asn1.DERBMPString; -import com.fr.third.org.bouncycastle.asn1.DERBitString; -import com.fr.third.org.bouncycastle.asn1.DERGeneralString; -import com.fr.third.org.bouncycastle.asn1.DERIA5String; -import com.fr.third.org.bouncycastle.asn1.DERNumericString; -import com.fr.third.org.bouncycastle.asn1.DERPrintableString; -import com.fr.third.org.bouncycastle.asn1.DERT61String; -import com.fr.third.org.bouncycastle.asn1.DERUTF8String; -import com.fr.third.org.bouncycastle.asn1.DERUniversalString; -import com.fr.third.org.bouncycastle.asn1.DERVisibleString; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * X.690 test example - */ -public class StringTest - extends SimpleTest -{ - public String getName() - { - return "String"; - } - - public void performTest() - throws IOException - { - DERBitString bs = new DERBitString( - new byte[] { (byte)0x01,(byte)0x23,(byte)0x45,(byte)0x67,(byte)0x89,(byte)0xab,(byte)0xcd,(byte)0xef }); - - if (!bs.getString().equals("#0309000123456789ABCDEF")) - { - fail("DERBitString.getString() result incorrect"); - } - - if (!bs.toString().equals("#0309000123456789ABCDEF")) - { - fail("DERBitString.toString() result incorrect"); - } - - bs = new DERBitString( - new byte[] { (byte)0xfe,(byte)0xdc,(byte)0xba,(byte)0x98,(byte)0x76,(byte)0x54,(byte)0x32,(byte)0x10 }); - - if (!bs.getString().equals("#030900FEDCBA9876543210")) - { - fail("DERBitString.getString() result incorrect"); - } - - if (!bs.toString().equals("#030900FEDCBA9876543210")) - { - fail("DERBitString.toString() result incorrect"); - } - - DERUniversalString us = new DERUniversalString( - new byte[] { (byte)0x01,(byte)0x23,(byte)0x45,(byte)0x67,(byte)0x89,(byte)0xab,(byte)0xcd,(byte)0xef }); - - if (!us.getString().equals("#1C080123456789ABCDEF")) - { - fail("DERUniversalString.getString() result incorrect"); - } - - if (!us.toString().equals("#1C080123456789ABCDEF")) - { - fail("DERUniversalString.toString() result incorrect"); - } - - us = new DERUniversalString( - new byte[] { (byte)0xfe,(byte)0xdc,(byte)0xba,(byte)0x98,(byte)0x76,(byte)0x54,(byte)0x32,(byte)0x10 }); - - if (!us.getString().equals("#1C08FEDCBA9876543210")) - { - fail("DERUniversalString.getString() result incorrect"); - } - - if (!us.toString().equals("#1C08FEDCBA9876543210")) - { - fail("DERUniversalString.toString() result incorrect"); - } - - byte[] t61Bytes = new byte[] { -1, -2, -3, -4, -5, -6, -7, -8 }; - String t61String = new String(t61Bytes, "iso-8859-1"); - DERT61String t61 = new DERT61String(Strings.fromByteArray(t61Bytes)); - - if (!t61.getString().equals(t61String)) - { - fail("DERT61String.getString() result incorrect"); - } - - if (!t61.toString().equals(t61String)) - { - fail("DERT61String.toString() result incorrect"); - } - - char[] shortChars = new char[] { 'a', 'b', 'c', 'd', 'e'}; - char[] longChars = new char[1000]; - - for (int i = 0; i != longChars.length; i++) - { - longChars[i] = 'X'; - } - - checkString(new DERBMPString(new String(shortChars)), new DERBMPString(new String(longChars))); - checkString(new DERUTF8String(new String(shortChars)), new DERUTF8String(new String(longChars))); - checkString(new DERIA5String(new String(shortChars)), new DERIA5String(new String(longChars))); - checkString(new DERPrintableString(new String(shortChars)), new DERPrintableString(new String(longChars))); - checkString(new DERVisibleString(new String(shortChars)), new DERVisibleString(new String(longChars))); - checkString(new DERGeneralString(new String(shortChars)), new DERGeneralString(new String(longChars))); - checkString(new DERT61String(new String(shortChars)), new DERT61String(new String(longChars))); - - shortChars = new char[] { '1', '2', '3', '4', '5'}; - longChars = new char[1000]; - - for (int i = 0; i != longChars.length; i++) - { - longChars[i] = '1'; - } - - checkString(new DERNumericString(new String(shortChars)), new DERNumericString(new String(longChars))); - - byte[] shortBytes = new byte[] { (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e'}; - byte[] longBytes = new byte[1000]; - - for (int i = 0; i != longChars.length; i++) - { - longBytes[i] = (byte)'X'; - } - - checkString(new DERUniversalString(shortBytes), new DERUniversalString(longBytes)); - - } - - private void checkString(ASN1String shortString, ASN1String longString) - throws IOException - { - ASN1String short2 = (ASN1String)ASN1Primitive.fromByteArray(((ASN1Primitive)shortString).getEncoded()); - - if (!shortString.toString().equals(short2.toString())) - { - fail(short2.getClass().getName() + " shortBytes result incorrect"); - } - - ASN1String long2 = (ASN1String)ASN1Primitive.fromByteArray(((ASN1Primitive)longString).getEncoded()); - - if (!longString.toString().equals(long2.toString())) - { - fail(long2.getClass().getName() + " longBytes result incorrect"); - } - } - - public static void main( - String[] args) - { - runTest(new StringTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SubjectKeyIdentifierTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SubjectKeyIdentifierTest.java deleted file mode 100644 index ba1ef54b3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/SubjectKeyIdentifierTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class SubjectKeyIdentifierTest - extends SimpleTest -{ - private static byte[] pubKeyInfo = Base64.decode( - "MFgwCwYJKoZIhvcNAQEBA0kAMEYCQQC6wMMmHYMZszT/7bNFMn+gaZoiWJLVP8ODRuu1C2jeAe" + - "QpxM+5Oe7PaN2GNy3nBE4EOYkB5pMJWA0y9n04FX8NAgED"); - - private static byte[] shaID = Hex.decode("d8128a06d6c2feb0865994a2936e7b75b836a021"); - private static byte[] shaTruncID = Hex.decode("436e7b75b836a021"); - - public String getName() - { - return "SubjectKeyIdentifier"; - } - - public void performTest() - throws IOException - { -// SubjectPublicKeyInfo pubInfo = SubjectPublicKeyInfo.getInstance(ASN1Primitive.fromByteArray(pubKeyInfo)); -// SubjectKeyIdentifier ski = SubjectKeyIdentifier.createSHA1KeyIdentifier(pubInfo); -// -// if (!Arrays.areEqual(shaID, ski.getKeyIdentifier())) -// { -// fail("SHA-1 ID does not match"); -// } -// -// ski = SubjectKeyIdentifier.createTruncatedSHA1KeyIdentifier(pubInfo); -// -// if (!Arrays.areEqual(shaTruncID, ski.getKeyIdentifier())) -// { -// fail("truncated SHA-1 ID does not match"); -// } - } - - public static void main( - String[] args) - { - runTest(new SubjectKeyIdentifierTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TagTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TagTest.java deleted file mode 100644 index 3bc524fc9..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TagTest.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.asn1.ASN1ApplicationSpecific; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.ASN1TaggedObject; -import com.fr.third.org.bouncycastle.asn1.DERApplicationSpecific; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -/** - * X.690 test example - */ -public class TagTest - extends SimpleTest -{ - byte[] longTagged = Base64.decode( - "ZSRzIp8gEEZFRENCQTk4NzY1NDMyMTCfIQwyMDA2MDQwMTEyMzSUCCAFERVz" - + "A4kCAHEXGBkalAggBRcYGRqUCCAFZS6QAkRFkQlURUNITklLRVKSBQECAwQF" - + "kxAREhMUFRYXGBkalAggBREVcwOJAgBxFxgZGpQIIAUXGBkalAggBWUukAJE" - + "RZEJVEVDSE5JS0VSkgUBAgMEBZMQERITFBUWFxgZGpQIIAURFXMDiQIAcRcY" - + "GRqUCCAFFxgZGpQIIAVlLpACREWRCVRFQ0hOSUtFUpIFAQIDBAWTEBESExQV" - + "FhcYGRqUCCAFERVzA4kCAHEXGBkalAggBRcYGRqUCCAFFxgZGpQIIAUXGBka" - + "lAg="); - - byte[] longAppSpecificTag = Hex.decode("5F610101"); - - public String getName() - { - return "Tag"; - } - - public void performTest() - throws IOException - { - ASN1InputStream aIn = new ASN1InputStream(longTagged); - - ASN1ApplicationSpecific app = (ASN1ApplicationSpecific)aIn.readObject(); - - aIn = new ASN1InputStream(app.getContents()); - - app = (ASN1ApplicationSpecific)aIn.readObject(); - - aIn = new ASN1InputStream(app.getContents()); - - ASN1TaggedObject tagged = (ASN1TaggedObject)aIn.readObject(); - - if (tagged.getTagNo() != 32) - { - fail("unexpected tag value found - not 32"); - } - - tagged = (ASN1TaggedObject)ASN1Primitive.fromByteArray(tagged.getEncoded()); - - if (tagged.getTagNo() != 32) - { - fail("unexpected tag value found on recode - not 32"); - } - - tagged = (ASN1TaggedObject)aIn.readObject(); - - if (tagged.getTagNo() != 33) - { - fail("unexpected tag value found - not 33"); - } - - tagged = (ASN1TaggedObject)ASN1Primitive.fromByteArray(tagged.getEncoded()); - - if (tagged.getTagNo() != 33) - { - fail("unexpected tag value found on recode - not 33"); - } - - aIn = new ASN1InputStream(longAppSpecificTag); - - app = (ASN1ApplicationSpecific)aIn.readObject(); - - if (app.getApplicationTag() != 97) - { - fail("incorrect tag number read"); - } - - app = (ASN1ApplicationSpecific)ASN1Primitive.fromByteArray(app.getEncoded()); - - if (app.getApplicationTag() != 97) - { - fail("incorrect tag number read on recode"); - } - - SecureRandom sr = new SecureRandom(); - for (int i = 0; i < 100; ++i) - { - int testTag = sr.nextInt() >>> (1 + (sr.nextInt() >>> 1) % 26); - app = new DERApplicationSpecific(testTag, new byte[]{ 1 }); - app = (ASN1ApplicationSpecific)ASN1Primitive.fromByteArray(app.getEncoded()); - - if (app.getApplicationTag() != testTag) - { - fail("incorrect tag number read on recode (random test value: " + testTag + ")"); - } - } - } - - public static void main( - String[] args) - { - runTest(new TagTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TaggedAttributeTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TaggedAttributeTest.java deleted file mode 100644 index 99e1ca92a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TaggedAttributeTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.DERIA5String; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERSet; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.asn1.cmc.CMCObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.cmc.TaggedAttribute; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class TaggedAttributeTest - extends SimpleTest -{ - public String getName() - { - return "TaggedAttributeTest"; - } - - public void performTest() - throws Exception - { - // - // This creates and tests the various get instance methods. - // - TaggedAttribute ta = new TaggedAttribute( - new BodyPartID(10L), - CMCObjectIdentifiers.id_cct_PKIData, - new DERSet(new DERIA5String("Cats"))); - - byte[] d = ta.getEncoded(); - - { - TaggedAttribute res1 = TaggedAttribute.getInstance(d); - isEquals(ta.getBodyPartID(), res1.getBodyPartID()); - isEquals(ta.getAttrType(), res1.getAttrType()); - isEquals(ta.getAttrValues().getObjectAt(0), res1.getAttrValues().getObjectAt(0)); - isTrue(Arrays.areEqual(res1.getEncoded(), d)); - } - - // - // Where sequence is too short. - // - try - { - ASN1Sequence seq = new DERSequence(new ASN1Encodable[] { new BodyPartID(10) }); - - TaggedAttribute.getInstance(seq); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("incorrect sequence size", e.getMessage()); - } - - // - // Where sequence is too long. - // - try - { - ASN1Sequence seq = new DERSequence(new ASN1Encodable[] { ta.getBodyPartID(), ta.getAttrType(), ta.getAttrValues(), new ASN1Integer(0)}); - - TaggedAttribute.getInstance(seq); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("incorrect sequence size", e.getMessage()); - } - } - - public static void main(String[] args) - throws Exception - { - runTest(new TaggedAttributeTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TaggedCertificationRequestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TaggedCertificationRequestTest.java deleted file mode 100644 index 98103e5bd..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TaggedCertificationRequestTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.asn1.cmc.CertificationRequest; -import com.fr.third.org.bouncycastle.asn1.cmc.TaggedCertificationRequest; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - - -public class TaggedCertificationRequestTest extends SimpleTest -{ - public static void main(String[] args) { - runTest(new TaggedCertificationRequestTest()); - } - - public String getName() - { - return "TaggedCertificationRequestTest"; - } - - - private static byte[] req1 = Base64.decode( - "MIHoMIGTAgEAMC4xDjAMBgNVBAMTBVRlc3QyMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNF" - + "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALlEt31Tzt2MlcOljvacJgzQVhmlMoqAOgqJ9Pgd3Gux" - + "Z7/WcIlgW4QCB7WZT21O1YoghwBhPDMcNGrHei9kHQkCAwEAAaAAMA0GCSqGSIb3DQEBBQUAA0EA" - + "NDEI4ecNtJ3uHwGGlitNFq9WxcoZ0djbQJ5hABMotav6gtqlrwKXY2evaIrsNwkJtNdwwH18aQDU" - + "KCjOuBL38Q=="); - - - public void performTest() - throws Exception - { - CertificationRequest r = CertificationRequest.getInstance(req1); - TaggedCertificationRequest tcr = new TaggedCertificationRequest(new BodyPartID(10L), r); - - byte[] b = tcr.getEncoded(); - TaggedCertificationRequest tcrResp = TaggedCertificationRequest.getInstance(b); - - isEquals(tcrResp,tcr); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TaggedContentInfoTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TaggedContentInfoTest.java deleted file mode 100644 index 39aec8268..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TaggedContentInfoTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERUTF8String; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.asn1.cmc.TaggedContentInfo; -import com.fr.third.org.bouncycastle.asn1.cms.ContentInfo; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class TaggedContentInfoTest - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new TaggedContentInfoTest()); - } - - public String getName() - { - return "TaggedContentInfoTest"; - } - - public void performTest() - throws Exception - { - TaggedContentInfo tci = new TaggedContentInfo( - new BodyPartID(10L), - new ContentInfo(PKCSObjectIdentifiers.pkcs_9_at_contentType, new DERUTF8String("Cats"))); - - byte[] b = tci.getEncoded(); - - TaggedContentInfo tciResp = TaggedContentInfo.getInstance(b); - - isEquals("bodyPartID", tci.getBodyPartID(), tciResp.getBodyPartID()); - isEquals("contentInfo", tci.getContentInfo(), tciResp.getContentInfo()); - - try - { - TaggedContentInfo.getInstance(new DERSequence()); - fail("Sequence must be 2"); - } - catch (Throwable t) - { - isEquals("Exception type", t.getClass(), IllegalArgumentException.class); - } - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TaggedRequestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TaggedRequestTest.java deleted file mode 100644 index 3e9eee1ad..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TaggedRequestTest.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.DERBitString; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERSet; -import com.fr.third.org.bouncycastle.asn1.DERTaggedObject; -import com.fr.third.org.bouncycastle.asn1.cmc.BodyPartID; -import com.fr.third.org.bouncycastle.asn1.cmc.CertificationRequest; -import com.fr.third.org.bouncycastle.asn1.cmc.TaggedCertificationRequest; -import com.fr.third.org.bouncycastle.asn1.cmc.TaggedRequest; -import com.fr.third.org.bouncycastle.asn1.crmf.AttributeTypeAndValue; -import com.fr.third.org.bouncycastle.asn1.crmf.CertReqMsg; -import com.fr.third.org.bouncycastle.asn1.crmf.CertRequest; -import com.fr.third.org.bouncycastle.asn1.crmf.CertTemplate; -import com.fr.third.org.bouncycastle.asn1.crmf.Controls; -import com.fr.third.org.bouncycastle.asn1.crmf.POPOSigningKey; -import com.fr.third.org.bouncycastle.asn1.crmf.POPOSigningKeyInput; -import com.fr.third.org.bouncycastle.asn1.crmf.ProofOfPossession; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class TaggedRequestTest - extends SimpleTest -{ - public static void main(String[] args) - { - runTest(new TaggedRequestTest()); - } - - public String getName() - { - return "TaggedRequestTest"; - } - - private static byte[] req1 = Base64.decode( - "MIHoMIGTAgEAMC4xDjAMBgNVBAMTBVRlc3QyMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNF" - + "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALlEt31Tzt2MlcOljvacJgzQVhmlMoqAOgqJ9Pgd3Gux" - + "Z7/WcIlgW4QCB7WZT21O1YoghwBhPDMcNGrHei9kHQkCAwEAAaAAMA0GCSqGSIb3DQEBBQUAA0EA" - + "NDEI4ecNtJ3uHwGGlitNFq9WxcoZ0djbQJ5hABMotav6gtqlrwKXY2evaIrsNwkJtNdwwH18aQDU" - + "KCjOuBL38Q=="); - - - public void performTest() - throws Exception - { - { // TaggedCertificationRequest - TaggedRequest tr = new TaggedRequest( - new TaggedCertificationRequest( - new BodyPartID(10L), - CertificationRequest.getInstance(req1)) - ); - byte[] b = tr.getEncoded(); - TaggedRequest trResult = TaggedRequest.getInstance(b); - isEquals("Tag", tr.getTagNo(), trResult.getTagNo()); - isEquals("Is TCR tag", TaggedRequest.TCR, tr.getTagNo()); - isEquals("Value", tr.getValue(), trResult.getValue()); - } - - { // CertReqMsg - - POPOSigningKeyInput pski = new POPOSigningKeyInput( - new GeneralName(GeneralName.rfc822Name, "fish"), - new SubjectPublicKeyInfo(new AlgorithmIdentifier( - PKCSObjectIdentifiers.certBag, - new ASN1Integer(5L)), new ASN1Integer(4L) - )); - - AlgorithmIdentifier aid = new AlgorithmIdentifier(PKCSObjectIdentifiers.crlTypes, new ASN1Integer(1L)); - DERBitString dbi = new DERBitString(2); - - POPOSigningKey popoSigningKey = new POPOSigningKey(pski, aid, dbi); - ProofOfPossession proofOfPossession = new ProofOfPossession(new POPOSigningKey(pski, aid, dbi)); - - TaggedRequest tr = new TaggedRequest( - new CertReqMsg(new CertRequest( - new ASN1Integer(1L), - CertTemplate.getInstance(new DERSequence(new DERTaggedObject(0,new ASN1Integer(3L)))), - new Controls(new AttributeTypeAndValue(PKCSObjectIdentifiers.pkcs_9,new ASN1Integer(3)))), - proofOfPossession, - new AttributeTypeAndValue[0]) - ); - byte[] b = tr.getEncoded(); - TaggedRequest trResult = TaggedRequest.getInstance(b); - isEquals("Tag", tr.getTagNo(), trResult.getTagNo()); - isEquals("Is CRM tag", TaggedRequest.CRM, tr.getTagNo()); - isEquals("Value", tr.getValue(), trResult.getValue()); - } - - - { // ORM - TaggedRequest tr = TaggedRequest.getInstance( new DERTaggedObject(TaggedRequest.ORM, new DERSequence(new ASN1Encodable[]{ - new BodyPartID(1L), - PKCSObjectIdentifiers.data, - new DERSet(new ASN1Encodable[]{new ASN1Integer(5L)}) - }))); - byte[] b = tr.getEncoded(); - TaggedRequest trResult = TaggedRequest.getInstance(b); - isEquals("Tag", tr.getTagNo(), trResult.getTagNo()); - isEquals("Is ORM tag", TaggedRequest.ORM, tr.getTagNo()); - isEquals("Value", tr.getValue(), trResult.getValue()); - } - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TargetInformationTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TargetInformationTest.java deleted file mode 100644 index 7236a4b09..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TargetInformationTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.x509.GeneralName; -import com.fr.third.org.bouncycastle.asn1.x509.Target; -import com.fr.third.org.bouncycastle.asn1.x509.TargetInformation; -import com.fr.third.org.bouncycastle.asn1.x509.Targets; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class TargetInformationTest - extends SimpleTest -{ - - public String getName() - { - return "TargetInformation"; - } - - public void performTest() throws Exception - { - Target[] targets = new Target[2]; - Target targetName = new Target(Target.targetName, new GeneralName(GeneralName.dNSName, "www.test.com")); - Target targetGroup = new Target(Target.targetGroup, new GeneralName(GeneralName.directoryName, "o=Test, ou=Test")); - targets[0] = targetName; - targets[1] = targetGroup; - Targets targetss = new Targets(targets); - TargetInformation targetInformation1 = new TargetInformation(targetss); - // use an Target array - TargetInformation targetInformation2 = new TargetInformation(targets); - // targetInformation1 and targetInformation2 must have same - // encoding. - if (!targetInformation1.equals(targetInformation2)) - { - fail("targetInformation1 and targetInformation2 should have the same encoding."); - } - TargetInformation targetInformation3 = TargetInformation.getInstance(targetInformation1); - TargetInformation targetInformation4 = TargetInformation.getInstance(targetInformation2); - if (!targetInformation3.equals(targetInformation4)) - { - fail("targetInformation3 and targetInformation4 should have the same encoding."); - } - } - - public static void main(String[] args) - { - runTest(new TargetInformationTest()); - } -} - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TypeOfBiometricDataUnitTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TypeOfBiometricDataUnitTest.java deleted file mode 100644 index b662514b0..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/TypeOfBiometricDataUnitTest.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.x509.qualified.TypeOfBiometricData; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class TypeOfBiometricDataUnitTest - extends SimpleTest -{ - public String getName() - { - return "TypeOfBiometricData"; - } - - public void performTest() - throws Exception - { - // - // predefined - // - checkPredefinedType(TypeOfBiometricData.PICTURE); - - checkPredefinedType(TypeOfBiometricData.HANDWRITTEN_SIGNATURE); - - // - // non-predefined - // - ASN1ObjectIdentifier localType = new ASN1ObjectIdentifier("1.1"); - - TypeOfBiometricData type = new TypeOfBiometricData(localType); - - checkNonPredefined(type, localType); - - type = TypeOfBiometricData.getInstance(type); - - checkNonPredefined(type, localType); - - ASN1Primitive obj = type.toASN1Primitive(); - - type = TypeOfBiometricData.getInstance(obj); - - checkNonPredefined(type, localType); - - type = TypeOfBiometricData.getInstance(null); - - if (type != null) - { - fail("null getInstance() failed."); - } - - try - { - TypeOfBiometricData.getInstance(new Object()); - - fail("getInstance() failed to detect bad object."); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - new TypeOfBiometricData(100); - - fail("constructor failed to detect bad predefined type."); - } - catch (IllegalArgumentException e) - { - // expected - } - - if (TypeOfBiometricData.PICTURE != 0) - { - fail("predefined picture should be 0"); - } - - if (TypeOfBiometricData.HANDWRITTEN_SIGNATURE != 1) - { - fail("predefined handwritten signature should be 1"); - } - } - - private void checkPredefinedType( - int predefinedType) - throws IOException - { - TypeOfBiometricData type = new TypeOfBiometricData(predefinedType); - - checkPredefined(type, predefinedType); - - type = TypeOfBiometricData.getInstance(type); - - checkPredefined(type, predefinedType); - - ASN1InputStream aIn = new ASN1InputStream(type.toASN1Primitive().getEncoded()); - - ASN1Primitive obj = aIn.readObject(); - - type = TypeOfBiometricData.getInstance(obj); - - checkPredefined(type, predefinedType); - } - - private void checkPredefined( - TypeOfBiometricData type, - int value) - { - if (!type.isPredefined()) - { - fail("predefined type expected but not found."); - } - - if (type.getPredefinedBiometricType() != value) - { - fail("predefined type does not match."); - } - } - - private void checkNonPredefined( - TypeOfBiometricData type, - ASN1ObjectIdentifier value) - { - if (type.isPredefined()) - { - fail("predefined type found when not expected."); - } - - if (!type.getBiometricDataOid().equals(value)) - { - fail("data oid does not match."); - } - } - - public static void main( - String[] args) - { - runTest(new TypeOfBiometricDataUnitTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/UTCTimeTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/UTCTimeTest.java deleted file mode 100644 index 5738a30de..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/UTCTimeTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.text.SimpleDateFormat; -import java.util.SimpleTimeZone; - -import com.fr.third.org.bouncycastle.asn1.DERUTCTime; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * X.690 test example - */ -public class UTCTimeTest - extends SimpleTest -{ - String[] input = - { - "020122122220Z", - "020122122220-1000", - "020122122220+1000", - "020122122220+00", - "0201221222Z", - "0201221222-1000", - "0201221222+1000", - "0201221222+00", - "550122122220Z", - "5501221222Z" - }; - - String[] output = { - "20020122122220GMT+00:00", - "20020122122220GMT-10:00", - "20020122122220GMT+10:00", - "20020122122220GMT+00:00", - "20020122122200GMT+00:00", - "20020122122200GMT-10:00", - "20020122122200GMT+10:00", - "20020122122200GMT+00:00", - "19550122122220GMT+00:00", - "19550122122200GMT+00:00" - }; - - String[] zOutput1 = { - "20020122122220Z", - "20020122222220Z", - "20020122022220Z", - "20020122122220Z", - "20020122122200Z", - "20020122222200Z", - "20020122022200Z", - "20020122122200Z", - "19550122122220Z", - "19550122122200Z" - }; - - String[] zOutput2 = { - "20020122122220Z", - "20020122222220Z", - "20020122022220Z", - "20020122122220Z", - "20020122122200Z", - "20020122222200Z", - "20020122022200Z", - "20020122122200Z", - "19550122122220Z", - "19550122122200Z" - }; - - public String getName() - { - return "UTCTime"; - } - - public void performTest() - throws Exception - { - SimpleDateFormat yyyyF = new SimpleDateFormat("yyyyMMddHHmmss'Z'"); - SimpleDateFormat yyF = new SimpleDateFormat("yyyyMMddHHmmss'Z'"); - - yyyyF.setTimeZone(new SimpleTimeZone(0,"Z")); - yyF.setTimeZone(new SimpleTimeZone(0,"Z")); - - for (int i = 0; i != input.length; i++) - { - DERUTCTime t = new DERUTCTime(input[i]); - - if (!t.getAdjustedTime().equals(output[i])) - { - fail("failed conversion test " + i); - } - - if (!yyyyF.format(t.getAdjustedDate()).equals(zOutput1[i])) - { - fail("failed date conversion test " + i); - } - - if (!yyF.format(t.getDate()).equals(zOutput2[i])) - { - fail("failed date shortened conversion test " + i); - } - } - } - - public static void main( - String[] args) - { - runTest(new UTCTimeTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/X500NameTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/X500NameTest.java deleted file mode 100644 index 73e89c1cf..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/X500NameTest.java +++ /dev/null @@ -1,758 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; -import com.fr.third.org.bouncycastle.asn1.ASN1GeneralizedTime; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.ASN1Set; -import com.fr.third.org.bouncycastle.asn1.ASN1String; -import com.fr.third.org.bouncycastle.asn1.ASN1TaggedObject; -import com.fr.third.org.bouncycastle.asn1.DERIA5String; -import com.fr.third.org.bouncycastle.asn1.DERPrintableString; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERSet; -import com.fr.third.org.bouncycastle.asn1.DERTaggedObject; -import com.fr.third.org.bouncycastle.asn1.DERUTF8String; -import com.fr.third.org.bouncycastle.asn1.x500.RDN; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x500.X500NameBuilder; -import com.fr.third.org.bouncycastle.asn1.x500.style.BCStrictStyle; -import com.fr.third.org.bouncycastle.asn1.x500.style.BCStyle; -import com.fr.third.org.bouncycastle.asn1.x500.style.IETFUtils; -import com.fr.third.org.bouncycastle.asn1.x509.X509DefaultEntryConverter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class X500NameTest - extends SimpleTest -{ - String[] subjects = - { - "C=AU,ST=Victoria,L=South Melbourne,O=Connect 4 Pty Ltd,OU=Webserver Team,CN=www2.connect4.com.au,E=webmaster@connect4.com.au", - "C=AU,ST=Victoria,L=South Melbourne,O=Connect 4 Pty Ltd,OU=Certificate Authority,CN=Connect 4 CA,E=webmaster@connect4.com.au", - "C=AU,ST=QLD,CN=SSLeay/rsa test cert", - "C=US,O=National Aeronautics and Space Administration,SERIALNUMBER=16+CN=Steve Schoch", - "E=cooke@issl.atl.hp.com,C=US,OU=Hewlett Packard Company (ISSL),CN=Paul A. Cooke", - "O=Sun Microsystems Inc,CN=store.sun.com", - "unstructuredAddress=192.168.1.33,unstructuredName=pixfirewall.ciscopix.com,CN=pixfirewall.ciscopix.com", - "CN=*.canal-plus.com,OU=Provided by TBS INTERNET http://www.tbs-certificats.com/,OU=\\ CANAL \\+,O=CANAL\\+DISTRIBUTION,L=issy les moulineaux,ST=Hauts de Seine,C=FR", - "O=Bouncy Castle,CN=www.bouncycastle.org\\ ", - "O=Bouncy Castle,CN=c:\\\\fred\\\\bob", - "C=0,O=1,OU=2,T=3,CN=4,SERIALNUMBER=5,STREET=6,SERIALNUMBER=7,L=8,ST=9,SURNAME=10,GIVENNAME=11,INITIALS=12," + - "GENERATION=13,UniqueIdentifier=14,BusinessCategory=15,PostalCode=16,DN=17,Pseudonym=18,PlaceOfBirth=19," + - "Gender=20,CountryOfCitizenship=21,CountryOfResidence=22,NameAtBirth=23,PostalAddress=24,2.5.4.54=25," + - "TelephoneNumber=26,Name=27,E=28,unstructuredName=29,unstructuredAddress=30,E=31,DC=32,UID=33" - - }; - - String[] hexSubjects = - { - "CN=\\20Test\\20X,O=\\20Test,C=GB", // input - "CN=\\ Test X,O=\\ Test,C=GB", // expected - "CN=\\20Test\\20X\\20,O=\\20Test,C=GB", // input - "CN=\\ Test X\\ ,O=\\ Test,C=GB" // expected - }; - - public String getName() - { - return "X500Name"; - } - - private static X500Name fromBytes(byte[] bytes) throws IOException - { - return X500Name.getInstance(ASN1Primitive.fromByteArray(bytes)); - } - - private ASN1Encodable createEntryValue(ASN1ObjectIdentifier oid, String value) - { - X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE); - - builder.addRDN(oid, value); - - X500Name name = builder.build(); - - ASN1Sequence seq = (ASN1Sequence)name.toASN1Primitive(); - ASN1Set set = ASN1Set.getInstance(seq.getObjectAt(0).toASN1Primitive()); - seq = (ASN1Sequence)set.getObjectAt(0); - - return seq.getObjectAt(1); - } - - private ASN1Encodable createEntryValueFromString(ASN1ObjectIdentifier oid, String value) - { - X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE); - - builder.addRDN(oid, value); - - X500Name name = new X500Name(builder.build().toString()); - - ASN1Sequence seq = (ASN1Sequence)name.toASN1Primitive(); - ASN1Set set = ASN1Set.getInstance(seq.getObjectAt(0).toASN1Primitive()); - seq = (ASN1Sequence)set.getObjectAt(0); - - return seq.getObjectAt(1); - } - - private void testEncodingPrintableString(ASN1ObjectIdentifier oid, String value) - { - ASN1Encodable converted = createEntryValue(oid, value); - if (!(converted instanceof DERPrintableString)) - { - fail("encoding for " + oid + " not printable string"); - } - } - - private void testEncodingIA5String(ASN1ObjectIdentifier oid, String value) - { - ASN1Encodable converted = createEntryValue(oid, value); - if (!(converted instanceof DERIA5String)) - { - fail("encoding for " + oid + " not IA5String"); - } - } - - private void testEncodingUTF8String(ASN1ObjectIdentifier oid, String value) - throws IOException - { - ASN1Encodable converted = createEntryValue(oid, value); - if (!(converted instanceof DERUTF8String)) - { - fail("encoding for " + oid + " not IA5String"); - } - if (!value.equals((DERUTF8String.getInstance(converted.toASN1Primitive().getEncoded()).getString()))) - { - fail("decoding not correct"); - } - } - - private void testEncodingGeneralizedTime(ASN1ObjectIdentifier oid, String value) - { - ASN1Encodable converted = createEntryValue(oid, value); - if (!(converted instanceof ASN1GeneralizedTime)) - { - fail("encoding for " + oid + " not GeneralizedTime"); - } - converted = createEntryValueFromString(oid, value); - if (!(converted instanceof ASN1GeneralizedTime)) - { - fail("encoding for " + oid + " not GeneralizedTime"); - } - } - - public void performTest() - throws Exception - { - ietfUtilsTest(); - - testEncodingPrintableString(BCStyle.C, "AU"); - testEncodingPrintableString(BCStyle.SERIALNUMBER, "123456"); - testEncodingPrintableString(BCStyle.DN_QUALIFIER, "123456"); - testEncodingIA5String(BCStyle.EmailAddress, "test@test.com"); - testEncodingIA5String(BCStyle.DC, "test"); - // correct encoding - testEncodingGeneralizedTime(BCStyle.DATE_OF_BIRTH, "#180F32303032303132323132323232305A"); - // compatibility encoding - testEncodingGeneralizedTime(BCStyle.DATE_OF_BIRTH, "20020122122220Z"); - testEncodingUTF8String(BCStyle.CN, "Mörsky"); - testEncodingUTF8String(BCStyle.ORGANIZATION_IDENTIFIER, "Mörsky"); - - // - // composite - // - X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE); - - builder.addRDN(BCStyle.C, "AU"); - builder.addRDN(BCStyle.O, "The Legion of the Bouncy Castle"); - builder.addRDN(BCStyle.L, "Melbourne"); - builder.addRDN(BCStyle.ST, "Victoria"); - builder.addRDN(BCStyle.E, "feedback-crypto@bouncycastle.org"); - - X500Name name1 = builder.build(); - - if (!name1.equals(name1)) - { - fail("Failed same object test"); - } - -// if (!name1.equals(name1, true)) -// { -// fail("Failed same object test - in Order"); -// } - - builder = new X500NameBuilder(BCStyle.INSTANCE); - - builder.addRDN(BCStyle.C, "AU"); - builder.addRDN(BCStyle.O, "The Legion of the Bouncy Castle"); - builder.addRDN(BCStyle.L, "Melbourne"); - builder.addRDN(BCStyle.ST, "Victoria"); - builder.addRDN(BCStyle.E, "feedback-crypto@bouncycastle.org"); - - X500Name name2 = builder.build(); - - if (!name1.equals(name2)) - { - fail("Failed same name test"); - } - -// if (!name1.equals(name2, true)) -// { -// fail("Failed same name test - in Order"); -// } - - if (name1.hashCode() != name2.hashCode()) - { - fail("Failed same name test - in Order"); - } - - X500NameBuilder builder1 = new X500NameBuilder(BCStyle.INSTANCE); - - builder.addRDN(BCStyle.C, "AU"); - builder.addRDN(BCStyle.O, "The Legion of the Bouncy Castle"); - builder.addRDN(BCStyle.L, "Melbourne"); - builder.addRDN(BCStyle.ST, "Victoria"); - builder.addRDN(BCStyle.E, "feedback-crypto@bouncycastle.org"); - - X500NameBuilder builder2 = new X500NameBuilder(BCStyle.INSTANCE); - - builder.addRDN(BCStyle.E, "feedback-crypto@bouncycastle.org"); - builder.addRDN(BCStyle.C, "AU"); - builder.addRDN(BCStyle.O, "The Legion of the Bouncy Castle"); - builder.addRDN(BCStyle.L, "Melbourne"); - builder.addRDN(BCStyle.ST, "Victoria"); - - name1 = builder1.build(); - name2 = builder2.build(); - - if (!name1.equals(name2)) - { - fail("Failed reverse name test"); - } - - if (name1.hashCode() != name2.hashCode()) - { - fail("Failed reverse name test hashCode"); - } - -// if (name1.equals(name2, true)) -// { -// fail("Failed reverse name test - in Order"); -// } -// -// if (!name1.equals(name2, false)) -// { -// fail("Failed reverse name test - in Order false"); -// } - -// Vector oids = name1.getOIDs(); -// if (!compareVectors(oids, ord1)) -// { -// fail("oid comparison test"); -// } - /* - Vector val1 = new Vector(); - - val1.addElement("AU"); - val1.addElement("The Legion of the Bouncy Castle"); - val1.addElement("Melbourne"); - val1.addElement("Victoria"); - val1.addElement("feedback-crypto@bouncycastle.org"); - - name1 = new X500Name(ord1, val1); - - Vector values = name1.getValues(); - if (!compareVectors(values, val1)) - { - fail("value comparison test"); - } - - ord2 = new Vector(); - - ord2.addElement(X500Name.ST); - ord2.addElement(X500Name.ST); - ord2.addElement(X500Name.L); - ord2.addElement(X500Name.O); - ord2.addElement(X500Name.C); - - name1 = new X500Name(ord1, attrs); - name2 = new X500Name(ord2, attrs); - - if (name1.equals(name2)) - { - fail("Failed different name test"); - } - - ord2 = new Vector(); - - ord2.addElement(X500Name.ST); - ord2.addElement(X500Name.L); - ord2.addElement(X500Name.O); - ord2.addElement(X500Name.C); - - name1 = new X500Name(ord1, attrs); - name2 = new X500Name(ord2, attrs); - - if (name1.equals(name2)) - { - fail("Failed subset name test"); - } - - compositeTest(); - */ - /* - // - // getValues test - // - Vector v1 = name1.getValues(X500Name.O); - - if (v1.size() != 1 || !v1.elementAt(0).equals("The Legion of the Bouncy Castle")) - { - fail("O test failed"); - } - - Vector v2 = name1.getValues(X500Name.L); - - if (v2.size() != 1 || !v2.elementAt(0).equals("Melbourne")) - { - fail("L test failed"); - } - */ - // - // general subjects test - // - for (int i = 0; i != subjects.length; i++) - { - X500Name name = new X500Name(subjects[i]); - name = X500Name.getInstance(ASN1Primitive.fromByteArray(name.getEncoded())); - if (!name.toString().equals(subjects[i])) - { - fail("failed regeneration test " + i + " got: " + name.toString() + " expected " + subjects[i]); - } - } - - for (int i = 0; i < hexSubjects.length; i += 2) - { - X500Name name = new X500Name(hexSubjects[i]); - name = X500Name.getInstance(ASN1Primitive.fromByteArray(name.getEncoded())); - if (!name.toString().equals(hexSubjects[i + 1])) - { - fail("failed hex regeneration test " + i + " got: " + name.toString() + " expected " + subjects[i]); - } - } - - // - // sort test - // - X500Name unsorted = new X500Name("SERIALNUMBER=BBB + CN=AA"); - - if (!fromBytes(unsorted.getEncoded()).toString().equals("CN=AA+SERIALNUMBER=BBB")) - { - fail("failed sort test 1"); - } - - unsorted = new X500Name("CN=AA + SERIALNUMBER=BBB"); - - if (!fromBytes(unsorted.getEncoded()).toString().equals("CN=AA+SERIALNUMBER=BBB")) - { - fail("failed sort test 2"); - } - - unsorted = new X500Name("SERIALNUMBER=B + CN=AA"); - - if (!fromBytes(unsorted.getEncoded()).toString().equals("SERIALNUMBER=B+CN=AA")) - { - fail("failed sort test 3"); - } - - unsorted = new X500Name("CN=AA + SERIALNUMBER=B"); - - if (!fromBytes(unsorted.getEncoded()).toString().equals("SERIALNUMBER=B+CN=AA")) - { - fail("failed sort test 4"); - } - - // - // equality tests - // - equalityTest(new X500Name("CN=The Legion"), new X500Name("CN=The Legion")); - equalityTest(new X500Name("CN= The Legion"), new X500Name("CN=The Legion")); - equalityTest(new X500Name("CN=The Legion "), new X500Name("CN=The Legion")); - equalityTest(new X500Name("CN= The Legion "), new X500Name("CN=The Legion")); - equalityTest(new X500Name("CN= the legion "), new X500Name("CN=The Legion")); - - equalityTest(new X500Name("CN= the legion+C=AU, O=Legion "), new X500Name("CN=The Legion+C=AU, O=Legion")); - // # test - - X500Name n1 = new X500Name("SERIALNUMBER=8,O=ABC,CN=ABC Class 3 CA,C=LT"); - X500Name n2 = new X500Name("2.5.4.5=8,O=ABC,CN=ABC Class 3 CA,C=LT"); - X500Name n3 = new X500Name("2.5.4.5=#130138,O=ABC,CN=ABC Class 3 CA,C=LT"); - - equalityTest(n1, n2); - equalityTest(n2, n3); - equalityTest(n3, n1); - - n1 = new X500Name("2.5.4.5=#130138,CN=SSC Class 3 CA,O=UAB Skaitmeninio sertifikavimo centras,C=LT"); - n2 = new X500Name("SERIALNUMBER=#130138,CN=SSC Class 3 CA,O=UAB Skaitmeninio sertifikavimo centras,C=LT"); - n3 = X500Name.getInstance(ASN1Primitive.fromByteArray(Hex.decode("3063310b3009060355040613024c54312f302d060355040a1326" - + "55414220536b6169746d656e696e696f20736572746966696b6176696d6f2063656e74726173311730150603550403130e53534320436c6173732033204341310a30080603550405130138"))); - - equalityTest(n1, n2); - equalityTest(n2, n3); - equalityTest(n3, n1); - - n1 = new X500Name("SERIALNUMBER=8,O=XX,CN=ABC Class 3 CA,C=LT"); - n2 = new X500Name("2.5.4.5=8,O=,CN=ABC Class 3 CA,C=LT"); - -// if (n1.equals(n2)) -// { -// fail("empty inequality check failed"); -// } - - n1 = new X500Name("SERIALNUMBER=8,O=,CN=ABC Class 3 CA,C=LT"); - n2 = new X500Name("2.5.4.5=8,O=,CN=ABC Class 3 CA,C=LT"); - - equalityTest(n1, n2); - - equalityTest(X500Name.getInstance(BCStrictStyle.INSTANCE, n1), X500Name.getInstance(BCStrictStyle.INSTANCE, n2)); - - n2 = new X500Name("C=LT,2.5.4.5=8,O=,CN=ABC Class 3 CA"); - - equalityTest(n1, n2); - - if (X500Name.getInstance(BCStrictStyle.INSTANCE, n1).equals(X500Name.getInstance(BCStrictStyle.INSTANCE, n2))) - { - fail("strict comparison failed"); - } - - // - // inequality to sequences - // - name1 = new X500Name("CN=The Legion"); - - if (name1.equals(new DERSequence())) - { - fail("inequality test with sequence"); - } - - if (name1.equals(new DERSequence(new DERSet()))) - { - fail("inequality test with sequence and set"); - } - - ASN1EncodableVector v = new ASN1EncodableVector(); - - v.add(new ASN1ObjectIdentifier("1.1")); - v.add(new ASN1ObjectIdentifier("1.1")); - if (name1.equals(new DERSequence(new DERSet(new DERSet(v))))) - { - fail("inequality test with sequence and bad set"); - } - - if (name1.equals(new DERSequence(new DERSet(new DERSet(v))))) - { - fail("inequality test with sequence and bad set"); - } - - if (name1.equals(new DERSequence(new DERSet(new DERSequence())))) - { - fail("inequality test with sequence and short sequence"); - } - - if (name1.equals(new DERSequence(new DERSet(new DERSequence())))) - { - fail("inequality test with sequence and short sequence"); - } - - v = new ASN1EncodableVector(); - - v.add(new ASN1ObjectIdentifier("1.1")); - v.add(new DERSequence()); - - if (name1.equals(new DERSequence(new DERSet(new DERSequence(v))))) - { - fail("inequality test with sequence and bad sequence"); - } - - if (name1.equals(null)) - { - fail("inequality test with null"); - } - -// if (name1.equals(null, true)) -// { -// fail("inequality test with null"); -// } - - // - // this is contrived but it checks sorting of sets with equal elements - // - unsorted = new X500Name("CN=AA + CN=AA + CN=AA"); - - ASN1ObjectIdentifier[] types = unsorted.getAttributeTypes(); - if (types.length != 3 || !types[0].equals(BCStyle.CN) || !types[1].equals(BCStyle.CN) || !types[2].equals(BCStyle.CN)) - { - fail("types not matched correctly"); - } - - // general type test - X500Name nested = new X500Name("CN=AA + CN=AA, C=AU"); - - types = nested.getAttributeTypes(); - if (types.length != 3 || !types[0].equals(BCStyle.CN) || !types[1].equals(BCStyle.CN) || !types[2].equals(BCStyle.C)) - { - fail("nested types not matched correctly"); - } - // - // tagging test - only works if CHOICE implemented - // - ASN1TaggedObject tag = new DERTaggedObject(false, 1, new X500Name("CN=AA")); - - if (!tag.isExplicit()) - { - fail("failed to explicitly tag CHOICE object"); - } - - X500Name name = X500Name.getInstance(tag, false); - - if (!name.equals(new X500Name("CN=AA"))) - { - fail("failed to recover tagged name"); - } - - DERUTF8String testString = new DERUTF8String("The Legion of the Bouncy Castle"); - byte[] encodedBytes = testString.getEncoded(); - byte[] hexEncodedBytes = Hex.encode(encodedBytes); - String hexEncodedString = "#" + new String(hexEncodedBytes); - - DERUTF8String converted = (DERUTF8String) - new X509DefaultEntryConverter().getConvertedValue( - BCStyle.L , hexEncodedString); - - if (!converted.equals(testString)) - { - fail("failed X509DefaultEntryConverter test"); - } - - // - // try escaped. - // - converted = (DERUTF8String) - new X509DefaultEntryConverter().getConvertedValue( - BCStyle.L , "\\" + hexEncodedString); - - if (!converted.equals(new DERUTF8String(hexEncodedString))) - { - fail("failed X509DefaultEntryConverter test got " + converted + " expected: " + hexEncodedString); - } - - // - // try a weird value - // - X500Name n = new X500Name("CN=\\#nothex#string"); - - if (!n.toString().equals("CN=\\#nothex#string")) - { - fail("# string not properly escaped."); - } - - RDN[] vls = n.getRDNs(BCStyle.CN); - if (vls.length != 1 || !getValue(vls[0]).equals("#nothex#string")) - { - fail("escaped # not reduced properly"); - } - - types = n.getAttributeTypes(); - if (types.length != 1 || !types[0].equals(BCStyle.CN)) - { - fail("type not matched correctly"); - } - - n = new X500Name("CN=\"a+b\""); - - vls = n.getRDNs(BCStyle.CN); - if (vls.length != 1 || !getValue(vls[0]).equals("a+b")) - { - fail("escaped + not reduced properly"); - } - - n = new X500Name("CN=a\\+b"); - - vls = n.getRDNs(BCStyle.CN); - if (vls.length != 1 || !getValue(vls[0]).equals("a+b")) - { - fail("escaped + not reduced properly"); - } - - if (!n.toString().equals("CN=a\\+b")) - { - fail("+ in string not properly escaped."); - } - - n = new X500Name("CN=a\\=b"); - - vls = n.getRDNs(BCStyle.CN); - if (vls.length != 1 || !getValue(vls[0]).equals("a=b")) - { - fail("escaped = not reduced properly"); - } - - if (!n.toString().equals("CN=a\\=b")) - { - fail("= in string not properly escaped."); - } - - n = new X500Name("TELEPHONENUMBER=\"+61999999999\""); - - vls = n.getRDNs(BCStyle.TELEPHONE_NUMBER); - if (vls.length != 1 || !getValue(vls[0]).equals("+61999999999")) - { - fail("telephonenumber escaped + not reduced properly"); - } - - n = new X500Name("TELEPHONENUMBER=\\+61999999999"); - - vls = n.getRDNs(BCStyle.TELEPHONE_NUMBER); - if (vls.length != 1 || !getValue(vls[0]).equals("+61999999999")) - { - fail("telephonenumber escaped + not reduced properly"); - } - - // test query methods - if (!"E".equals(BCStyle.INSTANCE.oidToDisplayName(BCStyle.EmailAddress))) - { - fail("display name for E incorrect"); - } - - String[] aliases = BCStyle.INSTANCE.oidToAttrNames(BCStyle.EmailAddress); - if (aliases.length != 2) - { - fail("no aliases found"); - } - if (!("e".equals(aliases[0]) || "e".equals(aliases[1]))) - { - fail("first alias name for E incorrect"); - } - if (!("emailaddress".equals(aliases[0]) || "emailaddress".equals(aliases[1]))) - { - fail("second alias name for E incorrect"); - } - - if (BCStyle.INSTANCE.oidToDisplayName(new ASN1ObjectIdentifier("1.2.1")) != null) - { - fail("unknown oid matched!"); - } - - if (BCStyle.INSTANCE.oidToAttrNames(new ASN1ObjectIdentifier("1.2.1")).length != 0) - { - fail("unknown oid matched aliases!"); - } - - if (!new X500Name("CN=\" CA1 - CP.04.03\", OU=Testing, OU=Dod, O=U.S. Government, C=US") - .equals(new X500Name("CN=\"ca1 - CP.04.03 \", OU=Testing, OU=Dod, O=U.S. Government, C=US"))) - { - fail("padded equality test failed"); - } - } - - private String getValue(RDN vl) - { - return ((ASN1String)vl.getFirst().getValue()).getString(); - } - - private void ietfUtilsTest() - throws Exception - { - IETFUtils.valueToString(new DERUTF8String(" ")); - } - - /* - private boolean compareVectors(Vector a, Vector b) // for compatibility with early JDKs - { - if (a.size() != b.size()) - { - return false; - } - - for (int i = 0; i != a.size(); i++) - { - if (!a.elementAt(i).equals(b.elementAt(i))) - { - return false; - } - } - - return true; - } - - private void compositeTest() - throws IOException - { - // - // composite test - // - byte[] enc = Hex.decode("305e310b300906035504061302415531283026060355040a0c1f546865204c6567696f6e206f662074686520426f756e637920436173746c653125301006035504070c094d656c626f75726e653011060355040b0c0a4173636f742056616c65"); - ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(enc)); - - X500Name n = X500Name.getInstance(aIn.readObject()); - - if (!n.toString().equals("C=AU,O=The Legion of the Bouncy Castle,L=Melbourne+OU=Ascot Vale")) - { - fail("Failed composite to string test got: " + n.toString()); - } - - if (!n.toString(true, X500Name.DefaultSymbols).equals("L=Melbourne+OU=Ascot Vale,O=The Legion of the Bouncy Castle,C=AU")) - { - fail("Failed composite to string test got: " + n.toString(true, X500Name.DefaultSymbols)); - } - - n = new X500Name(true, "L=Melbourne+OU=Ascot Vale,O=The Legion of the Bouncy Castle,C=AU"); - if (!n.toString().equals("C=AU,O=The Legion of the Bouncy Castle,L=Melbourne+OU=Ascot Vale")) - { - fail("Failed composite to string reversal test got: " + n.toString()); - } - - n = new X500Name("C=AU, O=The Legion of the Bouncy Castle, L=Melbourne + OU=Ascot Vale"); - - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - ASN1OutputStream aOut = new ASN1OutputStream(bOut); - - aOut.writeObject(n); - - byte[] enc2 = bOut.toByteArray(); - - if (!Arrays.areEqual(enc, enc2)) - { - fail("Failed composite string to encoding test"); - } - - // - // dud name test - handle empty DN without barfing. - // - n = new X500Name("C=CH,O=,OU=dummy,CN=mail@dummy.com"); - - n = X500Name.getInstance(ASN1Object.fromByteArray(n.getEncoded())); - } - */ - private void equalityTest(X500Name name1, X500Name name2) - { - if (!name1.equals(name2)) - { - fail("equality test failed for " + name1 + " : " + name2); - } - - if (name1.hashCode() != name2.hashCode()) - { - fail("hashCodeTest test failed for " + name1 + " : " + name2); - } - } - - - public static void main( - String[] args) - { - runTest(new X500NameTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/X509ExtensionsTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/X509ExtensionsTest.java deleted file mode 100644 index 47338a352..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/X509ExtensionsTest.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.x509.X509Extensions; -import com.fr.third.org.bouncycastle.asn1.x509.X509ExtensionsGenerator; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class X509ExtensionsTest - extends SimpleTest -{ - private static final ASN1ObjectIdentifier OID_2 = new ASN1ObjectIdentifier("1.2.2"); - private static final ASN1ObjectIdentifier OID_3 = new ASN1ObjectIdentifier("1.2.3"); - private static final ASN1ObjectIdentifier OID_1 = new ASN1ObjectIdentifier("1.2.1"); - - public String getName() - { - return "X509Extensions"; - } - - public void performTest() throws Exception - { - X509ExtensionsGenerator gen = new X509ExtensionsGenerator(); - - gen.addExtension(OID_1, true, new byte[20]); - gen.addExtension(OID_2, true, new byte[20]); - - X509Extensions ext1 = gen.generate(); - X509Extensions ext2 = gen.generate(); - - if (!ext1.equals(ext2)) - { - fail("equals test failed"); - } - - gen.reset(); - - gen.addExtension(OID_2, true, new byte[20]); - gen.addExtension(OID_1, true, new byte[20]); - - ext2 = gen.generate(); - - if (ext1.equals(ext2)) - { - fail("inequality test failed"); - } - - if (!ext1.equivalent(ext2)) - { - fail("equivalence true failed"); - } - - gen.reset(); - - gen.addExtension(OID_1, true, new byte[22]); - gen.addExtension(OID_2, true, new byte[20]); - - ext2 = gen.generate(); - - if (ext1.equals(ext2)) - { - fail("inequality 1 failed"); - } - - if (ext1.equivalent(ext2)) - { - fail("non-equivalence 1 failed"); - } - - gen.reset(); - - gen.addExtension(OID_3, true, new byte[20]); - gen.addExtension(OID_2, true, new byte[20]); - - ext2 = gen.generate(); - - if (ext1.equals(ext2)) - { - fail("inequality 2 failed"); - } - - if (ext1.equivalent(ext2)) - { - fail("non-equivalence 2 failed"); - } - - try - { - gen.addExtension(OID_2, true, new byte[20]); - fail("repeated oid"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("extension 1.2.2 already added")) - { - fail("wrong exception on repeated oid: " + e.getMessage()); - } - } - } - - public static void main( - String[] args) - { - runTest(new X509ExtensionsTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/X509NameTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/X509NameTest.java deleted file mode 100644 index 8197c9980..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/X509NameTest.java +++ /dev/null @@ -1,676 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Hashtable; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; -import com.fr.third.org.bouncycastle.asn1.ASN1GeneralizedTime; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1OutputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.ASN1Set; -import com.fr.third.org.bouncycastle.asn1.DERIA5String; -import com.fr.third.org.bouncycastle.asn1.DERPrintableString; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.DERSet; -import com.fr.third.org.bouncycastle.asn1.DERUTF8String; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; -import com.fr.third.org.bouncycastle.asn1.x500.X500NameBuilder; -import com.fr.third.org.bouncycastle.asn1.x500.style.BCStyle; -import com.fr.third.org.bouncycastle.asn1.x509.X509DefaultEntryConverter; -import com.fr.third.org.bouncycastle.asn1.x509.X509Name; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class X509NameTest - extends SimpleTest -{ - String[] subjects = - { - "C=AU,ST=Victoria,L=South Melbourne,O=Connect 4 Pty Ltd,OU=Webserver Team,CN=www2.connect4.com.au,E=webmaster@connect4.com.au", - "C=AU,ST=Victoria,L=South Melbourne,O=Connect 4 Pty Ltd,OU=Certificate Authority,CN=Connect 4 CA,E=webmaster@connect4.com.au", - "C=AU,ST=QLD,CN=SSLeay/rsa test cert", - "C=US,O=National Aeronautics and Space Administration,SERIALNUMBER=16+CN=Steve Schoch", - "E=cooke@issl.atl.hp.com,C=US,OU=Hewlett Packard Company (ISSL),CN=Paul A. Cooke", - "O=Sun Microsystems Inc,CN=store.sun.com", - "unstructuredAddress=192.168.1.33,unstructuredName=pixfirewall.ciscopix.com,CN=pixfirewall.ciscopix.com", - "CN=*.canal-plus.com,OU=Provided by TBS INTERNET http://www.tbs-certificats.com/,OU=\\ CANAL \\+,O=CANAL\\+DISTRIBUTION,L=issy les moulineaux,ST=Hauts de Seine,C=FR", - "O=Bouncy Castle,CN=www.bouncycastle.org\\ ", - "O=Bouncy Castle,CN=c:\\\\fred\\\\bob" - }; - - public String getName() - { - return "X509Name"; - } - - private static X509Name fromBytes(byte[] bytes) throws IOException - { - return X509Name.getInstance(ASN1Primitive.fromByteArray(bytes)); - } - - private ASN1Encodable createEntryValue(ASN1ObjectIdentifier oid, String value) - { - Hashtable attrs = new Hashtable(); - - attrs.put(oid, value); - - Vector order = new Vector(); - - order.addElement(oid); - - X509Name name = new X509Name(order, attrs); - - ASN1Sequence seq = (ASN1Sequence)name.toASN1Primitive(); - ASN1Set set = (ASN1Set)seq.getObjectAt(0); - seq = (ASN1Sequence)set.getObjectAt(0); - - return seq.getObjectAt(1); - } - - private ASN1Encodable createEntryValueFromString(ASN1ObjectIdentifier oid, String value) - { - Hashtable attrs = new Hashtable(); - - attrs.put(oid, value); - - Vector order = new Vector(); - - order.addElement(oid); - - X509Name name = new X509Name(new X509Name(order, attrs).toString()); - - ASN1Sequence seq = (ASN1Sequence)name.toASN1Primitive(); - ASN1Set set = (ASN1Set)seq.getObjectAt(0); - seq = (ASN1Sequence)set.getObjectAt(0); - - return seq.getObjectAt(1); - } - - private void testEncodingPrintableString(ASN1ObjectIdentifier oid, String value) - { - ASN1Encodable converted = createEntryValue(oid, value); - if (!(converted instanceof DERPrintableString)) - { - fail("encoding for " + oid + " not printable string"); - } - } - - private void testEncodingIA5String(ASN1ObjectIdentifier oid, String value) - { - ASN1Encodable converted = createEntryValue(oid, value); - if (!(converted instanceof DERIA5String)) - { - fail("encoding for " + oid + " not IA5String"); - } - } - - - private void testEncodingUTF8String(ASN1ObjectIdentifier oid, String value) - throws IOException - { - ASN1Encodable converted = createEntryValue(oid, value); - if (!(converted instanceof DERUTF8String)) - { - fail("encoding for " + oid + " not IA5String"); - } - if (!value.equals((DERUTF8String.getInstance(converted.toASN1Primitive().getEncoded()).getString()))) - { - fail("decoding not correct"); - } - } - - private void testEncodingGeneralizedTime(ASN1ObjectIdentifier oid, String value) - { - ASN1Encodable converted = createEntryValue(oid, value); - if (!(converted instanceof ASN1GeneralizedTime)) - { - fail("encoding for " + oid + " not GeneralizedTime"); - } - converted = createEntryValueFromString(oid, value); - if (!(converted instanceof ASN1GeneralizedTime)) - { - fail("encoding for " + oid + " not GeneralizedTime"); - } - } - - public void performTest() - throws Exception - { - testEncodingPrintableString(X509Name.C, "AU"); - testEncodingPrintableString(X509Name.SERIALNUMBER, "123456"); - testEncodingPrintableString(X509Name.DN_QUALIFIER, "123456"); - testEncodingIA5String(X509Name.EmailAddress, "test@test.com"); - testEncodingIA5String(X509Name.DC, "test"); - // correct encoding - testEncodingGeneralizedTime(X509Name.DATE_OF_BIRTH, "#180F32303032303132323132323232305A"); - // compatibility encoding - testEncodingGeneralizedTime(X509Name.DATE_OF_BIRTH, "20020122122220Z"); - testEncodingUTF8String(X509Name.CN, "Mörsky"); - // - // composite - // - Hashtable attrs = new Hashtable(); - - attrs.put(X509Name.C, "AU"); - attrs.put(X509Name.O, "The Legion of the Bouncy Castle"); - attrs.put(X509Name.L, "Melbourne"); - attrs.put(X509Name.ST, "Victoria"); - attrs.put(X509Name.E, "feedback-crypto@bouncycastle.org"); - - Vector order = new Vector(); - - order.addElement(X509Name.C); - order.addElement(X509Name.O); - order.addElement(X509Name.L); - order.addElement(X509Name.ST); - order.addElement(X509Name.E); - - X509Name name1 = new X509Name(order, attrs); - - if (!name1.equals(name1)) - { - fail("Failed same object test"); - } - - if (!name1.equals(name1, true)) - { - fail("Failed same object test - in Order"); - } - - X509Name name2 = new X509Name(order, attrs); - - if (!name1.equals(name2)) - { - fail("Failed same name test"); - } - - if (!name1.equals(name2, true)) - { - fail("Failed same name test - in Order"); - } - - if (name1.hashCode() != name2.hashCode()) - { - fail("Failed same name test - in Order"); - } - - Vector ord1 = new Vector(); - - ord1.addElement(X509Name.C); - ord1.addElement(X509Name.O); - ord1.addElement(X509Name.L); - ord1.addElement(X509Name.ST); - ord1.addElement(X509Name.E); - - Vector ord2 = new Vector(); - - ord2.addElement(X509Name.E); - ord2.addElement(X509Name.ST); - ord2.addElement(X509Name.L); - ord2.addElement(X509Name.O); - ord2.addElement(X509Name.C); - - name1 = new X509Name(ord1, attrs); - name2 = new X509Name(ord2, attrs); - - if (!name1.equals(name2)) - { - fail("Failed reverse name test"); - } - - if (name1.hashCode() != name2.hashCode()) - { - fail("Failed reverse name test hashCode"); - } - - if (name1.equals(name2, true)) - { - fail("Failed reverse name test - in Order"); - } - - if (!name1.equals(name2, false)) - { - fail("Failed reverse name test - in Order false"); - } - - Vector oids = name1.getOIDs(); - if (!compareVectors(oids, ord1)) - { - fail("oid comparison test"); - } - - Vector val1 = new Vector(); - - val1.addElement("AU"); - val1.addElement("The Legion of the Bouncy Castle"); - val1.addElement("Melbourne"); - val1.addElement("Victoria"); - val1.addElement("feedback-crypto@bouncycastle.org"); - - name1 = new X509Name(ord1, val1); - - Vector values = name1.getValues(); - if (!compareVectors(values, val1)) - { - fail("value comparison test"); - } - - ord2 = new Vector(); - - ord2.addElement(X509Name.ST); - ord2.addElement(X509Name.ST); - ord2.addElement(X509Name.L); - ord2.addElement(X509Name.O); - ord2.addElement(X509Name.C); - - name1 = new X509Name(ord1, attrs); - name2 = new X509Name(ord2, attrs); - - if (name1.equals(name2)) - { - fail("Failed different name test"); - } - - ord2 = new Vector(); - - ord2.addElement(X509Name.ST); - ord2.addElement(X509Name.L); - ord2.addElement(X509Name.O); - ord2.addElement(X509Name.C); - - name1 = new X509Name(ord1, attrs); - name2 = new X509Name(ord2, attrs); - - if (name1.equals(name2)) - { - fail("Failed subset name test"); - } - - compositeTest(); - - ByteArrayOutputStream bOut; - ASN1OutputStream aOut; - ASN1InputStream aIn; - - // - // getValues test - // - Vector v1 = name1.getValues(X509Name.O); - - if (v1.size() != 1 || !v1.elementAt(0).equals("The Legion of the Bouncy Castle")) - { - fail("O test failed"); - } - - Vector v2 = name1.getValues(X509Name.L); - - if (v2.size() != 1 || !v2.elementAt(0).equals("Melbourne")) - { - fail("L test failed"); - } - - // - // general subjects test - // - for (int i = 0; i != subjects.length; i++) - { - X509Name name = new X509Name(subjects[i]); - name = X509Name.getInstance(ASN1Primitive.fromByteArray(name.getEncoded())); - if (!name.toString().equals(subjects[i])) - { - fail("failed regeneration test " + i + " got " + name.toString()); - } - } - - // - // sort test - // - X509Name unsorted = new X509Name("SERIALNUMBER=BBB + CN=AA"); - - if (!fromBytes(unsorted.getEncoded()).toString().equals("CN=AA+SERIALNUMBER=BBB")) - { - fail("failed sort test 1"); - } - - unsorted = new X509Name("CN=AA + SERIALNUMBER=BBB"); - - if (!fromBytes(unsorted.getEncoded()).toString().equals("CN=AA+SERIALNUMBER=BBB")) - { - fail("failed sort test 2"); - } - - unsorted = new X509Name("SERIALNUMBER=B + CN=AA"); - - if (!fromBytes(unsorted.getEncoded()).toString().equals("SERIALNUMBER=B+CN=AA")) - { - fail("failed sort test 3"); - } - - unsorted = new X509Name("CN=AA + SERIALNUMBER=B"); - - if (!fromBytes(unsorted.getEncoded()).toString().equals("SERIALNUMBER=B+CN=AA")) - { - fail("failed sort test 4"); - } - - // - // equality tests - // - equalityTest(new X509Name("CN=The Legion"), new X509Name("CN=The Legion")); - equalityTest(new X509Name("CN= The Legion"), new X509Name("CN=The Legion")); - equalityTest(new X509Name("CN=The Legion "), new X509Name("CN=The Legion")); - equalityTest(new X509Name("CN= The Legion "), new X509Name("CN=The Legion")); - equalityTest(new X509Name("CN= the legion "), new X509Name("CN=The Legion")); - - // # test - - X509Name n1 = new X509Name("SERIALNUMBER=8,O=ABC,CN=ABC Class 3 CA,C=LT"); - X509Name n2 = new X509Name("2.5.4.5=8,O=ABC,CN=ABC Class 3 CA,C=LT"); - X509Name n3 = new X509Name("2.5.4.5=#130138,O=ABC,CN=ABC Class 3 CA,C=LT"); - - equalityTest(n1, n2); - equalityTest(n2, n3); - equalityTest(n3, n1); - - n1 = new X509Name(true, "2.5.4.5=#130138,CN=SSC Class 3 CA,O=UAB Skaitmeninio sertifikavimo centras,C=LT"); - n2 = new X509Name(true, "SERIALNUMBER=#130138,CN=SSC Class 3 CA,O=UAB Skaitmeninio sertifikavimo centras,C=LT"); - n3 = X509Name.getInstance(ASN1Primitive.fromByteArray(Hex.decode("3063310b3009060355040613024c54312f302d060355040a1326" - + "55414220536b6169746d656e696e696f20736572746966696b6176696d6f2063656e74726173311730150603550403130e53534320436c6173732033204341310a30080603550405130138"))); - - equalityTest(n1, n2); - equalityTest(n2, n3); - equalityTest(n3, n1); - - n1 = new X509Name("SERIALNUMBER=8,O=XX,CN=ABC Class 3 CA,C=LT"); - n2 = new X509Name("2.5.4.5=8,O=,CN=ABC Class 3 CA,C=LT"); - - if (n1.equals(n2)) - { - fail("empty inequality check failed"); - } - - n1 = new X509Name("SERIALNUMBER=8,O=,CN=ABC Class 3 CA,C=LT"); - n2 = new X509Name("2.5.4.5=8,O=,CN=ABC Class 3 CA,C=LT"); - - equalityTest(n1, n2); - - // - // inequality to sequences - // - name1 = new X509Name("CN=The Legion"); - - if (name1.equals(new DERSequence())) - { - fail("inequality test with sequence"); - } - - if (name1.equals(new DERSequence(new DERSet()))) - { - fail("inequality test with sequence and set"); - } - - ASN1EncodableVector v = new ASN1EncodableVector(); - - v.add(new ASN1ObjectIdentifier("1.1")); - v.add(new ASN1ObjectIdentifier("1.1")); - if (name1.equals(new DERSequence(new DERSet(new DERSet(v))))) - { - fail("inequality test with sequence and bad set"); - } - - if (name1.equals(new DERSequence(new DERSet(new DERSet(v))), true)) - { - fail("inequality test with sequence and bad set"); - } - - if (name1.equals(new DERSequence(new DERSet(new DERSequence())))) - { - fail("inequality test with sequence and short sequence"); - } - - if (name1.equals(new DERSequence(new DERSet(new DERSequence())), true)) - { - fail("inequality test with sequence and short sequence"); - } - - v = new ASN1EncodableVector(); - - v.add(new ASN1ObjectIdentifier("1.1")); - v.add(new DERSequence()); - - if (name1.equals(new DERSequence(new DERSet(new DERSequence(v))))) - { - fail("inequality test with sequence and bad sequence"); - } - - if (name1.equals(null)) - { - fail("inequality test with null"); - } - - if (name1.equals(null, true)) - { - fail("inequality test with null"); - } - - // - // this is contrived but it checks sorting of sets with equal elements - // - unsorted = new X509Name("CN=AA + CN=AA + CN=AA"); - - // - // tagging test - only works if CHOICE implemented - // - /* - ASN1TaggedObject tag = new DERTaggedObject(false, 1, new X509Name("CN=AA")); - - if (!tag.isExplicit()) - { - fail("failed to explicitly tag CHOICE object"); - } - - X509Name name = X509Name.getInstance(tag, false); - - if (!name.equals(new X509Name("CN=AA"))) - { - fail("failed to recover tagged name"); - } - */ - - DERUTF8String testString = new DERUTF8String("The Legion of the Bouncy Castle"); - byte[] encodedBytes = testString.getEncoded(); - byte[] hexEncodedBytes = Hex.encode(encodedBytes); - String hexEncodedString = "#" + new String(hexEncodedBytes); - - DERUTF8String converted = (DERUTF8String) - new X509DefaultEntryConverter().getConvertedValue( - X509Name.L , hexEncodedString); - - if (!converted.equals(testString)) - { - fail("failed X509DefaultEntryConverter test"); - } - - // - // try escaped. - // - converted = (DERUTF8String) - new X509DefaultEntryConverter().getConvertedValue( - X509Name.L , "\\" + hexEncodedString); - - if (!converted.equals(new DERUTF8String(hexEncodedString))) - { - fail("failed X509DefaultEntryConverter test got " + converted + " expected: " + hexEncodedString); - } - - // - // try a weird value - // - X509Name n = new X509Name("CN=\\#nothex#string"); - - if (!n.toString().equals("CN=\\#nothex#string")) - { - fail("# string not properly escaped."); - } - - Vector vls = n.getValues(X509Name.CN); - if (vls.size() != 1 || !vls.elementAt(0).equals("#nothex#string")) - { - fail("escaped # not reduced properly"); - } - - n = new X509Name("CN=\"a+b\""); - - vls = n.getValues(X509Name.CN); - if (vls.size() != 1 || !vls.elementAt(0).equals("a+b")) - { - fail("escaped + not reduced properly"); - } - - n = new X509Name("CN=a\\+b"); - - vls = n.getValues(X509Name.CN); - if (vls.size() != 1 || !vls.elementAt(0).equals("a+b")) - { - fail("escaped + not reduced properly"); - } - - if (!n.toString().equals("CN=a\\+b")) - { - fail("+ in string not properly escaped."); - } - - n = new X509Name("CN=a\\=b"); - - vls = n.getValues(X509Name.CN); - if (vls.size() != 1 || !vls.elementAt(0).equals("a=b")) - { - fail("escaped = not reduced properly"); - } - - if (!n.toString().equals("CN=a\\=b")) - { - fail("= in string not properly escaped."); - } - - n = new X509Name("TELEPHONENUMBER=\"+61999999999\""); - - vls = n.getValues(X509Name.TELEPHONE_NUMBER); - if (vls.size() != 1 || !vls.elementAt(0).equals("+61999999999")) - { - fail("telephonenumber escaped + not reduced properly"); - } - - n = new X509Name("TELEPHONENUMBER=\\+61999999999"); - - vls = n.getValues(X509Name.TELEPHONE_NUMBER); - if (vls.size() != 1 || !vls.elementAt(0).equals("+61999999999")) - { - fail("telephonenumber escaped + not reduced properly"); - } - - // migration - X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE); - builder.addMultiValuedRDN(new ASN1ObjectIdentifier[] { BCStyle.CN, BCStyle.SN }, new String[] { "Thomas", "CVR:12341233-UID:1111" }); - builder.addRDN(BCStyle.O, "Test"); - builder.addRDN(BCStyle.C, "DK"); - - X500Name subject = builder.build(); - ASN1Primitive derObject = subject.toASN1Primitive(); - X509Name instance = X509Name.getInstance(derObject); - } - - private boolean compareVectors(Vector a, Vector b) // for compatibility with early JDKs - { - if (a.size() != b.size()) - { - return false; - } - - for (int i = 0; i != a.size(); i++) - { - if (!a.elementAt(i).equals(b.elementAt(i))) - { - return false; - } - } - - return true; - } - - private void compositeTest() - throws IOException - { - // - // composite test - // - byte[] enc = Hex.decode( - "305e310b300906035504061302415531283026060355040a0c1f546865204c6567696f6e206f662074686520426f756e637920436173746c653125301006035504070c094d656c626f75726e653011060355040b0c0a4173636f742056616c65"); - - X509Name n = X509Name.getInstance(ASN1Primitive.fromByteArray(enc)); - - if (!n.toString().equals("C=AU,O=The Legion of the Bouncy Castle,L=Melbourne+OU=Ascot Vale")) - { - fail("Failed composite to string test got: " + n.toString()); - } - - if (!n.toString(true, X509Name.DefaultSymbols).equals("L=Melbourne+OU=Ascot Vale,O=The Legion of the Bouncy Castle,C=AU")) - { - fail("Failed composite to string test got: " + n.toString(true, X509Name.DefaultSymbols)); - } - - n = new X509Name(true, "L=Melbourne+OU=Ascot Vale,O=The Legion of the Bouncy Castle,C=AU"); - if (!n.toString().equals("C=AU,O=The Legion of the Bouncy Castle,L=Melbourne+OU=Ascot Vale")) - { - fail("Failed composite to string reversal test got: " + n.toString()); - } - - n = new X509Name("C=AU, O=The Legion of the Bouncy Castle, L=Melbourne + OU=Ascot Vale"); - - byte[] enc2 = n.getEncoded(); - - if (!Arrays.areEqual(enc, enc2)) - { - fail("Failed composite string to encoding test"); - } - - // - // dud name test - handle empty DN without barfing. - // - n = new X509Name("C=CH,O=,OU=dummy,CN=mail@dummy.com"); - - n = X509Name.getInstance(ASN1Primitive.fromByteArray(n.getEncoded())); - } - - private void equalityTest(X509Name x509Name, X509Name x509Name1) - { - if (!x509Name.equals(x509Name1)) - { - fail("equality test failed for " + x509Name + " : " + x509Name1); - } - - if (x509Name.hashCode() != x509Name1.hashCode()) - { - fail("hashCodeTest test failed for " + x509Name + " : " + x509Name1); - } - - if (!x509Name.equals(x509Name1, true)) - { - fail("equality test failed for " + x509Name + " : " + x509Name1); - } - } - - - public static void main( - String[] args) - { - runTest(new X509NameTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/X9Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/X9Test.java deleted file mode 100644 index e8aa32abf..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/X9Test.java +++ /dev/null @@ -1,174 +0,0 @@ -package com.fr.third.org.bouncycastle.asn1.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.asn1.ASN1OctetString; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.pkcs.PrivateKeyInfo; -import com.fr.third.org.bouncycastle.asn1.sec.ECPrivateKey; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.asn1.x9.X962NamedCurves; -import com.fr.third.org.bouncycastle.asn1.x9.X962Parameters; -import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; -import com.fr.third.org.bouncycastle.asn1.x9.X9ECPoint; -import com.fr.third.org.bouncycastle.asn1.x9.X9IntegerConverter; -import com.fr.third.org.bouncycastle.asn1.x9.X9ObjectIdentifiers; -import com.fr.third.org.bouncycastle.math.ec.ECPoint; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class X9Test - extends SimpleTest -{ - private byte[] namedPub = Base64.decode("MDcwEwYHKoZIzj0CAQYIKoZIzj0DAQEDIAADG5xRI+Iki/JrvL20hoDUa7Cggzorv5B9yyqSMjYu"); - private byte[] expPub = Base64.decode( - "MIH8MIHXBgcqhkjOPQIBMIHLAgEBMCkGByqGSM49AQECHn///////////////3///////4AAAA" + - "AAAH///////zBXBB5///////////////9///////+AAAAAAAB///////wEHiVXBfoqMGZUsfTL" + - "A9anUKMMJQEC1JiHF9m6FattPgMVAH1zdBaP/jRxtgqFdoahlHXTv6L/BB8DZ2iujhi7ks/PAF" + - "yUmqLG2UhT0OZgu/hUsclQX+laAh5///////////////9///+XXetBs6YFfDxDIUZSZVECAQED" + - "IAADG5xRI+Iki/JrvL20hoDUa7Cggzorv5B9yyqSMjYu"); - - private byte[] namedPriv = Base64.decode("MDkCAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQEEHzAdAgEBBB" + - "gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAo="); - - private byte[] expPriv = Base64.decode( - "MIIBBAIBADCB1wYHKoZIzj0CATCBywIBATApBgcqhkjOPQEBAh5///////////////9///////" + - "+AAAAAAAB///////8wVwQef///////////////f///////gAAAAAAAf//////8BB4lVwX6KjBmVL" + - "H0ywPWp1CjDCUBAtSYhxfZuhWrbT4DFQB9c3QWj/40cbYKhXaGoZR107+i/wQfA2doro4Yu5LPzw" + - "BclJqixtlIU9DmYLv4VLHJUF/pWgIef///////////////f///l13rQbOmBXw8QyFGUmVRAgEBBC" + - "UwIwIBAQQeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU"); - - private void encodePublicKey() - throws Exception - { - X9ECParameters ecP = X962NamedCurves.getByOID(X9ObjectIdentifiers.prime239v3); - - X9IntegerConverter conv = new X9IntegerConverter(); - - if (conv.getByteLength(ecP.getCurve()) != 30) - { - fail("wrong byte length reported for curve"); - } - - if (ecP.getCurve().getFieldSize() != 239) - { - fail("wrong field size reported for curve"); - } - - // - // named curve - // - X962Parameters params = new X962Parameters(X9ObjectIdentifiers.prime192v1); - ECPoint point = ecP.getG().multiply(BigInteger.valueOf(100)); - - ASN1OctetString p = new DEROctetString(point.getEncoded(true)); - - SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params), p.getOctets()); - if (!areEqual(info.getEncoded(), namedPub)) - { - fail("failed public named generation"); - } - - X9ECPoint x9P = new X9ECPoint(ecP.getCurve(), p); - - if (!Arrays.areEqual(p.getOctets(), x9P.getPointEncoding())) - { - fail("point encoding not preserved"); - } - - ASN1Primitive o = ASN1Primitive.fromByteArray(namedPub); - - if (!info.equals(o)) - { - fail("failed public named equality"); - } - - // - // explicit curve parameters - // - params = new X962Parameters(ecP); - - info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params), p.getOctets()); - - if (!areEqual(info.getEncoded(), expPub)) - { - fail("failed public explicit generation"); - } - - o = ASN1Primitive.fromByteArray(expPub); - - if (!info.equals(o)) - { - fail("failed public explicit equality"); - } - } - - private void encodePrivateKey() - throws Exception - { - X9ECParameters ecP = X962NamedCurves.getByOID(X9ObjectIdentifiers.prime192v1); - - // - // named curve - // - X962Parameters params = new X962Parameters(X9ObjectIdentifiers.prime192v1); - - PrivateKeyInfo info = new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params), - new ECPrivateKey(ecP.getN().bitLength(), BigInteger.valueOf(10))); - - if (!areEqual(info.getEncoded(), namedPriv)) - { - fail("failed private named generation"); - } - - ASN1Primitive o = ASN1Primitive.fromByteArray(namedPriv); - - if (!info.equals(o)) - { - fail("failed private named equality"); - } - - // - // explicit curve parameters - // - ecP = X962NamedCurves.getByOID(X9ObjectIdentifiers.prime239v3); - - params = new X962Parameters(ecP); - - info = new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params), - new ECPrivateKey(ecP.getN().bitLength(), BigInteger.valueOf(20))); - - if (!areEqual(info.getEncoded(), expPriv)) - { - fail("failed private explicit generation"); - } - - o = ASN1Primitive.fromByteArray(expPriv); - - if (!info.equals(o)) - { - fail("failed private explicit equality"); - } - } - - public void performTest() - throws Exception - { - encodePublicKey(); - encodePrivateKey(); - } - - public String getName() - { - return "X9"; - } - - public static void main( - String[] args) - { - runTest(new X9Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/package.html deleted file mode 100644 index df45e190e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/test/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Test programs for the ASN.1 package. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/tsp/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/tsp/package.html deleted file mode 100644 index d6265f044..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/tsp/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding and supporting Time Stamp Protocol as described RFC 3161. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ua/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ua/package.html deleted file mode 100644 index 0fc273f1e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/ua/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for the Ukrainian DSTU standard. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/util/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/util/package.html deleted file mode 100644 index 1db893d19..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/util/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -An ASN.1 dump utility. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x500/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x500/package.html deleted file mode 100644 index 9a3f9c600..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x500/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for the creation and processing of object based on X.500 names. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x500/style/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x500/style/package.html deleted file mode 100644 index 219d3f54b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x500/style/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Template classes for the common styles used for converting X.500 names to strings and back. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/AuthorityInformationAccess.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/AuthorityInformationAccess.java index 32d2fd858..491ba4065 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/AuthorityInformationAccess.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/AuthorityInformationAccess.java @@ -1,6 +1,5 @@ package com.fr.third.org.bouncycastle.asn1.x509; -import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; import com.fr.third.org.bouncycastle.asn1.ASN1Object; import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; @@ -28,6 +27,13 @@ public class AuthorityInformationAccess { private AccessDescription[] descriptions; + private static AccessDescription[] copy(AccessDescription[] descriptions) + { + AccessDescription[] result = new AccessDescription[descriptions.length]; + System.arraycopy(descriptions, 0, result, 0, descriptions.length); + return result; + } + public static AuthorityInformationAccess getInstance( Object obj) { @@ -46,7 +52,7 @@ public class AuthorityInformationAccess public static AuthorityInformationAccess fromExtensions(Extensions extensions) { - return AuthorityInformationAccess.getInstance(extensions.getExtensionParsedValue(Extension.authorityInfoAccess)); + return getInstance(Extensions.getExtensionParsedValue(extensions, Extension.authorityInfoAccess)); } private AuthorityInformationAccess( @@ -58,7 +64,7 @@ public class AuthorityInformationAccess } descriptions = new AccessDescription[seq.size()]; - + for (int i = 0; i != seq.size(); i++) { descriptions[i] = AccessDescription.getInstance(seq.getObjectAt(i)); @@ -68,14 +74,13 @@ public class AuthorityInformationAccess public AuthorityInformationAccess( AccessDescription description) { - this(new AccessDescription[]{ description }); + this.descriptions = new AccessDescription[]{ description }; } public AuthorityInformationAccess( AccessDescription[] descriptions) { - this.descriptions = new AccessDescription[descriptions.length]; - System.arraycopy(descriptions, 0, this.descriptions, 0, descriptions.length); + this.descriptions = copy(descriptions); } /** @@ -94,9 +99,9 @@ public class AuthorityInformationAccess */ public AccessDescription[] getAccessDescriptions() { - return descriptions; + return copy(descriptions); } - + public ASN1Primitive toASN1Primitive() { return new DERSequence(descriptions); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/AuthorityKeyIdentifier.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/AuthorityKeyIdentifier.java index 27d7668c5..da2b5ebc9 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/AuthorityKeyIdentifier.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/AuthorityKeyIdentifier.java @@ -34,9 +34,9 @@ import com.fr.third.org.bouncycastle.util.encoders.Hex; public class AuthorityKeyIdentifier extends ASN1Object { - ASN1OctetString keyidentifier=null; - GeneralNames certissuer=null; - ASN1Integer certserno=null; + ASN1OctetString keyidentifier = null; + GeneralNames certissuer = null; + ASN1Integer certserno = null; public static AuthorityKeyIdentifier getInstance( ASN1TaggedObject obj, @@ -62,7 +62,7 @@ public class AuthorityKeyIdentifier public static AuthorityKeyIdentifier fromExtensions(Extensions extensions) { - return AuthorityKeyIdentifier.getInstance(extensions.getExtensionParsedValue(Extension.authorityKeyIdentifier)); + return getInstance(Extensions.getExtensionParsedValue(extensions, Extension.authorityKeyIdentifier)); } protected AuthorityKeyIdentifier( @@ -72,7 +72,7 @@ public class AuthorityKeyIdentifier while (e.hasMoreElements()) { - ASN1TaggedObject o = DERTaggedObject.getInstance(e.nextElement()); + ASN1TaggedObject o = ASN1TaggedObject.getInstance(e.nextElement()); switch (o.getTagNo()) { @@ -107,13 +107,7 @@ public class AuthorityKeyIdentifier public AuthorityKeyIdentifier( SubjectPublicKeyInfo spki) { - Digest digest = new SHA1Digest(); - byte[] resBuf = new byte[digest.getDigestSize()]; - - byte[] bytes = spki.getPublicKeyData().getBytes(); - digest.update(bytes, 0, bytes.length); - digest.doFinal(resBuf, 0); - this.keyidentifier = new DEROctetString(resBuf); + this(spki, null, null); } /** @@ -134,8 +128,8 @@ public class AuthorityKeyIdentifier digest.doFinal(resBuf, 0); this.keyidentifier = new DEROctetString(resBuf); - this.certissuer = GeneralNames.getInstance(name.toASN1Primitive()); - this.certserno = new ASN1Integer(serialNumber); + this.certissuer = name; + this.certserno = (serialNumber != null) ? new ASN1Integer(serialNumber) : null; } /** @@ -224,6 +218,8 @@ public class AuthorityKeyIdentifier public String toString() { - return ("AuthorityKeyIdentifier: KeyID(" + ((keyidentifier != null) ? Hex.toHexString(this.keyidentifier.getOctets()) : "null") + ")"); + String keyID = (keyidentifier != null) ? Hex.toHexString(keyidentifier.getOctets()) : "null"; + + return "AuthorityKeyIdentifier: KeyID(" + keyID + ")"; } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/BasicConstraints.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/BasicConstraints.java index 00eb61ccb..2dcecc133 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/BasicConstraints.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/BasicConstraints.java @@ -45,7 +45,7 @@ public class BasicConstraints public static BasicConstraints fromExtensions(Extensions extensions) { - return BasicConstraints.getInstance(extensions.getExtensionParsedValue(Extension.basicConstraints)); + return getInstance(Extensions.getExtensionParsedValue(extensions, Extension.basicConstraints)); } private BasicConstraints( @@ -152,10 +152,6 @@ public class BasicConstraints { if (pathLenConstraint == null) { - if (cA == null) - { - return "BasicConstraints: isCa(false)"; - } return "BasicConstraints: isCa(" + this.isCA() + ")"; } return "BasicConstraints: isCa(" + this.isCA() + "), pathLenConstraint = " + pathLenConstraint.getValue(); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/CRLDistPoint.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/CRLDistPoint.java index 330ab8db3..0f81e1660 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/CRLDistPoint.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/CRLDistPoint.java @@ -19,11 +19,6 @@ public class CRLDistPoint return getInstance(ASN1Sequence.getInstance(obj, explicit)); } - public static CRLDistPoint fromExtensions(Extensions extensions) - { - return CRLDistPoint.getInstance(extensions.getExtensionParsedValue(Extension.cRLDistributionPoints)); - } - public static CRLDistPoint getInstance( Object obj) { @@ -39,6 +34,11 @@ public class CRLDistPoint return null; } + public static CRLDistPoint fromExtensions(Extensions extensions) + { + return getInstance(Extensions.getExtensionParsedValue(extensions, Extension.cRLDistributionPoints)); + } + private CRLDistPoint( ASN1Sequence seq) { diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/CertificatePolicies.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/CertificatePolicies.java index d02fbdbba..fd37b7b88 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/CertificatePolicies.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/CertificatePolicies.java @@ -12,6 +12,13 @@ public class CertificatePolicies { private final PolicyInformation[] policyInformation; + private static PolicyInformation[] copy(PolicyInformation[] policyInfo) + { + PolicyInformation[] result = new PolicyInformation[policyInfo.length]; + System.arraycopy(policyInfo, 0, result, 0, policyInfo.length); + return result; + } + public static CertificatePolicies getInstance( Object obj) { @@ -43,7 +50,7 @@ public class CertificatePolicies */ public static CertificatePolicies fromExtensions(Extensions extensions) { - return CertificatePolicies.getInstance(extensions.getExtensionParsedValue(Extension.certificatePolicies)); + return getInstance(Extensions.getExtensionParsedValue(extensions, Extension.certificatePolicies)); } /** @@ -60,7 +67,7 @@ public class CertificatePolicies public CertificatePolicies( PolicyInformation[] policyInformation) { - this.policyInformation = copyPolicyInfo(policyInformation); + this.policyInformation = copy(policyInformation); } private CertificatePolicies( @@ -76,16 +83,7 @@ public class CertificatePolicies public PolicyInformation[] getPolicyInformation() { - return copyPolicyInfo(policyInformation); - } - - private PolicyInformation[] copyPolicyInfo(PolicyInformation[] policyInfo) - { - PolicyInformation[] tmp = new PolicyInformation[policyInfo.length]; - - System.arraycopy(policyInfo, 0, tmp, 0, policyInfo.length); - - return tmp; + return copy(policyInformation); } public PolicyInformation getPolicyInformation(ASN1ObjectIdentifier policyIdentifier) diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/ExtendedKeyUsage.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/ExtendedKeyUsage.java index 8c539afe1..108995110 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/ExtendedKeyUsage.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/ExtendedKeyUsage.java @@ -68,7 +68,7 @@ public class ExtendedKeyUsage */ public static ExtendedKeyUsage fromExtensions(Extensions extensions) { - return ExtendedKeyUsage.getInstance(extensions.getExtensionParsedValue(Extension.extendedKeyUsage)); + return getInstance(Extensions.getExtensionParsedValue(extensions, Extension.extendedKeyUsage)); } /** diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/Extensions.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/Extensions.java index 9b5adeacc..8eebcbb2d 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/Extensions.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/Extensions.java @@ -29,6 +29,16 @@ public class Extensions private Hashtable extensions = new Hashtable(); private Vector ordering = new Vector(); + public static Extension getExtension(Extensions extensions, ASN1ObjectIdentifier oid) + { + return null == extensions ? null : extensions.getExtension(oid); + } + + public static ASN1Encodable getExtensionParsedValue(Extensions extensions, ASN1ObjectIdentifier oid) + { + return null == extensions ? null : extensions.getExtensionParsedValue(oid); + } + public static Extensions getInstance( ASN1TaggedObject obj, boolean explicit) diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/GeneralNames.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/GeneralNames.java index da760fb04..faeb1e293 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/GeneralNames.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/GeneralNames.java @@ -13,6 +13,13 @@ public class GeneralNames { private final GeneralName[] names; + private static GeneralName[] copy(GeneralName[] names) + { + GeneralName[] result = new GeneralName[names.length]; + System.arraycopy(names, 0, result, 0, names.length); + return result; + } + public static GeneralNames getInstance( Object obj) { @@ -38,7 +45,7 @@ public class GeneralNames public static GeneralNames fromExtensions(Extensions extensions, ASN1ObjectIdentifier extOID) { - return GeneralNames.getInstance(extensions.getExtensionParsedValue(extOID)); + return getInstance(Extensions.getExtensionParsedValue(extensions, extOID)); } /** @@ -75,15 +82,6 @@ public class GeneralNames return copy(names); } - private GeneralName[] copy(GeneralName[] nms) - { - GeneralName[] tmp = new GeneralName[nms.length]; - - System.arraycopy(nms, 0, tmp, 0, tmp.length); - - return tmp; - } - /** * Produce an object suitable for an ASN1OutputStream. *diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/KeyUsage.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/KeyUsage.java index 5eae4b2b7..cacf0eb11 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/KeyUsage.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/KeyUsage.java @@ -52,7 +52,7 @@ public class KeyUsage public static KeyUsage fromExtensions(Extensions extensions) { - return KeyUsage.getInstance(extensions.getExtensionParsedValue(Extension.keyUsage)); + return getInstance(Extensions.getExtensionParsedValue(extensions, Extension.keyUsage)); } /** diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/PKIXNameConstraintValidator.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/PKIXNameConstraintValidator.java index c51210c96..c8cd8364f 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/PKIXNameConstraintValidator.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/PKIXNameConstraintValidator.java @@ -67,24 +67,19 @@ public class PKIXNameConstraintValidator checkPermittedOtherName(permittedSubtreesOtherName, OtherName.getInstance(name.getName())); break; case GeneralName.rfc822Name: - checkPermittedEmail(permittedSubtreesEmail, - extractNameAsString(name)); + checkPermittedEmail(permittedSubtreesEmail, extractNameAsString(name)); break; case GeneralName.dNSName: - checkPermittedDNS(permittedSubtreesDNS, DERIA5String.getInstance( - name.getName()).getString()); + checkPermittedDNS(permittedSubtreesDNS, extractNameAsString(name)); break; case GeneralName.directoryName: checkPermittedDN(X500Name.getInstance(name.getName())); break; case GeneralName.uniformResourceIdentifier: - checkPermittedURI(permittedSubtreesURI, DERIA5String.getInstance( - name.getName()).getString()); + checkPermittedURI(permittedSubtreesURI, extractNameAsString(name)); break; case GeneralName.iPAddress: - byte[] ip = ASN1OctetString.getInstance(name.getName()).getOctets(); - - checkPermittedIP(permittedSubtreesIP, ip); + checkPermittedIP(permittedSubtreesIP, ASN1OctetString.getInstance(name.getName()).getOctets()); break; default: // other tags to be ignored. @@ -110,20 +105,16 @@ public class PKIXNameConstraintValidator checkExcludedEmail(excludedSubtreesEmail, extractNameAsString(name)); break; case GeneralName.dNSName: - checkExcludedDNS(excludedSubtreesDNS, DERIA5String.getInstance( - name.getName()).getString()); + checkExcludedDNS(excludedSubtreesDNS, extractNameAsString(name)); break; case GeneralName.directoryName: checkExcludedDN(X500Name.getInstance(name.getName())); break; case GeneralName.uniformResourceIdentifier: - checkExcludedURI(excludedSubtreesURI, DERIA5String.getInstance( - name.getName()).getString()); + checkExcludedURI(excludedSubtreesURI, extractNameAsString(name)); break; case GeneralName.iPAddress: - byte[] ip = ASN1OctetString.getInstance(name.getName()).getOctets(); - - checkExcludedIP(excludedSubtreesIP, ip); + checkExcludedIP(excludedSubtreesIP, ASN1OctetString.getInstance(name.getName()).getOctets()); break; default: // other tags to be ignored. @@ -254,8 +245,8 @@ public class PKIXNameConstraintValidator extractNameAsString(base)); break; case GeneralName.iPAddress: - excludedSubtreesIP = unionIP(excludedSubtreesIP, ASN1OctetString - .getInstance(base.getName()).getOctets()); + excludedSubtreesIP = unionIP(excludedSubtreesIP, + ASN1OctetString.getInstance(base.getName()).getOctets()); break; default: throw new IllegalStateException("Unknown tag encountered: " + base.getTagNo()); @@ -331,7 +322,7 @@ public class PKIXNameConstraintValidator { start = j; RDN dnsRdn = RDN.getInstance(dns.getObjectAt(j)); - if (dnsRdn.equals(subtreeRdnStart)) + if (IETFUtils.rDNAreEqual(subtreeRdnStart, dnsRdn)) { break; } @@ -487,7 +478,7 @@ public class PKIXNameConstraintValidator Iterator it = excluded.iterator(); while (it.hasNext()) { - ASN1Sequence subtree = (ASN1Sequence)it.next(); + ASN1Sequence subtree = ASN1Sequence.getInstance(it.next()); if (withinDNSubtree(dn, subtree)) { @@ -513,13 +504,13 @@ public class PKIXNameConstraintValidator Set intersect = new HashSet(); for (Iterator it = otherNames.iterator(); it.hasNext();) { - Object otName = it.next(); + OtherName otName1 = OtherName.getInstance(((GeneralSubtree)it.next()).getBase().getName()); if (permitted == null) { - if (otName != null) + if (otName1 != null) { - intersect.add(otName); + intersect.add(otName1); } } else @@ -527,16 +518,16 @@ public class PKIXNameConstraintValidator Iterator it2 = permitted.iterator(); while (it2.hasNext()) { - String _permitted = (String)it2.next(); + OtherName otName2 = OtherName.getInstance(it2.next()); - intersectOtherName(otName, _permitted, intersect); + intersectOtherName(otName1, otName2, intersect); } } } return intersect; } - private void intersectOtherName(Object otName1, Object otName2, Set intersect) + private void intersectOtherName(OtherName otName1, OtherName otName2, Set intersect) { if (otName1.equals(otName2)) { @@ -865,7 +856,7 @@ public class PKIXNameConstraintValidator while (it.hasNext()) { - OtherName str = ((OtherName)it.next()); + OtherName str = OtherName.getInstance(it.next()); if (otherNameIsConstrained(name, str)) { diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/PolicyConstraints.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/PolicyConstraints.java index 033037ab8..8b02574f2 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/PolicyConstraints.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/PolicyConstraints.java @@ -74,7 +74,7 @@ public class PolicyConstraints public static PolicyConstraints fromExtensions(Extensions extensions) { - return PolicyConstraints.getInstance(extensions.getExtensionParsedValue(Extension.policyConstraints)); + return getInstance(Extensions.getExtensionParsedValue(extensions, Extension.policyConstraints)); } public BigInteger getRequireExplicitPolicyMapping() diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/SubjectKeyIdentifier.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/SubjectKeyIdentifier.java index f2122e534..7ca8c1063 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/SubjectKeyIdentifier.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/SubjectKeyIdentifier.java @@ -42,7 +42,7 @@ public class SubjectKeyIdentifier public static SubjectKeyIdentifier fromExtensions(Extensions extensions) { - return SubjectKeyIdentifier.getInstance(extensions.getExtensionParsedValue(Extension.subjectKeyIdentifier)); + return getInstance(Extensions.getExtensionParsedValue(extensions, Extension.subjectKeyIdentifier)); } public SubjectKeyIdentifier( diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/TBSCertificate.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/TBSCertificate.java index 4bad201a3..471c83988 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/TBSCertificate.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/TBSCertificate.java @@ -2,13 +2,18 @@ package com.fr.third.org.bouncycastle.asn1.x509; import java.math.BigInteger; +import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; import com.fr.third.org.bouncycastle.asn1.ASN1Integer; import com.fr.third.org.bouncycastle.asn1.ASN1Object; import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; import com.fr.third.org.bouncycastle.asn1.ASN1TaggedObject; import com.fr.third.org.bouncycastle.asn1.DERBitString; +import com.fr.third.org.bouncycastle.asn1.DERSequence; +import com.fr.third.org.bouncycastle.asn1.DERTaggedObject; import com.fr.third.org.bouncycastle.asn1.x500.X500Name; +import com.fr.third.org.bouncycastle.util.BigIntegers; +import com.fr.third.org.bouncycastle.util.Properties; /** * The TBSCertificate object. @@ -218,6 +223,69 @@ public class TBSCertificate public ASN1Primitive toASN1Primitive() { - return seq; + if (Properties.getPropertyValue("com.fr.third.org.bouncycastle.x509.allow_non-der_tbscert") != null) + { + if (Properties.isOverrideSet("com.fr.third.org.bouncycastle.x509.allow_non-der_tbscert")) + { + return seq; + } + } + else + { + return seq; + } + + ASN1EncodableVector v = new ASN1EncodableVector(); + + // DEFAULT Zero + if (!version.hasValue(BigIntegers.ZERO)) + { + v.add(new DERTaggedObject(true, 0, version)); + } + + v.add(serialNumber); + v.add(signature); + v.add(issuer); + + // + // before and after dates + // + { + ASN1EncodableVector validity = new ASN1EncodableVector(2); + validity.add(startDate); + validity.add(endDate); + + v.add(new DERSequence(validity)); + } + + if (subject != null) + { + v.add(subject); + } + else + { + v.add(new DERSequence()); + } + + v.add(subjectPublicKeyInfo); + + // Note: implicit tag + if (issuerUniqueId != null) + { + v.add(new DERTaggedObject(false, 1, issuerUniqueId)); + } + + // Note: implicit tag + if (subjectUniqueId != null) + { + v.add(new DERTaggedObject(false, 2, subjectUniqueId)); + } + + if (extensions != null) + { + v.add(new DERTaggedObject(true, 3, extensions)); + } + + return new DERSequence(v); } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/X509Name.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/X509Name.java index 0a6752dc6..18e26f435 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/X509Name.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/X509Name.java @@ -374,7 +374,7 @@ public class X509Name public static X509Name getInstance( Object obj) { - if (obj == null || obj instanceof X509Name) + if (obj instanceof X509Name) { return (X509Name)obj; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/X509ObjectIdentifiers.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/X509ObjectIdentifiers.java index a7097e6bd..699dab3f4 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/X509ObjectIdentifiers.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/X509ObjectIdentifiers.java @@ -4,7 +4,6 @@ import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; public interface X509ObjectIdentifiers { - /** Subject RDN components: commonName = 2.5.4.3 */ static final ASN1ObjectIdentifier commonName = new ASN1ObjectIdentifier("2.5.4.3").intern(); /** Subject RDN components: countryName = 2.5.4.6 */ @@ -57,6 +56,34 @@ public interface X509ObjectIdentifiers */ static final ASN1ObjectIdentifier id_pkix = new ASN1ObjectIdentifier("1.3.6.1.5.5.7"); + /** + * id-RSASSA-PSS-SHAKE128 OBJECT IDENTIFIER ::= { iso(1) + * identified-organization(3) dod(6) internet(1) + * security(5) mechanisms(5) pkix(7) algorithms(6) 30 } + */ + static final ASN1ObjectIdentifier id_rsassa_pss_shake128 = id_pkix.branch("6.30"); + + /** + * id-RSASSA-PSS-SHAKE256 OBJECT IDENTIFIER ::= { iso(1) + * identified-organization(3) dod(6) internet(1) + * security(5) mechanisms(5) pkix(7) algorithms(6) 31 } + */ + static final ASN1ObjectIdentifier id_rsassa_pss_shake256 = id_pkix.branch("6.31"); + + /** + * id-ecdsa-with-shake128 OBJECT IDENTIFIER ::= { iso(1) + * identified-organization(3) dod(6) internet(1) + * security(5) mechanisms(5) pkix(7) algorithms(6) 32 } + */ + static final ASN1ObjectIdentifier id_ecdsa_with_shake128 = id_pkix.branch("6.32"); + + /** + * id-ecdsa-with-shake256 OBJECT IDENTIFIER ::= { iso(1) + * identified-organization(3) dod(6) internet(1) + * security(5) mechanisms(5) pkix(7) algorithms(6) 33 } + */ + static final ASN1ObjectIdentifier id_ecdsa_with_shake256 = id_pkix.branch("6.33"); + /** * private internet extensions; OID = 1.3.6.1.5.5.7.1 */ diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/package.html deleted file mode 100644 index 728921a1d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding and processing X.509 certificates. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/qualified/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/qualified/package.html deleted file mode 100644 index 28cfef900..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/qualified/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding and processing messages based around RFC3739 - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/sigi/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/sigi/package.html deleted file mode 100644 index 4e073ceff..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x509/sigi/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for the German SigI (Signature Interoperability Specification) standard. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x9/ECNamedCurveTable.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x9/ECNamedCurveTable.java index 09258deb1..d7d45d67a 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x9/ECNamedCurveTable.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x9/ECNamedCurveTable.java @@ -5,13 +5,13 @@ import java.util.Vector; import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; import com.fr.third.org.bouncycastle.asn1.anssi.ANSSINamedCurves; +import com.fr.third.org.bouncycastle.asn1.cryptlib.CryptlibObjectIdentifiers; import com.fr.third.org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves; import com.fr.third.org.bouncycastle.asn1.gm.GMNamedCurves; import com.fr.third.org.bouncycastle.asn1.nist.NISTNamedCurves; import com.fr.third.org.bouncycastle.asn1.sec.SECNamedCurves; import com.fr.third.org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves; import com.fr.third.org.bouncycastle.crypto.ec.CustomNamedCurves; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; /** * A general class that reads all X9.62 style EC curve tables. @@ -52,7 +52,7 @@ public class ECNamedCurveTable if (ecP == null) { - ecP = fromDomainParameters(ECGOST3410NamedCurves.getByName(name)); + ecP = ECGOST3410NamedCurves.getByNameX9(name); } if (ecP == null) @@ -104,6 +104,11 @@ public class ECNamedCurveTable oid = GMNamedCurves.getOID(name); } + if (oid == null && name.equals("curve25519")) + { + oid = CryptlibObjectIdentifiers.curvey25519; + } + return oid; } @@ -188,7 +193,7 @@ public class ECNamedCurveTable if (ecP == null) { - ecP = fromDomainParameters(ECGOST3410NamedCurves.getByOID(oid)); + ecP = ECGOST3410NamedCurves.getByOIDX9(oid); } if (ecP == null) @@ -228,9 +233,4 @@ public class ECNamedCurveTable v.addElement(e.nextElement()); } } - - private static X9ECParameters fromDomainParameters(ECDomainParameters dp) - { - return dp == null ? null : new X9ECParameters(dp.getCurve(), new X9ECPoint(dp.getG(), false), dp.getN(), dp.getH(), dp.getSeed()); - } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x9/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x9/package.html deleted file mode 100644 index 42fc97c79..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/asn1/x9/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes useful for encoding and supporting X9.62 elliptic curve. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/CryptoServicesRegistrar.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/CryptoServicesRegistrar.java index 3df331a33..d7f6eca5a 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/CryptoServicesRegistrar.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/CryptoServicesRegistrar.java @@ -128,6 +128,17 @@ public final class CryptoServicesRegistrar } } + /** + * Return either the passed-in SecureRandom, or if it is null, then the default source of randomness. + * + * @param secureRandom the SecureRandom to use if it is not null. + * @return the SecureRandom parameter if it is not null, or else the default SecureRandom + */ + public static SecureRandom getSecureRandom(SecureRandom secureRandom) + { + return null == secureRandom ? getSecureRandom() : secureRandom; + } + /** * Set a default secure random to be used where none is otherwise provided. * diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/KeyGenerationParameters.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/KeyGenerationParameters.java index 19cb4668e..a06cff30a 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/KeyGenerationParameters.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/KeyGenerationParameters.java @@ -21,7 +21,7 @@ public class KeyGenerationParameters SecureRandom random, int strength) { - this.random = random; + this.random = CryptoServicesRegistrar.getSecureRandom(random); this.strength = strength; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/StagedAgreement.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/StagedAgreement.java new file mode 100644 index 000000000..304a0eaf2 --- /dev/null +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/StagedAgreement.java @@ -0,0 +1,9 @@ +package com.fr.third.org.bouncycastle.crypto; + +import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; + +public interface StagedAgreement + extends BasicAgreement +{ + AsymmetricKeyParameter calculateStage(CipherParameters pubKey); +} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/DHStandardGroups.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/DHStandardGroups.java index da7b048b5..df59d5aae 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/DHStandardGroups.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/DHStandardGroups.java @@ -17,19 +17,19 @@ public class DHStandardGroups return new BigInteger(1, Hex.decodeStrict(hex)); } - private static DHParameters fromPG(String hexP, String hexG) - { - return new DHParameters(fromHex(hexP), fromHex(hexG)); - } +// private static DHParameters fromPG(String hexP, String hexG) +// { +// return new DHParameters(fromHex(hexP), fromHex(hexG)); +// } - private static DHParameters fromPGQ(String hexP, String hexG, String hexQ) + private static DHParameters safePrimeGen2(String hexP) { - return new DHParameters(fromHex(hexP), fromHex(hexG), fromHex(hexQ)); + return safePrimeGen2(hexP, 0); } - private static DHParameters rfc7919Parameters(String hexP, int l) + private static DHParameters safePrimeGen2(String hexP, int l) { - // NOTE: All the groups in RFC 7919 use safe primes, i.e. q = (p-1)/2, and generator g = 2 + // NOTE: A group using a safe prime (i.e. q = (p-1)/2), and generator g = 2 BigInteger p = fromHex(hexP); return new DHParameters(p, TWO, p.shiftRight(1), l); } @@ -40,15 +40,13 @@ public class DHStandardGroups private static final String rfc2409_768_p = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" + "E485B576625E7EC6F44C42E9A63A3620FFFFFFFFFFFFFFFF"; - private static final String rfc2409_768_g = "02"; - public static final DHParameters rfc2409_768 = fromPG(rfc2409_768_p, rfc2409_768_g); + public static final DHParameters rfc2409_768 = safePrimeGen2(rfc2409_768_p); private static final String rfc2409_1024_p = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381" + "FFFFFFFFFFFFFFFF"; - private static final String rfc2409_1024_g = "02"; - public static final DHParameters rfc2409_1024 = fromPG(rfc2409_1024_p, rfc2409_1024_g); + public static final DHParameters rfc2409_1024 = safePrimeGen2(rfc2409_1024_p); /* * RFC 3526 @@ -58,8 +56,8 @@ public class DHStandardGroups + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" + "83655D23DCA3AD961C62F356208552BB9ED529077096966D" + "670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF"; - private static final String rfc3526_1536_g = "02"; - public static final DHParameters rfc3526_1536 = fromPG(rfc3526_1536_p, rfc3526_1536_g); + private static final int rfc3526_1536_l = 200; // RFC3526/RFC7919 + public static final DHParameters rfc3526_1536 = safePrimeGen2(rfc3526_1536_p, rfc3526_1536_l); private static final String rfc3526_2048_p = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" @@ -67,8 +65,8 @@ public class DHStandardGroups + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" + "83655D23DCA3AD961C62F356208552BB9ED529077096966D" + "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" + "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" + "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" + "15728E5A8AACAA68FFFFFFFFFFFFFFFF"; - private static final String rfc3526_2048_g = "02"; - public static final DHParameters rfc3526_2048 = fromPG(rfc3526_2048_p, rfc3526_2048_g); + private static final int rfc3526_2048_l = Math.max(225, 112 * 2); // MAX(RFC3526/RFC7919,FIPS) + public static final DHParameters rfc3526_2048 = safePrimeGen2(rfc3526_2048_p, rfc3526_2048_l); private static final String rfc3526_3072_p = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" @@ -79,8 +77,8 @@ public class DHStandardGroups + "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" + "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" + "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" + "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" + "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF"; - private static final String rfc3526_3072_g = "02"; - public static final DHParameters rfc3526_3072 = fromPG(rfc3526_3072_p, rfc3526_3072_g); + private static final int rfc3526_3072_l = Math.max(275, 128 * 2); // MAX(RFC3526/RFC7919,FIPS) + public static final DHParameters rfc3526_3072 = safePrimeGen2(rfc3526_3072_p, rfc3526_3072_l); private static final String rfc3526_4096_p = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" @@ -94,8 +92,8 @@ public class DHStandardGroups + "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" + "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" + "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" + "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199" + "FFFFFFFFFFFFFFFF"; - private static final String rfc3526_4096_g = "02"; - public static final DHParameters rfc3526_4096 = fromPG(rfc3526_4096_p, rfc3526_4096_g); + private static final int rfc3526_4096_l = Math.max(325, 152 * 2); // MAX(RFC3526/RFC7919,FIPS) + public static final DHParameters rfc3526_4096 = safePrimeGen2(rfc3526_4096_p, rfc3526_4096_l); private static final String rfc3526_6144_p = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E08" + "8A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B" @@ -125,8 +123,8 @@ public class DHStandardGroups + "B7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632" + "387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E" + "6DCC4024FFFFFFFFFFFFFFFF"; - private static final String rfc3526_6144_g = "02"; - public static final DHParameters rfc3526_6144 = fromPG(rfc3526_6144_p, rfc3526_6144_g); + private static final int rfc3526_6144_l = Math.max(375, 176 * 2); // MAX(RFC3526/RFC7919,FIPS) + public static final DHParameters rfc3526_6144 = safePrimeGen2(rfc3526_6144_p, rfc3526_6144_l); private static final String rfc3526_8192_p = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" @@ -150,8 +148,8 @@ public class DHStandardGroups + "062B3CF5B3A278A66D2A13F83F44F82DDF310EE074AB6A36" + "4597E899A0255DC164F31CC50846851DF9AB48195DED7EA1" + "B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F92" + "4009438B481C6CD7889A002ED5EE382BC9190DA6FC026E47" + "9558E4475677E9AA9E3050E2765694DFC81F56E880B96E71" + "60C980DD98EDD3DFFFFFFFFFFFFFFFFF"; - private static final String rfc3526_8192_g = "02"; - public static final DHParameters rfc3526_8192 = fromPG(rfc3526_8192_p, rfc3526_8192_g); + private static final int rfc3526_8192_l = Math.max(400, 200 * 2); // MAX(RFC3526/RFC7919,FIPS) + public static final DHParameters rfc3526_8192 = safePrimeGen2(rfc3526_8192_p, rfc3526_8192_l); /* * RFC 4306 @@ -159,66 +157,6 @@ public class DHStandardGroups public static final DHParameters rfc4306_768 = rfc2409_768; public static final DHParameters rfc4306_1024 = rfc2409_1024; - /* - * RFC 5114 - */ - private static final String rfc5114_1024_160_p = "B10B8F96A080E01DDE92DE5EAE5D54EC52C99FBCFB06A3C6" - + "9A6A9DCA52D23B616073E28675A23D189838EF1E2EE652C0" + "13ECB4AEA906112324975C3CD49B83BFACCBDD7D90C4BD70" - + "98488E9C219A73724EFFD6FAE5644738FAA31A4FF55BCCC0" + "A151AF5F0DC8B4BD45BF37DF365C1A65E68CFDA76D4DA708" - + "DF1FB2BC2E4A4371"; - private static final String rfc5114_1024_160_g = "A4D1CBD5C3FD34126765A442EFB99905F8104DD258AC507F" - + "D6406CFF14266D31266FEA1E5C41564B777E690F5504F213" + "160217B4B01B886A5E91547F9E2749F4D7FBD7D3B9A92EE1" - + "909D0D2263F80A76A6A24C087A091F531DBF0A0169B6A28A" + "D662A4D18E73AFA32D779D5918D08BC8858F4DCEF97C2A24" - + "855E6EEB22B3B2E5"; - private static final String rfc5114_1024_160_q = "F518AA8781A8DF278ABA4E7D64B7CB9D49462353"; - - /** - * @deprecated Existence of a "hidden SNFS" backdoor cannot be ruled out. see https://eprint.iacr.org/2016/961.pdf - */ - public static final DHParameters rfc5114_1024_160 = fromPGQ(rfc5114_1024_160_p, rfc5114_1024_160_g, - rfc5114_1024_160_q); - - private static final String rfc5114_2048_224_p = "AD107E1E9123A9D0D660FAA79559C51FA20D64E5683B9FD1" - + "B54B1597B61D0A75E6FA141DF95A56DBAF9A3C407BA1DF15" + "EB3D688A309C180E1DE6B85A1274A0A66D3F8152AD6AC212" - + "9037C9EDEFDA4DF8D91E8FEF55B7394B7AD5B7D0B6C12207" + "C9F98D11ED34DBF6C6BA0B2C8BBC27BE6A00E0A0B9C49708" - + "B3BF8A317091883681286130BC8985DB1602E714415D9330" + "278273C7DE31EFDC7310F7121FD5A07415987D9ADC0A486D" - + "CDF93ACC44328387315D75E198C641A480CD86A1B9E587E8" + "BE60E69CC928B2B9C52172E413042E9B23F10B0E16E79763" - + "C9B53DCF4BA80A29E3FB73C16B8E75B97EF363E2FFA31F71" + "CF9DE5384E71B81C0AC4DFFE0C10E64F"; - private static final String rfc5114_2048_224_g = "AC4032EF4F2D9AE39DF30B5C8FFDAC506CDEBE7B89998CAF" - + "74866A08CFE4FFE3A6824A4E10B9A6F0DD921F01A70C4AFA" + "AB739D7700C29F52C57DB17C620A8652BE5E9001A8D66AD7" - + "C17669101999024AF4D027275AC1348BB8A762D0521BC98A" + "E247150422EA1ED409939D54DA7460CDB5F6C6B250717CBE" - + "F180EB34118E98D119529A45D6F834566E3025E316A330EF" + "BB77A86F0C1AB15B051AE3D428C8F8ACB70A8137150B8EEB" - + "10E183EDD19963DDD9E263E4770589EF6AA21E7F5F2FF381" + "B539CCE3409D13CD566AFBB48D6C019181E1BCFE94B30269" - + "EDFE72FE9B6AA4BD7B5A0F1C71CFFF4C19C418E1F6EC0179" + "81BC087F2A7065B384B890D3191F2BFA"; - private static final String rfc5114_2048_224_q = "801C0D34C58D93FE997177101F80535A4738CEBCBF389A99B36371EB"; - - /** - * @deprecated Existence of a "hidden SNFS" backdoor cannot be ruled out. see https://eprint.iacr.org/2016/961.pdf - */ - public static final DHParameters rfc5114_2048_224 = fromPGQ(rfc5114_2048_224_p, rfc5114_2048_224_g, - rfc5114_2048_224_q); - - private static final String rfc5114_2048_256_p = "87A8E61DB4B6663CFFBBD19C651959998CEEF608660DD0F2" - + "5D2CEED4435E3B00E00DF8F1D61957D4FAF7DF4561B2AA30" + "16C3D91134096FAA3BF4296D830E9A7C209E0C6497517ABD" - + "5A8A9D306BCF67ED91F9E6725B4758C022E0B1EF4275BF7B" + "6C5BFC11D45F9088B941F54EB1E59BB8BC39A0BF12307F5C" - + "4FDB70C581B23F76B63ACAE1CAA6B7902D52526735488A0E" + "F13C6D9A51BFA4AB3AD8347796524D8EF6A167B5A41825D9" - + "67E144E5140564251CCACB83E6B486F6B3CA3F7971506026" + "C0B857F689962856DED4010ABD0BE621C3A3960A54E710C3" - + "75F26375D7014103A4B54330C198AF126116D2276E11715F" + "693877FAD7EF09CADB094AE91E1A1597"; - private static final String rfc5114_2048_256_g = "3FB32C9B73134D0B2E77506660EDBD484CA7B18F21EF2054" - + "07F4793A1A0BA12510DBC15077BE463FFF4FED4AAC0BB555" + "BE3A6C1B0C6B47B1BC3773BF7E8C6F62901228F8C28CBB18" - + "A55AE31341000A650196F931C77A57F2DDF463E5E9EC144B" + "777DE62AAAB8A8628AC376D282D6ED3864E67982428EBC83" - + "1D14348F6F2F9193B5045AF2767164E1DFC967C1FB3F2E55" + "A4BD1BFFE83B9C80D052B985D182EA0ADB2A3B7313D3FE14" - + "C8484B1E052588B9B7D2BBD2DF016199ECD06E1557CD0915" + "B3353BBB64E0EC377FD028370DF92B52C7891428CDC67EB6" - + "184B523D1DB246C32F63078490F00EF8D647D148D4795451" + "5E2327CFEF98C582664B4C0F6CC41659"; - private static final String rfc5114_2048_256_q = "8CF83642A709A097B447997640129DA299B1A47D1EB3750B" - + "A308B0FE64F5FBD3"; - - /** - * @deprecated Existence of a "hidden SNFS" backdoor cannot be ruled out. see https://eprint.iacr.org/2016/961.pdf - */ - public static final DHParameters rfc5114_2048_256 = fromPGQ(rfc5114_2048_256_p, rfc5114_2048_256_g, - rfc5114_2048_256_q); - /* * RFC 5996 */ @@ -234,7 +172,8 @@ public class DHStandardGroups + "30ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FB" + "B96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB19" + "0B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F61" + "9172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD73" + "3BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA" + "886B423861285C97FFFFFFFFFFFFFFFF"; - public static final DHParameters rfc7919_ffdhe2048 = rfc7919Parameters(rfc7919_ffdhe2048_p, 225); + private static final int rfc7919_ffdhe2048_l = Math.max(225, 112 * 2); // MAX(RFC7919,FIPS) + public static final DHParameters rfc7919_ffdhe2048 = safePrimeGen2(rfc7919_ffdhe2048_p, rfc7919_ffdhe2048_l); private static final String rfc7919_ffdhe3072_p = "FFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1" + "D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF9" + "7D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD6561" @@ -245,7 +184,8 @@ public class DHStandardGroups + "61B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91C" + "AEFE130985139270B4130C93BC437944F4FD4452E2D74DD3" + "64F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0D" + "ABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF" + "3C1B20EE3FD59D7C25E41D2B66C62E37FFFFFFFFFFFFFFFF"; - public static final DHParameters rfc7919_ffdhe3072 = rfc7919Parameters(rfc7919_ffdhe3072_p, 275); + private static final int rfc7919_ffdhe3072_l = Math.max(275, 128 * 2); // MAX(RFC7919,FIPS) + public static final DHParameters rfc7919_ffdhe3072 = safePrimeGen2(rfc7919_ffdhe3072_p, rfc7919_ffdhe3072_l); private static final String rfc7919_ffdhe4096_p = "FFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1" + "D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF9" + "7D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD6561" @@ -259,7 +199,8 @@ public class DHStandardGroups + "87F55BA57E31CC7A7135C886EFB4318AED6A1E012D9E6832" + "A907600A918130C46DC778F971AD0038092999A333CB8B7A" + "1A1DB93D7140003C2A4ECEA9F98D0ACC0A8291CDCEC97DCF" + "8EC9B55A7F88A46B4DB5A851F44182E1C68A007E5E655F6A" + "FFFFFFFFFFFFFFFF"; - public static final DHParameters rfc7919_ffdhe4096 = rfc7919Parameters(rfc7919_ffdhe4096_p, 325); + private static final int rfc7919_ffdhe4096_l = Math.max(325, 152 * 2); // MAX(RFC7919,FIPS) + public static final DHParameters rfc7919_ffdhe4096 = safePrimeGen2(rfc7919_ffdhe4096_p, rfc7919_ffdhe4096_l); private static final String rfc7919_ffdhe6144_p = "FFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1" + "D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF9" + "7D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD6561" @@ -278,7 +219,8 @@ public class DHStandardGroups + "B3A739C1226116820AE8DB5847A67CBEF9C9091B462D538C" + "D72B03746AE77F5E62292C311562A846505DC82DB854338A" + "E49F5235C95B91178CCF2DD5CACEF403EC9D1810C6272B04" + "5B3B71F9DC6B80D63FDD4A8E9ADB1E6962A69526D43161C1" + "A41D570D7938DAD4A40E329CD0E40E65FFFFFFFFFFFFFFFF"; - public static final DHParameters rfc7919_ffdhe6144 = rfc7919Parameters(rfc7919_ffdhe6144_p, 375); + private static final int rfc7919_ffdhe6144_l = Math.max(375, 176 * 2); // MAX(RFC7919,FIPS) + public static final DHParameters rfc7919_ffdhe6144 = safePrimeGen2(rfc7919_ffdhe6144_p, rfc7919_ffdhe6144_l); private static final String rfc7919_ffdhe8192_p = "FFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1" + "D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF9" + "7D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD6561" @@ -302,5 +244,6 @@ public class DHStandardGroups + "51AA691E0E423CFC99E9E31650C1217B624816CDAD9A95F9" + "D5B8019488D9C0A0A1FE3075A577E23183F81D4A3F2FA457" + "1EFC8CE0BA8A4FE8B6855DFE72B0A66EDED2FBABFBE58A30" + "FAFABE1C5D71A87E2F741EF8C1FE86FEA6BBFDE530677F0D" + "97D11D49F7A8443D0822E506A9F4614E011E2A94838FF88C" + "D68C8BB7C5C6424CFFFFFFFFFFFFFFFF"; - public static final DHParameters rfc7919_ffdhe8192 = rfc7919Parameters(rfc7919_ffdhe8192_p, 400); + private static final int rfc7919_ffdhe8192_l = Math.max(400, 200 * 2); // MAX(RFC7919,FIPS) + public static final DHParameters rfc7919_ffdhe8192 = safePrimeGen2(rfc7919_ffdhe8192_p, rfc7919_ffdhe8192_l); } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/DHUnifiedAgreement.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/DHUnifiedAgreement.java index c290e1bd0..3eebf98e3 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/DHUnifiedAgreement.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/DHUnifiedAgreement.java @@ -5,7 +5,6 @@ import java.math.BigInteger; import com.fr.third.org.bouncycastle.crypto.CipherParameters; import com.fr.third.org.bouncycastle.crypto.params.DHUPrivateParameters; import com.fr.third.org.bouncycastle.crypto.params.DHUPublicParameters; -import com.fr.third.org.bouncycastle.util.Arrays; import com.fr.third.org.bouncycastle.util.BigIntegers; /** @@ -41,8 +40,10 @@ public class DHUnifiedAgreement BigInteger eComp = eAgree.calculateAgreement(pubParams.getEphemeralPublicKey()); - return Arrays.concatenate( - BigIntegers.asUnsignedByteArray(this.getFieldSize(), eComp), - BigIntegers.asUnsignedByteArray(this.getFieldSize(), sComp)); + int fieldSize = getFieldSize(); + byte[] result = new byte[fieldSize * 2]; + BigIntegers.asUnsignedByteArray(eComp, result, 0, fieldSize); + BigIntegers.asUnsignedByteArray(sComp, result, fieldSize, fieldSize); + return result; } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/ECDHCStagedAgreement.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/ECDHCStagedAgreement.java new file mode 100644 index 000000000..de3e2ccb4 --- /dev/null +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/ECDHCStagedAgreement.java @@ -0,0 +1,73 @@ +package com.fr.third.org.bouncycastle.crypto.agreement; + +import java.math.BigInteger; + +import com.fr.third.org.bouncycastle.crypto.CipherParameters; +import com.fr.third.org.bouncycastle.crypto.StagedAgreement; +import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; +import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; +import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; +import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; +import com.fr.third.org.bouncycastle.math.ec.ECAlgorithms; +import com.fr.third.org.bouncycastle.math.ec.ECPoint; + +public class ECDHCStagedAgreement + implements StagedAgreement +{ + ECPrivateKeyParameters key; + + public void init( + CipherParameters key) + { + this.key = (ECPrivateKeyParameters)key; + } + + public int getFieldSize() + { + return (key.getParameters().getCurve().getFieldSize() + 7) / 8; + } + + public AsymmetricKeyParameter calculateStage( + CipherParameters pubKey) + { + ECPoint P = calculateNextPoint((ECPublicKeyParameters)pubKey); + + return new ECPublicKeyParameters(P, key.getParameters()); + } + + public BigInteger calculateAgreement( + CipherParameters pubKey) + { + ECPoint P = calculateNextPoint((ECPublicKeyParameters)pubKey); + + return P.getAffineXCoord().toBigInteger(); + } + + private ECPoint calculateNextPoint(ECPublicKeyParameters pubKey) + { + ECPublicKeyParameters pub = pubKey; + ECDomainParameters params = key.getParameters(); + if (!params.equals(pub.getParameters())) + { + throw new IllegalStateException("ECDHC public key has wrong domain parameters"); + } + + BigInteger hd = params.getH().multiply(key.getD()).mod(params.getN()); + + // Always perform calculations on the exact curve specified by our private key's parameters + ECPoint pubPoint = ECAlgorithms.cleanPoint(params.getCurve(), pub.getQ()); + if (pubPoint.isInfinity()) + { + throw new IllegalStateException("Infinity is not a valid public key for ECDHC"); + } + + ECPoint P = pubPoint.multiply(hd).normalize(); + + if (P.isInfinity()) + { + throw new IllegalStateException("Infinity is not a valid agreement value for ECDHC"); + } + + return P; + } +} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/ECDHCUnifiedAgreement.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/ECDHCUnifiedAgreement.java index 78a79b222..36df7c0d6 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/ECDHCUnifiedAgreement.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/ECDHCUnifiedAgreement.java @@ -5,7 +5,6 @@ import java.math.BigInteger; import com.fr.third.org.bouncycastle.crypto.CipherParameters; import com.fr.third.org.bouncycastle.crypto.params.ECDHUPrivateParameters; import com.fr.third.org.bouncycastle.crypto.params.ECDHUPublicParameters; -import com.fr.third.org.bouncycastle.util.Arrays; import com.fr.third.org.bouncycastle.util.BigIntegers; /** @@ -41,8 +40,10 @@ public class ECDHCUnifiedAgreement BigInteger eComp = eAgree.calculateAgreement(pubParams.getEphemeralPublicKey()); - return Arrays.concatenate( - BigIntegers.asUnsignedByteArray(this.getFieldSize(), eComp), - BigIntegers.asUnsignedByteArray(this.getFieldSize(), sComp)); + int fieldSize = getFieldSize(); + byte[] result = new byte[fieldSize * 2]; + BigIntegers.asUnsignedByteArray(eComp, result, 0, fieldSize); + BigIntegers.asUnsignedByteArray(sComp, result, fieldSize, fieldSize); + return result; } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/jpake/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/jpake/package.html deleted file mode 100644 index df16b4fe4..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/jpake/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for Password Authenticated Key Exchange by Juggling (J-PAKE) key exchange. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/kdf/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/kdf/package.html deleted file mode 100644 index a00160f35..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/kdf/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for KDF based key derivation functions. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/package.html deleted file mode 100644 index 4b49331c7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Basic key agreement classes. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/srp/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/srp/package.html deleted file mode 100644 index c125ffe2f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/agreement/srp/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Support classes for Secure Remote Password (SRP) protocol. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/commitments/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/commitments/package.html deleted file mode 100644 index 5bab3fc1e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/commitments/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Classes for supporting commitment calculation. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/Blake2bDigest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/Blake2bDigest.java index d39d5e79d..9c7181149 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/Blake2bDigest.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/Blake2bDigest.java @@ -25,6 +25,7 @@ package com.fr.third.org.bouncycastle.crypto.digests; import com.fr.third.org.bouncycastle.crypto.ExtendedDigest; import com.fr.third.org.bouncycastle.util.Arrays; +import com.fr.third.org.bouncycastle.util.Longs; import com.fr.third.org.bouncycastle.util.Pack; @@ -482,18 +483,13 @@ public class Blake2bDigest { internalState[posA] = internalState[posA] + internalState[posB] + m1; - internalState[posD] = rotr64(internalState[posD] ^ internalState[posA], 32); + internalState[posD] = Longs.rotateRight(internalState[posD] ^ internalState[posA], 32); internalState[posC] = internalState[posC] + internalState[posD]; - internalState[posB] = rotr64(internalState[posB] ^ internalState[posC], 24); // replaces 25 of BLAKE + internalState[posB] = Longs.rotateRight(internalState[posB] ^ internalState[posC], 24); // replaces 25 of BLAKE internalState[posA] = internalState[posA] + internalState[posB] + m2; - internalState[posD] = rotr64(internalState[posD] ^ internalState[posA], 16); + internalState[posD] = Longs.rotateRight(internalState[posD] ^ internalState[posA], 16); internalState[posC] = internalState[posC] + internalState[posD]; - internalState[posB] = rotr64(internalState[posB] ^ internalState[posC], 63); // replaces 11 of BLAKE - } - - private static long rotr64(long x, int rot) - { - return x >>> rot | (x << (64 - rot)); + internalState[posB] = Longs.rotateRight(internalState[posB] ^ internalState[posC], 63); // replaces 11 of BLAKE } /** diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/CSHAKEDigest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/CSHAKEDigest.java index 03858dc71..82d4c9ca0 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/CSHAKEDigest.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/CSHAKEDigest.java @@ -15,8 +15,8 @@ public class CSHAKEDigest * Base constructor. * * @param bitLength bit length of the underlying SHAKE function, 128 or 256. - * @param N the function name string, note this is reserved for use by NIST. Avoid using it if not required. - * @param S the customization string - available for local use. + * @param N the function name string, note this is reserved for use by NIST. Avoid using it if not required. + * @param S the customization string - available for local use. */ public CSHAKEDigest(int bitLength, byte[] N, byte[] S) { @@ -28,59 +28,49 @@ public class CSHAKEDigest } else { - diff = Arrays.concatenate(leftEncode(rate / 8), encodeString(N), encodeString(S)); + diff = Arrays.concatenate(XofUtils.leftEncode(rate / 8), encodeString(N), encodeString(S)); diffPadAndAbsorb(); } } + // bytepad in SP 800-185 private void diffPadAndAbsorb() { int blockSize = rate / 8; absorb(diff, 0, diff.length); - int required = blockSize - (diff.length % blockSize); + int delta = diff.length % blockSize; - while (required > padding.length) + // only add padding if needed + if (delta != 0) { - absorb(padding, 0, padding.length); - required -= padding.length; + int required = blockSize - delta; + + while (required > padding.length) + { + absorb(padding, 0, padding.length); + required -= padding.length; + } + + absorb(padding, 0, required); } - - absorb(padding, 0, required); } private byte[] encodeString(byte[] str) { if (str == null || str.length == 0) { - return leftEncode(0); + return XofUtils.leftEncode(0); } - return Arrays.concatenate(leftEncode(str.length * 8L), str); + return Arrays.concatenate(XofUtils.leftEncode(str.length * 8L), str); } - - private static byte[] leftEncode(long strLen) - { - byte n = 1; - long v = strLen; - while ((v >>= 8) != 0) - { - n++; - } - - byte[] b = new byte[n + 1]; - - b[0] = n; - - for (int i = 1; i <= n; i++) - { - b[i] = (byte)(strLen >> (8 * (n - i))); - } - - return b; + public String getAlgorithmName() + { + return "CSHAKE" + fixedOutputLength; } - + public int doOutput(byte[] out, int outOff, int outLen) { if (diff != null) @@ -103,7 +93,7 @@ public class CSHAKEDigest public void reset() { super.reset(); - + if (diff != null) { diffPadAndAbsorb(); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/KeccakDigest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/KeccakDigest.java index 7f2f7db45..ac8ce10f9 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/KeccakDigest.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/KeccakDigest.java @@ -3,6 +3,7 @@ package com.fr.third.org.bouncycastle.crypto.digests; import com.fr.third.org.bouncycastle.crypto.ExtendedDigest; import com.fr.third.org.bouncycastle.util.Arrays; import com.fr.third.org.bouncycastle.util.Pack; +import com.fr.third.org.bouncycastle.util.encoders.Hex; /** * implementation of Keccak based on following KeccakNISTInterface.c from http://keccak.noekeon.org/ @@ -12,12 +13,12 @@ import com.fr.third.org.bouncycastle.util.Pack; public class KeccakDigest implements ExtendedDigest { - private static long[] KeccakRoundConstants = new long[]{ 0x0000000000000001L, 0x0000000000008082L, + private static long[] KeccakRoundConstants = new long[]{0x0000000000000001L, 0x0000000000008082L, 0x800000000000808aL, 0x8000000080008000L, 0x000000000000808bL, 0x0000000080000001L, 0x8000000080008081L, 0x8000000000008009L, 0x000000000000008aL, 0x0000000000000088L, 0x0000000080008009L, 0x000000008000000aL, 0x000000008000808bL, 0x800000000000008bL, 0x8000000000008089L, 0x8000000000008003L, 0x8000000000008002L, 0x8000000000000080L, 0x000000000000800aL, 0x800000008000000aL, 0x8000000080008081L, 0x8000000000008080L, - 0x0000000080000001L, 0x8000000080008008L }; + 0x0000000080000001L, 0x8000000080008008L}; protected long[] state = new long[25]; protected byte[] dataQueue = new byte[192]; @@ -36,6 +37,7 @@ public class KeccakDigest init(bitLength); } + public KeccakDigest(KeccakDigest source) { System.arraycopy(source.state, 0, this.state, 0, source.state.length); @@ -58,7 +60,7 @@ public class KeccakDigest public void update(byte in) { - absorb(new byte[]{ in }, 0, 1); + absorb(in); } public void update(byte[] in, int inOff, int len) @@ -142,6 +144,25 @@ public class KeccakDigest this.fixedOutputLength = (1600 - rate) / 2; } + protected void absorb(byte data) + { + if ((bitsInQueue % 8) != 0) + { + throw new IllegalStateException("attempt to absorb with odd length queue"); + } + if (squeezing) + { + throw new IllegalStateException("attempt to absorb while squeezing"); + } + + dataQueue[bitsInQueue >>> 3] = data; + if ((bitsInQueue += 8) == rate) + { + KeccakAbsorb(dataQueue, 0); + bitsInQueue = 0; + } + } + protected void absorb(byte[] data, int off, int len) { if ((bitsInQueue % 8) != 0) @@ -153,38 +174,34 @@ public class KeccakDigest throw new IllegalStateException("attempt to absorb while squeezing"); } - int bytesInQueue = bitsInQueue >> 3; - int rateBytes = rate >> 3; + int bytesInQueue = bitsInQueue >>> 3; + int rateBytes = rate >>> 3; - int count = 0; - while (count < len) + int available = rateBytes - bytesInQueue; + if (len < available) { - if (bytesInQueue == 0 && count <= (len - rateBytes)) - { - do - { - KeccakAbsorb(data, off + count); - count += rateBytes; - } - while (count <= (len - rateBytes)); - } - else - { - int partialBlock = Math.min(rateBytes - bytesInQueue, len - count); - System.arraycopy(data, off + count, dataQueue, bytesInQueue, partialBlock); + System.arraycopy(data, off, dataQueue, bytesInQueue, len); + this.bitsInQueue += len << 3; + return; + } - bytesInQueue += partialBlock; - count += partialBlock; + int count = 0; + if (bytesInQueue > 0) + { + System.arraycopy(data, off, dataQueue, bytesInQueue, available); + count += available; + KeccakAbsorb(dataQueue, 0); + } - if (bytesInQueue == rateBytes) - { - KeccakAbsorb(dataQueue, 0); - bytesInQueue = 0; - } - } + int remaining; + while ((remaining = (len - count)) >= rateBytes) + { + KeccakAbsorb(data, off + count); + count += rateBytes; } - bitsInQueue = bytesInQueue << 3; + System.arraycopy(data, off + count, dataQueue, 0, remaining); + this.bitsInQueue = remaining << 3; } protected void absorbBits(int data, int bits) @@ -203,43 +220,57 @@ public class KeccakDigest } int mask = (1 << bits) - 1; - dataQueue[bitsInQueue >> 3] = (byte)(data & mask); + dataQueue[bitsInQueue >>> 3] = (byte)(data & mask); // NOTE: After this, bitsInQueue is no longer a multiple of 8, so no more absorbs will work bitsInQueue += bits; } + + protected byte[] dumpState() + { + byte[] out = new byte[state.length * 8]; + int p = 0; + for (int i = 0; i != state.length; i++) + { + Pack.longToLittleEndian(state[i], out, p); + p += 8; + } + + return out; + } + + private void padAndSwitchToSqueezingPhase() { - dataQueue[bitsInQueue >> 3] |= (byte)(1L << (bitsInQueue & 7)); + dataQueue[bitsInQueue >>> 3] |= (byte)(1 << (bitsInQueue & 7)); if (++bitsInQueue == rate) { KeccakAbsorb(dataQueue, 0); - bitsInQueue = 0; } - + else { - int full = bitsInQueue >> 6, partial = bitsInQueue & 63; + int full = bitsInQueue >>> 6, partial = bitsInQueue & 63; int off = 0; for (int i = 0; i < full; ++i) { state[i] ^= Pack.littleEndianToLong(dataQueue, off); off += 8; } + + byte[] z = dumpState(); + if (partial > 0) { long mask = (1L << partial) - 1L; state[full] ^= Pack.littleEndianToLong(dataQueue, off) & mask; } - state[(rate - 1) >> 6] ^= (1L << 63); } - KeccakPermutation(); - - KeccakExtract(); - bitsInQueue = rate; + state[(rate - 1) >>> 6] ^= (1L << 63); + bitsInQueue = 0; squeezing = true; } @@ -249,6 +280,9 @@ public class KeccakDigest { padAndSwitchToSqueezingPhase(); } + + byte[] z = dumpState(); + if ((outputLength % 8) != 0) { throw new IllegalStateException("outputLength not a multiple of 8"); @@ -259,40 +293,51 @@ public class KeccakDigest { if (bitsInQueue == 0) { - KeccakPermutation(); KeccakExtract(); - bitsInQueue = rate; } int partialBlock = (int)Math.min((long)bitsInQueue, outputLength - i); System.arraycopy(dataQueue, (rate - bitsInQueue) / 8, output, offset + (int)(i / 8), partialBlock / 8); bitsInQueue -= partialBlock; i += partialBlock; } + + z = dumpState(); + } private void KeccakAbsorb(byte[] data, int off) { - int count = rate >> 6; +// assert 0 == bitsInQueue || (dataQueue == data && 0 == off); + + int count = rate >>> 6; for (int i = 0; i < count; ++i) { state[i] ^= Pack.littleEndianToLong(data, off); off += 8; } - + String z = Hex.toHexString(dumpState()).toLowerCase(); KeccakPermutation(); } private void KeccakExtract() { - Pack.longToLittleEndian(state, 0, rate >> 6, dataQueue, 0); +// assert 0 == bitsInQueue; + + KeccakPermutation(); + + byte[] z = dumpState(); + + Pack.longToLittleEndian(state, 0, rate >>> 6, dataQueue, 0); + + this.bitsInQueue = rate; } private void KeccakPermutation() { long[] A = state; - long a00 = A[ 0], a01 = A[ 1], a02 = A[ 2], a03 = A[ 3], a04 = A[ 4]; - long a05 = A[ 5], a06 = A[ 6], a07 = A[ 7], a08 = A[ 8], a09 = A[ 9]; + long a00 = A[0], a01 = A[1], a02 = A[2], a03 = A[3], a04 = A[4]; + long a05 = A[5], a06 = A[6], a07 = A[7], a08 = A[8], a09 = A[9]; long a10 = A[10], a11 = A[11], a12 = A[12], a13 = A[13], a14 = A[14]; long a15 = A[15], a16 = A[16], a17 = A[17], a18 = A[18], a19 = A[19]; long a20 = A[20], a21 = A[21], a22 = A[22], a23 = A[23], a24 = A[24]; @@ -312,37 +357,57 @@ public class KeccakDigest long d4 = (c4 << 1 | c4 >>> -1) ^ c2; long d0 = (c0 << 1 | c0 >>> -1) ^ c3; - a00 ^= d1; a05 ^= d1; a10 ^= d1; a15 ^= d1; a20 ^= d1; - a01 ^= d2; a06 ^= d2; a11 ^= d2; a16 ^= d2; a21 ^= d2; - a02 ^= d3; a07 ^= d3; a12 ^= d3; a17 ^= d3; a22 ^= d3; - a03 ^= d4; a08 ^= d4; a13 ^= d4; a18 ^= d4; a23 ^= d4; - a04 ^= d0; a09 ^= d0; a14 ^= d0; a19 ^= d0; a24 ^= d0; + a00 ^= d1; + a05 ^= d1; + a10 ^= d1; + a15 ^= d1; + a20 ^= d1; + a01 ^= d2; + a06 ^= d2; + a11 ^= d2; + a16 ^= d2; + a21 ^= d2; + a02 ^= d3; + a07 ^= d3; + a12 ^= d3; + a17 ^= d3; + a22 ^= d3; + a03 ^= d4; + a08 ^= d4; + a13 ^= d4; + a18 ^= d4; + a23 ^= d4; + a04 ^= d0; + a09 ^= d0; + a14 ^= d0; + a19 ^= d0; + a24 ^= d0; // rho/pi - c1 = a01 << 1 | a01 >>> 63; + c1 = a01 << 1 | a01 >>> 63; a01 = a06 << 44 | a06 >>> 20; a06 = a09 << 20 | a09 >>> 44; - a09 = a22 << 61 | a22 >>> 3; + a09 = a22 << 61 | a22 >>> 3; a22 = a14 << 39 | a14 >>> 25; a14 = a20 << 18 | a20 >>> 46; - a20 = a02 << 62 | a02 >>> 2; + a20 = a02 << 62 | a02 >>> 2; a02 = a12 << 43 | a12 >>> 21; a12 = a13 << 25 | a13 >>> 39; - a13 = a19 << 8 | a19 >>> 56; - a19 = a23 << 56 | a23 >>> 8; + a13 = a19 << 8 | a19 >>> 56; + a19 = a23 << 56 | a23 >>> 8; a23 = a15 << 41 | a15 >>> 23; a15 = a04 << 27 | a04 >>> 37; a04 = a24 << 14 | a24 >>> 50; - a24 = a21 << 2 | a21 >>> 62; - a21 = a08 << 55 | a08 >>> 9; + a24 = a21 << 2 | a21 >>> 62; + a21 = a08 << 55 | a08 >>> 9; a08 = a16 << 45 | a16 >>> 19; a16 = a05 << 36 | a05 >>> 28; a05 = a03 << 28 | a03 >>> 36; a03 = a18 << 21 | a18 >>> 43; a18 = a17 << 15 | a17 >>> 49; a17 = a11 << 10 | a11 >>> 54; - a11 = a07 << 6 | a07 >>> 58; - a07 = a10 << 3 | a10 >>> 61; + a11 = a07 << 6 | a07 >>> 58; + a07 = a10 << 3 | a10 >>> 61; a10 = c1; // chi @@ -389,11 +454,31 @@ public class KeccakDigest // iota a00 ^= KeccakRoundConstants[i]; } - - A[ 0] = a00; A[ 1] = a01; A[ 2] = a02; A[ 3] = a03; A[ 4] = a04; - A[ 5] = a05; A[ 6] = a06; A[ 7] = a07; A[ 8] = a08; A[ 9] = a09; - A[10] = a10; A[11] = a11; A[12] = a12; A[13] = a13; A[14] = a14; - A[15] = a15; A[16] = a16; A[17] = a17; A[18] = a18; A[19] = a19; - A[20] = a20; A[21] = a21; A[22] = a22; A[23] = a23; A[24] = a24; + + A[0] = a00; + A[1] = a01; + A[2] = a02; + A[3] = a03; + A[4] = a04; + A[5] = a05; + A[6] = a06; + A[7] = a07; + A[8] = a08; + A[9] = a09; + A[10] = a10; + A[11] = a11; + A[12] = a12; + A[13] = a13; + A[14] = a14; + A[15] = a15; + A[16] = a16; + A[17] = a17; + A[18] = a18; + A[19] = a19; + A[20] = a20; + A[21] = a21; + A[22] = a22; + A[23] = a23; + A[24] = a24; } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/SHA3Digest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/SHA3Digest.java index b7fd66e2d..fd6647c58 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/SHA3Digest.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/SHA3Digest.java @@ -64,7 +64,7 @@ public class SHA3Digest if (finalBits >= 8) { - absorb(new byte[]{ (byte)finalInput }, 0, 1); + absorb((byte)finalInput); finalBits -= 8; finalInput >>>= 8; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/SHAKEDigest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/SHAKEDigest.java index bdc1b8df0..983744d00 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/SHAKEDigest.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/SHAKEDigest.java @@ -92,7 +92,7 @@ public class SHAKEDigest if (finalBits >= 8) { - absorb(new byte[]{ (byte)finalInput }, 0, 1); + absorb((byte)finalInput); finalBits -= 8; finalInput >>>= 8; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/XofUtils.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/XofUtils.java new file mode 100644 index 000000000..04e767001 --- /dev/null +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/XofUtils.java @@ -0,0 +1,48 @@ +package com.fr.third.org.bouncycastle.crypto.digests; + +public class XofUtils +{ + public static byte[] leftEncode(long strLen) + { + byte n = 1; + + long v = strLen; + while ((v >>= 8) != 0) + { + n++; + } + + byte[] b = new byte[n + 1]; + + b[0] = n; + + for (int i = 1; i <= n; i++) + { + b[i] = (byte)(strLen >> (8 * (n - i))); + } + + return b; + } + + public static byte[] rightEncode(long strLen) + { + byte n = 1; + + long v = strLen; + while ((v >>= 8) != 0) + { + n++; + } + + byte[] b = new byte[n + 1]; + + b[n] = n; + + for (int i = 0; i < n; i++) + { + b[i] = (byte)(strLen >> (8 * (n - i - 1))); + } + + return b; + } +} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/package.html deleted file mode 100644 index 0a0d95cea..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/digests/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Message digest classes. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/ec/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/ec/package.html deleted file mode 100644 index 223823e77..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/ec/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Utility classes for support Elliptic Curve cryptographic transforms. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/ec/test/ECElGamalTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/ec/test/ECElGamalTest.java deleted file mode 100644 index 04d7e3a7a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/ec/test/ECElGamalTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.ec.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.ec.ECDecryptor; -import com.fr.third.org.bouncycastle.crypto.ec.ECElGamalDecryptor; -import com.fr.third.org.bouncycastle.crypto.ec.ECElGamalEncryptor; -import com.fr.third.org.bouncycastle.crypto.ec.ECEncryptor; -import com.fr.third.org.bouncycastle.crypto.ec.ECPair; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.math.ec.ECConstants; -import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.math.ec.ECPoint; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class ECElGamalTest - extends SimpleTest -{ - public String getName() - { - return "ECElGamal"; - } - - public void performTest() - throws Exception - { - BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q - new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a - new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); - - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("0262b12d60690cdcf330babab6e69763b471f994dd702d16a5")), // Q - params); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("651056770906015076056810763456358567190100156695615665659"), // d - params); - - ParametersWithRandom pRandom = new ParametersWithRandom(pubKey, new SecureRandom()); - - doTest(priKey, pRandom, BigInteger.valueOf(20)); - - BigInteger rand = new BigInteger(pubKey.getParameters().getN().bitLength() - 1, new SecureRandom()); - - doTest(priKey, pRandom, rand); - } - - private void doTest(ECPrivateKeyParameters priKey, ParametersWithRandom pRandom, BigInteger value) - { - ECPoint data = priKey.getParameters().getG().multiply(value); - - ECEncryptor encryptor = new ECElGamalEncryptor(); - - encryptor.init(pRandom); - - ECPair pair = encryptor.encrypt(data); - - ECDecryptor decryptor = new ECElGamalDecryptor(); - - decryptor.init(priKey); - - ECPoint result = decryptor.decrypt(pair); - - if (!data.equals(result)) - { - fail("point pair failed to decrypt back to original"); - } - } - - public static void main(String[] args) - { - runTest(new ECElGamalTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/ec/test/ECTransformationTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/ec/test/ECTransformationTest.java deleted file mode 100644 index 41d5ca573..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/ec/test/ECTransformationTest.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.ec.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.ec.ECDecryptor; -import com.fr.third.org.bouncycastle.crypto.ec.ECElGamalDecryptor; -import com.fr.third.org.bouncycastle.crypto.ec.ECElGamalEncryptor; -import com.fr.third.org.bouncycastle.crypto.ec.ECEncryptor; -import com.fr.third.org.bouncycastle.crypto.ec.ECNewPublicKeyTransform; -import com.fr.third.org.bouncycastle.crypto.ec.ECNewRandomnessTransform; -import com.fr.third.org.bouncycastle.crypto.ec.ECPair; -import com.fr.third.org.bouncycastle.crypto.ec.ECPairTransform; -import com.fr.third.org.bouncycastle.crypto.generators.ECKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.math.ec.ECConstants; -import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.math.ec.ECPoint; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class ECTransformationTest - extends SimpleTest -{ - public String getName() - { - return "ECTransformationTest"; - } - - public void performTest() - throws Exception - { - BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q - new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a - new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); - - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("0262b12d60690cdcf330babab6e69763b471f994dd702d16a5")), // Q - params); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("651056770906015076056810763456358567190100156695615665659"), // d - params); - - - ParametersWithRandom pRandom = new ParametersWithRandom(pubKey, new SecureRandom()); - - doTest(priKey, pRandom, BigInteger.valueOf(20)); - - BigInteger rand = new BigInteger(pubKey.getParameters().getN().bitLength() - 1, new SecureRandom()); - - doTest(priKey, pRandom, rand); - doSameKeyTest(priKey, pRandom, rand); - } - - private void doTest(ECPrivateKeyParameters priKey, ParametersWithRandom pRandom, BigInteger value) - { - ECPoint data = priKey.getParameters().getG().multiply(value); - - ECEncryptor encryptor = new ECElGamalEncryptor(); - - encryptor.init(pRandom); - - ECPair pair = encryptor.encrypt(data); - - ECKeyPairGenerator ecGen = new ECKeyPairGenerator(); - - ecGen.init(new ECKeyGenerationParameters(priKey.getParameters(), new SecureRandom())); - - AsymmetricCipherKeyPair reEncKP = ecGen.generateKeyPair(); - - ECPairTransform ecr = new ECNewPublicKeyTransform(); - - ecr.init(reEncKP.getPublic()); - - ECPair srcPair = pair; - - // re-encrypt the message portion - pair = ecr.transform(srcPair); - - ECDecryptor decryptor = new ECElGamalDecryptor(); - - decryptor.init(priKey); - - // decrypt out the original private key - ECPoint p = decryptor.decrypt(new ECPair(srcPair.getX(), pair.getY())); - - decryptor.init(reEncKP.getPrivate()); - - // decrypt the fully transformed point. - ECPoint result = decryptor.decrypt(new ECPair(pair.getX(), p)); - - if (!data.equals(result)) - { - fail("point pair failed to decrypt back to original"); - } - } - - private void doSameKeyTest(ECPrivateKeyParameters priKey, ParametersWithRandom pRandom, BigInteger value) - { - ECPoint data = priKey.getParameters().getG().multiply(value); - - ECEncryptor encryptor = new ECElGamalEncryptor(); - - encryptor.init(pRandom); - - ECPair pair = encryptor.encrypt(data); - - ECPairTransform ecr = new ECNewRandomnessTransform(); - - ecr.init(pRandom); - - ECPair srcPair = pair; - - // re-encrypt the message portion - pair = ecr.transform(srcPair); - - ECDecryptor decryptor = new ECElGamalDecryptor(); - - decryptor.init(priKey); - - // decrypt the fully transformed point. - ECPoint result = decryptor.decrypt(pair); - - if (!data.equals(result)) - { - fail("point pair failed to decrypt back to original"); - } - } - - public static void main(String[] args) - { - runTest(new ECTransformationTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/encodings/PKCS1Encoding.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/encodings/PKCS1Encoding.java index 252ebe6f0..96ef01a86 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/encodings/PKCS1Encoding.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/encodings/PKCS1Encoding.java @@ -1,7 +1,5 @@ package com.fr.third.org.bouncycastle.crypto.encodings; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.security.SecureRandom; import com.fr.third.org.bouncycastle.crypto.AsymmetricBlockCipher; @@ -11,6 +9,7 @@ import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; import com.fr.third.org.bouncycastle.util.Arrays; +import com.fr.third.org.bouncycastle.util.Properties; /** * this does your basic PKCS 1 v1.5 padding - whether or not you should be using this @@ -95,28 +94,12 @@ public class PKCS1Encoding // private boolean useStrict() { - // required if security manager has been installed. - String strict = (String)AccessController.doPrivileged(new PrivilegedAction() + if (Properties.isOverrideSetTo(NOT_STRICT_LENGTH_ENABLED_PROPERTY, true)) { - public Object run() - { - return System.getProperty(STRICT_LENGTH_ENABLED_PROPERTY); - } - }); - String notStrict = (String)AccessController.doPrivileged(new PrivilegedAction() - { - public Object run() - { - return System.getProperty(NOT_STRICT_LENGTH_ENABLED_PROPERTY); - } - }); - - if (notStrict != null) - { - return !notStrict.equals("true"); + return false; } - return strict == null || strict.equals("true"); + return !Properties.isOverrideSetTo(STRICT_LENGTH_ENABLED_PROPERTY, false); } public AsymmetricBlockCipher getUnderlyingCipher() @@ -269,7 +252,7 @@ public class PKCS1Encoding * Now the padding check, check for no 0 byte in the padding */ int plen = encoded.length - ( - pLen /* Lenght of the PMS */ + pLen /* Length of the PMS */ + 1 /* Final 0-byte before PMS */ ); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/encodings/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/encodings/package.html deleted file mode 100644 index fc56f634c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/encodings/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Block encodings for asymmetric ciphers. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/AESEngine.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/AESEngine.java index 0ae176ce6..40ca573a6 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/AESEngine.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/AESEngine.java @@ -296,98 +296,97 @@ private static final int[] Tinv0 = { case 4: { - int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; - int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; - int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; - int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; + int col0 = Pack.littleEndianToInt(key, 0); W[0][0] = col0; + int col1 = Pack.littleEndianToInt(key, 4); W[0][1] = col1; + int col2 = Pack.littleEndianToInt(key, 8); W[0][2] = col2; + int col3 = Pack.littleEndianToInt(key, 12); W[0][3] = col3; for (int i = 1; i <= 10; ++i) { - int u = subWord(shift(t3, 8)) ^ rcon[i - 1]; - t0 ^= u; W[i][0] = t0; - t1 ^= t0; W[i][1] = t1; - t2 ^= t1; W[i][2] = t2; - t3 ^= t2; W[i][3] = t3; + int colx = subWord(shift(col3, 8)) ^ rcon[i - 1]; + col0 ^= colx; W[i][0] = col0; + col1 ^= col0; W[i][1] = col1; + col2 ^= col1; W[i][2] = col2; + col3 ^= col2; W[i][3] = col3; } break; } case 6: { - int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; - int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; - int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; - int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; - int t4 = Pack.littleEndianToInt(key, 16); W[1][0] = t4; - int t5 = Pack.littleEndianToInt(key, 20); W[1][1] = t5; - - int rcon = 1; - int u = subWord(shift(t5, 8)) ^ rcon; rcon <<= 1; - t0 ^= u; W[1][2] = t0; - t1 ^= t0; W[1][3] = t1; - t2 ^= t1; W[2][0] = t2; - t3 ^= t2; W[2][1] = t3; - t4 ^= t3; W[2][2] = t4; - t5 ^= t4; W[2][3] = t5; - - for (int i = 3; i < 12; i += 3) + int col0 = Pack.littleEndianToInt(key, 0); W[0][0] = col0; + int col1 = Pack.littleEndianToInt(key, 4); W[0][1] = col1; + int col2 = Pack.littleEndianToInt(key, 8); W[0][2] = col2; + int col3 = Pack.littleEndianToInt(key, 12); W[0][3] = col3; + + int col4 = Pack.littleEndianToInt(key, 16); + int col5 = Pack.littleEndianToInt(key, 20); + + int i = 1, rcon = 1, colx; + for (;;) { - u = subWord(shift(t5, 8)) ^ rcon; rcon <<= 1; - t0 ^= u; W[i ][0] = t0; - t1 ^= t0; W[i ][1] = t1; - t2 ^= t1; W[i ][2] = t2; - t3 ^= t2; W[i ][3] = t3; - t4 ^= t3; W[i + 1][0] = t4; - t5 ^= t4; W[i + 1][1] = t5; - u = subWord(shift(t5, 8)) ^ rcon; rcon <<= 1; - t0 ^= u; W[i + 1][2] = t0; - t1 ^= t0; W[i + 1][3] = t1; - t2 ^= t1; W[i + 2][0] = t2; - t3 ^= t2; W[i + 2][1] = t3; - t4 ^= t3; W[i + 2][2] = t4; - t5 ^= t4; W[i + 2][3] = t5; - } + W[i ][0] = col4; + W[i ][1] = col5; + colx = subWord(shift(col5, 8)) ^ rcon; rcon <<= 1; + col0 ^= colx; W[i ][2] = col0; + col1 ^= col0; W[i ][3] = col1; + + col2 ^= col1; W[i + 1][0] = col2; + col3 ^= col2; W[i + 1][1] = col3; + col4 ^= col3; W[i + 1][2] = col4; + col5 ^= col4; W[i + 1][3] = col5; + + colx = subWord(shift(col5, 8)) ^ rcon; rcon <<= 1; + col0 ^= colx; W[i + 2][0] = col0; + col1 ^= col0; W[i + 2][1] = col1; + col2 ^= col1; W[i + 2][2] = col2; + col3 ^= col2; W[i + 2][3] = col3; + + if ((i += 3) >= 13) + { + break; + } - u = subWord(shift(t5, 8)) ^ rcon; - t0 ^= u; W[12][0] = t0; - t1 ^= t0; W[12][1] = t1; - t2 ^= t1; W[12][2] = t2; - t3 ^= t2; W[12][3] = t3; + col4 ^= col3; + col5 ^= col4; + } break; } case 8: { - int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; - int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; - int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; - int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; - int t4 = Pack.littleEndianToInt(key, 16); W[1][0] = t4; - int t5 = Pack.littleEndianToInt(key, 20); W[1][1] = t5; - int t6 = Pack.littleEndianToInt(key, 24); W[1][2] = t6; - int t7 = Pack.littleEndianToInt(key, 28); W[1][3] = t7; - - int u, rcon = 1; - - for (int i = 2; i < 14; i += 2) + int col0 = Pack.littleEndianToInt(key, 0); W[0][0] = col0; + int col1 = Pack.littleEndianToInt(key, 4); W[0][1] = col1; + int col2 = Pack.littleEndianToInt(key, 8); W[0][2] = col2; + int col3 = Pack.littleEndianToInt(key, 12); W[0][3] = col3; + + int col4 = Pack.littleEndianToInt(key, 16); W[1][0] = col4; + int col5 = Pack.littleEndianToInt(key, 20); W[1][1] = col5; + int col6 = Pack.littleEndianToInt(key, 24); W[1][2] = col6; + int col7 = Pack.littleEndianToInt(key, 28); W[1][3] = col7; + + int i = 2, rcon = 1, colx; + for (;;) { - u = subWord(shift(t7, 8)) ^ rcon; rcon <<= 1; - t0 ^= u; W[i ][0] = t0; - t1 ^= t0; W[i ][1] = t1; - t2 ^= t1; W[i ][2] = t2; - t3 ^= t2; W[i ][3] = t3; - u = subWord(t3); - t4 ^= u; W[i + 1][0] = t4; - t5 ^= t4; W[i + 1][1] = t5; - t6 ^= t5; W[i + 1][2] = t6; - t7 ^= t6; W[i + 1][3] = t7; - } + colx = subWord(shift(col7, 8)) ^ rcon; rcon <<= 1; + col0 ^= colx; W[i][0] = col0; + col1 ^= col0; W[i][1] = col1; + col2 ^= col1; W[i][2] = col2; + col3 ^= col2; W[i][3] = col3; + ++i; + + if (i >= 15) + { + break; + } - u = subWord(shift(t7, 8)) ^ rcon; - t0 ^= u; W[14][0] = t0; - t1 ^= t0; W[14][1] = t1; - t2 ^= t1; W[14][2] = t2; - t3 ^= t2; W[14][3] = t3; + colx = subWord(col3); + col4 ^= colx; W[i][0] = col4; + col5 ^= col4; W[i][1] = col5; + col6 ^= col5; W[i][2] = col6; + col7 ^= col6; W[i][3] = col7; + ++i; + } break; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/AESFastEngine.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/AESFastEngine.java index 9b5d78d38..b6508626b 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/AESFastEngine.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/AESFastEngine.java @@ -625,98 +625,97 @@ public class AESFastEngine { case 4: { - int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; - int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; - int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; - int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; + int col0 = Pack.littleEndianToInt(key, 0); W[0][0] = col0; + int col1 = Pack.littleEndianToInt(key, 4); W[0][1] = col1; + int col2 = Pack.littleEndianToInt(key, 8); W[0][2] = col2; + int col3 = Pack.littleEndianToInt(key, 12); W[0][3] = col3; for (int i = 1; i <= 10; ++i) { - int u = subWord(shift(t3, 8)) ^ rcon[i - 1]; - t0 ^= u; W[i][0] = t0; - t1 ^= t0; W[i][1] = t1; - t2 ^= t1; W[i][2] = t2; - t3 ^= t2; W[i][3] = t3; + int colx = subWord(shift(col3, 8)) ^ rcon[i - 1]; + col0 ^= colx; W[i][0] = col0; + col1 ^= col0; W[i][1] = col1; + col2 ^= col1; W[i][2] = col2; + col3 ^= col2; W[i][3] = col3; } break; } case 6: { - int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; - int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; - int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; - int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; - int t4 = Pack.littleEndianToInt(key, 16); W[1][0] = t4; - int t5 = Pack.littleEndianToInt(key, 20); W[1][1] = t5; - - int rcon = 1; - int u = subWord(shift(t5, 8)) ^ rcon; rcon <<= 1; - t0 ^= u; W[1][2] = t0; - t1 ^= t0; W[1][3] = t1; - t2 ^= t1; W[2][0] = t2; - t3 ^= t2; W[2][1] = t3; - t4 ^= t3; W[2][2] = t4; - t5 ^= t4; W[2][3] = t5; - - for (int i = 3; i < 12; i += 3) + int col0 = Pack.littleEndianToInt(key, 0); W[0][0] = col0; + int col1 = Pack.littleEndianToInt(key, 4); W[0][1] = col1; + int col2 = Pack.littleEndianToInt(key, 8); W[0][2] = col2; + int col3 = Pack.littleEndianToInt(key, 12); W[0][3] = col3; + + int col4 = Pack.littleEndianToInt(key, 16); + int col5 = Pack.littleEndianToInt(key, 20); + + int i = 1, rcon = 1, colx; + for (;;) { - u = subWord(shift(t5, 8)) ^ rcon; rcon <<= 1; - t0 ^= u; W[i ][0] = t0; - t1 ^= t0; W[i ][1] = t1; - t2 ^= t1; W[i ][2] = t2; - t3 ^= t2; W[i ][3] = t3; - t4 ^= t3; W[i + 1][0] = t4; - t5 ^= t4; W[i + 1][1] = t5; - u = subWord(shift(t5, 8)) ^ rcon; rcon <<= 1; - t0 ^= u; W[i + 1][2] = t0; - t1 ^= t0; W[i + 1][3] = t1; - t2 ^= t1; W[i + 2][0] = t2; - t3 ^= t2; W[i + 2][1] = t3; - t4 ^= t3; W[i + 2][2] = t4; - t5 ^= t4; W[i + 2][3] = t5; - } + W[i ][0] = col4; + W[i ][1] = col5; + colx = subWord(shift(col5, 8)) ^ rcon; rcon <<= 1; + col0 ^= colx; W[i ][2] = col0; + col1 ^= col0; W[i ][3] = col1; + + col2 ^= col1; W[i + 1][0] = col2; + col3 ^= col2; W[i + 1][1] = col3; + col4 ^= col3; W[i + 1][2] = col4; + col5 ^= col4; W[i + 1][3] = col5; + + colx = subWord(shift(col5, 8)) ^ rcon; rcon <<= 1; + col0 ^= colx; W[i + 2][0] = col0; + col1 ^= col0; W[i + 2][1] = col1; + col2 ^= col1; W[i + 2][2] = col2; + col3 ^= col2; W[i + 2][3] = col3; + + if ((i += 3) >= 13) + { + break; + } - u = subWord(shift(t5, 8)) ^ rcon; - t0 ^= u; W[12][0] = t0; - t1 ^= t0; W[12][1] = t1; - t2 ^= t1; W[12][2] = t2; - t3 ^= t2; W[12][3] = t3; + col4 ^= col3; + col5 ^= col4; + } break; } case 8: { - int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; - int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; - int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; - int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; - int t4 = Pack.littleEndianToInt(key, 16); W[1][0] = t4; - int t5 = Pack.littleEndianToInt(key, 20); W[1][1] = t5; - int t6 = Pack.littleEndianToInt(key, 24); W[1][2] = t6; - int t7 = Pack.littleEndianToInt(key, 28); W[1][3] = t7; - - int u, rcon = 1; - - for (int i = 2; i < 14; i += 2) + int col0 = Pack.littleEndianToInt(key, 0); W[0][0] = col0; + int col1 = Pack.littleEndianToInt(key, 4); W[0][1] = col1; + int col2 = Pack.littleEndianToInt(key, 8); W[0][2] = col2; + int col3 = Pack.littleEndianToInt(key, 12); W[0][3] = col3; + + int col4 = Pack.littleEndianToInt(key, 16); W[1][0] = col4; + int col5 = Pack.littleEndianToInt(key, 20); W[1][1] = col5; + int col6 = Pack.littleEndianToInt(key, 24); W[1][2] = col6; + int col7 = Pack.littleEndianToInt(key, 28); W[1][3] = col7; + + int i = 2, rcon = 1, colx; + for (;;) { - u = subWord(shift(t7, 8)) ^ rcon; rcon <<= 1; - t0 ^= u; W[i ][0] = t0; - t1 ^= t0; W[i ][1] = t1; - t2 ^= t1; W[i ][2] = t2; - t3 ^= t2; W[i ][3] = t3; - u = subWord(t3); - t4 ^= u; W[i + 1][0] = t4; - t5 ^= t4; W[i + 1][1] = t5; - t6 ^= t5; W[i + 1][2] = t6; - t7 ^= t6; W[i + 1][3] = t7; - } + colx = subWord(shift(col7, 8)) ^ rcon; rcon <<= 1; + col0 ^= colx; W[i][0] = col0; + col1 ^= col0; W[i][1] = col1; + col2 ^= col1; W[i][2] = col2; + col3 ^= col2; W[i][3] = col3; + ++i; + + if (i >= 15) + { + break; + } - u = subWord(shift(t7, 8)) ^ rcon; - t0 ^= u; W[14][0] = t0; - t1 ^= t0; W[14][1] = t1; - t2 ^= t1; W[14][2] = t2; - t3 ^= t2; W[14][3] = t3; + colx = subWord(col3); + col4 ^= colx; W[i][0] = col4; + col5 ^= col4; W[i][1] = col5; + col6 ^= col5; W[i][2] = col6; + col7 ^= col6; W[i][3] = col7; + ++i; + } break; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/AESLightEngine.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/AESLightEngine.java index fb360cba4..9e0f42d3e 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/AESLightEngine.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/AESLightEngine.java @@ -187,7 +187,7 @@ public class AESLightEngine throw new IllegalArgumentException("Key length not 128/192/256 bits."); } - int KC = keyLen >> 2; + int KC = keyLen >>> 2; ROUNDS = KC + 6; // This is not always true for the generalized Rijndael that allows larger block sizes int[][] W = new int[ROUNDS+1][4]; // 4 words in a block @@ -195,98 +195,97 @@ public class AESLightEngine { case 4: { - int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; - int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; - int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; - int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; + int col0 = Pack.littleEndianToInt(key, 0); W[0][0] = col0; + int col1 = Pack.littleEndianToInt(key, 4); W[0][1] = col1; + int col2 = Pack.littleEndianToInt(key, 8); W[0][2] = col2; + int col3 = Pack.littleEndianToInt(key, 12); W[0][3] = col3; for (int i = 1; i <= 10; ++i) { - int u = subWord(shift(t3, 8)) ^ rcon[i - 1]; - t0 ^= u; W[i][0] = t0; - t1 ^= t0; W[i][1] = t1; - t2 ^= t1; W[i][2] = t2; - t3 ^= t2; W[i][3] = t3; + int colx = subWord(shift(col3, 8)) ^ rcon[i - 1]; + col0 ^= colx; W[i][0] = col0; + col1 ^= col0; W[i][1] = col1; + col2 ^= col1; W[i][2] = col2; + col3 ^= col2; W[i][3] = col3; } break; } case 6: { - int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; - int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; - int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; - int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; - int t4 = Pack.littleEndianToInt(key, 16); W[1][0] = t4; - int t5 = Pack.littleEndianToInt(key, 20); W[1][1] = t5; - - int rcon = 1; - int u = subWord(shift(t5, 8)) ^ rcon; rcon <<= 1; - t0 ^= u; W[1][2] = t0; - t1 ^= t0; W[1][3] = t1; - t2 ^= t1; W[2][0] = t2; - t3 ^= t2; W[2][1] = t3; - t4 ^= t3; W[2][2] = t4; - t5 ^= t4; W[2][3] = t5; - - for (int i = 3; i < 12; i += 3) + int col0 = Pack.littleEndianToInt(key, 0); W[0][0] = col0; + int col1 = Pack.littleEndianToInt(key, 4); W[0][1] = col1; + int col2 = Pack.littleEndianToInt(key, 8); W[0][2] = col2; + int col3 = Pack.littleEndianToInt(key, 12); W[0][3] = col3; + + int col4 = Pack.littleEndianToInt(key, 16); + int col5 = Pack.littleEndianToInt(key, 20); + + int i = 1, rcon = 1, colx; + for (;;) { - u = subWord(shift(t5, 8)) ^ rcon; rcon <<= 1; - t0 ^= u; W[i ][0] = t0; - t1 ^= t0; W[i ][1] = t1; - t2 ^= t1; W[i ][2] = t2; - t3 ^= t2; W[i ][3] = t3; - t4 ^= t3; W[i + 1][0] = t4; - t5 ^= t4; W[i + 1][1] = t5; - u = subWord(shift(t5, 8)) ^ rcon; rcon <<= 1; - t0 ^= u; W[i + 1][2] = t0; - t1 ^= t0; W[i + 1][3] = t1; - t2 ^= t1; W[i + 2][0] = t2; - t3 ^= t2; W[i + 2][1] = t3; - t4 ^= t3; W[i + 2][2] = t4; - t5 ^= t4; W[i + 2][3] = t5; - } + W[i ][0] = col4; + W[i ][1] = col5; + colx = subWord(shift(col5, 8)) ^ rcon; rcon <<= 1; + col0 ^= colx; W[i ][2] = col0; + col1 ^= col0; W[i ][3] = col1; + + col2 ^= col1; W[i + 1][0] = col2; + col3 ^= col2; W[i + 1][1] = col3; + col4 ^= col3; W[i + 1][2] = col4; + col5 ^= col4; W[i + 1][3] = col5; + + colx = subWord(shift(col5, 8)) ^ rcon; rcon <<= 1; + col0 ^= colx; W[i + 2][0] = col0; + col1 ^= col0; W[i + 2][1] = col1; + col2 ^= col1; W[i + 2][2] = col2; + col3 ^= col2; W[i + 2][3] = col3; + + if ((i += 3) >= 13) + { + break; + } - u = subWord(shift(t5, 8)) ^ rcon; - t0 ^= u; W[12][0] = t0; - t1 ^= t0; W[12][1] = t1; - t2 ^= t1; W[12][2] = t2; - t3 ^= t2; W[12][3] = t3; + col4 ^= col3; + col5 ^= col4; + } break; } case 8: { - int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; - int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; - int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; - int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; - int t4 = Pack.littleEndianToInt(key, 16); W[1][0] = t4; - int t5 = Pack.littleEndianToInt(key, 20); W[1][1] = t5; - int t6 = Pack.littleEndianToInt(key, 24); W[1][2] = t6; - int t7 = Pack.littleEndianToInt(key, 28); W[1][3] = t7; - - int u, rcon = 1; - - for (int i = 2; i < 14; i += 2) + int col0 = Pack.littleEndianToInt(key, 0); W[0][0] = col0; + int col1 = Pack.littleEndianToInt(key, 4); W[0][1] = col1; + int col2 = Pack.littleEndianToInt(key, 8); W[0][2] = col2; + int col3 = Pack.littleEndianToInt(key, 12); W[0][3] = col3; + + int col4 = Pack.littleEndianToInt(key, 16); W[1][0] = col4; + int col5 = Pack.littleEndianToInt(key, 20); W[1][1] = col5; + int col6 = Pack.littleEndianToInt(key, 24); W[1][2] = col6; + int col7 = Pack.littleEndianToInt(key, 28); W[1][3] = col7; + + int i = 2, rcon = 1, colx; + for (;;) { - u = subWord(shift(t7, 8)) ^ rcon; rcon <<= 1; - t0 ^= u; W[i ][0] = t0; - t1 ^= t0; W[i ][1] = t1; - t2 ^= t1; W[i ][2] = t2; - t3 ^= t2; W[i ][3] = t3; - u = subWord(t3); - t4 ^= u; W[i + 1][0] = t4; - t5 ^= t4; W[i + 1][1] = t5; - t6 ^= t5; W[i + 1][2] = t6; - t7 ^= t6; W[i + 1][3] = t7; - } + colx = subWord(shift(col7, 8)) ^ rcon; rcon <<= 1; + col0 ^= colx; W[i][0] = col0; + col1 ^= col0; W[i][1] = col1; + col2 ^= col1; W[i][2] = col2; + col3 ^= col2; W[i][3] = col3; + ++i; + + if (i >= 15) + { + break; + } - u = subWord(shift(t7, 8)) ^ rcon; - t0 ^= u; W[14][0] = t0; - t1 ^= t0; W[14][1] = t1; - t2 ^= t1; W[14][2] = t2; - t3 ^= t2; W[14][3] = t3; + colx = subWord(col3); + col4 ^= colx; W[i][0] = col4; + col5 ^= col4; W[i][1] = col5; + col6 ^= col5; W[i][2] = col6; + col7 ^= col6; W[i][3] = col7; + ++i; + } break; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/BlowfishEngine.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/BlowfishEngine.java index 1d63b5f80..28e8d0b98 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/BlowfishEngine.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/BlowfishEngine.java @@ -420,8 +420,9 @@ implements BlockCipher xr ^= P[ROUNDS + 1]; + // suppress LGTM warnings index-out-of-bounds since the loop increments s by 2 table[s] = xr; - table[s + 1] = xl; + table[s + 1] = xl; // lgtm [java/index-out-of-bounds] xr = xl; // end of cycle swap xl = table[s]; diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/ChaChaEngine.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/ChaChaEngine.java index 99de0327c..0f4ef7838 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/ChaChaEngine.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/ChaChaEngine.java @@ -1,5 +1,6 @@ package com.fr.third.org.bouncycastle.crypto.engines; +import com.fr.third.org.bouncycastle.util.Integers; import com.fr.third.org.bouncycastle.util.Pack; /** @@ -180,38 +181,38 @@ public class ChaChaEngine extends Salsa20Engine for (int i = rounds; i > 0; i -= 2) { - x00 += x04; x12 = rotl(x12 ^ x00, 16); - x08 += x12; x04 = rotl(x04 ^ x08, 12); - x00 += x04; x12 = rotl(x12 ^ x00, 8); - x08 += x12; x04 = rotl(x04 ^ x08, 7); - x01 += x05; x13 = rotl(x13 ^ x01, 16); - x09 += x13; x05 = rotl(x05 ^ x09, 12); - x01 += x05; x13 = rotl(x13 ^ x01, 8); - x09 += x13; x05 = rotl(x05 ^ x09, 7); - x02 += x06; x14 = rotl(x14 ^ x02, 16); - x10 += x14; x06 = rotl(x06 ^ x10, 12); - x02 += x06; x14 = rotl(x14 ^ x02, 8); - x10 += x14; x06 = rotl(x06 ^ x10, 7); - x03 += x07; x15 = rotl(x15 ^ x03, 16); - x11 += x15; x07 = rotl(x07 ^ x11, 12); - x03 += x07; x15 = rotl(x15 ^ x03, 8); - x11 += x15; x07 = rotl(x07 ^ x11, 7); - x00 += x05; x15 = rotl(x15 ^ x00, 16); - x10 += x15; x05 = rotl(x05 ^ x10, 12); - x00 += x05; x15 = rotl(x15 ^ x00, 8); - x10 += x15; x05 = rotl(x05 ^ x10, 7); - x01 += x06; x12 = rotl(x12 ^ x01, 16); - x11 += x12; x06 = rotl(x06 ^ x11, 12); - x01 += x06; x12 = rotl(x12 ^ x01, 8); - x11 += x12; x06 = rotl(x06 ^ x11, 7); - x02 += x07; x13 = rotl(x13 ^ x02, 16); - x08 += x13; x07 = rotl(x07 ^ x08, 12); - x02 += x07; x13 = rotl(x13 ^ x02, 8); - x08 += x13; x07 = rotl(x07 ^ x08, 7); - x03 += x04; x14 = rotl(x14 ^ x03, 16); - x09 += x14; x04 = rotl(x04 ^ x09, 12); - x03 += x04; x14 = rotl(x14 ^ x03, 8); - x09 += x14; x04 = rotl(x04 ^ x09, 7); + x00 += x04; x12 = Integers.rotateLeft(x12 ^ x00, 16); + x08 += x12; x04 = Integers.rotateLeft(x04 ^ x08, 12); + x00 += x04; x12 = Integers.rotateLeft(x12 ^ x00, 8); + x08 += x12; x04 = Integers.rotateLeft(x04 ^ x08, 7); + x01 += x05; x13 = Integers.rotateLeft(x13 ^ x01, 16); + x09 += x13; x05 = Integers.rotateLeft(x05 ^ x09, 12); + x01 += x05; x13 = Integers.rotateLeft(x13 ^ x01, 8); + x09 += x13; x05 = Integers.rotateLeft(x05 ^ x09, 7); + x02 += x06; x14 = Integers.rotateLeft(x14 ^ x02, 16); + x10 += x14; x06 = Integers.rotateLeft(x06 ^ x10, 12); + x02 += x06; x14 = Integers.rotateLeft(x14 ^ x02, 8); + x10 += x14; x06 = Integers.rotateLeft(x06 ^ x10, 7); + x03 += x07; x15 = Integers.rotateLeft(x15 ^ x03, 16); + x11 += x15; x07 = Integers.rotateLeft(x07 ^ x11, 12); + x03 += x07; x15 = Integers.rotateLeft(x15 ^ x03, 8); + x11 += x15; x07 = Integers.rotateLeft(x07 ^ x11, 7); + x00 += x05; x15 = Integers.rotateLeft(x15 ^ x00, 16); + x10 += x15; x05 = Integers.rotateLeft(x05 ^ x10, 12); + x00 += x05; x15 = Integers.rotateLeft(x15 ^ x00, 8); + x10 += x15; x05 = Integers.rotateLeft(x05 ^ x10, 7); + x01 += x06; x12 = Integers.rotateLeft(x12 ^ x01, 16); + x11 += x12; x06 = Integers.rotateLeft(x06 ^ x11, 12); + x01 += x06; x12 = Integers.rotateLeft(x12 ^ x01, 8); + x11 += x12; x06 = Integers.rotateLeft(x06 ^ x11, 7); + x02 += x07; x13 = Integers.rotateLeft(x13 ^ x02, 16); + x08 += x13; x07 = Integers.rotateLeft(x07 ^ x08, 12); + x02 += x07; x13 = Integers.rotateLeft(x13 ^ x02, 8); + x08 += x13; x07 = Integers.rotateLeft(x07 ^ x08, 7); + x03 += x04; x14 = Integers.rotateLeft(x14 ^ x03, 16); + x09 += x14; x04 = Integers.rotateLeft(x04 ^ x09, 12); + x03 += x04; x14 = Integers.rotateLeft(x14 ^ x03, 8); + x09 += x14; x04 = Integers.rotateLeft(x04 ^ x09, 7); } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/CramerShoupCoreEngine.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/CramerShoupCoreEngine.java index fdc819e07..4bbf037a3 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/CramerShoupCoreEngine.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/CramerShoupCoreEngine.java @@ -290,7 +290,7 @@ public class CramerShoupCoreEngine protected SecureRandom initSecureRandom(boolean needed, SecureRandom provided) { - return !needed ? null : (provided != null) ? provided : CryptoServicesRegistrar.getSecureRandom(); + return needed ? CryptoServicesRegistrar.getSecureRandom(provided) : null; } /** diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/NoekeonEngine.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/NoekeonEngine.java index 2adf2bf53..dfb05c350 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/NoekeonEngine.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/NoekeonEngine.java @@ -5,259 +5,253 @@ import com.fr.third.org.bouncycastle.crypto.CipherParameters; import com.fr.third.org.bouncycastle.crypto.DataLengthException; import com.fr.third.org.bouncycastle.crypto.OutputLengthException; import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; +import com.fr.third.org.bouncycastle.util.Integers; +import com.fr.third.org.bouncycastle.util.Pack; /** * A Noekeon engine, using direct-key mode. */ - public class NoekeonEngine implements BlockCipher { - private static final int genericSize = 16; // Block and key size, as well as the amount of rounds. - - private static final int[] nullVector = - { - 0x00, 0x00, 0x00, 0x00 // Used in decryption - }, - - roundConstants = - { - 0x80, 0x1b, 0x36, 0x6c, - 0xd8, 0xab, 0x4d, 0x9a, - 0x2f, 0x5e, 0xbc, 0x63, - 0xc6, 0x97, 0x35, 0x6a, - 0xd4 - }; - - private int[] state = new int[4], // a - subKeys = new int[4], // k - decryptKeys = new int[4]; - - private boolean _initialised, - _forEncryption; - + // Block and key size, as well as the amount of rounds. + private static final int SIZE = 16; + + // Used in decryption + private static final byte[] roundConstants = { (byte)0x80, 0x1b, 0x36, 0x6c, (byte)0xd8, (byte)0xab, 0x4d, + (byte)0x9a, 0x2f, 0x5e, (byte)0xbc, 0x63, (byte)0xc6, (byte)0x97, 0x35, 0x6a, (byte)0xd4 }; + + private final int[] k = new int[4]; + + private boolean _initialised, _forEncryption; + /** - * Create an instance of the Noekeon encryption algorithm - * and set some defaults + * Create an instance of the Noekeon encryption algorithm and set some defaults */ public NoekeonEngine() { _initialised = false; } - + public String getAlgorithmName() { return "Noekeon"; } - + public int getBlockSize() { - return genericSize; + return SIZE; } - + /** * initialise * - * @param forEncryption whether or not we are for encryption. - * @param params the parameters required to set up the cipher. - * @exception IllegalArgumentException if the params argument is - * inappropriate. + * @param forEncryption + * whether or not we are for encryption. + * @param params + * the parameters required to set up the cipher. + * @exception IllegalArgumentException + * if the params argument is inappropriate. */ - public void init( - boolean forEncryption, - CipherParameters params) + public void init(boolean forEncryption, CipherParameters params) { if (!(params instanceof KeyParameter)) { - throw new IllegalArgumentException("invalid parameter passed to Noekeon init - " + params.getClass().getName()); + throw new IllegalArgumentException( + "invalid parameter passed to Noekeon init - " + params.getClass().getName()); + } + + this._forEncryption = forEncryption; + this._initialised = true; + + KeyParameter p = (KeyParameter)params; + + Pack.bigEndianToInt(p.getKey(), 0, k, 0, 4); + + if (!forEncryption) + { + // theta(k, new int[]{ 0x00, 0x00, 0x00, 0x00 }); + { + int a0 = k[0], a1 = k[1], a2 = k[2], a3 = k[3]; + + int t = a0 ^ a2; + t ^= Integers.rotateLeft(t, 8) ^ Integers.rotateLeft(t, 24); + a1 ^= t; + a3 ^= t; + + t = a1 ^ a3; + t ^= Integers.rotateLeft(t, 8) ^ Integers.rotateLeft(t, 24); + a0 ^= t; + a2 ^= t; + + k[0] = a0; k[1] = a1; k[2] = a2; k[3] = a3; + } } - - _forEncryption = forEncryption; - _initialised = true; - - KeyParameter p = (KeyParameter)params; - - setKey(p.getKey()); } - - public int processBlock( - byte[] in, - int inOff, - byte[] out, - int outOff) + + public int processBlock(byte[] in, int inOff, byte[] out, int outOff) { if (!_initialised) { - throw new IllegalStateException(getAlgorithmName()+" not initialised"); + throw new IllegalStateException(getAlgorithmName() + " not initialised"); } - - if ((inOff + genericSize) > in.length) + if (inOff > in.length - SIZE) { throw new DataLengthException("input buffer too short"); } - - if ((outOff + genericSize) > out.length) + if (outOff > out.length - SIZE) { throw new OutputLengthException("output buffer too short"); } - - return (_forEncryption) ? encryptBlock(in, inOff, out, outOff) - : decryptBlock(in, inOff, out, outOff); + + return _forEncryption ? encryptBlock(in, inOff, out, outOff) : decryptBlock(in, inOff, out, outOff); } - + public void reset() { } - - /** - * Re-key the cipher. - *+ * * @param secondDigest the content digest - * @param signingTime the signing time + * @param signingTime the signing time * @return the byte array representation of the authenticatedAttributes ready to be signed - */ + */ public byte[] getAuthenticatedAttributeBytes(byte secondDigest[], Calendar signingTime, byte[] ocsp) { try { return getAuthenticatedAttributeSet(secondDigest, signingTime, ocsp).getEncoded("DER"); - } - catch (Exception e) { + } catch (Exception e) { throw new ExceptionConverter(e); } } - + private DERSet getAuthenticatedAttributeSet(byte secondDigest[], Calendar signingTime, byte[] ocsp) { try { ASN1EncodableVector attribute = new ASN1EncodableVector(); ASN1EncodableVector v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(ID_CONTENT_TYPE)); - v.add(new DERSet(new DERObjectIdentifier(ID_PKCS7_DATA))); + v.add(new ASN1ObjectIdentifier(ID_CONTENT_TYPE)); + v.add(new DERSet(new ASN1ObjectIdentifier(ID_PKCS7_DATA))); attribute.add(new DERSequence(v)); v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(ID_SIGNING_TIME)); + v.add(new ASN1ObjectIdentifier(ID_SIGNING_TIME)); v.add(new DERSet(new DERUTCTime(signingTime.getTime()))); attribute.add(new DERSequence(v)); v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(ID_MESSAGE_DIGEST)); + v.add(new ASN1ObjectIdentifier(ID_MESSAGE_DIGEST)); v.add(new DERSet(new DEROctetString(secondDigest))); attribute.add(new DERSequence(v)); if (ocsp != null) { v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(ID_ADBE_REVOCATION)); + v.add(new ASN1ObjectIdentifier(ID_ADBE_REVOCATION)); DEROctetString doctet = new DEROctetString(ocsp); ASN1EncodableVector vo1 = new ASN1EncodableVector(); ASN1EncodableVector v2 = new ASN1EncodableVector(); v2.add(OCSPObjectIdentifiers.id_pkix_ocsp_basic); v2.add(doctet); - DEREnumerated den = new DEREnumerated(0); + ASN1Enumerated den = new ASN1Enumerated(0); ASN1EncodableVector v3 = new ASN1EncodableVector(); v3.add(den); v3.add(new DERTaggedObject(true, 0, new DERSequence(v2))); vo1.add(new DERSequence(v3)); v.add(new DERSet(new DERSequence(new DERTaggedObject(true, 1, new DERSequence(vo1))))); attribute.add(new DERSequence(v)); - } - else if (!crls.isEmpty()) { + } else if (!crls.isEmpty()) { v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(ID_ADBE_REVOCATION)); + v.add(new ASN1ObjectIdentifier(ID_ADBE_REVOCATION)); ASN1EncodableVector v2 = new ASN1EncodableVector(); - for (Iterator i = crls.iterator();i.hasNext();) { - ASN1InputStream t = new ASN1InputStream(new ByteArrayInputStream(((X509CRL)i.next()).getEncoded())); + for (Iterator i = crls.iterator(); i.hasNext(); ) { + ASN1InputStream t = new ASN1InputStream(new ByteArrayInputStream(((X509CRL) i.next()).getEncoded())); v2.add(t.readObject()); } v.add(new DERSet(new DERSequence(new DERTaggedObject(true, 0, new DERSequence(v2))))); attribute.add(new DERSequence(v)); } return new DERSet(attribute); - } - catch (Exception e) { + } catch (Exception e) { throw new ExceptionConverter(e); } } - + /** * Getter for property reason. + * * @return Value of property reason. */ public String getReason() { return this.reason; } - + /** * Setter for property reason. + * * @param reason New value of property reason. */ public void setReason(String reason) { this.reason = reason; } - + /** * Getter for property location. + * * @return Value of property location. */ public String getLocation() { return this.location; } - + /** * Setter for property location. + * * @param location New value of property location. */ public void setLocation(String location) { this.location = location; } - + /** * Getter for property signDate. + * * @return Value of property signDate. */ public Calendar getSignDate() { return this.signDate; } - + /** * Setter for property signDate. + * * @param signDate New value of property signDate. */ public void setSignDate(Calendar signDate) { this.signDate = signDate; } - + /** * Getter for property sigName. + * * @return Value of property sigName. */ public String getSignName() { return this.signName; } - + /** * Setter for property sigName. + * * @param signName New value of property sigName. */ public void setSignName(String signName) { this.signName = signName; } - + /** * a class that holds an X509 name */ @@ -1467,74 +1479,90 @@ public class PdfPKCS7 { /** * country code - StringType(SIZE(2)) */ - public static final DERObjectIdentifier C = new DERObjectIdentifier("2.5.4.6"); + public static final ASN1ObjectIdentifier C = new ASN1ObjectIdentifier("2.5.4.6"); /** * organization - StringType(SIZE(1..64)) */ - public static final DERObjectIdentifier O = new DERObjectIdentifier("2.5.4.10"); + public static final ASN1ObjectIdentifier O = new ASN1ObjectIdentifier("2.5.4.10"); /** * organizational unit name - StringType(SIZE(1..64)) */ - public static final DERObjectIdentifier OU = new DERObjectIdentifier("2.5.4.11"); + public static final ASN1ObjectIdentifier OU = new ASN1ObjectIdentifier("2.5.4.11"); /** * Title */ - public static final DERObjectIdentifier T = new DERObjectIdentifier("2.5.4.12"); + public static final ASN1ObjectIdentifier T = new ASN1ObjectIdentifier("2.5.4.12"); /** * common name - StringType(SIZE(1..64)) */ - public static final DERObjectIdentifier CN = new DERObjectIdentifier("2.5.4.3"); + public static final ASN1ObjectIdentifier CN = new ASN1ObjectIdentifier("2.5.4.3"); /** * device serial number name - StringType(SIZE(1..64)) */ - public static final DERObjectIdentifier SN = new DERObjectIdentifier("2.5.4.5"); + public static final ASN1ObjectIdentifier SN = new ASN1ObjectIdentifier("2.5.4.5"); /** * locality name - StringType(SIZE(1..64)) */ - public static final DERObjectIdentifier L = new DERObjectIdentifier("2.5.4.7"); + public static final ASN1ObjectIdentifier L = new ASN1ObjectIdentifier("2.5.4.7"); /** * state, or province name - StringType(SIZE(1..64)) */ - public static final DERObjectIdentifier ST = new DERObjectIdentifier("2.5.4.8"); - - /** Naming attribute of type X520name */ - public static final DERObjectIdentifier SURNAME = new DERObjectIdentifier("2.5.4.4"); - /** Naming attribute of type X520name */ - public static final DERObjectIdentifier GIVENNAME = new DERObjectIdentifier("2.5.4.42"); - /** Naming attribute of type X520name */ - public static final DERObjectIdentifier INITIALS = new DERObjectIdentifier("2.5.4.43"); - /** Naming attribute of type X520name */ - public static final DERObjectIdentifier GENERATION = new DERObjectIdentifier("2.5.4.44"); - /** Naming attribute of type X520name */ - public static final DERObjectIdentifier UNIQUE_IDENTIFIER = new DERObjectIdentifier("2.5.4.45"); + public static final ASN1ObjectIdentifier ST = new ASN1ObjectIdentifier("2.5.4.8"); + + /** + * Naming attribute of type X520name + */ + public static final ASN1ObjectIdentifier SURNAME = new ASN1ObjectIdentifier("2.5.4.4"); + /** + * Naming attribute of type X520name + */ + public static final ASN1ObjectIdentifier GIVENNAME = new ASN1ObjectIdentifier("2.5.4.42"); + /** + * Naming attribute of type X520name + */ + public static final ASN1ObjectIdentifier INITIALS = new ASN1ObjectIdentifier("2.5.4.43"); + /** + * Naming attribute of type X520name + */ + public static final ASN1ObjectIdentifier GENERATION = new ASN1ObjectIdentifier("2.5.4.44"); + /** + * Naming attribute of type X520name + */ + public static final ASN1ObjectIdentifier UNIQUE_IDENTIFIER = new ASN1ObjectIdentifier("2.5.4.45"); /** * Email address (RSA PKCS#9 extension) - IA5String. *- * @param key the key to be used - */ - private void setKey( - byte[] key) - { - subKeys[0] = bytesToIntBig(key, 0); - subKeys[1] = bytesToIntBig(key, 4); - subKeys[2] = bytesToIntBig(key, 8); - subKeys[3] = bytesToIntBig(key, 12); - } - - private int encryptBlock( - byte[] in, - int inOff, - byte[] out, - int outOff) - { - state[0] = bytesToIntBig(in, inOff); - state[1] = bytesToIntBig(in, inOff+4); - state[2] = bytesToIntBig(in, inOff+8); - state[3] = bytesToIntBig(in, inOff+12); - - int i; - for (i = 0; i < genericSize; i++) - { - state[0] ^= roundConstants[i]; - theta(state, subKeys); - pi1(state); - gamma(state); - pi2(state); - } - - state[0] ^= roundConstants[i]; - theta(state, subKeys); - - intToBytesBig(state[0], out, outOff); - intToBytesBig(state[1], out, outOff+4); - intToBytesBig(state[2], out, outOff+8); - intToBytesBig(state[3], out, outOff+12); - - return genericSize; - } - - private int decryptBlock( - byte[] in, - int inOff, - byte[] out, - int outOff) + + private int encryptBlock(byte[] in, int inOff, byte[] out, int outOff) { - state[0] = bytesToIntBig(in, inOff); - state[1] = bytesToIntBig(in, inOff+4); - state[2] = bytesToIntBig(in, inOff+8); - state[3] = bytesToIntBig(in, inOff+12); - - System.arraycopy(subKeys, 0, decryptKeys, 0, subKeys.length); - theta(decryptKeys, nullVector); - - int i; - for (i = genericSize; i > 0; i--) + int a0 = Pack.bigEndianToInt(in, inOff); + int a1 = Pack.bigEndianToInt(in, inOff + 4); + int a2 = Pack.bigEndianToInt(in, inOff + 8); + int a3 = Pack.bigEndianToInt(in, inOff + 12); + + int k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3]; + + int round = 0, t; + for (;;) { - theta(state, decryptKeys); - state[0] ^= roundConstants[i]; - pi1(state); - gamma(state); - pi2(state); + a0 ^= roundConstants[round] & 0xFF; + + // theta(a, k); + { + t = a0 ^ a2; + t ^= Integers.rotateLeft(t, 8) ^ Integers.rotateLeft(t, 24); + a1 ^= t; + a3 ^= t; + + a0 ^= k0; + a1 ^= k1; + a2 ^= k2; + a3 ^= k3; + + t = a1 ^ a3; + t ^= Integers.rotateLeft(t, 8) ^ Integers.rotateLeft(t, 24); + a0 ^= t; + a2 ^= t; + } + + if (++round > SIZE) + { + break; + } + + // pi1(a); + { + a1 = Integers.rotateLeft(a1, 1); + a2 = Integers.rotateLeft(a2, 5); + a3 = Integers.rotateLeft(a3, 2); + } + + // gamma(a); + { + a1 ^= ~a3 & ~a2; + a0 ^= a2 & a1; + + t = a3; a3 = a0; a0 = t; + a2 ^= a0 ^ a1 ^ a3; + + a1 ^= ~a3 & ~a2; + a0 ^= a2 & a1; + } + + // pi2(a); + { + a1 = Integers.rotateLeft(a1, 31); + a2 = Integers.rotateLeft(a2, 27); + a3 = Integers.rotateLeft(a3, 30); + } } - - theta(state, decryptKeys); - state[0] ^= roundConstants[i]; - - intToBytesBig(state[0], out, outOff); - intToBytesBig(state[1], out, outOff+4); - intToBytesBig(state[2], out, outOff+8); - intToBytesBig(state[3], out, outOff+12); - - return genericSize; - } - - private void gamma(int[] a) - { - a[1] ^= ~a[3] & ~a[2]; - a[0] ^= a[2] & a[1]; - - int tmp = a[3]; - a[3] = a[0]; - a[0] = tmp; - a[2] ^= a[0]^a[1]^a[3]; - - a[1] ^= ~a[3] & ~a[2]; - a[0] ^= a[2] & a[1]; + + Pack.intToBigEndian(a0, out, outOff); + Pack.intToBigEndian(a1, out, outOff + 4); + Pack.intToBigEndian(a2, out, outOff + 8); + Pack.intToBigEndian(a3, out, outOff + 12); + + return SIZE; } - - private void theta(int[] a, int[] k) + + private int decryptBlock(byte[] in, int inOff, byte[] out, int outOff) { - int tmp; - - tmp = a[0]^a[2]; - tmp ^= rotl(tmp,8)^rotl(tmp,24); - a[1] ^= tmp; - a[3] ^= tmp; - - for (int i = 0; i < 4; i++) + int a0 = Pack.bigEndianToInt(in, inOff); + int a1 = Pack.bigEndianToInt(in, inOff + 4); + int a2 = Pack.bigEndianToInt(in, inOff + 8); + int a3 = Pack.bigEndianToInt(in, inOff + 12); + + int k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3]; + + int round = SIZE, t; + for (;;) { - a[i] ^= k[i]; + // theta(a, k); + { + t = a0 ^ a2; + t ^= Integers.rotateLeft(t, 8) ^ Integers.rotateLeft(t, 24); + a1 ^= t; + a3 ^= t; + + a0 ^= k0; + a1 ^= k1; + a2 ^= k2; + a3 ^= k3; + + t = a1 ^ a3; + t ^= Integers.rotateLeft(t, 8) ^ Integers.rotateLeft(t, 24); + a0 ^= t; + a2 ^= t; + } + + a0 ^= roundConstants[round] & 0xFF; + + if (--round < 0) + { + break; + } + + // pi1(a); + { + a1 = Integers.rotateLeft(a1, 1); + a2 = Integers.rotateLeft(a2, 5); + a3 = Integers.rotateLeft(a3, 2); + } + + // gamma(a); + { + a1 ^= ~a3 & ~a2; + a0 ^= a2 & a1; + + t = a3; a3 = a0; a0 = t; + a2 ^= a0 ^ a1 ^ a3; + + a1 ^= ~a3 & ~a2; + a0 ^= a2 & a1; + } + + // pi2(a); + { + a1 = Integers.rotateLeft(a1, 31); + a2 = Integers.rotateLeft(a2, 27); + a3 = Integers.rotateLeft(a3, 30); + } } - - tmp = a[1]^a[3]; - tmp ^= rotl(tmp,8)^rotl(tmp,24); - a[0] ^= tmp; - a[2] ^= tmp; - } - - private void pi1(int[] a) - { - a[1] = rotl(a[1], 1); - a[2] = rotl(a[2], 5); - a[3] = rotl(a[3], 2); - } - - private void pi2(int[] a) - { - a[1] = rotl(a[1], 31); - a[2] = rotl(a[2], 27); - a[3] = rotl(a[3], 30); - } - - // Helpers - - private int bytesToIntBig(byte[] in, int off) - { - return ((in[off++]) << 24) | - ((in[off++] & 0xff) << 16) | - ((in[off++] & 0xff) << 8) | - (in[off ] & 0xff); - } - - private void intToBytesBig(int x, byte[] out, int off) - { - out[off++] = (byte)(x >>> 24); - out[off++] = (byte)(x >>> 16); - out[off++] = (byte)(x >>> 8); - out[off ] = (byte)x; - } - - private int rotl(int x, int y) - { - return (x << y) | (x >>> (32-y)); + + Pack.intToBigEndian(a0, out, outOff); + Pack.intToBigEndian(a1, out, outOff + 4); + Pack.intToBigEndian(a2, out, outOff + 8); + Pack.intToBigEndian(a3, out, outOff + 12); + + return SIZE; } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/RFC5649WrapEngine.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/RFC5649WrapEngine.java index 61873ed7a..d0706ee6e 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/RFC5649WrapEngine.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/RFC5649WrapEngine.java @@ -154,7 +154,7 @@ public class RFC5649WrapEngine throw new InvalidCipherTextException("unwrap data must be a multiple of 8 bytes"); } - if (n == 1) + if (n <= 1) { throw new InvalidCipherTextException("unwrap data must be at least 16 bytes"); } @@ -215,12 +215,13 @@ public class RFC5649WrapEngine isValid = false; } - // Check the number of padded zeros + // Check the number of padding zeros int expectedZeros = upperBound - mli; - if (expectedZeros >= paddedPlaintext.length) + if (expectedZeros >= 8 || expectedZeros < 0) { + // We have to pick a "typical" amount of padding to avoid timing attacks. isValid = false; - expectedZeros = paddedPlaintext.length; + expectedZeros = 4; } byte[] zeros = new byte[expectedZeros]; diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/RSABlindedEngine.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/RSABlindedEngine.java index 380c3e7a2..0903992c5 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/RSABlindedEngine.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/RSABlindedEngine.java @@ -125,7 +125,7 @@ public class RSABlindedEngine BigInteger blindedInput = r.modPow(e, m).multiply(input).mod(m); BigInteger blindedResult = core.processBlock(blindedInput); - BigInteger rInv = r.modInverse(m); + BigInteger rInv = BigIntegers.modOddInverse(m, r); result = blindedResult.multiply(rInv).mod(m); // defence against Arjen Lenstra’s CRT attack if (!input.equals(result.modPow(e, m))) diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/RSABlindingEngine.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/RSABlindingEngine.java index 058823ffa..0f0dbfa08 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/RSABlindingEngine.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/RSABlindingEngine.java @@ -1,13 +1,14 @@ package com.fr.third.org.bouncycastle.crypto.engines; +import java.math.BigInteger; + import com.fr.third.org.bouncycastle.crypto.AsymmetricBlockCipher; import com.fr.third.org.bouncycastle.crypto.CipherParameters; import com.fr.third.org.bouncycastle.crypto.DataLengthException; import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; import com.fr.third.org.bouncycastle.crypto.params.RSABlindingParameters; import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; - -import java.math.BigInteger; +import com.fr.third.org.bouncycastle.util.BigIntegers; /** * This does your basic RSA Chaum's blinding and unblinding as outlined in @@ -128,7 +129,7 @@ public class RSABlindingEngine { BigInteger m = key.getModulus(); BigInteger msg = blindedMsg; - BigInteger blindFactorInverse = blindingFactor.modInverse(m); + BigInteger blindFactorInverse = BigIntegers.modOddInverse(m, blindingFactor); msg = msg.multiply(blindFactorInverse); msg = msg.mod(m); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/Salsa20Engine.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/Salsa20Engine.java index cbf8171f6..e1cc00a09 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/Salsa20Engine.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/Salsa20Engine.java @@ -7,6 +7,7 @@ import com.fr.third.org.bouncycastle.crypto.OutputLengthException; import com.fr.third.org.bouncycastle.crypto.SkippingStreamCipher; import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; +import com.fr.third.org.bouncycastle.util.Integers; import com.fr.third.org.bouncycastle.util.Pack; import com.fr.third.org.bouncycastle.util.Strings; @@ -437,39 +438,39 @@ public class Salsa20Engine for (int i = rounds; i > 0; i -= 2) { - x04 ^= rotl(x00 + x12, 7); - x08 ^= rotl(x04 + x00, 9); - x12 ^= rotl(x08 + x04, 13); - x00 ^= rotl(x12 + x08, 18); - x09 ^= rotl(x05 + x01, 7); - x13 ^= rotl(x09 + x05, 9); - x01 ^= rotl(x13 + x09, 13); - x05 ^= rotl(x01 + x13, 18); - x14 ^= rotl(x10 + x06, 7); - x02 ^= rotl(x14 + x10, 9); - x06 ^= rotl(x02 + x14, 13); - x10 ^= rotl(x06 + x02, 18); - x03 ^= rotl(x15 + x11, 7); - x07 ^= rotl(x03 + x15, 9); - x11 ^= rotl(x07 + x03, 13); - x15 ^= rotl(x11 + x07, 18); - - x01 ^= rotl(x00 + x03, 7); - x02 ^= rotl(x01 + x00, 9); - x03 ^= rotl(x02 + x01, 13); - x00 ^= rotl(x03 + x02, 18); - x06 ^= rotl(x05 + x04, 7); - x07 ^= rotl(x06 + x05, 9); - x04 ^= rotl(x07 + x06, 13); - x05 ^= rotl(x04 + x07, 18); - x11 ^= rotl(x10 + x09, 7); - x08 ^= rotl(x11 + x10, 9); - x09 ^= rotl(x08 + x11, 13); - x10 ^= rotl(x09 + x08, 18); - x12 ^= rotl(x15 + x14, 7); - x13 ^= rotl(x12 + x15, 9); - x14 ^= rotl(x13 + x12, 13); - x15 ^= rotl(x14 + x13, 18); + x04 ^= Integers.rotateLeft(x00 + x12, 7); + x08 ^= Integers.rotateLeft(x04 + x00, 9); + x12 ^= Integers.rotateLeft(x08 + x04, 13); + x00 ^= Integers.rotateLeft(x12 + x08, 18); + x09 ^= Integers.rotateLeft(x05 + x01, 7); + x13 ^= Integers.rotateLeft(x09 + x05, 9); + x01 ^= Integers.rotateLeft(x13 + x09, 13); + x05 ^= Integers.rotateLeft(x01 + x13, 18); + x14 ^= Integers.rotateLeft(x10 + x06, 7); + x02 ^= Integers.rotateLeft(x14 + x10, 9); + x06 ^= Integers.rotateLeft(x02 + x14, 13); + x10 ^= Integers.rotateLeft(x06 + x02, 18); + x03 ^= Integers.rotateLeft(x15 + x11, 7); + x07 ^= Integers.rotateLeft(x03 + x15, 9); + x11 ^= Integers.rotateLeft(x07 + x03, 13); + x15 ^= Integers.rotateLeft(x11 + x07, 18); + + x01 ^= Integers.rotateLeft(x00 + x03, 7); + x02 ^= Integers.rotateLeft(x01 + x00, 9); + x03 ^= Integers.rotateLeft(x02 + x01, 13); + x00 ^= Integers.rotateLeft(x03 + x02, 18); + x06 ^= Integers.rotateLeft(x05 + x04, 7); + x07 ^= Integers.rotateLeft(x06 + x05, 9); + x04 ^= Integers.rotateLeft(x07 + x06, 13); + x05 ^= Integers.rotateLeft(x04 + x07, 18); + x11 ^= Integers.rotateLeft(x10 + x09, 7); + x08 ^= Integers.rotateLeft(x11 + x10, 9); + x09 ^= Integers.rotateLeft(x08 + x11, 13); + x10 ^= Integers.rotateLeft(x09 + x08, 18); + x12 ^= Integers.rotateLeft(x15 + x14, 7); + x13 ^= Integers.rotateLeft(x12 + x15, 9); + x14 ^= Integers.rotateLeft(x13 + x12, 13); + x15 ^= Integers.rotateLeft(x14 + x13, 18); } x[ 0] = x00 + input[ 0]; @@ -490,19 +491,6 @@ public class Salsa20Engine x[15] = x15 + input[15]; } - /** - * Rotate left - * - * @param x value to rotate - * @param y amount to rotate x - * - * @return rotated x - */ - protected static int rotl(int x, int y) - { - return (x << y) | (x >>> -y); - } - private void resetLimitCounter() { cW0 = 0; diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/package.html deleted file mode 100644 index e945dac00..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/engines/package.html +++ /dev/null @@ -1,5 +0,0 @@ - -
-Basic cipher classes. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/examples/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/examples/package.html deleted file mode 100644 index 390a54009..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/examples/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Simple examples of light weight API usage. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/Argon2BytesGenerator.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/Argon2BytesGenerator.java index 1913b6706..3cc9b3b87 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/Argon2BytesGenerator.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/Argon2BytesGenerator.java @@ -4,16 +4,14 @@ import com.fr.third.org.bouncycastle.crypto.Digest; import com.fr.third.org.bouncycastle.crypto.digests.Blake2bDigest; import com.fr.third.org.bouncycastle.crypto.params.Argon2Parameters; import com.fr.third.org.bouncycastle.util.Arrays; +import com.fr.third.org.bouncycastle.util.Longs; import com.fr.third.org.bouncycastle.util.Pack; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - /** * Argon2 PBKDF - Based on the results of https://password-hashing.net/ and https://www.ietf.org/archive/id/draft-irtf-cfrg-argon2-03.txt */ public class Argon2BytesGenerator { - private static final int ARGON2_BLOCK_SIZE = 1024; private static final int ARGON2_QWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 8; @@ -34,20 +32,17 @@ public class Argon2BytesGenerator /* Minimum and maximum number of passes */ private static final int MIN_ITERATIONS = 1; - private Block[] memory; + private static final long M32L = 0xFFFFFFFFL; + private static final byte[] ZERO_BYTES = new byte[4]; + private Argon2Parameters parameters; + private Block[] memory; private int segmentLength; private int laneLength; - - private Argon2Parameters parameters; - - private byte[] result; - public Argon2BytesGenerator() { - } /** @@ -59,7 +54,6 @@ public class Argon2BytesGenerator { this.parameters = parameters; - if (parameters.getLanes() < Argon2BytesGenerator.MIN_PARALLELISM) { throw new IllegalStateException("lanes must be greater than " + Argon2BytesGenerator.MIN_PARALLELISM); @@ -102,11 +96,11 @@ public class Argon2BytesGenerator throw new IllegalStateException("output length less than " + Argon2BytesGenerator.MIN_OUTLEN); } - initialize(password, outLen); - fillMemoryBlocks(); - digest(outLen); + byte[] tmpBlockBytes = new byte[ARGON2_BLOCK_SIZE]; - System.arraycopy(result, 0, out, outOff, outLen); + initialize(tmpBlockBytes, password, outLen); + fillMemoryBlocks(); + digest(tmpBlockBytes, out, outOff, outLen); reset(); @@ -117,14 +111,17 @@ public class Argon2BytesGenerator private void reset() { // Reset memory. - for (int i = 0; i < memory.length; i++) + if (null != memory) { - Block b = memory[i]; - - b.clear(); + for (int i = 0; i < memory.length; i++) + { + Block b = memory[i]; + if (null != b) + { + b.clear(); + } + } } - memory = null; - Arrays.fill(result, (byte)0); } private void doInit(Argon2Parameters parameters) @@ -147,7 +144,6 @@ public class Argon2BytesGenerator initMemory(memoryBlocks); } - private void initMemory(int memoryBlocks) { this.memory = new Block[memoryBlocks]; @@ -162,13 +158,18 @@ public class Argon2BytesGenerator { FillBlock filler = new FillBlock(); Position position = new Position(); - for (int i = 0; i < parameters.getIterations(); i++) + for (int pass = 0; pass < parameters.getIterations(); ++pass) { - for (int j = 0; j < ARGON2_SYNC_POINTS; j++) + position.pass = pass; + + for (int slice = 0; slice < ARGON2_SYNC_POINTS; ++slice) { - for (int k = 0; k < parameters.getLanes(); k++) + position.slice = slice; + + for (int lane = 0; lane < parameters.getLanes(); ++lane) { - position.update(i, k, j, 0); + position.lane = lane; + fillSegment(filler, position); } } @@ -177,8 +178,7 @@ public class Argon2BytesGenerator private void fillSegment(FillBlock filler, Position position) { - - Block addressBlock = null, inputBlock = null, zeroBlock = null; + Block addressBlock = null, inputBlock = null; boolean dataIndependentAddressing = isDataIndependentAddressing(position); int startingIndex = getStartingIndex(position); @@ -188,26 +188,25 @@ public class Argon2BytesGenerator if (dataIndependentAddressing) { addressBlock = filler.addressBlock.clear(); - zeroBlock = filler.zeroBlock.clear(); inputBlock = filler.inputBlock.clear(); - initAddressBlocks(filler, position, zeroBlock, inputBlock, addressBlock); + initAddressBlocks(filler, position, inputBlock, addressBlock); } - for (position.index = startingIndex; position.index < segmentLength; position.index++, currentOffset++, prevOffset++) - { - prevOffset = rotatePrevOffset(currentOffset, prevOffset); + final boolean withXor = isWithXor(position); - long pseudoRandom = getPseudoRandom(filler, position, addressBlock, inputBlock, zeroBlock, prevOffset, dataIndependentAddressing); + for (int index = startingIndex; index < segmentLength; ++index) + { + long pseudoRandom = getPseudoRandom(filler, index, addressBlock, inputBlock, prevOffset, dataIndependentAddressing); int refLane = getRefLane(position, pseudoRandom); - int refColumn = getRefColumn(position, pseudoRandom, refLane == position.lane); + int refColumn = getRefColumn(position, index, pseudoRandom, refLane == position.lane); /* 2 Creating a new block */ Block prevBlock = memory[prevOffset]; Block refBlock = memory[((laneLength) * refLane + refColumn)]; Block currentBlock = memory[currentOffset]; - if (isWithXor(position)) + if (withXor) { filler.fillBlockWithXor(prevBlock, refBlock, currentBlock); } @@ -215,6 +214,9 @@ public class Argon2BytesGenerator { filler.fillBlock(prevBlock, refBlock, currentBlock); } + + prevOffset = currentOffset; + currentOffset++; } } @@ -227,7 +229,7 @@ public class Argon2BytesGenerator ); } - private void initAddressBlocks(FillBlock filler, Position position, Block zeroBlock, Block inputBlock, Block addressBlock) + private void initAddressBlocks(FillBlock filler, Position position, Block inputBlock, Block addressBlock) { inputBlock.v[0] = intToLong(position.pass); inputBlock.v[1] = intToLong(position.lane); @@ -239,7 +241,7 @@ public class Argon2BytesGenerator if ((position.pass == 0) && (position.slice == 0)) { /* Don't forget to generate the first block of addresses: */ - nextAddresses(filler, zeroBlock, inputBlock, addressBlock); + nextAddresses(filler, inputBlock, addressBlock); } } @@ -262,15 +264,6 @@ public class Argon2BytesGenerator } } - private int rotatePrevOffset(int currentOffset, int prevOffset) - { - if (currentOffset % laneLength == 1) - { - prevOffset = currentOffset - 1; - } - return prevOffset; - } - private static int getStartingIndex(Position position) { if ((position.pass == 0) && (position.slice == 0)) @@ -283,24 +276,26 @@ public class Argon2BytesGenerator } } - private void nextAddresses(FillBlock filler, Block zeroBlock, Block inputBlock, Block addressBlock) + private void nextAddresses(FillBlock filler, Block inputBlock, Block addressBlock) { inputBlock.v[6]++; - filler.fillBlock(zeroBlock, inputBlock, addressBlock); - filler.fillBlock(zeroBlock, addressBlock, addressBlock); + filler.fillBlock(inputBlock, addressBlock); + filler.fillBlock(addressBlock, addressBlock); } /* 1.2 Computing the index of the reference block */ /* 1.2.1 Taking pseudo-random value from the previous block */ - private long getPseudoRandom(FillBlock filler, Position position, Block addressBlock, Block inputBlock, Block zeroBlock, int prevOffset, boolean dataIndependentAddressing) + private long getPseudoRandom(FillBlock filler, int index, Block addressBlock, Block inputBlock, int prevOffset, + boolean dataIndependentAddressing) { if (dataIndependentAddressing) { - if (position.index % ARGON2_ADDRESSES_IN_BLOCK == 0) + int addressIndex = index % ARGON2_ADDRESSES_IN_BLOCK; + if (addressIndex == 0) { - nextAddresses(filler, zeroBlock, inputBlock, addressBlock); + nextAddresses(filler, inputBlock, addressBlock); } - return addressBlock.v[position.index % ARGON2_ADDRESSES_IN_BLOCK]; + return addressBlock.v[addressIndex]; } else { @@ -320,10 +315,8 @@ public class Argon2BytesGenerator return refLane; } - private int getRefColumn(Position position, long pseudoRandom, - boolean sameLane) + private int getRefColumn(Position position, int index, long pseudoRandom, boolean sameLane) { - int referenceAreaSize; int startPosition; @@ -334,14 +327,13 @@ public class Argon2BytesGenerator if (sameLane) { /* The same lane => add current segment */ - referenceAreaSize = position.slice * segmentLength + position.index - 1; + referenceAreaSize = position.slice * segmentLength + index - 1; } else { /* pass == 0 && !sameLane => position.slice > 0*/ - referenceAreaSize = position.slice * segmentLength + ((position.index == 0) ? (-1) : 0); + referenceAreaSize = position.slice * segmentLength + ((index == 0) ? (-1) : 0); } - } else { @@ -349,23 +341,22 @@ public class Argon2BytesGenerator if (sameLane) { - referenceAreaSize = laneLength - segmentLength + position.index - 1; + referenceAreaSize = laneLength - segmentLength + index - 1; } else { - referenceAreaSize = laneLength - segmentLength + ((position.index == 0) ? (-1) : 0); + referenceAreaSize = laneLength - segmentLength + ((index == 0) ? (-1) : 0); } } long relativePosition = pseudoRandom & 0xFFFFFFFFL; -// long relativePosition = pseudoRandom << 32 >>> 32; relativePosition = (relativePosition * relativePosition) >>> 32; relativePosition = referenceAreaSize - 1 - ((referenceAreaSize * relativePosition) >>> 32); return (int)(startPosition + relativePosition) % laneLength; } - private void digest(int outputLength) + private void digest(byte[] tmpBlockBytes, byte[] out, int outOff, int outLen) { Block finalBlock = memory[laneLength - 1]; @@ -376,54 +367,28 @@ public class Argon2BytesGenerator finalBlock.xorWith(memory[lastBlockInLane]); } - byte[] finalBlockBytes = finalBlock.toBytes(); + finalBlock.toBytes(tmpBlockBytes); - result = hash(finalBlockBytes, outputLength); - } - - /** - * H0 = H64(p, τ, m, t, v, y, |P|, P, |S|, S, |L|, K, |X|, X) - * -> 64 byte (ARGON2_PREHASH_DIGEST_LENGTH) - */ - private byte[] initialHash(Argon2Parameters parameters, int outputLength, byte[] password) - { - Blake2bDigest blake = new Blake2bDigest(ARGON2_PREHASH_DIGEST_LENGTH * 8); - - addIntToLittleEndian(blake, parameters.getLanes()); - addIntToLittleEndian(blake, outputLength); - addIntToLittleEndian(blake, parameters.getMemory()); - addIntToLittleEndian(blake, parameters.getIterations()); - addIntToLittleEndian(blake, parameters.getVersion()); - addIntToLittleEndian(blake, parameters.getType()); - - addByteString(blake, password); - addByteString(blake, parameters.getSalt()); - addByteString(blake, parameters.getSecret()); - addByteString(blake, parameters.getAdditional()); - - byte[] blake2hash = new byte[blake.getDigestSize()]; - blake.doFinal(blake2hash, 0); - - return blake2hash; + hash(tmpBlockBytes, out, outOff, outLen); } /** * H' - hash - variable length hash function */ - private byte[] hash(byte[] input, int outputLength) + private void hash(byte[] input, byte[] out, int outOff, int outLen) { - byte[] result = new byte[outputLength]; - byte[] outlenBytes = Pack.intToLittleEndian(outputLength); + byte[] outLenBytes = new byte[4]; + Pack.intToLittleEndian(outLen, outLenBytes, 0); int blake2bLength = 64; - if (outputLength <= blake2bLength) + if (outLen <= blake2bLength) { - Blake2bDigest blake = new Blake2bDigest(outputLength * 8); + Blake2bDigest blake = new Blake2bDigest(outLen * 8); - blake.update(outlenBytes, 0, outlenBytes.length); + blake.update(outLenBytes, 0, outLenBytes.length); blake.update(input, 0, input.length); - blake.doFinal(result, 0); + blake.doFinal(out, outOff); } else { @@ -431,35 +396,33 @@ public class Argon2BytesGenerator byte[] outBuffer = new byte[blake2bLength]; /* V1 */ - digest.update(outlenBytes, 0, outlenBytes.length); + digest.update(outLenBytes, 0, outLenBytes.length); digest.update(input, 0, input.length); digest.doFinal(outBuffer, 0); - System.arraycopy(outBuffer, 0, result, 0, blake2bLength / 2); - - int r = ((outputLength + 31) / 32) - 2; + int halfLen = blake2bLength / 2, outPos = outOff; + System.arraycopy(outBuffer, 0, out, outPos, halfLen); + outPos += halfLen; - int position = blake2bLength / 2; + int r = ((outLen + 31) / 32) - 2; - for (int i = 2; i <= r; i++, position += blake2bLength / 2) + for (int i = 2; i <= r; i++, outPos += halfLen) { /* V2 to Vr */ digest.update(outBuffer, 0, outBuffer.length); digest.doFinal(outBuffer, 0); - System.arraycopy(outBuffer, 0, result, position, blake2bLength / 2); + System.arraycopy(outBuffer, 0, out, outPos, halfLen); } - int lastLength = outputLength - 32 * r; + int lastLength = outLen - 32 * r; /* Vr+1 */ digest = new Blake2bDigest(lastLength * 8); digest.update(outBuffer, 0, outBuffer.length); - digest.doFinal(result, position); + digest.doFinal(out, outPos); } - - return result; } private static void roundFunction(Block block, @@ -468,117 +431,124 @@ public class Argon2BytesGenerator int v8, int v9, int v10, int v11, int v12, int v13, int v14, int v15) { + final long[] v = block.v; - F(block, v0, v4, v8, v12); - F(block, v1, v5, v9, v13); - F(block, v2, v6, v10, v14); - F(block, v3, v7, v11, v15); + F(v, v0, v4, v8, v12); + F(v, v1, v5, v9, v13); + F(v, v2, v6, v10, v14); + F(v, v3, v7, v11, v15); - F(block, v0, v5, v10, v15); - F(block, v1, v6, v11, v12); - F(block, v2, v7, v8, v13); - F(block, v3, v4, v9, v14); + F(v, v0, v5, v10, v15); + F(v, v1, v6, v11, v12); + F(v, v2, v7, v8, v13); + F(v, v3, v4, v9, v14); } - private static void F(Block block, int a, int b, int c, int d) + private static void F(long[] v, int a, int b, int c, int d) { - fBlaMka(block, a, b); - rotr64(block, d, a, 32); + quarterRound(v, a, b, d, 32); + quarterRound(v, c, d, b, 24); + quarterRound(v, a, b, d, 16); + quarterRound(v, c, d, b, 63); + } - fBlaMka(block, c, d); - rotr64(block, b, c, 24); + private static void quarterRound(long[] v, int x, int y, int z, int s) + { +// fBlaMka(v, x, y); +// rotr64(v, z, x, s); + + long a = v[x], b = v[y], c = v[z]; - fBlaMka(block, a, b); - rotr64(block, d, a, 16); + a += b + 2 * (a & M32L) * (b & M32L); + c = Longs.rotateRight(c ^ a, s); - fBlaMka(block, c, d); - rotr64(block, b, c, 63); + v[x] = a; + v[z] = c; } /*designed by the Lyra PHC team */ /* a <- a + b + 2*aL*bL * + == addition modulo 2^64 * aL = least 32 bit */ - private static void fBlaMka(Block block, int x, int y) - { - final long m = 0xFFFFFFFFL; - final long xy = (block.v[x] & m) * (block.v[y] & m); +// private static void fBlaMka(long[] v, int x, int y) +// { +// final long a = v[x], b = v[y]; +// final long ab = (a & M32L) * (b & M32L); +// +// v[x] = a + b + 2 * ab; +// } +// +// private static void rotr64(long[] v, int x, int y, int s) +// { +// v[x] = Longs.rotateRight(v[x] ^ v[y], s); +// } + + private void initialize(byte[] tmpBlockBytes, byte[] password, int outputLength) + { + /** + * H0 = H64(p, τ, m, t, v, y, |P|, P, |S|, S, |L|, K, |X|, X) + * -> 64 byte (ARGON2_PREHASH_DIGEST_LENGTH) + */ - block.v[x] = block.v[x] + block.v[y] + 2 * xy; - } + Blake2bDigest blake = new Blake2bDigest(ARGON2_PREHASH_DIGEST_LENGTH * 8); - private static void rotr64(Block block, int v, int w, long c) - { - final long temp = block.v[v] ^ block.v[w]; - block.v[v] = (temp >>> c) | (temp << (64 - c)); - } + int[] values = { parameters.getLanes(), outputLength, parameters.getMemory(), parameters.getIterations(), + parameters.getVersion(), parameters.getType() }; - private void initialize(byte[] password, int outputLength) - { - byte[] initialHash = initialHash(parameters, outputLength, password); + Pack.intToLittleEndian(values, tmpBlockBytes, 0); + blake.update(tmpBlockBytes, 0, values.length * 4); - fillFirstBlocks(initialHash); - } + addByteString(tmpBlockBytes, blake, password); + addByteString(tmpBlockBytes, blake, parameters.getSalt()); + addByteString(tmpBlockBytes, blake, parameters.getSecret()); + addByteString(tmpBlockBytes, blake, parameters.getAdditional()); - private static void addIntToLittleEndian(Digest digest, int n) - { - digest.update((byte)(n)); - digest.update((byte)(n >>> 8)); - digest.update((byte)(n >>> 16)); - digest.update((byte)(n >>> 24)); + byte[] initialHashWithZeros = new byte[ARGON2_PREHASH_SEED_LENGTH]; + blake.doFinal(initialHashWithZeros, 0); + + fillFirstBlocks(tmpBlockBytes, initialHashWithZeros); } - private static void addByteString(Digest digest, byte[] octets) + private static void addByteString(byte[] tmpBlockBytes, Digest digest, byte[] octets) { - if (octets != null) + if (null == octets) { - addIntToLittleEndian(digest, octets.length); - digest.update(octets, 0, octets.length); - } - else - { - addIntToLittleEndian(digest, 0); + digest.update(ZERO_BYTES, 0, 4); + return; } + + Pack.intToLittleEndian(octets.length, tmpBlockBytes, 0); + digest.update(tmpBlockBytes, 0, 4); + digest.update(octets, 0, octets.length); } /** * (H0 || 0 || i) 72 byte -> 1024 byte * (H0 || 1 || i) 72 byte -> 1024 byte */ - private void fillFirstBlocks(byte[] initialHash) + private void fillFirstBlocks(byte[] tmpBlockBytes, byte[] initialHashWithZeros) { - final byte[] zeroBytes = {0, 0, 0, 0}; - final byte[] oneBytes = {1, 0, 0, 0}; - - byte[] initialHashWithZeros = getInitialHashLong(initialHash, zeroBytes); - byte[] initialHashWithOnes = getInitialHashLong(initialHash, oneBytes); + byte[] initialHashWithOnes = new byte[ARGON2_PREHASH_SEED_LENGTH]; + System.arraycopy(initialHashWithZeros, 0, initialHashWithOnes, 0, ARGON2_PREHASH_DIGEST_LENGTH); +// Pack.intToLittleEndian(1, initialHashWithOnes, ARGON2_PREHASH_DIGEST_LENGTH); + initialHashWithOnes[ARGON2_PREHASH_DIGEST_LENGTH] = 1; for (int i = 0; i < parameters.getLanes(); i++) { Pack.intToLittleEndian(i, initialHashWithZeros, ARGON2_PREHASH_DIGEST_LENGTH + 4); Pack.intToLittleEndian(i, initialHashWithOnes, ARGON2_PREHASH_DIGEST_LENGTH + 4); - byte[] blockhashBytes = hash(initialHashWithZeros, ARGON2_BLOCK_SIZE); - memory[i * laneLength + 0].fromBytes(blockhashBytes); + hash(initialHashWithZeros, tmpBlockBytes, 0, ARGON2_BLOCK_SIZE); + memory[i * laneLength + 0].fromBytes(tmpBlockBytes); - blockhashBytes = hash(initialHashWithOnes, ARGON2_BLOCK_SIZE); - memory[i * laneLength + 1].fromBytes(blockhashBytes); + hash(initialHashWithOnes, tmpBlockBytes, 0, ARGON2_BLOCK_SIZE); + memory[i * laneLength + 1].fromBytes(tmpBlockBytes); } } - private byte[] getInitialHashLong(byte[] initialHash, byte[] appendix) - { - byte[] initialHashLong = new byte[ARGON2_PREHASH_SEED_LENGTH]; - - System.arraycopy(initialHash, 0, initialHashLong, 0, ARGON2_PREHASH_DIGEST_LENGTH); - System.arraycopy(appendix, 0, initialHashLong, ARGON2_PREHASH_DIGEST_LENGTH, 4); - - return initialHashLong; - } - private long intToLong(int x) { - return (long)(x & 0xffffffffL); + return (long)(x & M32L); } private static class FillBlock @@ -587,7 +557,6 @@ public class Argon2BytesGenerator Block Z = new Block(); Block addressBlock = new Block(); - Block zeroBlock = new Block(); Block inputBlock = new Block(); private void applyBlake() @@ -625,16 +594,16 @@ public class Argon2BytesGenerator } } + private void fillBlock(Block Y, Block currentBlock) + { + Z.copyBlock(Y); + applyBlake(); + currentBlock.xor(Y, Z); + } + private void fillBlock(Block X, Block Y, Block currentBlock) { - if (X == zeroBlock) - { - R.copyBlock(Y); - } - else - { - R.xor(X, Y); - } + R.xor(X, Y); Z.copyBlock(R); applyBlake(); currentBlock.xor(R, Z); @@ -645,7 +614,7 @@ public class Argon2BytesGenerator R.xor(X, Y); Z.copyBlock(R); applyBlake(); - currentBlock.xor(R, Z, currentBlock); + currentBlock.xorWith(R, Z); } } @@ -663,27 +632,22 @@ public class Argon2BytesGenerator void fromBytes(byte[] input) { - if (input.length != ARGON2_BLOCK_SIZE) + if (input.length < ARGON2_BLOCK_SIZE) { throw new IllegalArgumentException("input shorter than blocksize"); } - for (int i = 0; i < SIZE; i++) - { - v[i] = Pack.littleEndianToLong(input, i * 8); - } + Pack.littleEndianToLong(input, 0, v); } - byte[] toBytes() + void toBytes(byte[] output) { - byte[] result = new byte[ARGON2_BLOCK_SIZE]; - - for (int i = 0; i < SIZE; i++) + if (output.length < ARGON2_BLOCK_SIZE) { - Pack.longToLittleEndian(v[i], result, i * 8); + throw new IllegalArgumentException("output shorter than blocksize"); } - return result; + Pack.longToLittleEndian(v, output, 0); } private void copyBlock(Block other) @@ -693,37 +657,29 @@ public class Argon2BytesGenerator private void xor(Block b1, Block b2) { + long[] v0 = v, v1 = b1.v, v2 = b2.v; for (int i = 0; i < SIZE; i++) { - v[i] = b1.v[i] ^ b2.v[i]; + v0[i] = v1[i] ^ v2[i]; } } - public void xor(Block b1, Block b2, Block b3) + private void xorWith(Block b1) { + long[] v0 = v, v1 = b1.v; for (int i = 0; i < SIZE; i++) { - v[i] = b1.v[i] ^ b2.v[i] ^ b3.v[i]; - } - } - - private void xorWith(Block other) - { - for (int i = 0; i < v.length; i++) - { - v[i] = v[i] ^ other.v[i]; + v0[i] ^= v1[i]; } } - public String toString() + private void xorWith(Block b1, Block b2) { - StringBuffer result = new StringBuffer(); + long[] v0 = v, v1 = b1.v, v2 = b2.v; for (int i = 0; i < SIZE; i++) { - result.append(Hex.toHexString(Pack.longToLittleEndian(v[i]))); + v0[i] ^= v1[i] ^ v2[i]; } - - return result.toString(); } public Block clear() @@ -738,19 +694,9 @@ public class Argon2BytesGenerator int pass; int lane; int slice; - int index; Position() { - - } - - void update(int pass, int lane, int slice, int index) - { - this.pass = pass; - this.lane = lane; - this.slice = slice; - this.index = index; } } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/BCrypt.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/BCrypt.java index 66609fedf..17f6c36bf 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/BCrypt.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/BCrypt.java @@ -368,7 +368,7 @@ public final class BCrypt xr ^= P[ROUNDS + 1]; table[s] = xr; - table[s + 1] = xl; + table[s + 1] = xl; // lgtm [java/index-out-of-bounds] xr = xl; // end of cycle swap xl = table[s]; @@ -489,8 +489,9 @@ public final class BCrypt } xr ^= P[ROUNDS + 1]; + // suppress LGTM warnings index-out-of-bounds since the loop increments s by 4 table[s] = xr; - table[s + 1] = xl; + table[s + 1] = xl; // lgtm [java/index-out-of-bounds] yl = salt32Bit[2] ^ xr; yr = salt32Bit[3] ^ xl; @@ -508,8 +509,8 @@ public final class BCrypt } yr ^= P[ROUNDS + 1]; - table[s + 2] = yr; - table[s + 3] = yl; + table[s + 2] = yr; // lgtm [java/index-out-of-bounds] + table[s + 3] = yl; // lgtm [java/index-out-of-bounds] xl = salt32Bit[0] ^ yr; xr = salt32Bit[1] ^ yl; @@ -614,28 +615,29 @@ public final class BCrypt } /** - * Calculates the bcrypt hash of a password. + * Calculates the bcrypt hash of an input - note for processing general passwords you want to + * make sure the password is terminated in a manner similar to what is done by passwordToByteArray(). ** This implements the raw bcrypt function as defined in the bcrypt specification, not * the crypt encoded version implemented in OpenBSD. *
- * @param password the password bytes (up to 72 bytes) to use for this invocation. + * @param pwInput the password bytes (up to 72 bytes) to use for this invocation. * @param salt the 128 bit salt to use for this invocation. * @param cost the bcrypt cost parameter. The cost of the bcrypt function grows as *2^cost
. Legal values are 4..31 inclusive. * @return the output of the raw bcrypt operation: a 192 bit (24 byte) hash. */ - public static byte[] generate(byte[] password, byte[] salt, int cost) + public static byte[] generate(byte[] pwInput, byte[] salt, int cost) { - if (password == null || salt == null) + if (pwInput == null || salt == null) { - throw new IllegalArgumentException("Password and salt are required"); + throw new IllegalArgumentException("pwInput and salt are required"); } if (salt.length != SALT_SIZE_BYTES) { throw new IllegalArgumentException("BCrypt salt must be 128 bits"); } - if (password.length > MAX_PASSWORD_BYTES) + if (pwInput.length > MAX_PASSWORD_BYTES) { throw new IllegalArgumentException("BCrypt password must be <= 72 bytes"); } @@ -644,6 +646,6 @@ public final class BCrypt throw new IllegalArgumentException("BCrypt cost must be from 4..31"); } - return new BCrypt().deriveRawKey(cost, salt, password); + return new BCrypt().deriveRawKey(cost, salt, pwInput); } } \ No newline at end of file diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/ECKeyPairGenerator.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/ECKeyPairGenerator.java index 0acace5b5..589bb92f6 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/ECKeyPairGenerator.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/ECKeyPairGenerator.java @@ -5,7 +5,6 @@ import java.security.SecureRandom; import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.CryptoServicesRegistrar; import com.fr.third.org.bouncycastle.crypto.KeyGenerationParameters; import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; @@ -31,11 +30,6 @@ public class ECKeyPairGenerator this.random = ecP.getRandom(); this.params = ecP.getDomainParameters(); - - if (this.random == null) - { - this.random = CryptoServicesRegistrar.getSecureRandom(); - } } /** diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/OpenBSDBCrypt.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/OpenBSDBCrypt.java index 01e16e4c6..9c74d792b 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/OpenBSDBCrypt.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/OpenBSDBCrypt.java @@ -40,6 +40,8 @@ public class OpenBSDBCrypt static { // Presently just the Bcrypt versions. + allowedVersions.add("2"); + allowedVersions.add("2x"); allowedVersions.add("2a"); allowedVersions.add("2y"); allowedVersions.add("2b"); @@ -55,64 +57,94 @@ public class OpenBSDBCrypt } } - public OpenBSDBCrypt() + private OpenBSDBCrypt() { } + /** + * Creates a 60 character Bcrypt String, including + * version, cost factor, salt and hash, separated by '$' using version + * '2y'. + * + * @param cost the cost factor, treated as an exponent of 2 + * @param salt a 16 byte salt + * @param password the password + * @return a 60 character Bcrypt String + */ + public static String generate( + char[] password, + byte[] salt, + int cost) + { + return generate(defaultVersion, password, salt, cost); + } + + /** + * Creates a 60 character Bcrypt String, including + * version, cost factor, salt and hash, separated by '$' using version + * '2y'. + * + * @param cost the cost factor, treated as an exponent of 2 + * @param salt a 16 byte salt + * @param password the password + * @return a 60 character Bcrypt String + */ + public static String generate( + byte[] password, + byte[] salt, + int cost) + { + return generate(defaultVersion, password, salt, cost); + } + /** * Creates a 60 character Bcrypt String, including * version, cost factor, salt and hash, separated by '$' * - * @param version the version, 2y,2b or 2a. (2a is not backwards compatible.) + * @param version the version, may be 2b, 2y or 2a. (2a is not backwards compatible.) * @param cost the cost factor, treated as an exponent of 2 * @param salt a 16 byte salt * @param password the password * @return a 60 character Bcrypt String */ - private static String createBcryptString(String version, - byte[] password, - byte[] salt, - int cost) + public static String generate( + String version, + char[] password, + byte[] salt, + int cost) { - if (!allowedVersions.contains(version)) + if (password == null) { - throw new IllegalArgumentException("Version " + version + " is not accepted by this implementation."); + throw new IllegalArgumentException("Password required."); } - StringBuffer sb = new StringBuffer(60); - sb.append('$'); - sb.append(version); - sb.append('$'); - sb.append(cost < 10 ? ("0" + cost) : Integer.toString(cost)); - sb.append('$'); - sb.append(encodeData(salt)); - - byte[] key = BCrypt.generate(password, salt, cost); - - sb.append(encodeData(key)); - - return sb.toString(); + return doGenerate(version, Strings.toUTF8ByteArray(password), salt, cost); } /** * Creates a 60 character Bcrypt String, including - * version, cost factor, salt and hash, separated by '$' using version - * '2y'. + * version, cost factor, salt and hash, separated by '$' * + * @param version the version, may be 2b, 2y or 2a. (2a is not backwards compatible.) * @param cost the cost factor, treated as an exponent of 2 * @param salt a 16 byte salt - * @param password the password + * @param password the password already encoded as a byte array. * @return a 60 character Bcrypt String */ public static String generate( - char[] password, + String version, + byte[] password, byte[] salt, int cost) { - return generate(defaultVersion, password, salt, cost); - } + if (password == null) + { + throw new IllegalArgumentException("Password required."); + } + return doGenerate(version, Arrays.clone(password), salt, cost); + } /** * Creates a 60 character Bcrypt String, including @@ -121,12 +153,12 @@ public class OpenBSDBCrypt * @param version the version, may be 2b, 2y or 2a. (2a is not backwards compatible.) * @param cost the cost factor, treated as an exponent of 2 * @param salt a 16 byte salt - * @param password the password + * @param psw the password * @return a 60 character Bcrypt String */ - public static String generate( + private static String doGenerate( String version, - char[] password, + byte[] psw, byte[] salt, int cost) { @@ -135,10 +167,6 @@ public class OpenBSDBCrypt throw new IllegalArgumentException("Version " + version + " is not accepted by this implementation."); } - if (password == null) - { - throw new IllegalArgumentException("Password required."); - } if (salt == null) { throw new IllegalArgumentException("Salt required."); @@ -152,8 +180,6 @@ public class OpenBSDBCrypt throw new IllegalArgumentException("Invalid cost factor."); } - byte[] psw = Strings.toUTF8ByteArray(password); - // 0 termination: byte[] tmp = new byte[psw.length >= 72 ? 72 : psw.length + 1]; @@ -190,21 +216,97 @@ public class OpenBSDBCrypt String bcryptString, char[] password) { + if (password == null) + { + throw new IllegalArgumentException("Missing password."); + } + + return doCheckPassword(bcryptString, Strings.toUTF8ByteArray(password)); + } + + /** + * Checks if a password corresponds to a 60 character Bcrypt String + * + * @param bcryptString a 60 character Bcrypt String, including + * version, cost factor, salt and hash, + * separated by '$' + * @param password the password as an array of bytes + * @return true if the password corresponds to the + * Bcrypt String, otherwise false + */ + public static boolean checkPassword( + String bcryptString, + byte[] password) + { + if (password == null) + { + throw new IllegalArgumentException("Missing password."); + } + + return doCheckPassword(bcryptString, Arrays.clone(password)); + } + + /** + * Checks if a password corresponds to a 60 character Bcrypt String + * + * @param bcryptString a 60 character Bcrypt String, including + * version, cost factor, salt and hash, + * separated by '$' + * @param password the password as an array of chars + * @return true if the password corresponds to the + * Bcrypt String, otherwise false + */ + private static boolean doCheckPassword( + String bcryptString, + byte[] password) + { + if (bcryptString == null) + { + throw new IllegalArgumentException("Missing bcryptString."); + } + + if (bcryptString.charAt(1) != '2') // check for actual Bcrypt type. + { + throw new IllegalArgumentException("not a Bcrypt string"); + } + // validate bcryptString: - if (bcryptString.length() != 60) + final int sLength = bcryptString.length(); + if (sLength != 60 && !(sLength == 59 && bcryptString.charAt(2) == '$')) // check for $2$ { - throw new DataLengthException("Bcrypt String length: " - + bcryptString.length() + ", 60 required."); + throw new DataLengthException("Bcrypt String length: " + sLength + ", 60 required."); } - if (bcryptString.charAt(0) != '$' - || bcryptString.charAt(3) != '$' - || bcryptString.charAt(6) != '$') + if (bcryptString.charAt(2) == '$') + { + if (bcryptString.charAt(0) != '$' + || bcryptString.charAt(5) != '$') + { + throw new IllegalArgumentException("Invalid Bcrypt String format."); + } + } + else { - throw new IllegalArgumentException("Invalid Bcrypt String format."); + if (bcryptString.charAt(0) != '$' + || bcryptString.charAt(3) != '$' + || bcryptString.charAt(6) != '$') + { + throw new IllegalArgumentException("Invalid Bcrypt String format."); + } } - String version = bcryptString.substring(1, 3); + String version; + int base; + if (bcryptString.charAt(2) == '$') + { + version = bcryptString.substring(1, 2); + base = 3; + } + else + { + version = bcryptString.substring(1, 3); + base = 4; + } if (!allowedVersions.contains(version)) { @@ -212,7 +314,7 @@ public class OpenBSDBCrypt } int cost = 0; - String costStr = bcryptString.substring(4, 6); + String costStr = bcryptString.substring(base, base + 2); try { cost = Integer.parseInt(costStr); @@ -226,17 +328,53 @@ public class OpenBSDBCrypt throw new IllegalArgumentException("Invalid cost factor: " + cost + ", 4 < cost < 31 expected."); } // check password: - if (password == null) - { - throw new IllegalArgumentException("Missing password."); - } byte[] salt = decodeSaltString( bcryptString.substring(bcryptString.lastIndexOf('$') + 1, - bcryptString.length() - 31)); + sLength - 31)); + + String newBcryptString = doGenerate(version, password, salt, cost); + + boolean isEqual = sLength == newBcryptString.length(); + for (int i = 0; i != sLength; i++) + { + isEqual &= (bcryptString.charAt(i) == newBcryptString.charAt(i)); + } + return isEqual; + } + + /** + * Creates a 60 character Bcrypt String, including + * version, cost factor, salt and hash, separated by '$' + * + * @param version the version, 2y,2b or 2a. (2a is not backwards compatible.) + * @param cost the cost factor, treated as an exponent of 2 + * @param salt a 16 byte salt + * @param password the password + * @return a 60 character Bcrypt String + */ + private static String createBcryptString(String version, + byte[] password, + byte[] salt, + int cost) + { + if (!allowedVersions.contains(version)) + { + throw new IllegalArgumentException("Version " + version + " is not accepted by this implementation."); + } + + StringBuilder sb = new StringBuilder(60); + sb.append('$'); + sb.append(version); + sb.append('$'); + sb.append(cost < 10 ? ("0" + cost) : Integer.toString(cost)); + sb.append('$'); + encodeData(sb, salt); - String newBcryptString = generate(version, password, salt, cost); + byte[] key = BCrypt.generate(password, salt, cost); + + encodeData(sb, key); - return bcryptString.equals(newBcryptString); + return sb.toString(); } /* @@ -245,9 +383,9 @@ public class OpenBSDBCrypt * @param a byte representation of the salt or the password * @return the Bcrypt base64 String */ - private static String encodeData( + private static void encodeData( + StringBuilder sb, byte[] data) - { if (data.length != 24 && data.length != 16) // 192 bit key or 128 bit salt expected { @@ -266,7 +404,6 @@ public class OpenBSDBCrypt data[data.length - 1] = (byte)0; } - ByteArrayOutputStream out = new ByteArrayOutputStream(); int len = data.length; int a1, a2, a3; @@ -274,27 +411,25 @@ public class OpenBSDBCrypt for (i = 0; i < len; i += 3) { a1 = data[i] & 0xff; - a2 = data[i + 1] & 0xff; - a3 = data[i + 2] & 0xff; + a2 = data[i + 1] & 0xff; // lgtm [java/index-out-of-bounds] + a3 = data[i + 2] & 0xff; // lgtm [java/index-out-of-bounds] - out.write(encodingTable[(a1 >>> 2) & 0x3f]); - out.write(encodingTable[((a1 << 4) | (a2 >>> 4)) & 0x3f]); - out.write(encodingTable[((a2 << 2) | (a3 >>> 6)) & 0x3f]); - out.write(encodingTable[a3 & 0x3f]); + sb.append((char)encodingTable[(a1 >>> 2) & 0x3f]); + sb.append((char)encodingTable[((a1 << 4) | (a2 >>> 4)) & 0x3f]); + sb.append((char)encodingTable[((a2 << 2) | (a3 >>> 6)) & 0x3f]); + sb.append((char)encodingTable[a3 & 0x3f]); } - String result = Strings.fromByteArray(out.toByteArray()); if (salt == true)// truncate padding { - return result.substring(0, 22); + sb.setLength(sb.length() - 2); } else { - return result.substring(0, result.length() - 1); + sb.setLength(sb.length() -1); } } - /* * decodes the bcrypt base 64 encoded SaltString * @@ -337,10 +472,11 @@ public class OpenBSDBCrypt for (int i = 0; i < len; i += 4) { + // suppress LGTM warnings index-out-of-bounds since the loop increments i by 4 b1 = decodingTable[saltChars[i]]; - b2 = decodingTable[saltChars[i + 1]]; - b3 = decodingTable[saltChars[i + 2]]; - b4 = decodingTable[saltChars[i + 3]]; + b2 = decodingTable[saltChars[i + 1]]; // lgtm [java/index-out-of-bounds] + b3 = decodingTable[saltChars[i + 2]]; // lgtm [java/index-out-of-bounds] + b4 = decodingTable[saltChars[i + 3]]; // lgtm [java/index-out-of-bounds] out.write((b1 << 2) | (b2 >> 4)); out.write((b2 << 4) | (b3 >> 2)); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/RSAKeyPairGenerator.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/RSAKeyPairGenerator.java index eef20b112..58594cb19 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/RSAKeyPairGenerator.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/RSAKeyPairGenerator.java @@ -139,7 +139,7 @@ public class RSAKeyPairGenerator dP = d.remainder(pSub1); dQ = d.remainder(qSub1); - qInv = q.modInverse(p); + qInv = BigIntegers.modOddInverse(p, q); result = new AsymmetricCipherKeyPair( new RSAKeyParameters(false, n, e), diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/SCrypt.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/SCrypt.java index 8b23c8dcd..2e2eee451 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/SCrypt.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/SCrypt.java @@ -5,6 +5,7 @@ import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; import com.fr.third.org.bouncycastle.crypto.engines.Salsa20Engine; import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; import com.fr.third.org.bouncycastle.util.Arrays; +import com.fr.third.org.bouncycastle.util.Integers; import com.fr.third.org.bouncycastle.util.Pack; /** @@ -83,11 +84,22 @@ public class SCrypt Pack.littleEndianToInt(bytes, 0, B); + /* + * Chunk memory allocations; We choose 'd' so that there will be 2**d chunks, each not + * larger than 32KiB, except that the minimum chunk size is 2 * r * 32. + */ + int d = 0, total = N * r; + while ((N - d) > 2 && total > (1 << 10)) + { + ++d; + total >>>= 1; + } + int MFLenWords = MFLenBytes >>> 2; for (int BOff = 0; BOff < BLen; BOff += MFLenWords) { // TODO These can be done in parallel threads - SMix(B, BOff, N, r); + SMix(B, BOff, N, d, r); } Pack.intToLittleEndian(B, bytes, 0); @@ -109,8 +121,12 @@ public class SCrypt return key.getKey(); } - private static void SMix(int[] B, int BOff, int N, int r) + private static void SMix(int[] B, int BOff, int N, int d, int r) { + int powN = Integers.numberOfTrailingZeros(N); + int blocksPerChunk = N >>> d; + int chunkCount = 1 << d, chunkMask = blocksPerChunk - 1, chunkPow = powN - d; + int BCount = r * 32; int[] blockX1 = new int[16]; @@ -118,28 +134,36 @@ public class SCrypt int[] blockY = new int[BCount]; int[] X = new int[BCount]; - int[] V = new int[N * BCount]; + int[][] VV = new int[chunkCount][]; try { System.arraycopy(B, BOff, X, 0, BCount); - int off = 0; - for (int i = 0; i < N; i += 2) + for (int c = 0; c < chunkCount; ++c) { - System.arraycopy(X, 0, V, off, BCount); - off += BCount; - BlockMix(X, blockX1, blockX2, blockY, r); - System.arraycopy(blockY, 0, V, off, BCount); - off += BCount; - BlockMix(blockY, blockX1, blockX2, X, r); + int[] V = new int[blocksPerChunk * BCount]; + VV[c] = V; + + int off = 0; + for (int i = 0; i < blocksPerChunk; i += 2) + { + System.arraycopy(X, 0, V, off, BCount); + off += BCount; + BlockMix(X, blockX1, blockX2, blockY, r); + System.arraycopy(blockY, 0, V, off, BCount); + off += BCount; + BlockMix(blockY, blockX1, blockX2, X, r); + } } int mask = N - 1; for (int i = 0; i < N; ++i) { int j = X[BCount - 16] & mask; - System.arraycopy(V, j * BCount, blockY, 0, BCount); + int[] V = VV[j >>> chunkPow]; + int VOff = (j & chunkMask) * BCount; + System.arraycopy(V, VOff, blockY, 0, BCount); Xor(blockY, X, 0, blockY); BlockMix(blockY, blockX1, blockX2, X, r); } @@ -148,7 +172,7 @@ public class SCrypt } finally { - Clear(V); + ClearAll(VV); ClearAll(new int[][]{X, blockX1, blockX2, blockY}); } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/package.html deleted file mode 100644 index 9d73ce3e8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/generators/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Generators for keys, key pairs and password based encryption algorithms. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/io/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/io/package.html deleted file mode 100644 index f2c9e406e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/io/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Classes for doing "enhanced" I/O with Digests and MACs. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/kems/ECIESKeyEncapsulation.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/kems/ECIESKeyEncapsulation.java index 40923aec2..45ecc1e82 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/kems/ECIESKeyEncapsulation.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/kems/ECIESKeyEncapsulation.java @@ -205,7 +205,7 @@ public class ECIESKeyEncapsulation BigInteger xHat = ecPrivKey.getD(); if (CofactorMode) { - xHat = xHat.multiply(h.modInverse(n)).mod(n); + xHat = xHat.multiply(ecParams.getHInv()).mod(n); } ECPoint hTilde = gHat.multiply(xHat).normalize(); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/kems/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/kems/package.html deleted file mode 100644 index 88fddd0e7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/kems/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Key Encapsulation Mechanisms. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/macs/KMAC.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/macs/KMAC.java new file mode 100644 index 000000000..66a98b672 --- /dev/null +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/macs/KMAC.java @@ -0,0 +1,204 @@ +package com.fr.third.org.bouncycastle.crypto.macs; + +import com.fr.third.org.bouncycastle.crypto.CipherParameters; +import com.fr.third.org.bouncycastle.crypto.DataLengthException; +import com.fr.third.org.bouncycastle.crypto.Mac; +import com.fr.third.org.bouncycastle.crypto.Xof; +import com.fr.third.org.bouncycastle.crypto.digests.CSHAKEDigest; +import com.fr.third.org.bouncycastle.crypto.digests.XofUtils; +import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; +import com.fr.third.org.bouncycastle.util.Arrays; +import com.fr.third.org.bouncycastle.util.Strings; + +/** + * KMAC - MAC with optional XOF mode. + *+ * From NIST Special Publication 800-185 - SHA-3 Derived Functions:cSHAKE, KMAC, TupleHash and ParallelHash + *
+ */ +public class KMAC + implements Mac, Xof +{ + private static final byte[] padding = new byte[100]; + + private final CSHAKEDigest cshake; + private final int bitLength; + private final int outputLength; + + private byte[] key; + private boolean initialised; + private boolean firstOutput; + + /** + * Base constructor. + * + * @param bitLength bit length of the underlying SHAKE function, 128 or 256. + * @param S the customization string - available for local use. + */ + public KMAC(int bitLength, byte[] S) + { + this.cshake = new CSHAKEDigest(bitLength, Strings.toByteArray("KMAC"), S); + this.bitLength = bitLength; + this.outputLength = bitLength * 2 / 8; + } + + public void init(CipherParameters params) + throws IllegalArgumentException + { + KeyParameter kParam = (KeyParameter)params; + + this.key = Arrays.clone(kParam.getKey()); + this.initialised = true; + + reset(); + } + + public String getAlgorithmName() + { + return "KMAC" + cshake.getAlgorithmName().substring(6); + } + + public int getByteLength() + { + return cshake.getByteLength(); + } + + public int getMacSize() + { + return outputLength; + } + + public int getDigestSize() + { + return outputLength; + } + + public void update(byte in) + throws IllegalStateException + { + if (!initialised) + { + throw new IllegalStateException("KMAC not initialized"); + } + + cshake.update(in); + } + + public void update(byte[] in, int inOff, int len) + throws DataLengthException, IllegalStateException + { + if (!initialised) + { + throw new IllegalStateException("KMAC not initialized"); + } + + cshake.update(in, inOff, len); + } + + public int doFinal(byte[] out, int outOff) + throws DataLengthException, IllegalStateException + { + if (firstOutput) + { + if (!initialised) + { + throw new IllegalStateException("KMAC not initialized"); + } + + byte[] encOut = XofUtils.rightEncode(getMacSize() * 8); + + cshake.update(encOut, 0, encOut.length); + } + + int rv = cshake.doFinal(out, outOff, getMacSize()); + + reset(); + + return rv; + } + + public int doFinal(byte[] out, int outOff, int outLen) + { + if (firstOutput) + { + if (!initialised) + { + throw new IllegalStateException("KMAC not initialized"); + } + + byte[] encOut = XofUtils.rightEncode(outLen * 8); + + cshake.update(encOut, 0, encOut.length); + } + + int rv = cshake.doFinal(out, outOff, outLen); + + reset(); + + return rv; + } + + public int doOutput(byte[] out, int outOff, int outLen) + { + if (firstOutput) + { + if (!initialised) + { + throw new IllegalStateException("KMAC not initialized"); + } + + byte[] encOut = XofUtils.rightEncode(0); + + cshake.update(encOut, 0, encOut.length); + + firstOutput = false; + } + + return cshake.doOutput(out, outOff, outLen); + } + + public void reset() + { + cshake.reset(); + + if (key != null) + { + if (bitLength == 128) + { + bytePad(key, 168); + } + else + { + bytePad(key, 136); + } + } + + firstOutput = true; + } + + private void bytePad(byte[] X, int w) + { + byte[] bytes = XofUtils.leftEncode(w); + update(bytes, 0, bytes.length); + byte[] encX = encode(X); + update(encX, 0, encX.length); + + int required = w - ((bytes.length + encX.length) % w); + + if (required > 0 && required != w) + { + while (required > padding.length) + { + update(padding, 0, padding.length); + required -= padding.length; + } + + update(padding, 0, required); + } + } + + private static byte[] encode(byte[] X) + { + return Arrays.concatenate(XofUtils.leftEncode(X.length * 8), X); + } +} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/macs/SipHash128.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/macs/SipHash128.java new file mode 100644 index 000000000..06697d508 --- /dev/null +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/macs/SipHash128.java @@ -0,0 +1,85 @@ +package com.fr.third.org.bouncycastle.crypto.macs; + +import com.fr.third.org.bouncycastle.crypto.DataLengthException; +import com.fr.third.org.bouncycastle.util.Pack; + +/** + * Implementation of SipHash with 128 bit output. + *+ * Based on the {@link SipHash} and the C reference implementation + * https://github.com/veorq/SipHash. + * + */ +public class SipHash128 + extends SipHash +{ + + /** + * SipHash128-2-4 + */ + public SipHash128() + { + super(); + } + + /** + * SipHash128-c-d + * + * @param c the number of compression rounds + * @param d the number of finalization rounds + */ + public SipHash128(int c, int d) + { + super(c, d); + } + + public String getAlgorithmName() + { + return "SipHash128-" + c + "-" + d; + } + + public int getMacSize() + { + return 16; + } + + public long doFinal() + throws DataLengthException, IllegalStateException { + throw new UnsupportedOperationException("doFinal() is not supported"); + } + + public int doFinal(byte[] out, int outOff) + throws DataLengthException, IllegalStateException + { + // NOTE: 2 distinct shifts to avoid "64-bit shift" when wordPos == 0 + m >>>= ((7 - wordPos) << 3); + m >>>= 8; + m |= (((wordCount << 3) + wordPos) & 0xffL) << 56; + + processMessageWord(); + + v2 ^= 0xeeL; + + applySipRounds(d); + + long r0 = v0 ^ v1 ^ v2 ^ v3; + + v1 ^= 0xddL; + applySipRounds(d); + + long r1 = v0 ^ v1 ^ v2 ^ v3; + + reset(); + + Pack.longToLittleEndian(r0, out, outOff); + Pack.longToLittleEndian(r1, out, outOff + 8); + return 16; + } + + public void reset() + { + super.reset(); + v1 ^= 0xeeL; + } + +} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/macs/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/macs/package.html deleted file mode 100644 index 0b1f86dd3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/macs/package.html +++ /dev/null @@ -1,5 +0,0 @@ - -
-Classes for creating MACs and HMACs. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/CFBBlockCipher.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/CFBBlockCipher.java index 7bdb3994a..68c6d6801 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/CFBBlockCipher.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/CFBBlockCipher.java @@ -36,6 +36,11 @@ public class CFBBlockCipher { super(cipher); + if (bitBlockSize > (cipher.getBlockSize() * 8) || bitBlockSize < 8 || bitBlockSize % 8 != 0) + { + throw new IllegalArgumentException("CFB" + bitBlockSize + " not supported"); + } + this.cipher = cipher; this.blockSize = bitBlockSize / 8; diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/ChaCha20Poly1305.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/ChaCha20Poly1305.java index c6a0b51e7..8b7ca8c06 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/ChaCha20Poly1305.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/ChaCha20Poly1305.java @@ -175,7 +175,7 @@ public class ChaCha20Poly1305 case State.ENC_DATA: return total + MAC_SIZE; default: - throw new IllegalStateException("state="+state); + throw new IllegalStateException(); } } @@ -281,9 +281,15 @@ public class ChaCha20Poly1305 { throw new NullPointerException("'in' cannot be null"); } + /* + * The BC provider can pass null when it expects no output (e.g. based on a + * getUpdateOutputSize call). + * + * See https://github.com/bcgit/bc-java/issues/674 + */ if (null == out) { - throw new NullPointerException("'out' cannot be null"); +// throw new NullPointerException("'out' cannot be null"); } if (inOff < 0) { @@ -542,7 +548,7 @@ public class ChaCha20Poly1305 private void padMAC(long count) { - int partial = (int)count % MAC_SIZE; + int partial = (int)count & (MAC_SIZE - 1); if (0 != partial) { poly1305.update(ZEROES, 0, MAC_SIZE - partial); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/OFBBlockCipher.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/OFBBlockCipher.java index 311c0ca5c..40937f432 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/OFBBlockCipher.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/OFBBlockCipher.java @@ -25,16 +25,21 @@ public class OFBBlockCipher * * @param cipher the block cipher to be used as the basis of the * feedback mode. - * @param blockSize the block size in bits (note: a multiple of 8) + * @param bitBlockSize the block size in bits (note: a multiple of 8) */ public OFBBlockCipher( BlockCipher cipher, - int blockSize) + int bitBlockSize) { super(cipher); + if (bitBlockSize > (cipher.getBlockSize() * 8) || bitBlockSize < 8 || bitBlockSize % 8 != 0) + { + throw new IllegalArgumentException("0FB" + bitBlockSize + " not supported"); + } + this.cipher = cipher; - this.blockSize = blockSize / 8; + this.blockSize = bitBlockSize / 8; this.IV = new byte[cipher.getBlockSize()]; this.ofbV = new byte[cipher.getBlockSize()]; diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/gcm/GCMUtil.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/gcm/GCMUtil.java index cbca24249..f9abcf2c5 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/gcm/GCMUtil.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/gcm/GCMUtil.java @@ -1,6 +1,7 @@ package com.fr.third.org.bouncycastle.crypto.modes.gcm; import com.fr.third.org.bouncycastle.math.raw.Interleave; +import com.fr.third.org.bouncycastle.util.Longs; import com.fr.third.org.bouncycastle.util.Pack; public abstract class GCMUtil @@ -140,24 +141,58 @@ public abstract class GCMUtil public static void multiply(long[] x, long[] y) { +// long x0 = x[0], x1 = x[1]; +// long y0 = y[0], y1 = y[1]; +// long z0 = 0, z1 = 0, z2 = 0; +// +// for (int j = 0; j < 64; ++j) +// { +// long m0 = x0 >> 63; x0 <<= 1; +// z0 ^= (y0 & m0); +// z1 ^= (y1 & m0); +// +// long m1 = x1 >> 63; x1 <<= 1; +// z1 ^= (y0 & m1); +// z2 ^= (y1 & m1); +// +// long c = (y1 << 63) >> 8; +// y1 = (y1 >>> 1) | (y0 << 63); +// y0 = (y0 >>> 1) ^ (c & E1L); +// } +// +// z0 ^= z2 ^ (z2 >>> 1) ^ (z2 >>> 2) ^ (z2 >>> 7); +// z1 ^= (z2 << 63) ^ (z2 << 62) ^ (z2 << 57); +// +// x[0] = z0; +// x[1] = z1; + + /* + * "Three-way recursion" as described in "Batch binary Edwards", Daniel J. Bernstein. + * + * Without access to the high part of a 64x64 product x * y, we use a bit reversal to calculate it: + * rev(x) * rev(y) == rev((x * y) << 1) + */ + long x0 = x[0], x1 = x[1]; long y0 = y[0], y1 = y[1]; - long z0 = 0, z1 = 0, z2 = 0; + long x0r = Longs.reverse(x0), x1r = Longs.reverse(x1); + long y0r = Longs.reverse(y0), y1r = Longs.reverse(y1); - for (int j = 0; j < 64; ++j) - { - long m0 = x0 >> 63; x0 <<= 1; - z0 ^= (y0 & m0); - z1 ^= (y1 & m0); + long h0 = Longs.reverse(implMul64(x0r, y0r)); + long h1 = implMul64(x0, y0) << 1; + long h2 = Longs.reverse(implMul64(x1r, y1r)); + long h3 = implMul64(x1, y1) << 1; + long h4 = Longs.reverse(implMul64(x0r ^ x1r, y0r ^ y1r)); + long h5 = implMul64(x0 ^ x1, y0 ^ y1) << 1; - long m1 = x1 >> 63; x1 <<= 1; - z1 ^= (y0 & m1); - z2 ^= (y1 & m1); + long z0 = h0; + long z1 = h1 ^ h0 ^ h2 ^ h4; + long z2 = h2 ^ h1 ^ h3 ^ h5; + long z3 = h3; - long c = (y1 << 63) >> 8; - y1 = (y1 >>> 1) | (y0 << 63); - y0 = (y0 >>> 1) ^ (c & E1L); - } + z1 ^= z3 ^ (z3 >>> 1) ^ (z3 >>> 2) ^ (z3 >>> 7); +// z2 ^= (z3 << 63) ^ (z3 << 62) ^ (z3 << 57); + z2 ^= (z3 << 62) ^ (z3 << 57); z0 ^= z2 ^ (z2 >>> 1) ^ (z2 >>> 2) ^ (z2 >>> 7); z1 ^= (z2 << 63) ^ (z2 << 62) ^ (z2 << 57); @@ -382,4 +417,29 @@ public abstract class GCMUtil z[0] = x[0] ^ y[0]; z[1] = x[1] ^ y[1]; } + + private static long implMul64(long x, long y) + { + long x0 = x & 0x1111111111111111L; + long x1 = x & 0x2222222222222222L; + long x2 = x & 0x4444444444444444L; + long x3 = x & 0x8888888888888888L; + + long y0 = y & 0x1111111111111111L; + long y1 = y & 0x2222222222222222L; + long y2 = y & 0x4444444444444444L; + long y3 = y & 0x8888888888888888L; + + long z0 = (x0 * y0) ^ (x1 * y3) ^ (x2 * y2) ^ (x3 * y1); + long z1 = (x0 * y1) ^ (x1 * y0) ^ (x2 * y3) ^ (x3 * y2); + long z2 = (x0 * y2) ^ (x1 * y1) ^ (x2 * y0) ^ (x3 * y3); + long z3 = (x0 * y3) ^ (x1 * y2) ^ (x2 * y1) ^ (x3 * y0); + + z0 &= 0x1111111111111111L; + z1 &= 0x2222222222222222L; + z2 &= 0x4444444444444444L; + z3 &= 0x8888888888888888L; + + return z0 | z1 | z2 | z3; + } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/gcm/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/gcm/package.html deleted file mode 100644 index 09c42f03b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/gcm/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -GCM mode support classes. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/package.html deleted file mode 100644 index 5402df449..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/modes/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Modes for symmetric ciphers. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/package.html deleted file mode 100644 index ee5487ffa..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Base classes for the lightweight API. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/paddings/ISO10126d2Padding.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/paddings/ISO10126d2Padding.java index 959006886..cbf3bcfe3 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/paddings/ISO10126d2Padding.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/paddings/ISO10126d2Padding.java @@ -21,14 +21,7 @@ public class ISO10126d2Padding public void init(SecureRandom random) throws IllegalArgumentException { - if (random != null) - { - this.random = random; - } - else - { - this.random = CryptoServicesRegistrar.getSecureRandom(); - } + this.random = CryptoServicesRegistrar.getSecureRandom(random); } /** diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/paddings/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/paddings/package.html deleted file mode 100644 index 2b82e60f1..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/paddings/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Paddings for symmetric ciphers. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/DHPublicKeyParameters.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/DHPublicKeyParameters.java index 97cd2578c..5ed66830a 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/DHPublicKeyParameters.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/DHPublicKeyParameters.java @@ -2,6 +2,9 @@ package com.fr.third.org.bouncycastle.crypto.params; import java.math.BigInteger; +import com.fr.third.org.bouncycastle.math.raw.Nat; +import com.fr.third.org.bouncycastle.util.Integers; + public class DHPublicKeyParameters extends DHKeyParameters { @@ -26,25 +29,39 @@ public class DHPublicKeyParameters throw new NullPointerException("y value cannot be null"); } + BigInteger p = dhParams.getP(); + // TLS check - if (y.compareTo(TWO) < 0 || y.compareTo(dhParams.getP().subtract(TWO)) > 0) + if (y.compareTo(TWO) < 0 || y.compareTo(p.subtract(TWO)) > 0) { throw new IllegalArgumentException("invalid DH public key"); } - if (dhParams.getQ() != null) + BigInteger q = dhParams.getQ(); + if (q == null) { - if (ONE.equals(y.modPow(dhParams.getQ(), dhParams.getP()))) + return y; // we can't validate without Q. + } + + if (p.testBit(0) + && p.bitLength() - 1 == q.bitLength() + && p.shiftRight(1).equals(q)) + { + // Safe prime case + if (1 == legendre(y, p)) { return y; } - - throw new IllegalArgumentException("Y value does not appear to be in correct group"); } else { - return y; // we can't validate without Q. + if (ONE.equals(y.modPow(q, p))) + { + return y; + } } + + throw new IllegalArgumentException("Y value does not appear to be in correct group"); } public BigInteger getY() @@ -69,4 +86,79 @@ public class DHPublicKeyParameters return other.getY().equals(y) && super.equals(obj); } + + private static int legendre(BigInteger a, BigInteger b) + { +// int r = 0, bits = b.intValue(); +// +// for (;;) +// { +// int lowestSetBit = a.getLowestSetBit(); +// a = a.shiftRight(lowestSetBit); +// r ^= (bits ^ (bits >>> 1)) & (lowestSetBit << 1); +// +// int cmp = a.compareTo(b); +// if (cmp == 0) +// { +// break; +// } +// +// if (cmp < 0) +// { +// BigInteger t = a; a = b; b = t; +// +// int oldBits = bits; +// bits = b.intValue(); +// r ^= oldBits & bits; +// } +// +// a = a.subtract(b); +// } +// +// return ONE.equals(b) ? (1 - (r & 2)) : 0; + + int bitLength = b.bitLength(); + int[] A = Nat.fromBigInteger(bitLength, a); + int[] B = Nat.fromBigInteger(bitLength, b); + + int r = 0; + + int len = B.length; + for (;;) + { + while (A[0] == 0) + { + Nat.shiftDownWord(len, A, 0); + } + + int shift = Integers.numberOfTrailingZeros(A[0]); + if (shift > 0) + { + Nat.shiftDownBits(len, A, shift, 0); + int bits = B[0]; + r ^= (bits ^ (bits >>> 1)) & (shift << 1); + } + + int cmp = Nat.compare(len, A, B); + if (cmp == 0) + { + break; + } + + if (cmp < 0) + { + r ^= A[0] & B[0]; + int[] t = A; A = B; B = t; + } + + while (A[len - 1] == 0) + { + len = len - 1; + } + + Nat.sub(len, A, B, A); + } + + return Nat.isOne(len, B) ? (1 - (r & 2)) : 0; + } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ECDomainParameters.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ECDomainParameters.java index 73d396086..479f0b32f 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ECDomainParameters.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ECDomainParameters.java @@ -2,11 +2,13 @@ package com.fr.third.org.bouncycastle.crypto.params; import java.math.BigInteger; +import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; import com.fr.third.org.bouncycastle.math.ec.ECAlgorithms; import com.fr.third.org.bouncycastle.math.ec.ECConstants; import com.fr.third.org.bouncycastle.math.ec.ECCurve; import com.fr.third.org.bouncycastle.math.ec.ECPoint; import com.fr.third.org.bouncycastle.util.Arrays; +import com.fr.third.org.bouncycastle.util.BigIntegers; public class ECDomainParameters implements ECConstants @@ -19,6 +21,11 @@ public class ECDomainParameters private BigInteger hInv = null; + public ECDomainParameters(X9ECParameters x9) + { + this(x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed()); + } + public ECDomainParameters( ECCurve curve, ECPoint G, @@ -84,7 +91,7 @@ public class ECDomainParameters { if (hInv == null) { - hInv = h.modInverse(n); + hInv = BigIntegers.modOddInverseVar(n, h); } return hInv; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ECGOST3410Parameters.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ECGOST3410Parameters.java index 515326705..55a7ab342 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ECGOST3410Parameters.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ECGOST3410Parameters.java @@ -16,7 +16,7 @@ public class ECGOST3410Parameters public ECGOST3410Parameters(ECDomainParameters ecParameters, ASN1ObjectIdentifier publicKeyParamSet, ASN1ObjectIdentifier digestParamSet, ASN1ObjectIdentifier encryptionParamSet) { - super(publicKeyParamSet, ecParameters.getCurve(), ecParameters.getG(), ecParameters.getN(), ecParameters.getH(), ecParameters.getSeed()); + super(publicKeyParamSet, ecParameters); if (ecParameters instanceof ECNamedDomainParameters) { diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ECNamedDomainParameters.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ECNamedDomainParameters.java index 07c659553..23e2eed06 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ECNamedDomainParameters.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ECNamedDomainParameters.java @@ -3,6 +3,7 @@ package com.fr.third.org.bouncycastle.crypto.params; import java.math.BigInteger; import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; +import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; import com.fr.third.org.bouncycastle.math.ec.ECConstants; import com.fr.third.org.bouncycastle.math.ec.ECCurve; import com.fr.third.org.bouncycastle.math.ec.ECPoint; @@ -35,6 +36,12 @@ public class ECNamedDomainParameters this.name = name; } + public ECNamedDomainParameters(ASN1ObjectIdentifier name, X9ECParameters x9) + { + super(x9); + this.name = name; + } + public ASN1ObjectIdentifier getName() { return name; diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/Ed25519PrivateKeyParameters.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/Ed25519PrivateKeyParameters.java index 92c12b5f2..da6cb50d7 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/Ed25519PrivateKeyParameters.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/Ed25519PrivateKeyParameters.java @@ -17,6 +17,8 @@ public final class Ed25519PrivateKeyParameters private final byte[] data = new byte[KEY_SIZE]; + private Ed25519PublicKeyParameters cachedPublicKey; + public Ed25519PrivateKeyParameters(SecureRandom random) { super(true); @@ -53,22 +55,33 @@ public final class Ed25519PrivateKeyParameters public Ed25519PublicKeyParameters generatePublicKey() { - byte[] publicKey = new byte[Ed25519.PUBLIC_KEY_SIZE]; - Ed25519.generatePublicKey(data, 0, publicKey, 0); - return new Ed25519PublicKeyParameters(publicKey, 0); + synchronized (data) + { + if (null == cachedPublicKey) + { + byte[] publicKey = new byte[Ed25519.PUBLIC_KEY_SIZE]; + Ed25519.generatePublicKey(data, 0, publicKey, 0); + cachedPublicKey = new Ed25519PublicKeyParameters(publicKey, 0); + } + + return cachedPublicKey; + } } + /** + * @deprecated use overload that doesn't take a public key + */ public void sign(int algorithm, Ed25519PublicKeyParameters publicKey, byte[] ctx, byte[] msg, int msgOff, int msgLen, byte[] sig, int sigOff) { + sign(algorithm, ctx, msg, msgOff, msgLen, sig, sigOff); + } + + public void sign(int algorithm, byte[] ctx, byte[] msg, int msgOff, int msgLen, byte[] sig, int sigOff) + { + Ed25519PublicKeyParameters publicKey = generatePublicKey(); + byte[] pk = new byte[Ed25519.PUBLIC_KEY_SIZE]; - if (null == publicKey) - { - Ed25519.generatePublicKey(data, 0, pk, 0); - } - else - { - publicKey.encode(pk, 0); - } + publicKey.encode(pk, 0); switch (algorithm) { diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/Ed448PrivateKeyParameters.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/Ed448PrivateKeyParameters.java index 16cf444e9..3014367a6 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/Ed448PrivateKeyParameters.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/Ed448PrivateKeyParameters.java @@ -17,6 +17,8 @@ public final class Ed448PrivateKeyParameters private final byte[] data = new byte[KEY_SIZE]; + private Ed448PublicKeyParameters cachedPublicKey; + public Ed448PrivateKeyParameters(SecureRandom random) { super(true); @@ -53,22 +55,33 @@ public final class Ed448PrivateKeyParameters public Ed448PublicKeyParameters generatePublicKey() { - byte[] publicKey = new byte[Ed448.PUBLIC_KEY_SIZE]; - Ed448.generatePublicKey(data, 0, publicKey, 0); - return new Ed448PublicKeyParameters(publicKey, 0); + synchronized (data) + { + if (null == cachedPublicKey) + { + byte[] publicKey = new byte[Ed448.PUBLIC_KEY_SIZE]; + Ed448.generatePublicKey(data, 0, publicKey, 0); + cachedPublicKey = new Ed448PublicKeyParameters(publicKey, 0); + } + + return cachedPublicKey; + } } + /** + * @deprecated use overload that doesn't take a public key + */ public void sign(int algorithm, Ed448PublicKeyParameters publicKey, byte[] ctx, byte[] msg, int msgOff, int msgLen, byte[] sig, int sigOff) { + sign(algorithm, ctx, msg, msgOff, msgLen, sig, sigOff); + } + + public void sign(int algorithm, byte[] ctx, byte[] msg, int msgOff, int msgLen, byte[] sig, int sigOff) + { + Ed448PublicKeyParameters publicKey = generatePublicKey(); + byte[] pk = new byte[Ed448.PUBLIC_KEY_SIZE]; - if (null == publicKey) - { - Ed448.generatePublicKey(data, 0, pk, 0); - } - else - { - publicKey.encode(pk, 0); - } + publicKey.encode(pk, 0); switch (algorithm) { diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ParametersWithRandom.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ParametersWithRandom.java index a904f5d2b..de50fcffe 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ParametersWithRandom.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/ParametersWithRandom.java @@ -15,14 +15,14 @@ public class ParametersWithRandom CipherParameters parameters, SecureRandom random) { - this.random = random; + this.random = CryptoServicesRegistrar.getSecureRandom(random); this.parameters = parameters; } public ParametersWithRandom( CipherParameters parameters) { - this(parameters, CryptoServicesRegistrar.getSecureRandom()); + this(parameters, null); } public SecureRandom getRandom() diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/package.html deleted file mode 100644 index 4e00a7548..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/params/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Classes for parameter objects for ciphers and generators. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/parsers/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/parsers/package.html deleted file mode 100644 index 03d05c79e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/parsers/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Helper classes for parsing "on the wire" public keys. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/DRBGProvider.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/DRBGProvider.java index 9e9aa7e97..3b40c3ffa 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/DRBGProvider.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/DRBGProvider.java @@ -4,5 +4,7 @@ import com.fr.third.org.bouncycastle.crypto.prng.drbg.SP80090DRBG; interface DRBGProvider { + String getAlgorithm(); + SP80090DRBG get(EntropySource entropySource); } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/SP800SecureRandom.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/SP800SecureRandom.java index 51fb0da13..f572814c7 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/SP800SecureRandom.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/SP800SecureRandom.java @@ -45,6 +45,11 @@ public class SP800SecureRandom } } + public String getAlgorithm() + { + return drbgProvider.getAlgorithm(); + } + public void nextBytes(byte[] bytes) { synchronized (this) diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/SP800SecureRandomBuilder.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/SP800SecureRandomBuilder.java index 02eb02118..eb53220ef 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/SP800SecureRandomBuilder.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/SP800SecureRandomBuilder.java @@ -6,6 +6,8 @@ import com.fr.third.org.bouncycastle.crypto.BlockCipher; import com.fr.third.org.bouncycastle.crypto.CryptoServicesRegistrar; import com.fr.third.org.bouncycastle.crypto.Digest; import com.fr.third.org.bouncycastle.crypto.Mac; +import com.fr.third.org.bouncycastle.crypto.engines.DESedeEngine; +import com.fr.third.org.bouncycastle.crypto.macs.HMac; import com.fr.third.org.bouncycastle.crypto.prng.drbg.CTRSP800DRBG; import com.fr.third.org.bouncycastle.crypto.prng.drbg.HMacSP800DRBG; import com.fr.third.org.bouncycastle.crypto.prng.drbg.HashSP800DRBG; @@ -160,6 +162,11 @@ public class SP800SecureRandomBuilder this.securityStrength = securityStrength; } + public String getAlgorithm() + { + return "HASH-DRBG-" + getSimplifiedName(digest); + } + public SP80090DRBG get(EntropySource entropySource) { return new HashSP800DRBG(digest, securityStrength, entropySource, personalizationString, nonce); @@ -182,6 +189,16 @@ public class SP800SecureRandomBuilder this.securityStrength = securityStrength; } + public String getAlgorithm() + { + if (hMac instanceof HMac) + { + return "HMAC-DRBG-" + getSimplifiedName(((HMac)hMac).getUnderlyingDigest()); + } + + return "HMAC-DRBG-" + hMac.getAlgorithmName(); + } + public SP80090DRBG get(EntropySource entropySource) { return new HMacSP800DRBG(hMac, securityStrength, entropySource, personalizationString, nonce); @@ -207,9 +224,32 @@ public class SP800SecureRandomBuilder this.securityStrength = securityStrength; } + public String getAlgorithm() + { + if (blockCipher instanceof DESedeEngine) + { + return "CTR-DRBG-3KEY-TDES"; + } + return "CTR-DRBG-" + blockCipher.getAlgorithmName() + keySizeInBits; + } + public SP80090DRBG get(EntropySource entropySource) { return new CTRSP800DRBG(blockCipher, keySizeInBits, securityStrength, entropySource, personalizationString, nonce); } } + + private static String getSimplifiedName(Digest digest) + { + String name = digest.getAlgorithmName(); + + int dIndex = name.indexOf('-'); + if (dIndex > 0 && !name.startsWith("SHA3")) + { + return name.substring(0, dIndex) + name.substring(dIndex + 1); + } + + return name; + } + } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/drbg/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/drbg/package.html deleted file mode 100644 index c0061660b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/drbg/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -SP800-90A deterministic random bit generators, can be used stand alone or in conjunction with SP800SecureRandomBuilder class. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/package.html deleted file mode 100644 index bb583abd7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Lightweight psuedo-random number generators and SecureRandom builders. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/CTRDRBGTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/CTRDRBGTest.java deleted file mode 100644 index 7c8ba19a7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/CTRDRBGTest.java +++ /dev/null @@ -1,528 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.prng.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.AESFastEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESedeEngine; -import com.fr.third.org.bouncycastle.crypto.params.DESedeParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.prng.drbg.CTRSP800DRBG; -import com.fr.third.org.bouncycastle.crypto.prng.drbg.SP80090DRBG; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * CTR DRBG Test - */ -public class CTRDRBGTest - extends SimpleTest -{ - public String getName() - { - return "CTRDRBGTest"; - } - - public static void main(String[] args) - { - runTest(new CTRDRBGTest()); - } - - private DRBGTestVector[] createTestVectorData() - { - return new DRBGTestVector[] - { - new DRBGTestVector( - new DESedeEngine(), 168, - new Bit232EntropyProvider().get(232), - false, - "20212223242526", - 112, - new String[] - { - "ABC88224514D0316EA3D48AEE3C9A2B4", - "D3D3F372E43E7ABDC4FA293743EED076" - } - ), - new DRBGTestVector( - new DESedeEngine(), 168, - new Bit232EntropyProvider().get(232), - false, - "20212223242526", - 112, - new String[] - { - "D4564EE072ACA5BD279536E14F94CB12", - "1CCD9AFEF15A9679BA75E35225585DEA" - } - ) - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBC"), - new DRBGTestVector( - new DESedeEngine(), 168, - new Bit232EntropyProvider().get(232), - false, - "20212223242526", - 112, - new String[] - { - "760BED7D92B083B10AF31CF0656081EB", - "FD1AC41482384D823CF3FD6F0E6C88B3" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C"), - new DRBGTestVector( - new DESedeEngine(), 168, - new Bit232EntropyProvider().get(232), - false, - "20212223242526", - 112, - new String[] - { - "7A4C1D7ADC8A67FDB50100ED23583A2C", - "43044D311C0E07541CA5C8B0916976B2" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C") - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBC"), - new DRBGTestVector( - new DESedeEngine(), 168, - new Bit232EntropyProvider().get(232), - true, - "20212223242526", - 112, - new String[] - { - "8FB78ABCA75C9F284E974E36141866BC", - "9D9745FF31C42A4488CBB771B13B5D86" - } - ), - new DRBGTestVector( - new DESedeEngine(), 168, - new Bit232EntropyProvider().get(232), - true, - "20212223242526", - 112, - new String[] - { - "0E389920A09B485AA4ABD0CA7E60D89C", - "F4478EC6659A0D3577625B0C73A211DD" - } - ) - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBC"), - new DRBGTestVector( - new DESedeEngine(), 168, - new Bit232EntropyProvider().get(232), - true, - "20212223242526", - 112, - new String[] - { - "64983055D014550B39DE699E43130B64", - "035FDDA8582A2214EC722C410A8D95D3" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C"), - new DRBGTestVector( - new DESedeEngine(), 168, - new Bit232EntropyProvider().get(232), - true, - "20212223242526", - 112, - new String[] - { - "A29C1A8C42FBC562D7D1DBA7DC541FFE", - "0BDA66B049429061C013E4228C2F44C6" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C") - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBC"), - new DRBGTestVector( - new AESFastEngine(), 128, - new Bit256EntropyProvider().get(256), - false, - "2021222324252627", - 128, - new String[] - { - "8CF59C8CF6888B96EB1C1E3E79D82387AF08A9E5FF75E23F1FBCD4559B6B997E", - "69CDEF912C692D61B1DA4C05146B52EB7B8849BD87937835328254EC25A9180E" - } - ), - new DRBGTestVector( - new AESFastEngine(), 128, - new Bit256EntropyProvider().get(256), - false, - "2021222324252627", - 128, - new String[] - { - "E8C74A4B7BFFB53BEB80E78CA86BB6DF70E2032AEB473E0DD54D2339CEFCE9D0", - "26B3F823B4DBAFC23B141375E10B3AEB7A0B5DEF1C7D760B6F827D01ECD17AC7" - } - ) - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"), - new DRBGTestVector( - new AESFastEngine(), 128, - new Bit256EntropyProvider().get(256), - false, - "2021222324252627", - 128, - new String[] - { - "18FDEFBDC43D7A36D5D6D862205765D1D701C9F237007030DF1B8E70EE4EEE29", - "9888F1D38BB1CCE31B363AA1BD9B39616876C30DEE1FF0B7BD8C4C441715C833" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F"), - new DRBGTestVector( - new AESFastEngine(), 128, - new Bit256EntropyProvider().get(256), - true, - "2021222324252627", - 128, - new String[] - { - "BFF4B85D68C84529F24F69F9ACF1756E29BA648DDEB825C225FA32BA490EF4A9", - "9BD2635137A52AF7D0FCBEFEFB97EA93A0F4C438BD98956C0DACB04F15EE25B3" - } - ), - new DRBGTestVector( - new AESFastEngine(), 128, - new Bit256EntropyProvider().get(256), - true, - "2021222324252627", - 128, - new String[] - { - "4573AC8BBB33D7CC4DBEF3EEDF6EAE748B536C3A1082CEE4948CDB51C83A7F9C", - "99C628CDD87BD8C2F1FE443AA7F761DA16886436326323354DA6311FFF5BC678" - } - ) - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"), - new DRBGTestVector( - new AESFastEngine(), 128, - new Bit256EntropyProvider().get(256), - true, - "2021222324252627", - 128, - new String[] - { - "F324104E2FA14F79D8AA60DF06B93B3BC157324958F0A7EE1E193677A70E0250", - "78F4C840134F40DC001BFAD3A90B5EF4DEBDBFAC3CFDF0CD69A89DC4FD34713F" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F"), - new DRBGTestVector( - new AESFastEngine(), 192, - new Bit320EntropyProvider().get(320), - false, - "202122232425262728292A2B", - 192, - new String[] - { - "E231244B3235B085C81604424357E85201E3828B5C45568679A5555F867AAC8C", - "DDD0F7BCCADADAA31A67652259CE569A271DD85CF66C3D6A7E9FAED61F38D219" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F6061626364656667"), - new DRBGTestVector( - new AESFastEngine(), 192, - new Bit320EntropyProvider().get(320), - true, - "202122232425262728292A2B", - 192, - new String[] - { - "F780D4A2C25CF8EE7407D948EC0B724A4235D8B20E65081392755CA7912AD7C0", - "BA14617F915BA964CB79276BDADC840C14B631BBD1A59097054FA6DFF863B238" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F6061626364656667"), - new DRBGTestVector( - new AESFastEngine(), 256, - new Bit384EntropyProvider().get(384), - false, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "47111E146562E9AA2FB2A1B095D37A8165AF8FC7CA611D632BE7D4C145C83900", - "98A28E3B1BA363C9DAF0F6887A1CF52B833D3354D77A7C10837DD63DD2E645F8" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F") - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECF"), - new DRBGTestVector( - new AESFastEngine(), 256, - new Bit384EntropyProvider().get(384), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "71BB3F9C9CEAF4E6C92A83EB4C7225010EE150AC75E23F5F77AD5073EF24D88A", - "386DEBBBF091BBF0502957B0329938FB836B82E594A2F5FDD5EB28D4E35528F4" - } - ) - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECF"), - new DRBGTestVector( - new AESFastEngine(), 256, - new Bit384EntropyProvider().get(384), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "1A2E3FEE9056E98D375525FDC2B63B95B47CE51FCF594D804BD5A17F2E01139B", - "601F95384F0D85946301D1EACE8F645A825CE38F1E2565B0C0C439448E9CA8AC" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F"), - new DRBGTestVector( - new AESFastEngine(), 256, - new Bit384EntropyProvider().get(384), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "EAE6BCE781807E524D26605EA198077932D01EEB445B9AC6C5D99C101D29F46E", - "738E99C95AF59519AAD37FF3D5180986ADEBAB6E95836725097E50A8D1D0BD28" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F") - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECF"), - new DRBGTestVector( - new AESFastEngine(), 256, - new Bit384EntropyProvider().get(384), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "eae6bce781807e524d26605ea198077932d01eeb445b9ac6c5d99c101d29f46e30b27377", - "ec51b55b49904c3ff9e13939f1cf27398993e1b3acb2b0be0be8761261428f0aa8ba2657" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F") - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECF") - }; - } - - public void performTest() - throws Exception - { - DRBGTestVector[] tests = createTestVectorData(); - - for (int i = 0; i != tests.length; i++) - { - DRBGTestVector tv = tests[i]; - - byte[] nonce = tv.nonce(); - byte[] personalisationString = tv.personalizationString(); - - SP80090DRBG d = new CTRSP800DRBG(tv.getCipher(), tv.keySizeInBits(), tv.securityStrength(), tv.entropySource(), personalisationString, nonce); - - byte[] output = new byte[tv.expectedValue(0).length]; - - d.generate(output, tv.additionalInput(0), tv.predictionResistance()); - - byte[] expected = tv.expectedValue(0); - - if (!areEqual(expected, output)) - { - fail("Test #" + (i + 1) + ".1 failed, expected " + new String(Hex.encode(tv.expectedValue(0))) + " got " + new String(Hex.encode(output))); - } - - output = new byte[tv.expectedValue(0).length]; - - d.generate(output, tv.additionalInput(1), tv.predictionResistance()); - - expected = tv.expectedValue(1); - if (!areEqual(expected, output)) - { - fail("Test #" + (i + 1) + ".2 failed, expected " + new String(Hex.encode(tv.expectedValue(1))) + " got " + new String(Hex.encode(output))); - } - } - - // DESede/TDEA key parity test - DRBGTestVector tv = tests[0]; - - SP80090DRBG drbg = new CTRSP800DRBG(new KeyParityCipher(tv.getCipher()), tv.keySizeInBits(), tv.securityStrength(), tv.entropySource(), tv.personalizationString(), tv.nonce()); - - byte[] output = new byte[tv.expectedValue(0).length]; - - drbg.generate(output, tv.additionalInput(0), tv.predictionResistance()); - - // Exception tests - SP80090DRBG d; - try - { - d = new CTRSP800DRBG(new AESEngine(), 256, 256, new Bit232EntropyProvider().get(128), null, null); - fail("no exception thrown"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("Not enough entropy for security strength required")) - { - fail("Wrong exception", e); - } - } - - try - { - d = new CTRSP800DRBG(new DESedeEngine(), 256, 256, new Bit232EntropyProvider().get(232), null, null); - fail("no exception thrown"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("Requested security strength is not supported by block cipher and key size")) - { - fail("Wrong exception", e); - } - } - - try - { - d = new CTRSP800DRBG(new DESedeEngine(), 168, 256, new Bit232EntropyProvider().get(232), null, null); - fail("no exception thrown"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("Requested security strength is not supported by block cipher and key size")) - { - fail("Wrong exception", e); - } - } - - try - { - d = new CTRSP800DRBG(new AESEngine(), 192, 256, new Bit232EntropyProvider().get(232), null, null); - fail("no exception thrown"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("Requested security strength is not supported by block cipher and key size")) - { - fail("Wrong exception", e); - } - } - } - - private class Bit232EntropyProvider - extends TestEntropySourceProvider - { - Bit232EntropyProvider() - { - super(Hex.decode( - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C" + - "808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C" + - "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDC"), true); - } - } - - private class Bit256EntropyProvider - extends TestEntropySourceProvider - { - Bit256EntropyProvider() - { - super(Hex.decode( - "0001020304050607"+ - "08090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"+ - "8081828384858687"+ - "88898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F"+ - "C0C1C2C3C4C5C6C7"+ - "C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF"), true); - } - } - - private class Bit320EntropyProvider - extends TestEntropySourceProvider - { - Bit320EntropyProvider() - { - super(Hex.decode( - "000102030405060708090A0B0C0D0E0F"+ - "101112131415161718191A1B1C1D1E1F2021222324252627"+ - "808182838485868788898A8B8C8D8E8F"+ - "909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7"+ - "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF"+ - "D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7"), true); - } - } - - private class Bit384EntropyProvider - extends TestEntropySourceProvider - { - Bit384EntropyProvider() - { - super(Hex.decode( - "000102030405060708090A0B0C0D0E0F1011121314151617" + - "18191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F" + - "808182838485868788898A8B8C8D8E8F9091929394959697" + - "98999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAF" + - "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7" + - "D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF"), true); - } - } - - private class KeyParityCipher - implements BlockCipher - { - private BlockCipher cipher; - - KeyParityCipher(BlockCipher cipher) - { - this.cipher = cipher; - } - - public void init(boolean forEncryption, CipherParameters params) - throws IllegalArgumentException - { - byte[] k = Arrays.clone(((KeyParameter)params).getKey()); - - DESedeParameters.setOddParity(k); - - if (!Arrays.areEqual(((KeyParameter)params).getKey(), k)) - { - fail("key not odd parity"); - } - - cipher.init(forEncryption, params); - } - - public String getAlgorithmName() - { - return cipher.getAlgorithmName(); - } - - public int getBlockSize() - { - return cipher.getBlockSize(); - } - - public int processBlock(byte[] in, int inOff, byte[] out, int outOff) - throws DataLengthException, IllegalStateException - { - return cipher.processBlock(in, inOff, out, outOff); - } - - public void reset() - { - cipher.reset(); - } - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/DRBGTestVector.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/DRBGTestVector.java deleted file mode 100644 index c8b401123..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/DRBGTestVector.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.prng.test; - -import java.util.ArrayList; -import java.util.List; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.prng.EntropySource; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - -public class DRBGTestVector -{ - private Digest _digest; - private BlockCipher _cipher; - private int _keySizeInBits; - private EntropySource _eSource; - private boolean _pr; - private String _nonce; - private String _personalisation; - private int _ss; - private String[] _ev; - private List _ai = new ArrayList(); - - public DRBGTestVector(Digest digest, EntropySource eSource, boolean predictionResistance, String nonce, int securityStrength, String[] expected) - { - _digest = digest; - _eSource = eSource; - _pr = predictionResistance; - _nonce = nonce; - _ss = securityStrength; - _ev = expected; - _personalisation = null; - } - - public DRBGTestVector(BlockCipher cipher, int keySizeInBits, EntropySource eSource, boolean predictionResistance, String nonce, int securityStrength, String[] expected) - { - _cipher = cipher; - _keySizeInBits = keySizeInBits; - _eSource = eSource; - _pr = predictionResistance; - _nonce = nonce; - _ss = securityStrength; - _ev = expected; - _personalisation = null; - } - - public Digest getDigest() - { - return _digest; - } - - public BlockCipher getCipher() - { - return _cipher; - } - - public int keySizeInBits() - { - return _keySizeInBits; - } - - public DRBGTestVector addAdditionalInput(String input) - { - _ai.add(input); - - return this; - } - - public DRBGTestVector setPersonalizationString(String p) - { - _personalisation = p; - - return this; - } - - public EntropySource entropySource() - { - return _eSource; - } - - public boolean predictionResistance() - { - return _pr; - } - - public byte[] nonce() - { - if (_nonce == null) - { - return null; - } - - return Hex.decode(_nonce); - } - - public byte[] personalizationString() - { - if (_personalisation == null) - { - return null; - } - - return Hex.decode(_personalisation); - } - - public int securityStrength() - { - return _ss; - } - - public byte[] expectedValue(int index) - { - return Hex.decode(_ev[index]); - } - - public byte[] additionalInput(int position) - { - int len = _ai.size(); - byte[] rv; - if (position >= len) - { - rv = null; - } - else - { - rv = Hex.decode((String)(_ai.get(position))); - } - return rv; - } - - } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/DualECDRBGTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/DualECDRBGTest.java deleted file mode 100644 index e2c6b348d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/DualECDRBGTest.java +++ /dev/null @@ -1,415 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.prng.test; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA384Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512Digest; -import com.fr.third.org.bouncycastle.crypto.prng.drbg.DualECSP800DRBG; -import com.fr.third.org.bouncycastle.crypto.prng.drbg.SP80090DRBG; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Dual EC SP800-90 DRBG test - */ -public class DualECDRBGTest - extends SimpleTest -{ - public String getName() - { - return "DualECDRBG"; - } - - public static void main(String[] args) - { - runTest(new DualECDRBGTest()); - } - - private DRBGTestVector[] createTestVectorData() - { - return new DRBGTestVector[] - { - new DRBGTestVector( - new SHA256Digest(), - new SHA256EntropyProvider().get(128), - false, - "2021222324252627", - 128, - new String[] - { - "FF5163C388F791E96F1052D5C8F0BD6FBF7144839C4890FF85487C5C12702E4C9849AF518AE68DEB14D3A62702BBDE4B98AB211765FD87ACA12FC2A6", - "9A0A11F2DFB88F7260559DD8DA6134EB2B34CC0415FA8FD0474DB6B85E1A08385F41B435DF81296B1B4EDF66E0107C0844E3D28A89B05046B89177F2" - }), - new DRBGTestVector( - new SHA256Digest(), - new SHA256EntropyProvider().get(128), - false, - "2021222324252627", - 128, - new String[] - { - "C08E954FCD486D0B0934A0236692AC705A835D1A3C94D2ACD4684AB26E978D7D42E73CC06D6EC1472C63E51BED7F71518395836E2052BBD73A20CABB", - "1D76DEE36FCC5F9478C112EAFA1C4CCD0635435A6F3A247A3BA3849790B5245070E95C1A67BE7A39BFB213F2C0EFCC171A3253DA6D54DA4362EA2099" - }) - .addAdditionalInput("606162636465666768696A6B6C6D6E6F") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAF"), - new DRBGTestVector( - new SHA256Digest(), - new SHA256EntropyProvider().get(128), - false, - "2021222324252627", - 128, - new String[] - { - "3AB095CC493A8730D70DE923108B2E4710799044FFC27D0A1156250DDF97E8B05ACE055E49F3E3F5B928CCD18317A3E68FCB0B6F0459ADF9ECF79C87", - "7B902FC35B0AF50F57F8822936D08A96E41B16967C6B1AA0BC05032F0D53919DC587B664C883E2FE8F3948002FCD8BCBFC4706BCAA2075EF6BF41167" - }) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F"), - new DRBGTestVector( - new SHA256Digest(), - new SHA256EntropyProvider().get(128), - false, - "2021222324252627", - 128, - new String[] - { - "3B68A1D95ED0312150AC1991189780F37EC50E75249F915CD806BBA0C44F9E3A919B2390805E1E90C1D2D1C823B17B96DB44535B72E0CFB62723529D", - "250B933475E3BD4FC85D97FD797834B599DEDEDF8B6F15474E1F31B4AF215CFA7A8C0A0296A2E374B3886BB0CC7E49DBB19324564B451E64F12864F9" - }) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F") - .addAdditionalInput("606162636465666768696A6B6C6D6E6F") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAF"), - new DRBGTestVector( - new SHA256Digest(), - new SHA256EntropyProvider().get(128), - true, - "2021222324252627", - 128, - new String[] - { - "8C77288EDBEA9A742464F78D55E33593C1BF5F9D8CD8609D6D53BAC4E4B42252A227A99BAD0F2358B05955CD35723B549401C71C9C1F32F8A2018E24", - "56ECA61C64F69C1C232E992623C71418BD0B96D783118FAAD94A09E3A9DB74D15E805BA7F14625995CA77612B2EF7A05863699ECBABF70D3D422C014" - }), - new DRBGTestVector( - new SHA256Digest(), - new SHA256EntropyProvider().get(128), - true, - "2021222324252627", - 128, - new String[] - { - "A5C397DFEB540E86F0470E9625D5C5AC2D50016FB201E8DF574F2201DFBB42A799FEB9E238AAD301A493382250EEE60D2E2927E500E848E57535ABD1", - "BF9894630BEBAF0A0EDFE726285EB055FD2ED678B76673803DD327F49DBEDE87D3E447A6EB73B5D5C52A40078132677F412E9E7DE32B9B1CB32421B9" - }) - .addAdditionalInput("606162636465666768696A6B6C6D6E6F") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAF"), - new DRBGTestVector( - new SHA384Digest(), - new SHA384EntropyProvider().get(192), - false, - "202122232425262728292A2B", - 192, - new String[] - { - "1F858858B65357D6360E1ED8F8475767B08DAB30718CCA01C6FAE77A4BDCE2702C76D0FB4758EA1ED6AA587CFD26B9011DC8A75D0B4154193BB2C1798FFA52BCAB208310" + - "3CD2AAD44BEED56D042FC2B8915D7D9BED6437EFEB1582EE", - "6E4AAB63938212C870F24BB067A32CA9E7FC2343" + - "5D411729268C8BA6F90E87074D04888CE2CC5A916B7AC93F" + - "EDE85E2995645DFCC4CE44B9FB41F1BFCC5E9F59EE3A8E1B" + - "8F85247F741B7C480521EE6BF8BA319B59048E65F08FAA76" - }), - new DRBGTestVector( - new SHA384Digest(), - new SHA384EntropyProvider().get(192), - false, - "202122232425262728292A2B", - 192, - new String[] - { - "E6A30AB0C9AFCBA673E4F1C94B3DB1F0C7D78B3D" + - "87B967281BE1E7B3CAF5200AED502C26B84FC169FE8336BD" + - "23271CB299812F2CF1955AA63FC362044ABA246EF1610F9E" + - "DC613924A84A00F8DB3FC65C13373F3171EB20848FA9A70E", - "8585764DF1C86EA12ACCB882525BF6217B447486" + - "5EBFDA367B8657FA80471139BAC626172B9F219DF2CE9099" + - "F65833E07CD1A8DD80468779EA3C26620A2C9C9F5C7EFCDD" + - "C036E6F6C8BF70316D3C37FC246A4CC79B3F1DB971D72ED0" - }) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F5051525354555657"), - new DRBGTestVector( - new SHA384Digest(), - new SHA384EntropyProvider().get(192), - false, - "202122232425262728292A2B", - 192, - new String[] - { - "13F6EA9BBA7BABDC2A52A3B9FD73D65ECAA638A0" + - "4C74BCCA2ACDE6FD29FEA4B5D884E095E87D1B7C0DEB9D37" + - "7AD81FBFEEA2D5EF82C0F6F52B9FCC359E769AC9DF2A876C" + - "58BAF21657814F3E66D1680B1D4EBD65581E42534F85197D", - "FC0A36F4D20F8F83BE3430AA3C36A49191821A82" + - "072BBC3D5AFF8D7EC39484D646277CE87599B6FE8CCA9862" + - "559703A10F4DE1066BFD30B80C325E774B512525BC6D3734" + - "4C93906368243D31F89E99C4D2A6E9BEB24D5F7267360DCA" - }) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F5051525354555657") - .addAdditionalInput("606162636465666768696A6B6C6D6E6F7071727374757677") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7"), - new DRBGTestVector( - new SHA384Digest(), - new SHA384EntropyProvider().get(192), - true, - "202122232425262728292A2B", - 192, - new String[] - { - "FE55601BF734493013705CCEB76E44AAD48373F7" + - "42E72B83D4701FA6549255F1CDE6217953522FF973BA4F6E" + - "C96D2BDCF14A76BE7DEB61781E34B99335BD714F17C91739" + - "B4E2AB57E36E9C3116E215D3D94FCFAD532636874875CAC7", - "F5E59D0ABADE81F62FFAB9D4A6A26FF200016608" + - "A7215E389858FFED83FBC75CFD33DBA6688C89AA32AD22E4" + - "80EA3D04EADFB35567B67564207E64B77844E8E4A87502D5" + - "02DBBB6D8277F1CACDB7CF8D293D09DB7DD59A950821507A" - }) - .addAdditionalInput("606162636465666768696A6B6C6D6E6F7071727374757677") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7"), - new DRBGTestVector( - new SHA384Digest(), - new SHA384EntropyProvider().get(192), - true, - "202122232425262728292A2B", - 192, - new String[] - { - "CC788F70FB08F256D9604333630D85936D400F45" + - "718DC3F939A8B9F6F75D3E4EC17D68FBB924AEACB7021295" + - "48FA63CE9BCB82176639B64DE890A47025B5582312FE934E" + - "F0D0A12697C0F05D2DA108CCADB511BA0EB62F4051BB2354", - "2C922EA620D76E4137B315EBC29E518F80951B3F" + - "0E6173FA2BFD94A230EE513EE2E4EB330D802F620DD24911" + - "534EC0F95A1F1D44A2125F5D57476A666FC372092B55D0D6" + - "8B49738F5BC466EC206AB3CF6A972B38BCFAE5FCD53C7E21 " - }), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(256), - false, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "7A8313798EE1" + - "D1898712683F2D0B0DEE5804146ABA64FDA8DB4E539CC8D1" + - "E59C74EE5AA48E73E958C8EC85DD529D42E68B4F7E02FFAF" + - "3E3EF8312AEA68BC08A414885E60A7DF0B55F9D90210B319" + - "E9B8FD23E078A4153636F29AA3CAC8198CB1D5D846151653" + - "ECE275A591089261238014E5058410065AB8229EB9115E8E", - "918B5D79E646" + - "64966D954BC5E2946BF48F061BF0C2701C3C2D1F75EA821E" + - "1DA05D5B3C2C4EEA246E806B53BF6BDB3F3D53A3AE756C2A" + - "45C72603973A3DE1BC367C283CA124A5589CEAB30E5D2D74" + - "8A40DD874FF15B032CF4F4B2AAD590B0DB91A0D38FCE93C5" + - "AAD4E55AC482F86FF06FAE66B7C7CCA7E45557E1A5A3B85D" - }), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(256), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "C7ED88A2C690" + - "1C04802BA2BB04262921B19664835A4A3C002CB9F13E35E3" + - "DEB3698A436BF1C85B070E9E6977CA78A5130905AA0C01A9" + - "4130F5133DF904A4ACF59A7DD01227E8FCA1C8D51F093839" + - "46ECD950113104760D7E216CAF581FE9D3AACE6FC4CDDC4C" + - "CD736D26A60BE8BE2A6A78CD752D1EC7CCC802638B177307", - "83B78B206785" + - "4412EEB24AEA86064D510C68FD96DBF94EAC1BC2022752D7" + - "558AEB9F97B9CBC1B9648FE4D88E2C82A6F530675E1DB92D" + - "396D6D85BDAD2A23CBD10AD808ECCCFBFC811EB68AE835E4" + - "912E011DD10A4399C8DE2D9D88F81B6168B05D282B9DAC1E" + - "65E0A45F61043E1FA047870DD582295E6C50DD1185B13594 " - }) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F") - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(256), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "CC7035C73040" + - "5CF5DF7137ED9E10744B75B540AFFC68EB564B71C0F737E8" + - "F656B6171940497FA90D8F383EFB6FC6717BA14AAA164EF5" + - "6641C0F513312551DCD21D0A5B0DBDCD97F627E968DFD752" + - "56C11CF2BCCA5822EAACE796A34CB7D2F8CD8CC6DBE76274" + - "498289BBC4C2F1CADA6185D82605CF992EC285BC4945EE9E", - "0E6C329AD1BE" + - "681EB1E6F5E03A89E3D80153D6CCDD5A3ECF865003EE4A2D" + - "E5A23B7F43681361CFAFC3A3FEF17777E75CF9D6685573C8" + - "87A3962CB955076D45D6F1E45EE4B8CB31A4731CDA031FA2" + - "815B6D34E29F2603526CE186576F4CCA3FEDF7F8ACDB37C9" + - "9D762706ABE4967D44739C8CFCFCC76C58B1ED243AC394C0" - }), - // From http://csrc.nist.gov/groups/STM/cavp/documents/drbg/drbgtestvectors.zip - // modified to test partial block processing. - new DRBGTestVector( - new SHA256Digest(), - new TestEntropySourceProvider(Hex.decode("a826f1cd3fa24b9e71c316e5bf2bafff"), false).get(128), - false, - "82bc3bf050614b34", - 128, - new String[] - { - "14949b876e30f832331f59f2e687350bea9ba22b78549521a70748ca916c74ebff0b638266aa" + - "d81e089545eb60bfe332f7d134d91ed3c104f975fae0f71391add71e3380a725251ed5552a84" + - "650637eddfc88b5ab26311277cbc429aa152b2cfac61c67846512d7564114177a622f25e870a" + - "acec37c0977d", - "7050bf74a887809673ecd295071f7a457d1e2e227f68ef4b4445e34f3904b95d4833180ee522" + - "104bfc996234063e2c76173937b883c66b0e64a56643877228cad5212cddbf839270ef80889b" + - "c83424c141c2419f2231004c8860f8fd95435e2c9f8ac7409fcbfb6a74851fadc7d99bf5d68b" + - "591892f0e3a1" - }), - new DRBGTestVector( - new SHA256Digest(), - new TestEntropySourceProvider(Hex.decode("a826f1cd3fa24b9e71c316e5bf2bafff"), false).get(128), - false, - "82bc3bf050614b34", - 128, - new String[] - { - "14949b876e30f832331f59f2e687350bea9ba22b78549521a70748ca916c74ebff0b638266aa" + - "d81e089545eb60bfe332f7d134d91ed3c104f975fae0f71391add71e3380a725251ed5552a84" + - "650637eddfc88b5ab26311277cbc429aa152b2cfac61c67846512d7564114177a622f25e870a" + - "acec37c0977d", - "7050bf74a887809673ecd295071f7a457d1e2e227f68ef4b4445e34f3904b95d4833180ee522" + - "104bfc996234063e2c76173937b883c66b0e64a56643877228cad5212cddbf839270ef80889b" + - "c83424c141c2419f2231004c8860f8fd95435e2c9f8ac7409fcbfb6a74851fadc7d99bf5d68b" + - "591892f0e3" - }) - }; - } - - public void performTest() - throws Exception - { - DRBGTestVector[] tests = createTestVectorData(); - - for (int i = 0; i != tests.length; i++) - { - DRBGTestVector tv = tests[i]; - - byte[] nonce = tv.nonce(); - byte[] personalisationString = tv.personalizationString(); - - SP80090DRBG d = new DualECSP800DRBG(tv.getDigest(), tv.securityStrength(), tv.entropySource(), personalisationString, nonce); - - byte[] output = new byte[tv.expectedValue(0).length]; - - d.generate(output, tv.additionalInput(0), tv.predictionResistance()); - - byte[] expected = tv.expectedValue(0); - - if (!areEqual(expected, output)) - { - fail("Test #" + (i + 1) + ".1 failed, expected " + new String(Hex.encode(tv.expectedValue(0))) + " got " + new String(Hex.encode(output))); - } - - output = new byte[tv.expectedValue(1).length]; - - d.generate(output, tv.additionalInput(1), tv.predictionResistance()); - - expected = tv.expectedValue(1); - if (!areEqual(expected, output)) - { - fail("Test #" + (i + 1) + ".2 failed, expected " + new String(Hex.encode(tv.expectedValue(1))) + " got " + new String(Hex.encode(output))); - } - } - - // Exception tests - // - SP80090DRBG d; - - try - { - d = new DualECSP800DRBG(new SHA256Digest(), 256, new SHA256EntropyProvider().get(128), null, null); - fail("no exception thrown"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("EntropySource must provide between 256 and 4096 bits")) - { - fail("Wrong exception", e); - } - } - - try - { - d = new DualECSP800DRBG(new SHA256Digest(), 256, new SHA256EntropyProvider().get(1 << (13 - 1) + 1), null, null); - fail("no exception thrown"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("EntropySource must provide between 256 and 4096 bits")) - { - fail("Wrong exception", e); - } - } - - try - { - d = new DualECSP800DRBG(new SHA1Digest(), 256, new SHA256EntropyProvider().get(256), null, null); - fail("no exception thrown"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("Requested security strength is not supported by digest")) - { - fail("Wrong exception", e); - } - } - } - - private class SHA256EntropyProvider - extends TestEntropySourceProvider - { - SHA256EntropyProvider() - { - super(Hex.decode( - "000102030405060708090A0B0C0D0E0F " + - "808182838485868788898A8B8C8D8E8F" + - "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF"), true); - } - } - - private class SHA384EntropyProvider - extends TestEntropySourceProvider - { - SHA384EntropyProvider() - { - super(Hex.decode( - "000102030405060708090A0B0C0D0E0F1011121314151617" + - "808182838485868788898A8B8C8D8E8F9091929394959697" + - "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7"), true); - } - } - - private class SHA512EntropyProvider - extends TestEntropySourceProvider - { - SHA512EntropyProvider() - { - super(Hex.decode( - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" + - "808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F" + - "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF"), true); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/FixedSecureRandomTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/FixedSecureRandomTest.java deleted file mode 100644 index a60896188..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/FixedSecureRandomTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.prng.test; - -import com.fr.third.org.bouncycastle.crypto.prng.FixedSecureRandom; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class FixedSecureRandomTest - extends SimpleTest -{ - byte[] base = Hex.decode("deadbeefdeadbeef"); - byte[] r1 = Hex.decode("cafebabecafebabe"); - byte[] r2 = Hex.decode("ffffffffcafebabedeadbeef"); - - public String getName() - { - return "FixedSecureRandom"; - } - - public void performTest() - throws Exception - { - FixedSecureRandom fixed = new FixedSecureRandom(base); - byte[] buf = new byte[8]; - - fixed.nextBytes(buf); - - if (!Arrays.areEqual(buf, base)) - { - fail("wrong data returned"); - } - - fixed = new FixedSecureRandom(base); - - byte[] seed = fixed.generateSeed(8); - - if (!Arrays.areEqual(seed, base)) - { - fail("wrong seed data returned"); - } - - if (!fixed.isExhausted()) - { - fail("not exhausted"); - } - - fixed = new FixedSecureRandom(new byte[][] { r1, r2 }); - - seed = fixed.generateSeed(12); - - if (!Arrays.areEqual(seed, Hex.decode("cafebabecafebabeffffffff"))) - { - fail("wrong seed data returned - composite"); - } - - fixed.nextBytes(buf); - - if (!Arrays.areEqual(buf, Hex.decode("cafebabedeadbeef"))) - { - fail("wrong data returned"); - } - } - - public static void main(String[] args) - { - runTest(new FixedSecureRandomTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/HMacDRBGTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/HMacDRBGTest.java deleted file mode 100644 index ac40e7c71..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/HMacDRBGTest.java +++ /dev/null @@ -1,508 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.prng.test; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA384Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.prng.drbg.HMacSP800DRBG; -import com.fr.third.org.bouncycastle.crypto.prng.drbg.SP80090DRBG; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * HMAC SP800-90 DRBG - */ -public class HMacDRBGTest - extends SimpleTest -{ - public String getName() - { - return "HMacDRBG"; - } - - public static void main(String[] args) - { - runTest(new HMacDRBGTest()); - } - - private DRBGTestVector[] createTestVectorData() - { - return new DRBGTestVector[] - { - new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - false, - "2021222324", - 80, - new String[] - { - "5A7D3B449F481CB38DF79AD2B1FCC01E57F8135E8C0B22CD0630BFB0127FB5408C8EFC17A929896E", - "82cf772ec3e84b00fc74f5df104efbfb2428554e9ce367d03aeade37827fa8e9cb6a08196115d948" - }), - new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - false, - "2021222324", - 80, - new String[] - { - "B3BD05246CBA12A64735A4E3FDE599BC1BE30F439BD060208EEA7D71F9D123DF47B3CE069D98EDE6", - "B5DADA380E2872DF935BCA55B882C8C9376902AB639765472B71ACEBE2EA8B1B6B49629CB67317E0" - }) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576"), - new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - false, - "2021222324", - 80, - new String[] - { - "C7AAAC583C6EF6300714C2CC5D06C148CFFB40449AD0BB26FAC0497B5C57E161E36681BCC930CE80", - "6EBD2B7B5E0A2AD7A24B1BF9A1DBA47D43271719B9C37B7FE81BA94045A14A7CB514B446666EA5A7" - }) - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F90919293949596") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6"), - new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - true, - "2021222324", - 80, - new String[] - { - "FEC4597F06A3A8CC8529D59557B9E661053809C0BC0EFC282ABD87605CC90CBA9B8633DCB1DAE02E", - "84ADD5E2D2041C01723A4DE4335B13EFDF16B0E51A0AD39BD15E862E644F31E4A2D7D843E57C5968" - }), - new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - true, - "2021222324", - 80, - new String[] - { - "6C37FDD729AA40F80BC6AB08CA7CC649794F6998B57081E4220F22C5C283E2C91B8E305AB869C625", - "CAF57DCFEA393B9236BF691FA456FEA7FDF1DF8361482CA54D5FA723F4C88B4FA504BF03277FA783" - }) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576"), - new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - true, - "2021222324", - 80, - new String[] - { - "A1BA8FA58BB5013F43F7B6ED52B4539FA16DC77957AEE815B9C07004C7E992EB8C7E591964AFEEA2", - "84264A73A818C95C2F424B37D3CC990B046FB50C2DC64A164211889A010F2471A0912FFEA1BF0195" - }) - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F90919293949596") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6"), - new DRBGTestVector( - new SHA256Digest(), - new SHA256EntropyProvider().get(440), - false, - "2021222324252627", - 128, - new String[] - { - "D67B8C1734F46FA3F763CF57C6F9F4F2" + - "DC1089BD8BC1F6F023950BFC5617635208C8501238AD7A44" + - "00DEFEE46C640B61AF77C2D1A3BFAA90EDE5D207406E5403", - "8FDAEC20F8B421407059E3588920DA7E" + - "DA9DCE3CF8274DFA1C59C108C1D0AA9B0FA38DA5C792037C" + - "4D33CD070CA7CD0C5608DBA8B885654639DE2187B74CB263" - }), - new DRBGTestVector( - new SHA256Digest(), - new SHA256EntropyProvider().get(440), - true, - "2021222324252627", - 128, - new String[] - { - "FABD0AE25C69DC2EFDEFB7F20C5A31B5" + - "7AC938AB771AA19BF8F5F1468F665C938C9A1A5DF0628A56" + - "90F15A1AD8A613F31BBD65EEAD5457D5D26947F29FE91AA7", - "6BD925B0E1C232EFD67CCD84F722E927" + - "ECB46AB2B740014777AF14BA0BBF53A45BDBB62B3F7D0B9C" + - "8EEAD057C0EC754EF8B53E60A1F434F05946A8B686AFBC7A" - }), - new DRBGTestVector( - new SHA384Digest(), - new SHA384EntropyProvider().get(888), - false, - "202122232425262728292A2B", - 192, - new String[]{ - "03AB8BCE4D1DBBB636C5C5B7E1C58499FEB1C619CDD11D35" + - "CD6CF6BB8F20EF27B6F5F9054FF900DB9EBF7BF30ED4DCBB" + - "BC8D5B51C965EA226FFEE2CA5AB2EFD00754DC32F357BF7A" + - "E42275E0F7704DC44E50A5220AD05AB698A22640AC634829", - "B907E77144FD55A54E9BA1A6A0EED0AAC780020C41A15DD8" + - "9A6C163830BA1D094E6A17100FF71EE30A96E1EE04D2A966" + - "03832A4E404F1966C2B5F4CB61B9927E8D12AC1E1A24CF23" + - "88C14E8EC96C35181EAEE32AAA46330DEAAFE5E7CE783C74"}) - .setPersonalizationString( - "404142434445464748494A4B4C4D4E" + - "4F505152535455565758595A5B5C5D5E5F60616263646566" + - "6768696A6B6C6D6E6F707172737475767778797A7B7C7D7E" + - "7F808182838485868788898A8B8C8D8E8F90919293949596" + - "9798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAE"), - new DRBGTestVector( - new SHA384Digest(), - new SHA384EntropyProvider().get(888), - true, - "202122232425262728292A2B", - 192, - new String[]{ - "804A3AD720F4FCE8738D0632514FEF16430CB7D63A8DF1A5" + - "F02A3CE3BD7ED6A668B69E63E2BB93F096EE753D6194A0F1" + - "A32711063653009636337D22167CC4402D019AC216FA574F" + - "091CF6EA283568D737A77BE38E8F09382C69E76B142ABC3A", - "73B8E55C753202176A17B9B9754A9FE6F23B01861FCD4059" + - "6AEAA301AF1AEF8AF0EAF22FBF34541EFFAB1431666ACACC" + - "759338C7E28672819D53CFEF10A3E19DAFBD53295F1980A9" + - "F491504A2725506784B7AC826D92C838A8668171CAAA86E7"}) - .setPersonalizationString( - "404142434445464748494A4B4C4D4E" + - "4F505152535455565758595A5B5C5D5E5F60616263646566" + - "6768696A6B6C6D6E6F707172737475767778797A7B7C7D7E" + - "7F808182838485868788898A8B8C8D8E8F90919293949596" + - "9798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAE"), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(888), - false, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[]{ - "2A5FF6520C20F66E" + - "D5EA431BD4AEAC58F975EEC9A015137D5C94B73AA09CB8B5" + - "9D611DDEECEB34A52BB999424009EB9EAC5353F92A6699D2" + - "0A02164EEBBC6492941E10426323898465DFD731C7E04730" + - "60A5AA8973841FDF3446FB6E72A58DA8BDA2A57A36F3DD98" + - "6DF85C8A5C6FF31CDE660BF8A841B21DD6AA9D3AC356B87B", - "0EDC8D7D7CEEC7FE" + - "36333FB30C0A9A4B27AA0BECBF075568B006C1C3693B1C29" + - "0F84769C213F98EB5880909EDF068FDA6BFC43503987BBBD" + - "4FC23AFBE982FE4B4B007910CC4874EEC217405421C8D8A1" + - "BA87EC684D0AF9A6101D9DB787AE82C3A6A25ED478DF1B12" + - "212CEC325466F3AC7C48A56166DD0B119C8673A1A9D54F67"}) - .setPersonalizationString( - "404142434445464748494A4B4C4D4E" + - "4F505152535455565758595A5B5C5D5E5F60616263646566" + - "6768696A6B6C6D6E6F707172737475767778797A7B7C7D7E" + - "7F808182838485868788898A8B8C8D8E8F90919293949596" + - "9798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAE"), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(888), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[]{ - "AAE4DC3C9ECC74D9" + - "061DD527117EF3D29E1E52B26853C539D6CA797E8DA3D0BB" + - "171D8E30B8B194D8C28F7F6BE3B986B88506DC6A01B294A7" + - "165DD1C3470F7BE7B396AA0DB7D50C4051E7C7E1C8A7D21A" + - "2B5878C0BCB163CAA79366E7A1162FDC88429616CD3E6977" + - "8D327520A6BBBF71D8AA2E03EC4A9DAA0E77CF93E1EE30D2 ", - "129FF6D31A23FFBC" + - "870632B35EE477C2280DDD2ECDABEDB900C78418BE2D243B" + - "B9D8E5093ECE7B6BF48638D8F704D134ADDEB7F4E9D5C142" + - "CD05683E72B516486AF24AEC15D61E81E270DD4EBED91B62" + - "12EB8896A6250D5C8BC3A4A12F7E3068FBDF856F47EB23D3" + - "79F82C1EBCD1585FB260B9C0C42625FBCEE68CAD773CD5B1"}) - .setPersonalizationString( - "404142434445464748494A4B4C4D4E" + - "4F505152535455565758595A5B5C5D5E5F60616263646566" + - "6768696A6B6C6D6E6F707172737475767778797A7B7C7D7E" + - "7F808182838485868788898A8B8C8D8E8F90919293949596" + - "9798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAE"), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(888), - false, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[]{ - "7AE31A2DEC31075F" + - "E5972660C16D22ECC0D415C5693001BE5A468B590BC1AE2C" + - "43F647F8D681AEEA0D87B79B0B4E5D089CA2C9D327534234" + - "0254E6B04690D77A71A294DA9568479EEF8BB2A2110F18B6" + - "22F60F35235DE0E8F9D7E98105D84AA24AF0757AF005DFD5" + - "2FA51DE3F44FCE0C5F3A27FCE8B0F6E4A3F7C7B53CE34A3D", - "D83A8084630F286D" + - "A4DB49B9F6F608C8993F7F1397EA0D6F4A72CF3EF2733A11" + - "AB823C29F2EBDEC3EDE962F93D920A1DB59C84E1E879C29F" + - "5F9995FC3A6A3AF9B587CA7C13EA197D423E81E1D6469942" + - "B6E2CA83A97E91F6B298266AC148A1809776C26AF5E239A5" + - "5A2BEB9E752203A694E1F3FE2B3E6A0C9C314421CDB55FBD "}) - .setPersonalizationString( - "404142434445464748494A4B4C4D4E" + - "4F505152535455565758595A5B5C5D5E5F60616263646566" + - "6768696A6B6C6D6E6F707172737475767778797A7B7C7D7E" + - "7F808182838485868788898A8B8C8D8E8F90919293949596" + - "9798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAE") - .addAdditionalInput( - "606162636465666768696A6B6C6D6E" + - "6F707172737475767778797A7B7C7D7E7F80818283848586" + - "8788898A8B8C8D8E8F909192939495969798999A9B9C9D9E" + - "9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6" + - "B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCE") - .addAdditionalInput( - "A0A1A2A3A4A5A6A7A8A9AAABACADAE" + - "AFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6" + - "C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDE" + - "DFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6" + - "F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E"), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(888), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[]{ - "28FD6060C4F35F4D" + - "317AB2060EE32019E0DAA330F3F5650BBCA57CB67EE6AF1C" + - "6F25D1B01F3601EDA85DC2ED29A9B2BA4C85CF491CE7185F" + - "1A2BD9378AE3C655BD1CEC2EE108AE7FC382989F6D4FEA8A" + - "B01499697C2F07945CE02C5ED617D04287FEAF3BA638A4CE" + - "F3BB6B827E40AF16279580FCF1FDAD830930F7FDE341E2AF", - "C0B1601AFE39338B" + - "58DC2BE7C256AEBE3C21C5A939BEEC7E97B3528AC420F0C6" + - "341847187666E0FF578A8EB0A37809F877365A28DF2FA0F0" + - "6354A6F02496747369375B9A9D6B756FDC4A8FB308E08256" + - "9D79A85BB960F747256626389A3B45B0ABE7ECBC39D5CD7B" + - "2C18DF2E5FDE8C9B8D43474C54B6F9839468445929B438C7"}), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(888), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[]{ - "72691D2103FB567C" + - "CD30370715B36666F63430087B1C688281CA0974DB456BDB" + - "A7EB5C48CFF62EA05F9508F3B530CE995A272B11EC079C13" + - "923EEF8E011A93C19B58CC6716BC7CB8BD886CAA60C14D85" + - "C023348BD77738C475D6C7E1D9BFF4B12C43D8CC73F838DC" + - "4F8BD476CF8328EEB71B3D873D6B7B859C9B21065638FF95", - "8570DA3D47E1E160" + - "5CF3E44B8D328B995EFC64107B6292D1B1036B5F88CE3160" + - "2F12BEB71D801C0942E7C0864B3DB67A9356DB203490D881" + - "24FE86BCE38AC2269B4FDA6ABAA884039DF80A0336A24D79" + - "1EB3067C8F5F0CF0F18DD73B66A7B316FB19E02835CC6293" + - "65FCD1D3BE640178ED9093B91B36E1D68135F2785BFF505C"}) - .addAdditionalInput( - "606162636465666768696A6B6C6D6E" + - "6F707172737475767778797A7B7C7D7E7F80818283848586" + - "8788898A8B8C8D8E8F909192939495969798999A9B9C9D9E" + - "9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6" + - "B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCE") - .addAdditionalInput( - "A0A1A2A3A4A5A6A7A8A9AAABACADAE" + - "AFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6" + - "C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDE" + - "DFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6" + - "F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E"), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(888), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[]{ - "AAE4DC3C9ECC74D9" + - "061DD527117EF3D29E1E52B26853C539D6CA797E8DA3D0BB" + - "171D8E30B8B194D8C28F7F6BE3B986B88506DC6A01B294A7" + - "165DD1C3470F7BE7B396AA0DB7D50C4051E7C7E1C8A7D21A" + - "2B5878C0BCB163CAA79366E7A1162FDC88429616CD3E6977" + - "8D327520A6BBBF71D8AA2E03EC4A9DAA0E77CF93E1EE30D2 ", - "129FF6D31A23FFBC" + - "870632B35EE477C2280DDD2ECDABEDB900C78418BE2D243B" + - "B9D8E5093ECE7B6BF48638D8F704D134ADDEB7F4E9D5C142" + - "CD05683E72B516486AF24AEC15D61E81E270DD4EBED91B62" + - "12EB8896A6250D5C8BC3A4A12F7E3068FBDF856F47EB23D3" + - "79F82C1EBCD1585FB260B9C0C42625FBCEE68CAD773CD5B1"}) - .setPersonalizationString( - "404142434445464748494A4B4C4D4E" + - "4F505152535455565758595A5B5C5D5E5F60616263646566" + - "6768696A6B6C6D6E6F707172737475767778797A7B7C7D7E" + - "7F808182838485868788898A8B8C8D8E8F90919293949596" + - "9798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAE"), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(888), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[]{ - "B8E827652175E6E0" + - "6E513C7BE94B5810C14ED94AD903647940CAEB7EE014C848" + - "8DCBBE6D4D6616D06656A3DC707CDAC4F02EE6D8408C065F" + - "CB068C0760DA47C5D60E5D70D09DC3929B6979615D117F7B" + - "EDCC661A98514B3A1F55B2CBABDCA59F11823E4838065F1F" + - "8431CBF28A577738234AF3F188C7190CC19739E72E9BBFFF", - "7ED41B9CFDC8C256" + - "83BBB4C553CC2DC61F690E62ABC9F038A16B8C519690CABE" + - "BD1B5C196C57CF759BB9871BE0C163A57315EA96F615136D" + - "064572F09F26D659D24211F9610FFCDFFDA8CE23FFA96735" + - "7595182660877766035EED800B05364CE324A75EB63FD9B3" + - "EED956D147480B1D0A42DF8AA990BB628666F6F61D60CBE2"}) - .setPersonalizationString( - "404142434445464748494A4B4C4D4E" + - "4F505152535455565758595A5B5C5D5E5F60616263646566" + - "6768696A6B6C6D6E6F707172737475767778797A7B7C7D7E" + - "7F808182838485868788898A8B8C8D8E8F90919293949596" + - "9798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAE") - .addAdditionalInput( - "606162636465666768696A6B6C6D6E" + - "6F707172737475767778797A7B7C7D7E7F80818283848586" + - "8788898A8B8C8D8E8F909192939495969798999A9B9C9D9E" + - "9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6" + - "B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCE") - .addAdditionalInput( - "A0A1A2A3A4A5A6A7A8A9AAABACADAE" + - "AFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6" + - "C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDE" + - "DFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6" + - "F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E") - }; - } - - public void performTest() - throws Exception - { - DRBGTestVector[] tests = createTestVectorData(); - - for (int i = 0; i != tests.length; i++) - { - DRBGTestVector tv = tests[i]; - - byte[] nonce = tv.nonce(); - byte[] personalisationString = tv.personalizationString(); - - SP80090DRBG d = new HMacSP800DRBG(new HMac(tv.getDigest()), tv.securityStrength(), tv.entropySource(), personalisationString, nonce); - - byte[] output = new byte[tv.expectedValue(0).length]; - - d.generate(output, tv.additionalInput(0), tv.predictionResistance()); - - byte[] expected = tv.expectedValue(0); - - if (!areEqual(expected, output)) - { - fail("Test #" + (i + 1) + ".1 failed, expected " + new String(Hex.encode(tv.expectedValue(0))) + " got " + new String(Hex.encode(output))); - } - - output = new byte[tv.expectedValue(0).length]; - - d.generate(output, tv.additionalInput(1), tv.predictionResistance()); - - expected = tv.expectedValue(1); - if (!areEqual(expected, output)) - { - fail("Test #" + (i + 1) + ".2 failed, expected " + new String(Hex.encode(tv.expectedValue(1))) + " got " + new String(Hex.encode(output))); - } - } - - // Exception tests - // - SP80090DRBG d; - try - { - d = new HMacSP800DRBG(new HMac(new SHA256Digest()), 256, new SHA256EntropyProvider().get(128), null, null); - fail("no exception thrown"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("Not enough entropy for security strength required")) - { - fail("Wrong exception", e); - } - } - } - - private class SHA1EntropyProvider - extends TestEntropySourceProvider - { - SHA1EntropyProvider() - { - super( - Hex.decode( - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F30313233343536" - + "808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6" - + "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6"), true); - } - } - - private class SHA256EntropyProvider - extends TestEntropySourceProvider - { - SHA256EntropyProvider() - { - super(Hex.decode( - "00010203040506" + - "0708090A0B0C0D0E0F101112131415161718191A1B1C1D1E" + - "1F202122232425262728292A2B2C2D2E2F30313233343536" + - "80818283848586" + - "8788898A8B8C8D8E8F909192939495969798999A9B9C9D9E" + - "9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6" + - "C0C1C2C3C4C5C6" + - "C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDE" + - "DFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6"), true); - } - } - - private class SHA384EntropyProvider - extends TestEntropySourceProvider - { - SHA384EntropyProvider() - { - super(Hex.decode( - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20212223242526" - + "2728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F50515253545556" - + "5758595A5B5C5D5E5F606162636465666768696A6B6C6D6E" + - "808182838485868788898A8B8C8D8E" + - "8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6" + - "A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBE" + - "BFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6" + - "D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEE" + - "C0C1C2C3C4C5C6C7C8C9CACBCCCDCE" + - "CFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6" + - "E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFE" + - "FF000102030405060708090A0B0C0D0E0F10111213141516" + - "1718191A1B1C1D1E1F202122232425262728292A2B2C2D2E"), true); - } - } - - private class SHA512EntropyProvider - extends TestEntropySourceProvider - { - SHA512EntropyProvider() - { - super(Hex.decode( - "000102030405060708090A0B0C0D0E" + - "0F101112131415161718191A1B1C1D1E1F20212223242526" + - "2728292A2B2C2D2E2F303132333435363738393A3B3C3D3E" + - "3F404142434445464748494A4B4C4D4E4F50515253545556" + - "5758595A5B5C5D5E5F606162636465666768696A6B6C6D6E" + - "808182838485868788898A8B8C8D8E" + - "8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6" + - "A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBE" + - "BFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6" + - "D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEE" + - "C0C1C2C3C4C5C6C7C8C9CACBCCCDCE" + - "CFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6" + - "E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFE" + - "FF000102030405060708090A0B0C0D0E0F10111213141516" + - "1718191A1B1C1D1E1F202122232425262728292A2B2C2D2E"), true); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/HashDRBGTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/HashDRBGTest.java deleted file mode 100644 index e416e7b86..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/HashDRBGTest.java +++ /dev/null @@ -1,481 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.prng.test; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA384Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512Digest; -import com.fr.third.org.bouncycastle.crypto.prng.drbg.HashSP800DRBG; -import com.fr.third.org.bouncycastle.crypto.prng.drbg.SP80090DRBG; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * DRBG Test - */ -public class HashDRBGTest - extends SimpleTest -{ - public String getName() - { - return "HashDRBG"; - } - - public static void main(String[] args) - { - runTest(new HashDRBGTest()); - } - - private DRBGTestVector[] createTestVectorData() - { - return new DRBGTestVector[] - { - new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - false, - "2021222324", - 80, - new String[] - { - "9F7CFF1ECA23E750F66326969F11800F12088BA68E441D15D888B3FE12BF66FE057494F4546DE2F1", - "B77AA5C0CD55BBCEED7574AF223AFD988C7EEC8EFF4A94E5E89D26A04F58FA79F5E0D3702D7A9A6A" - } - ), - new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - false, - "2021222324", - 80, - new String[] - { - "AB438BD3B01A0AF85CFEE29F7D7B71621C4908B909124D430E7B406FB1086EA994C582E0D656D989", - "29D9098F987E7005314A0F51B3DD2B8122F4AED706735DE6AD5DDBF223177C1E5F3AEBC52FAB90B9" - }) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576"), - new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - false, - "2021222324", - 80, - new String[] - { - "E76B4EDD5C865BC8AFD809A59B69B429AC7F4352A579BCF3F75E56249A3491F87C3CA6848B0FAB25", - "6577B6B4F87A93240B199FE51A3B335313683103DECE171E3256FB7E803586CA4E45DD242EB01F70" - }) - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F90919293949596") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6"), - new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - true, - "2021222324", - 80, - new String[] - { - "56EF4913373994D5539F4D7D17AFE7448CDF5E72416CC6A71A340059FA0D5AE526B23250C46C0944", - "575B37A2739814F966C63B60A2C4F149CA9ACC84FC4B25493289B085C67B2E30F5F0B99A2C349E2A" - }), - new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - true, - "2021222324", - 80, - new String[] - { - "532CA1165DCFF21C55592687639884AF4BC4B057DF8F41DE653AB44E2ADEC7C9303E75ABE277EDBF", - "73C2C67C696D686D0C4DBCEB5C2AF7DDF6F020B6874FAE4390F102117ECAAFF54418529A367005A0" - }) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576"), - new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - true, - "2021222324", - 80, - new String[] - { - "183C242A1430E46C4ED70B4DBE1BF9AB0AB8721CDCA2A2D1820AD6F6C956858543B2AA191D8D1287", - "F196F9BD021C745CBD5AC7BFCE48EAAF0D0E7C091FBF436940E63A198EE770D9A4F0718669AF2BC9" - }) - .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F90919293949596") - .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6"), - new DRBGTestVector( - new SHA256Digest(), - new SHA256EntropyProvider().get(440), - false, - "2021222324252627", - 128, - new String[] - { - "77E05A0E7DC78AB5D8934D5E93E82C06" + - "A07C04CEE6C9C53045EEB485872777CF3B3E35C474F976B8" + - "94BF301A86FA651F463970E89D4A0534B2ECAD29EC044E7E", - "5FF4BA493C40CFFF3B01E472C575668C" + - "CE3880B9290B05BFEDE5EC96ED5E9B2898508B09BC800EEE" + - "099A3C90602ABD4B1D4F343D497C6055C87BB956D53BF351" - } - ), - new DRBGTestVector( - new SHA256Digest(), - new SHA256EntropyProvider().get(440), - true, - "2021222324252627", - 128, - new String[] - { - "92275523C70E567BCF9B35EC50B933F8" + - "12616DF586B7F72EE1BC7735A5C2654373CBBC72316DFF84" + - "20A33BF02B97AC8D1952583F270ACD7005CC027F4CF1187E", - "681A46B2AA8694A0FE4DEEA720927A84" + - "EAAA985E59C19F8BE0984D8CBEF8C69B754167641946E040" + - "EE2043E1CCB29DCF063C0A50830E428E6DCA262ECD77C542" - }), - new DRBGTestVector( - new SHA384Digest(), - new SHA384EntropyProvider().get(888), - false, - "202122232425262728292A2B", - 192, - new String[] - { - "04FF23AD15E78790ADD36B438BBC097C7A11747CC2CCEEDE" + - "2C978B23B3DC63B732C953061D7764990ABFEFC47A581B92" + - "1BC0428C4F12212460E406A0F0651E7F0CB9A90ABFDB07B5" + - "25565C74F0AA085082F6CF213AAFAD0C0646895078F1E1FE", - "4F35B85F95DEE3E873054905CFD02341653E18F529930CBE" + - "14D909F37FEAF2C790D22FAE7516B4590BE35D53E2FE1A35" + - "AFE4B6607CB358589C3B4D094A1D81FE0717F1DF5BDDEB3E" + - "114F130BB781E66C22B5B770E8AE115FF39F8ADAF66DEEDF" - } - ), - new DRBGTestVector( - new SHA384Digest(), - new SHA384EntropyProvider().get(888), - true, - "202122232425262728292A2B", - 192, - new String[] - { - "97993B78F7C31C0E876DC92EB7D6C408E09D608AD6B99D0E" + - "A2229B05A578C426334FCC8A1C7E676ED2D89A5B4CDF5B3F" + - "4ADF11936BF14F4E10909DBA9C24F4FDFFDE72351DA8E2CC" + - "3B135A395373899E5F1A5955B880CA9B9E9DD4C9CA7FA4D4", - "F5983946320E36C64EF283CA1F65D197CF81624EC6778E77" + - "0E78949D84EF21A45CDD62D1DB76920D4C2836FC6AE5299F" + - "AF1357D9701FAD10FBD88D1E2832239436D76EB271BDC3CA" + - "04425EC88BC0E89A4D5C37FFCE7C6C3ABDE9C413AE6D3FEA" - } - ), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(888), - false, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "DA126CF95C6BF97E" + - "2F731F2137A907ACC70FD7AC9EBACD1C6E31C74029B052E3" + - "AABC48F3B00993F2B2381F7650A55322A968C86E05DE88E6" + - "367F6EF89A601DB4342E9086C7AC13B5E56C32E9E668040B" + - "73847893C5BFD38A1CF44F348B4EEE4CD68ADB7E7B8C837F" + - "19BC4F902761F7CFF24AB1D704FD11C4E929D8553753B55D", - "400B977CE8A2BB6A" + - "84C6FD1CF901459685ABF5408CFF4588CEDF52E2D2DC300A" + - "A9B4FAED8CD0161C2172B1FD269253195883D6EBF21020F2" + - "C20E5F2C81AE60C8595B834A229B1F5B726C1125717E6207" + - "8886EF38E61E32707AD5F8116C6393DFB6E7C7AE0E8E92BB" + - "D7E0C3D04BBA02F5169F2F569A58158915FEE4C9D28D45DB" - } - ) - .setPersonalizationString( - "404142434445464748494A4B4C4D4E" + - "4F505152535455565758595A5B5C5D5E5F60616263646566" + - "6768696A6B6C6D6E6F707172737475767778797A7B7C7D7E" + - "7F808182838485868788898A8B8C8D8E8F90919293949596" + - "9798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAE") - .addAdditionalInput( - "606162636465666768696A6B6C6D6E" + - "6F707172737475767778797A7B7C7D7E7F80818283848586" + - "8788898A8B8C8D8E8F909192939495969798999A9B9C9D9E" + - "9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6" + - "B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCE") - .addAdditionalInput( - "A0A1A2A3A4A5A6A7A8A9AAABACADAE" + - "AFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6" + - "C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDE" + - "DFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6" + - "F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E"), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(888), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "F93CA6855590A77F" + - "07354097E90E026648B6115DF008FFEDBD9D9811F54E8286" + - "EF00FDD6BA1E58DF2535E3FBDD9A9BA3754A97F36EE83322" + - "1582060A1F37FCE4EE8826636B28EAD589593F4CA8B64738" + - "8F24EB3F0A34796968D21BDEE6F81FD5DF93536F935937B8" + - "025EC8CBF57DDB0C61F2E41463CC1516D657DA2829C6BF90", - "4817618F48C60FB1" + - "CE5BFBDA0CAF4591882A31F6EE3FE0F78779992A06EC60F3" + - "7FB9A8D6108C231F0A927754B0599FA4FA27A4E25E065EF0" + - "3085B892979DC0E7A1080883CAEBFDFD3665A8F2D061C521" + - "F7D6E3DA2AF8B97B6B43B6EC831AF515070A83BBB9AC95ED" + - "4EF49B756A2377A5F0833D847E27A88DDB0C2CE4AD782E7B " - } - ), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(888), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "0455DD4AD7DBACB2" + - "410BE58DF7248D765A4547ABAEE1743B0BCAD37EBD06DA7C" + - "F7CE5E2216E525327E9E2005EBEF2CE53BD733B18128627D" + - "3FD6153089373AF2606A1584646A0EA488BFEF45228699A0" + - "89CEA8AEC44502D86D9591F3552C688B7F7B45FCB0C3C2B9" + - "43C1CD8A6FC63DF4D81C3DA543C9CF2843855EA84E4F959C", - "C047D46D7F614E4E" + - "4A7952C79A451F8F7ACA379967E2977C401C626A2ED70D74" + - "A63660579A354115BC8C8C8CC3AEA3050686A0CFCDB6FA9C" + - "F78D4C2165BAF851C6F9B1CD16A2E14C15C6DAAC56C16E75" + - "FC84A14D58B41622E88B0F1B1995587FD8BAA999CBA98025" + - "4C8AB9A9691DF7B84D88B639A9A3106DEABEB63748B99C09" - } - ) - .addAdditionalInput( - "606162636465666768696A6B6C6D6E" + - "6F707172737475767778797A7B7C7D7E7F80818283848586" + - "8788898A8B8C8D8E8F909192939495969798999A9B9C9D9E" + - "9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6" + - "B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCE") - .addAdditionalInput( - "A0A1A2A3A4A5A6A7A8A9AAABACADAE" + - "AFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6" + - "C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDE" + - "DFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6" + - "F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E"), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(888), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "22EB93A67911DA73" + - "85D9180C78127DE1A04FF713114C07C9C615F7CC5EF72744" + - "A2DDCD7C3CB85E65DED8EF5F240FBDCBEBBDE2BAAC8ECF7D" + - "CBC8AC333E54607AD41DC495D83DF72A05EF55B127C1441C" + - "9A0EFFDA2C7954DB6C2D04342EB812E5E0B11D6C395F41ED" + - "A2702ECE5BA479E2DFA18F953097492636C12FE30CE5C968", - "E66698CFBF1B3F2E" + - "919C03036E584EAA81CF1C6666240AF05F70637043733954" + - "D8A1E5A66A04C53C6900FDC145D4A3A80A31F5868ACE9AC9" + - "4E14E2051F624A05EEA1F8B684AA5410BCE315E76EA07C71" + - "5D6F34731320FF0DCF78D795E6EFA2DF92B98BE636CDFBA2" + - "9008DD392112AEC202F2E481CB9D83F987FEA69CD1B368BB" - } - ) - .setPersonalizationString( - "404142434445464748494A4B4C4D4E" + - "4F505152535455565758595A5B5C5D5E5F60616263646566" + - "6768696A6B6C6D6E6F707172737475767778797A7B7C7D7E" + - "7F808182838485868788898A8B8C8D8E8F90919293949596" + - "9798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAE"), - new DRBGTestVector( - new SHA512Digest(), - new SHA512EntropyProvider().get(888), - true, - "202122232425262728292A2B2C2D2E2F", - 256, - new String[] - { - "7596A76372308BD5" + - "A5613439934678B35521A94D81ABFE63A21ACF61ABB88B61" + - "E86A12C37F308F2BBBE32BE4B38D03AE808386494D70EF52" + - "E9E1365DD18B7784CAB826F31D47579E4D57F69D8BF3152B" + - "95741946CEBE58571DF58ED39980D9AF44E69F01E8989759" + - "8E40171101A0E3302838E0AD9E849C01988993CF9F6E5263", - "DBE5EE36FCD85301" + - "303E1C3617C1AC5E23C08885D0BEFAAD0C85A0D89F85B9F1" + - "6ECE3D88A24EB96504F2F13EFA7049621782F5DE2C416A0D" + - "294CCFE53545C4E309C48E1E285A2B829A574B72B3C2FBE1" + - "34D01E3706B486F2401B9820E17298A342666918E15B8462" + - "87F8C5AF2D96B20FAF3D0BB392E15F4A06CDB0DECD1B6AD7" - } - ) - .setPersonalizationString( - "404142434445464748494A4B4C4D4E" + - "4F505152535455565758595A5B5C5D5E5F60616263646566" + - "6768696A6B6C6D6E6F707172737475767778797A7B7C7D7E" + - "7F808182838485868788898A8B8C8D8E8F90919293949596" + - "9798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAE") - .addAdditionalInput( - "606162636465666768696A6B6C6D6E" + - "6F707172737475767778797A7B7C7D7E7F80818283848586" + - "8788898A8B8C8D8E8F909192939495969798999A9B9C9D9E" + - "9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6" + - "B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCE") - .addAdditionalInput( - "A0A1A2A3A4A5A6A7A8A9AAABACADAE" + - "AFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6" + - "C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDE" + - "DFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6" + - "F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E") - }; - } - - public void performTest() - throws Exception - { - DRBGTestVector[] tests = createTestVectorData(); - - for (int i = 0; i != tests.length; i++) - { - DRBGTestVector tv = tests[i]; - - byte[] nonce = tv.nonce(); - byte[] personalisationString = tv.personalizationString(); - - SP80090DRBG d = new HashSP800DRBG(tv.getDigest(), tv.securityStrength(), tv.entropySource(), personalisationString, nonce); - - byte[] output = new byte[tv.expectedValue(0).length]; - - d.generate(output, tv.additionalInput(0), tv.predictionResistance()); - - byte[] expected = tv.expectedValue(0); - - if (!areEqual(expected, output)) - { - fail("Test #" + (i + 1) + ".1 failed, expected " + new String(Hex.encode(tv.expectedValue(0))) + " got " + new String(Hex.encode(output))); - } - - output = new byte[tv.expectedValue(0).length]; - - d.generate(output, tv.additionalInput(1), tv.predictionResistance()); - - expected = tv.expectedValue(1); - if (!areEqual(expected, output)) - { - fail("Test #" + (i + 1) + ".2 failed, expected " + new String(Hex.encode(tv.expectedValue(1))) + " got " + new String(Hex.encode(output))); - } - } - - // Exception tests - // - SP80090DRBG d; - try - { - d = new HashSP800DRBG(new SHA256Digest(), 256, new SHA256EntropyProvider().get(128), null, null); - fail("no exception thrown"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("Not enough entropy for security strength required")) - { - fail("Wrong exception", e); - } - } - - try - { - d = new HashSP800DRBG(new SHA1Digest(), 256, new SHA256EntropyProvider().get(256), null, null); - fail("no exception thrown"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("Requested security strength is not supported by the derivation function")) - { - fail("Wrong exception", e); - } - } - } - - private class SHA1EntropyProvider - extends TestEntropySourceProvider - { - SHA1EntropyProvider() - { - super( - Hex.decode( - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F30313233343536" - + "808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6" - + "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6"), true); - } - } - - private class SHA256EntropyProvider - extends TestEntropySourceProvider - { - SHA256EntropyProvider() - { - super(Hex.decode( - "00010203040506" + - "0708090A0B0C0D0E0F101112131415161718191A1B1C1D1E" + - "1F202122232425262728292A2B2C2D2E2F30313233343536" + - "80818283848586" + - "8788898A8B8C8D8E8F909192939495969798999A9B9C9D9E" + - "9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6" + - "C0C1C2C3C4C5C6" + - "C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDE" + - "DFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6"), true); - } - } - - private class SHA384EntropyProvider - extends TestEntropySourceProvider - { - SHA384EntropyProvider() - { - super(Hex.decode( - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20212223242526" - + "2728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F50515253545556" - + "5758595A5B5C5D5E5F606162636465666768696A6B6C6D6E" + - "808182838485868788898A8B8C8D8E" + - "8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6" + - "A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBE" + - "BFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6" + - "D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEE" + - "C0C1C2C3C4C5C6C7C8C9CACBCCCDCE" + - "CFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6" + - "E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFE" + - "FF000102030405060708090A0B0C0D0E0F10111213141516" + - "1718191A1B1C1D1E1F202122232425262728292A2B2C2D2E"), true); - } - } - - private class SHA512EntropyProvider - extends TestEntropySourceProvider - { - SHA512EntropyProvider() - { - super(Hex.decode( - "000102030405060708090A0B0C0D0E" + - "0F101112131415161718191A1B1C1D1E1F20212223242526" + - "2728292A2B2C2D2E2F303132333435363738393A3B3C3D3E" + - "3F404142434445464748494A4B4C4D4E4F50515253545556" + - "5758595A5B5C5D5E5F606162636465666768696A6B6C6D6E" + - "808182838485868788898A8B8C8D8E" + - "8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6" + - "A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBE" + - "BFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6" + - "D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEE" + - "C0C1C2C3C4C5C6C7C8C9CACBCCCDCE" + - "CFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6" + - "E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFE" + - "FF000102030405060708090A0B0C0D0E0F10111213141516" + - "1718191A1B1C1D1E1F202122232425262728292A2B2C2D2E"), true); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/RegressionTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/RegressionTest.java deleted file mode 100644 index 7628a41a5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/RegressionTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.prng.test; - -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.Test; - -public class RegressionTest -{ - public static Test[] tests = { - new CTRDRBGTest(), - new DualECDRBGTest(), - new HashDRBGTest(), - new HMacDRBGTest(), - new SP800RandomTest(), - new X931Test(), - new FixedSecureRandomTest() - }; - - public static void main(String[] args) - { - SimpleTest.runTests(tests); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/SP800RandomTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/SP800RandomTest.java deleted file mode 100644 index 2eeb83029..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/SP800RandomTest.java +++ /dev/null @@ -1,288 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.prng.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.engines.DESedeEngine; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.prng.BasicEntropySourceProvider; -import com.fr.third.org.bouncycastle.crypto.prng.SP800SecureRandomBuilder; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class SP800RandomTest - extends SimpleTest -{ - - public String getName() - { - return "SP800RandomTest"; - } - - private void testHashRandom() - { - DRBGTestVector tv = new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - true, - "2021222324", - 80, - new String[] - { - "532CA1165DCFF21C55592687639884AF4BC4B057DF8F41DE653AB44E2ADEC7C9303E75ABE277EDBF", - "73C2C67C696D686D0C4DBCEB5C2AF7DDF6F020B6874FAE4390F102117ECAAFF54418529A367005A0" - }) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576"); - - doHashTest(0, tv); - - tv = new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - false, - "2021222324", - 80, - new String[] - { - "AB438BD3B01A0AF85CFEE29F7D7B71621C4908B909124D430E7B406FB1086EA994C582E0D656D989", - "29D9098F987E7005314A0F51B3DD2B8122F4AED706735DE6AD5DDBF223177C1E5F3AEBC52FAB90B9" - }) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576"); - - doHashTest(1, tv); - } - - private void doHashTest(int index, DRBGTestVector tv) - { - SP800SecureRandomBuilder rBuild = new SP800SecureRandomBuilder(new SHA1EntropyProvider()); - - rBuild.setPersonalizationString(tv.personalizationString()); - rBuild.setSecurityStrength(tv.securityStrength()); - rBuild.setEntropyBitsRequired(tv.entropySource().getEntropy().length * 8); - - SecureRandom random = rBuild.buildHash(tv.getDigest(), tv.nonce(), tv.predictionResistance()); - - byte[] expected = tv.expectedValue(0); - byte[] produced = new byte[expected.length]; - - random.nextBytes(produced); - - if (!Arrays.areEqual(expected, produced)) - { - fail(index + " SP800 Hash SecureRandom produced incorrect result (1)"); - } - - random.nextBytes(produced); - expected = tv.expectedValue(1); - - if (!Arrays.areEqual(expected, produced)) - { - fail(index + " SP800 Hash SecureRandom produced incorrect result (2)"); - } - } - - private void testHMACRandom() - { - DRBGTestVector tv = new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - true, - "2021222324", - 80, - new String[] - { - "6C37FDD729AA40F80BC6AB08CA7CC649794F6998B57081E4220F22C5C283E2C91B8E305AB869C625", - "CAF57DCFEA393B9236BF691FA456FEA7FDF1DF8361482CA54D5FA723F4C88B4FA504BF03277FA783" - }) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576"); - - doHMACTest(tv); - - tv = new DRBGTestVector( - new SHA1Digest(), - new SHA1EntropyProvider().get(440), - false, - "2021222324", - 80, - new String[] - { - "5A7D3B449F481CB38DF79AD2B1FCC01E57F8135E8C0B22CD0630BFB0127FB5408C8EFC17A929896E", - "82cf772ec3e84b00fc74f5df104efbfb2428554e9ce367d03aeade37827fa8e9cb6a08196115d948" - }); - - doHMACTest(tv); - } - - private void doHMACTest(DRBGTestVector tv) - { - SP800SecureRandomBuilder rBuild = new SP800SecureRandomBuilder(new SHA1EntropyProvider()); - - rBuild.setPersonalizationString(tv.personalizationString()); - rBuild.setSecurityStrength(tv.securityStrength()); - rBuild.setEntropyBitsRequired(tv.entropySource().getEntropy().length * 8); - - SecureRandom random = rBuild.buildHMAC(new HMac(tv.getDigest()), tv.nonce(), tv.predictionResistance()); - - byte[] expected = tv.expectedValue(0); - byte[] produced = new byte[expected.length]; - - random.nextBytes(produced); - if (!Arrays.areEqual(expected, produced)) - { - fail("SP800 HMAC SecureRandom produced incorrect result (1)"); - } - - random.nextBytes(produced); - expected = tv.expectedValue(1); - - if (!Arrays.areEqual(expected, produced)) - { - fail("SP800 HMAC SecureRandom produced incorrect result (2)"); - } - } - - private void testCTRRandom() - { - DRBGTestVector tv = new DRBGTestVector( - new DESedeEngine(), 168, - new Bit232EntropyProvider().get(232), - false, - "20212223242526", - 112, - new String[] - { - "ABC88224514D0316EA3D48AEE3C9A2B4", - "D3D3F372E43E7ABDC4FA293743EED076" - } - ); - - doCTRTest(tv); - - tv = new DRBGTestVector( - new DESedeEngine(), 168, - new Bit232EntropyProvider().get(232), - true, - "20212223242526", - 112, - new String[] - { - "64983055D014550B39DE699E43130B64", - "035FDDA8582A2214EC722C410A8D95D3" - } - ) - .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C"); - - doCTRTest(tv); - } - - private void doCTRTest(DRBGTestVector tv) - { - SP800SecureRandomBuilder rBuild = new SP800SecureRandomBuilder(new Bit232EntropyProvider()); - - rBuild.setPersonalizationString(tv.personalizationString()); - rBuild.setSecurityStrength(tv.securityStrength()); - rBuild.setEntropyBitsRequired(tv.entropySource().getEntropy().length * 8); - - SecureRandom random = rBuild.buildCTR(tv.getCipher(), tv.keySizeInBits(), tv.nonce(), tv.predictionResistance()); - - byte[] expected = tv.expectedValue(0); - byte[] produced = new byte[expected.length]; - - random.nextBytes(produced); - if (!Arrays.areEqual(expected, produced)) - { - fail("SP800 CTR SecureRandom produced incorrect result (1)"); - } - - random.nextBytes(produced); - expected = tv.expectedValue(1); - - if (!Arrays.areEqual(expected, produced)) - { - fail("SP800 CTR SecureRandom produced incorrect result (2)"); - } - } - - private void testGenerateSeed() - { - SP800SecureRandomBuilder rBuild = new SP800SecureRandomBuilder(new Bit232EntropyProvider()); - - rBuild.setPersonalizationString(Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C")); - rBuild.setSecurityStrength(112); - rBuild.setEntropyBitsRequired(232); - - SecureRandom random = rBuild.buildCTR(new DESedeEngine(), 168, Hex.decode("20212223242526"), false); - - rBuild = new SP800SecureRandomBuilder(new BasicEntropySourceProvider(random, false)); - - rBuild.setPersonalizationString(Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C")); - rBuild.setSecurityStrength(112); - rBuild.setEntropyBitsRequired(232); - - random = rBuild.buildCTR(new DESedeEngine(), 168, Hex.decode("20212223242526"), false); - - byte[] expected = Hex.decode("760bed7d92b083b10af31cf0656081eb51d241f0"); - - byte[] produced = random.generateSeed(20); - - if (!Arrays.areEqual(expected, produced)) - { - fail("SP800 CTR SecureRandom.generateSeed() produced incorrect result (1)"); - } - } - - public void performTest() - throws Exception - { - testHashRandom(); - testHMACRandom(); - testCTRRandom(); - testGenerateSeed(); - } - - public static void main(String[] args) - { - runTest(new SP800RandomTest()); - } - - // for HMAC/Hash - private class SHA1EntropyProvider - extends TestEntropySourceProvider - { - SHA1EntropyProvider() - { - super( - Hex.decode( - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F30313233343536" - + "808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6" - + "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6"), true); - } - } - - // for Dual EC - private class SHA256EntropyProvider - extends TestEntropySourceProvider - { - SHA256EntropyProvider() - { - super(Hex.decode( - "000102030405060708090A0B0C0D0E0F " + - "808182838485868788898A8B8C8D8E8F" + - "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF"), true); - } - } - - private class Bit232EntropyProvider - extends TestEntropySourceProvider - { - Bit232EntropyProvider() - { - super(Hex.decode( - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C" + - "808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C" + - "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDC"), true); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/TestEntropySourceProvider.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/TestEntropySourceProvider.java deleted file mode 100644 index 04f9095b8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/TestEntropySourceProvider.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.prng.test; - -import com.fr.third.org.bouncycastle.crypto.prng.EntropySource; -import com.fr.third.org.bouncycastle.crypto.prng.EntropySourceProvider; - -public class TestEntropySourceProvider - implements EntropySourceProvider -{ - private final byte[] data; - private final boolean isPredictionResistant; - - protected TestEntropySourceProvider(byte[] data, boolean isPredictionResistant) - { - this.data = data; - this.isPredictionResistant = isPredictionResistant; - } - - public EntropySource get(final int bitsRequired) - { - return new EntropySource() - { - int index = 0; - - public boolean isPredictionResistant() - { - return isPredictionResistant; - } - - public byte[] getEntropy() - { - byte[] rv = new byte[bitsRequired / 8]; - - System.arraycopy(data, index, rv, 0, rv.length); - - index += bitsRequired / 8; - - return rv; - } - - public int entropySize() - { - return bitsRequired; - } - }; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/X931Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/X931Test.java deleted file mode 100644 index 6086e1b10..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/X931Test.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.prng.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESedeEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.prng.X931SecureRandomBuilder; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * HMAC SP800-90 DRBG - */ -public class X931Test - extends SimpleTest -{ - public String getName() - { - return "X931"; - } - - public static void main(String[] args) - { - runTest(new X931Test()); - } - - private X931TestVector[] createTestVectorData() - { - return new X931TestVector[] - { - new X931TestVector( - new AESEngine(), - new AES128EntropyProvider(), - "f7d36762b9915f1ed585eb8e91700eb2", - "259e67249288597a4d61e7c0e690afae", - false, - new String[] { - "15f013af5a8e9df9a8e37500edaeac43", - "a9d74bb1c90a222adc398546d64879cf", - "0379e404042d58180764fb9e6c5d94bb", - "3c74603e036d28c79947ffb56fee4e51", - "e872101a4df81ebbe1e632fc87195d52", - "26a6b3d33b8e7e68b75d9630ec036314" }), - new X931TestVector( - new DESedeEngine(), - new TDESEntropyProvider(), - "ef16ec643e5db5892cbc6eabba310b3410e6f8759e3e382c", - "55df103deaf68dc4", - false, - new String[] { - "9c960bb9662ce6de", - "d9d0e527fd0931da", - "3e2db9994e9e6995", - "0e3868aef8218cf7", - "7b0b0ca137f8fd81", - "f657df270ad12265" }) - }; - } - - public void performTest() - throws Exception - { - X931TestVector[] vectors = createTestVectorData(); - - for (int i = 0; i != vectors.length; i++) - { - X931TestVector tv = vectors[i]; - X931SecureRandomBuilder bld = new X931SecureRandomBuilder(tv.getEntropyProvider()); - - bld.setDateTimeVector(Hex.decode(tv.getDateTimeVector())); - - SecureRandom rand = bld.build(tv.getEngine(), new KeyParameter(Hex.decode(tv.getKey())), tv.isPredictionResistant()); - - for (int j = 0; j != tv.getExpected().length - 1; j++) - { - byte[] expected = Hex.decode(tv.getExpected()[j]); - byte[] res = new byte[expected.length]; - - rand.nextBytes(res); - - if (!Arrays.areEqual(expected, res)) - { - fail("expected output wrong [" + j + "] got : " + Strings.fromByteArray(Hex.encode(res))); - } - } - - byte[] expected = Hex.decode(tv.getExpected()[tv.getExpected().length - 1]); - byte[] res = new byte[expected.length]; - - for (int j = tv.getExpected().length - 1; j != 10000; j++) - { - rand.nextBytes(res); - } - - if (!Arrays.areEqual(expected, res)) - { - fail("expected output wrong [" + 10000 + "] got : " + Strings.fromByteArray(Hex.encode(res))); - } - } - } - - private class AES128EntropyProvider - extends TestEntropySourceProvider - { - AES128EntropyProvider() - { - super(Hex.decode( - "35cc0ea481fc8a4f5f05c7d4667233b2"), true); - } - } - - private class TDESEntropyProvider - extends TestEntropySourceProvider - { - TDESEntropyProvider() - { - super(Hex.decode( - "96d872b9122c5e74"), true); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/X931TestVector.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/X931TestVector.java deleted file mode 100644 index 8adfef282..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/prng/test/X931TestVector.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.prng.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.prng.EntropySourceProvider; - -public class X931TestVector -{ - private final BlockCipher engine; - private final EntropySourceProvider entropyProvider; - private final String key; - private final String dateTimeVector; - private final boolean predictionResistant; - private final String[] expected; - - public X931TestVector(BlockCipher engine, EntropySourceProvider entropyProvider, String key, String dateTimeVector, boolean predictionResistant, String[] expected) - { - this.engine = engine; - this.entropyProvider = entropyProvider; - this.key = key; - - - this.dateTimeVector = dateTimeVector; - this.predictionResistant = predictionResistant; - this.expected = expected; - } - - public String getDateTimeVector() - { - return dateTimeVector; - } - - public BlockCipher getEngine() - { - return engine; - } - - public EntropySourceProvider getEntropyProvider() - { - return entropyProvider; - } - - public String[] getExpected() - { - return expected; - } - - public String getKey() - { - return key; - } - - public boolean isPredictionResistant() - { - return predictionResistant; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/DSASigner.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/DSASigner.java index cb54db236..48c035404 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/DSASigner.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/DSASigner.java @@ -105,7 +105,7 @@ public class DSASigner // the randomizer is to conceal timing information related to k and x. BigInteger r = params.getG().modPow(k.add(getRandomizer(q, random)), params.getP()).mod(q); - k = k.modInverse(q).multiply(m.add(x.multiply(r))); + k = BigIntegers.modOddInverse(q, k).multiply(m.add(x.multiply(r))); BigInteger s = k.mod(q); @@ -137,7 +137,7 @@ public class DSASigner return false; } - BigInteger w = s.modInverse(q); + BigInteger w = BigIntegers.modOddInverseVar(q, s); BigInteger u1 = m.multiply(w).mod(q); BigInteger u2 = r.multiply(w).mod(q); @@ -169,7 +169,7 @@ public class DSASigner protected SecureRandom initSecureRandom(boolean needed, SecureRandom provided) { - return !needed ? null : (provided != null) ? provided : CryptoServicesRegistrar.getSecureRandom(); + return needed ? CryptoServicesRegistrar.getSecureRandom(provided) : null; } private BigInteger getRandomizer(BigInteger q, SecureRandom provided) @@ -177,6 +177,6 @@ public class DSASigner // Calculate a random multiple of q to add to k. Note that g^q = 1 (mod p), so adding multiple of q to k does not change r. int randomBits = 7; - return BigIntegers.createRandomBigInteger(randomBits, provided != null ? provided : CryptoServicesRegistrar.getSecureRandom()).add(BigInteger.valueOf(128)).multiply(q); + return BigIntegers.createRandomBigInteger(randomBits, CryptoServicesRegistrar.getSecureRandom(provided)).add(BigInteger.valueOf(128)).multiply(q); } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/ECDSASigner.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/ECDSASigner.java index 1a3a59dd5..54a11099a 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/ECDSASigner.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/ECDSASigner.java @@ -18,6 +18,7 @@ import com.fr.third.org.bouncycastle.math.ec.ECFieldElement; import com.fr.third.org.bouncycastle.math.ec.ECMultiplier; import com.fr.third.org.bouncycastle.math.ec.ECPoint; import com.fr.third.org.bouncycastle.math.ec.FixedPointCombMultiplier; +import com.fr.third.org.bouncycastle.util.BigIntegers; /** * EC-DSA as described in X9.62 @@ -125,7 +126,7 @@ public class ECDSASigner } while (r.equals(ZERO)); - s = k.modInverse(n).multiply(e.add(d.multiply(r))).mod(n); + s = BigIntegers.modOddInverse(n, k).multiply(e.add(d.multiply(r))).mod(n); } while (s.equals(ZERO)); @@ -159,7 +160,7 @@ public class ECDSASigner return false; } - BigInteger c = s.modInverse(n); + BigInteger c = BigIntegers.modOddInverseVar(n, s); BigInteger u1 = e.multiply(c).mod(n); BigInteger u2 = r.multiply(c).mod(n); @@ -253,6 +254,6 @@ public class ECDSASigner protected SecureRandom initSecureRandom(boolean needed, SecureRandom provided) { - return !needed ? null : (provided != null) ? provided : CryptoServicesRegistrar.getSecureRandom(); + return needed ? CryptoServicesRegistrar.getSecureRandom(provided) : null; } } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/ECGOST3410Signer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/ECGOST3410Signer.java index c660a9c92..27fca15e5 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/ECGOST3410Signer.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/ECGOST3410Signer.java @@ -130,7 +130,7 @@ public class ECGOST3410Signer return false; } - BigInteger v = e.modInverse(n); + BigInteger v = BigIntegers.modOddInverseVar(n, e); BigInteger z1 = s.multiply(v).mod(n); BigInteger z2 = (n.subtract(r)).multiply(v).mod(n); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/ECGOST3410_2012Signer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/ECGOST3410_2012Signer.java index 995fd6f70..1e7d17551 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/ECGOST3410_2012Signer.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/ECGOST3410_2012Signer.java @@ -130,7 +130,7 @@ public class ECGOST3410_2012Signer return false; } - BigInteger v = e.modInverse(n); + BigInteger v = BigIntegers.modOddInverseVar(n, e); BigInteger z1 = s.multiply(v).mod(n); BigInteger z2 = (n.subtract(r)).multiply(v).mod(n); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed25519Signer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed25519Signer.java index 7effd5480..3e02cce7a 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed25519Signer.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed25519Signer.java @@ -28,10 +28,8 @@ public class Ed25519Signer if (forSigning) { - // TODO Allow AsymmetricCipherKeyPair to be a CipherParameters? - this.privateKey = (Ed25519PrivateKeyParameters)parameters; - this.publicKey = privateKey.generatePublicKey(); + this.publicKey = null; } else { @@ -59,7 +57,7 @@ public class Ed25519Signer throw new IllegalStateException("Ed25519Signer not initialised for signature generation."); } - return buffer.generateSignature(privateKey, publicKey); + return buffer.generateSignature(privateKey); } public boolean verifySignature(byte[] signature) @@ -79,10 +77,10 @@ public class Ed25519Signer private static class Buffer extends ByteArrayOutputStream { - synchronized byte[] generateSignature(Ed25519PrivateKeyParameters privateKey, Ed25519PublicKeyParameters publicKey) + synchronized byte[] generateSignature(Ed25519PrivateKeyParameters privateKey) { byte[] signature = new byte[Ed25519PrivateKeyParameters.SIGNATURE_SIZE]; - privateKey.sign(Ed25519.Algorithm.Ed25519, publicKey, null, buf, 0, count, signature, 0); + privateKey.sign(Ed25519.Algorithm.Ed25519, null, buf, 0, count, signature, 0); reset(); return signature; } @@ -91,6 +89,7 @@ public class Ed25519Signer { if (Ed25519.SIGNATURE_SIZE != signature.length) { + reset(); return false; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed25519ctxSigner.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed25519ctxSigner.java index 57621a434..21c9538fe 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed25519ctxSigner.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed25519ctxSigner.java @@ -30,10 +30,8 @@ public class Ed25519ctxSigner if (forSigning) { - // TODO Allow AsymmetricCipherKeyPair to be a CipherParameters? - this.privateKey = (Ed25519PrivateKeyParameters)parameters; - this.publicKey = privateKey.generatePublicKey(); + this.publicKey = null; } else { @@ -61,7 +59,7 @@ public class Ed25519ctxSigner throw new IllegalStateException("Ed25519ctxSigner not initialised for signature generation."); } - return buffer.generateSignature(privateKey, publicKey, context); + return buffer.generateSignature(privateKey, context); } public boolean verifySignature(byte[] signature) @@ -81,10 +79,10 @@ public class Ed25519ctxSigner private static class Buffer extends ByteArrayOutputStream { - synchronized byte[] generateSignature(Ed25519PrivateKeyParameters privateKey, Ed25519PublicKeyParameters publicKey, byte[] ctx) + synchronized byte[] generateSignature(Ed25519PrivateKeyParameters privateKey, byte[] ctx) { byte[] signature = new byte[Ed25519PrivateKeyParameters.SIGNATURE_SIZE]; - privateKey.sign(Ed25519.Algorithm.Ed25519ctx, publicKey, ctx, buf, 0, count, signature, 0); + privateKey.sign(Ed25519.Algorithm.Ed25519ctx, ctx, buf, 0, count, signature, 0); reset(); return signature; } @@ -93,6 +91,7 @@ public class Ed25519ctxSigner { if (Ed25519.SIGNATURE_SIZE != signature.length) { + reset(); return false; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed25519phSigner.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed25519phSigner.java index 6ffaa9d38..53190bf95 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed25519phSigner.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed25519phSigner.java @@ -29,10 +29,8 @@ public class Ed25519phSigner if (forSigning) { - // TODO Allow AsymmetricCipherKeyPair to be a CipherParameters? - this.privateKey = (Ed25519PrivateKeyParameters)parameters; - this.publicKey = privateKey.generatePublicKey(); + this.publicKey = null; } else { @@ -67,7 +65,7 @@ public class Ed25519phSigner } byte[] signature = new byte[Ed25519PrivateKeyParameters.SIGNATURE_SIZE]; - privateKey.sign(Ed25519.Algorithm.Ed25519ph, publicKey, context, msg, 0, Ed25519.PREHASH_SIZE, signature, 0); + privateKey.sign(Ed25519.Algorithm.Ed25519ph, context, msg, 0, Ed25519.PREHASH_SIZE, signature, 0); return signature; } @@ -79,6 +77,7 @@ public class Ed25519phSigner } if (Ed25519.SIGNATURE_SIZE != signature.length) { + prehash.reset(); return false; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed448Signer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed448Signer.java index 1f48d9d66..49716dd2a 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed448Signer.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed448Signer.java @@ -31,10 +31,8 @@ public class Ed448Signer if (forSigning) { - // TODO Allow AsymmetricCipherKeyPair to be a CipherParameters? - this.privateKey = (Ed448PrivateKeyParameters)parameters; - this.publicKey = privateKey.generatePublicKey(); + this.publicKey = null; } else { @@ -62,7 +60,7 @@ public class Ed448Signer throw new IllegalStateException("Ed448Signer not initialised for signature generation."); } - return buffer.generateSignature(privateKey, publicKey, context); + return buffer.generateSignature(privateKey, context); } public boolean verifySignature(byte[] signature) @@ -82,10 +80,10 @@ public class Ed448Signer private static class Buffer extends ByteArrayOutputStream { - synchronized byte[] generateSignature(Ed448PrivateKeyParameters privateKey, Ed448PublicKeyParameters publicKey, byte[] ctx) + synchronized byte[] generateSignature(Ed448PrivateKeyParameters privateKey, byte[] ctx) { byte[] signature = new byte[Ed448PrivateKeyParameters.SIGNATURE_SIZE]; - privateKey.sign(Ed448.Algorithm.Ed448, publicKey, ctx, buf, 0, count, signature, 0); + privateKey.sign(Ed448.Algorithm.Ed448, ctx, buf, 0, count, signature, 0); reset(); return signature; } @@ -94,6 +92,7 @@ public class Ed448Signer { if (Ed448.SIGNATURE_SIZE != signature.length) { + reset(); return false; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed448phSigner.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed448phSigner.java index 9d6ea193f..446fd1e40 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed448phSigner.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/Ed448phSigner.java @@ -29,10 +29,8 @@ public class Ed448phSigner if (forSigning) { - // TODO Allow AsymmetricCipherKeyPair to be a CipherParameters? - this.privateKey = (Ed448PrivateKeyParameters)parameters; - this.publicKey = privateKey.generatePublicKey(); + this.publicKey = null; } else { @@ -67,7 +65,7 @@ public class Ed448phSigner } byte[] signature = new byte[Ed448PrivateKeyParameters.SIGNATURE_SIZE]; - privateKey.sign(Ed448.Algorithm.Ed448ph, publicKey, context, msg, 0, Ed448.PREHASH_SIZE, signature, 0); + privateKey.sign(Ed448.Algorithm.Ed448ph, context, msg, 0, Ed448.PREHASH_SIZE, signature, 0); return signature; } @@ -79,6 +77,7 @@ public class Ed448phSigner } if (Ed448.SIGNATURE_SIZE != signature.length) { + prehash.reset(); return false; } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/SM2Signer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/SM2Signer.java index 6e21c2136..c93f1ec52 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/SM2Signer.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/SM2Signer.java @@ -20,6 +20,7 @@ import com.fr.third.org.bouncycastle.math.ec.ECFieldElement; import com.fr.third.org.bouncycastle.math.ec.ECMultiplier; import com.fr.third.org.bouncycastle.math.ec.ECPoint; import com.fr.third.org.bouncycastle.math.ec.FixedPointCombMultiplier; +import com.fr.third.org.bouncycastle.util.BigIntegers; import com.fr.third.org.bouncycastle.util.encoders.Hex; /** @@ -177,7 +178,7 @@ public class SM2Signer while (r.equals(ZERO) || r.add(k).equals(n)); // A6 - BigInteger dPlus1ModN = d.add(ONE).modInverse(n); + BigInteger dPlus1ModN = BigIntegers.modOddInverse(n, d.add(ONE)); s = k.subtract(r.multiply(d)).mod(n); s = dPlus1ModN.multiply(s).mod(n); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/package.html deleted file mode 100644 index 151d3d5e8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/signers/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Basic signers. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AEADTestUtil.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AEADTestUtil.java deleted file mode 100644 index 4a031da12..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AEADTestUtil.java +++ /dev/null @@ -1,475 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.OutputLengthException; -import com.fr.third.org.bouncycastle.crypto.modes.AEADBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.AEADCipher; -import com.fr.third.org.bouncycastle.crypto.params.AEADParameters; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestFailedException; - -public class AEADTestUtil -{ - public static void testTampering(Test test, AEADCipher cipher, CipherParameters params) - throws InvalidCipherTextException - { - byte[] plaintext = new byte[1000]; - for (int i = 0; i < plaintext.length; i++) - { - plaintext[i] = (byte)i; - } - cipher.init(true, params); - - byte[] ciphertext = new byte[cipher.getOutputSize(plaintext.length)]; - int len = cipher.processBytes(plaintext, 0, plaintext.length, ciphertext, 0); - cipher.doFinal(ciphertext, len); - - int macLength = cipher.getMac().length; - - // Test tampering with a single byte - cipher.init(false, params); - byte[] tampered = new byte[ciphertext.length]; - byte[] output = new byte[plaintext.length]; - System.arraycopy(ciphertext, 0, tampered, 0, tampered.length); - tampered[0] += 1; - - cipher.processBytes(tampered, 0, tampered.length, output, 0); - try - { - cipher.doFinal(output, 0); - throw new TestFailedException( - new SimpleTestResult(false, test + " : tampering of ciphertext not detected.")); - } - catch (InvalidCipherTextException e) - { - // Expected - } - - // Test truncation of ciphertext to < tag length - cipher.init(false, params); - byte[] truncated = new byte[macLength - 1]; - System.arraycopy(ciphertext, 0, truncated, 0, truncated.length); - - cipher.processBytes(truncated, 0, truncated.length, output, 0); - try - { - cipher.doFinal(output, 0); - fail(test, "tampering of ciphertext not detected."); - } - catch (InvalidCipherTextException e) - { - // Expected - } - } - - private static void fail(Test test, String message) - { - throw new TestFailedException(SimpleTestResult.failed(test, message)); - } - - private static void fail(Test test, String message, String expected, String result) - { - throw new TestFailedException(SimpleTestResult.failed(test, message, expected, result)); - } - - public static void testReset(Test test, AEADCipher cipher1, AEADBlockCipher cipher2, CipherParameters params) - throws InvalidCipherTextException - { - cipher1.init(true, params); - - byte[] plaintext = new byte[1000]; - byte[] ciphertext = new byte[cipher1.getOutputSize(plaintext.length)]; - - // Establish baseline answer - crypt(cipher1, plaintext, ciphertext); - - // Test encryption resets - checkReset(test, cipher1, params, true, plaintext, ciphertext); - - // Test decryption resets with fresh instance - cipher2.init(false, params); - checkReset(test, cipher2, params, false, ciphertext, plaintext); - } - - private static void checkReset(Test test, - AEADCipher cipher, - CipherParameters params, - boolean encrypt, - byte[] pretext, - byte[] posttext) - throws InvalidCipherTextException - { - // Do initial run - byte[] output = new byte[posttext.length]; - crypt(cipher, pretext, output); - - // Check encrypt resets cipher - crypt(cipher, pretext, output); - if (!Arrays.areEqual(output, posttext)) - { - fail(test, (encrypt ? "Encrypt" : "Decrypt") + " did not reset cipher."); - } - - // Check init resets data - cipher.processBytes(pretext, 0, 100, output, 0); - cipher.init(encrypt, params); - - try - { - crypt(cipher, pretext, output); - } - catch (DataLengthException e) - { - fail(test, "Init did not reset data."); - } - if (!Arrays.areEqual(output, posttext)) - { - fail(test, "Init did not reset data.", new String(Hex.encode(posttext)), new String(Hex.encode(output))); - } - - // Check init resets AD - cipher.processAADBytes(pretext, 0, 100); - cipher.init(encrypt, params); - - try - { - crypt(cipher, pretext, output); - } - catch (DataLengthException e) - { - fail(test, "Init did not reset additional data."); - } - if (!Arrays.areEqual(output, posttext)) - { - fail(test, "Init did not reset additional data."); - } - - // Check reset resets data - cipher.processBytes(pretext, 0, 100, output, 0); - cipher.reset(); - - try - { - crypt(cipher, pretext, output); - } - catch (DataLengthException e) - { - fail(test, "Init did not reset data."); - } - if (!Arrays.areEqual(output, posttext)) - { - fail(test, "Reset did not reset data."); - } - - // Check reset resets AD - cipher.processAADBytes(pretext, 0, 100); - cipher.reset(); - - try - { - crypt(cipher, pretext, output); - } - catch (DataLengthException e) - { - fail(test, "Init did not reset data."); - } - if (!Arrays.areEqual(output, posttext)) - { - fail(test, "Reset did not reset additional data."); - } - } - - private static void crypt(AEADCipher cipher, byte[] plaintext, byte[] output) - throws InvalidCipherTextException - { - int len = cipher.processBytes(plaintext, 0, plaintext.length, output, 0); - cipher.doFinal(output, len); - } - - public static void testOutputSizes(Test test, AEADBlockCipher cipher, AEADParameters params) - throws IllegalStateException, - InvalidCipherTextException - { - int maxPlaintext = cipher.getUnderlyingCipher().getBlockSize() * 10; - byte[] plaintext = new byte[maxPlaintext]; - byte[] ciphertext = new byte[maxPlaintext * 2]; - - // Check output size calculations for truncated ciphertext lengths - cipher.init(true, params); - cipher.doFinal(ciphertext, 0); - int macLength = cipher.getMac().length; - - cipher.init(false, params); - for (int i = 0; i < macLength; i++) - { - cipher.reset(); - if (cipher.getUpdateOutputSize(i) != 0) - { - fail(test, "AE cipher should not produce update output with ciphertext length <= macSize"); - } - if (cipher.getOutputSize(i) != 0) - { - fail(test, "AE cipher should not produce output with ciphertext length <= macSize"); - } - } - - for (int i = 0; i < plaintext.length; i++) - { - cipher.init(true, params); - int expectedCTUpdateSize = cipher.getUpdateOutputSize(i); - int expectedCTOutputSize = cipher.getOutputSize(i); - - if (expectedCTUpdateSize < 0) - { - fail(test, "Encryption update output size should not be < 0 for size " + i); - } - - if (expectedCTOutputSize < 0) - { - fail(test, "Encryption update output size should not be < 0 for size " + i); - } - - int actualCTSize = cipher.processBytes(plaintext, 0, i, ciphertext, 0); - - if (expectedCTUpdateSize != actualCTSize) - { - fail(test, "Encryption update output size did not match calculated for plaintext length " + i, - String.valueOf(expectedCTUpdateSize), String.valueOf(actualCTSize)); - } - - actualCTSize += cipher.doFinal(ciphertext, actualCTSize); - - if (expectedCTOutputSize != actualCTSize) - { - fail(test, "Encryption actual final output size did not match calculated for plaintext length " + i, - String.valueOf(expectedCTOutputSize), String.valueOf(actualCTSize)); - } - - cipher.init(false, params); - int expectedPTUpdateSize = cipher.getUpdateOutputSize(actualCTSize); - int expectedPTOutputSize = cipher.getOutputSize(actualCTSize); - - if (expectedPTOutputSize != i) - { - fail(test, "Decryption update output size did not original plaintext length " + i, - String.valueOf(expectedPTUpdateSize), String.valueOf(i)); - } - - int actualPTSize = cipher.processBytes(ciphertext, 0, actualCTSize, plaintext, 0); - - if (expectedPTUpdateSize != actualPTSize) - { - fail(test, "Decryption update output size did not match calculated for plaintext length " + i, - String.valueOf(expectedPTUpdateSize), String.valueOf(actualPTSize)); - } - - actualPTSize += cipher.doFinal(plaintext, actualPTSize); - - if (expectedPTOutputSize != actualPTSize) - { - fail(test, "Decryption update output size did not match calculated for plaintext length " + i, - String.valueOf(expectedPTOutputSize), String.valueOf(actualPTSize)); - } - - } - } - - public static void testBufferSizeChecks(Test test, AEADBlockCipher cipher, AEADParameters params) - throws IllegalStateException, - InvalidCipherTextException - { - int blockSize = cipher.getUnderlyingCipher().getBlockSize(); - int maxPlaintext = (blockSize * 10); - byte[] plaintext = new byte[maxPlaintext]; - - - cipher.init(true, params); - - int expectedUpdateOutputSize = cipher.getUpdateOutputSize(plaintext.length); - byte[] ciphertext = new byte[cipher.getOutputSize(plaintext.length)]; - - try - { - cipher.processBytes(new byte[maxPlaintext - 1], 0, maxPlaintext, new byte[expectedUpdateOutputSize], 0); - fail(test, "processBytes should validate input buffer length"); - } - catch (DataLengthException e) - { - // Expected - } - cipher.reset(); - - if (expectedUpdateOutputSize > 0) - { - int outputTrigger = 0; - // Process bytes until output would be produced - for(int i = 0; i < plaintext.length; i++) { - if (cipher.getUpdateOutputSize(1) != 0) - { - outputTrigger = i + 1; - break; - } - cipher.processByte(plaintext[i], ciphertext, 0); - } - if (outputTrigger == 0) - { - fail(test, "Failed to find output trigger size"); - } - try - { - cipher.processByte(plaintext[0], new byte[cipher.getUpdateOutputSize(1) - 1], 0); - fail(test, "Encrypt processByte should validate output buffer length"); - } - catch (OutputLengthException e) - { - // Expected - } - cipher.reset(); - - // Repeat checking with entire input at once - try - { - cipher.processBytes(plaintext, 0, outputTrigger, - new byte[cipher.getUpdateOutputSize(outputTrigger) - 1], 0); - fail(test, "Encrypt processBytes should validate output buffer length"); - } - catch (OutputLengthException e) - { - // Expected - } - cipher.reset(); - - } - - // Remember the actual ciphertext for later - int actualOutputSize = cipher.processBytes(plaintext, 0, plaintext.length, ciphertext, 0); - actualOutputSize += cipher.doFinal(ciphertext, actualOutputSize); - int macSize = cipher.getMac().length; - - cipher.reset(); - try - { - cipher.processBytes(plaintext, 0, plaintext.length, ciphertext, 0); - cipher.doFinal(new byte[cipher.getOutputSize(0) - 1], 0); - fail(test, "Encrypt doFinal should validate output buffer length"); - } - catch (OutputLengthException e) - { - // Expected - } - - // Decryption tests - - cipher.init(false, params); - expectedUpdateOutputSize = cipher.getUpdateOutputSize(actualOutputSize); - - if (expectedUpdateOutputSize > 0) - { - // Process bytes until output would be produced - int outputTrigger = 0; - for (int i = 0; i < plaintext.length; i++) - { - if (cipher.getUpdateOutputSize(1) != 0) - { - outputTrigger = i + 1; - break; - } - cipher.processByte(ciphertext[i], plaintext, 0); - } - if (outputTrigger == 0) - { - fail(test, "Failed to find output trigger size"); - } - - try - { - cipher.processByte(ciphertext[0], new byte[cipher.getUpdateOutputSize(1) - 1], 0); - fail(test, "Decrypt processByte should validate output buffer length"); - } - catch (OutputLengthException e) - { - // Expected - } - cipher.reset(); - - // Repeat test with processBytes - try - { - cipher.processBytes(ciphertext, 0, outputTrigger, - new byte[cipher.getUpdateOutputSize(outputTrigger) - 1], 0); - fail(test, "Decrypt processBytes should validate output buffer length"); - } - catch (OutputLengthException e) - { - // Expected - } - } - - cipher.reset(); - // Data less than mac length should fail before output length check - try - { - // Assumes AE cipher on decrypt can't return any data until macSize bytes are received - if (cipher.processBytes(ciphertext, 0, macSize - 1, plaintext, 0) != 0) - { - fail(test, "AE cipher unexpectedly produced output"); - } - cipher.doFinal(new byte[0], 0); - fail(test, "Decrypt doFinal should check ciphertext length"); - } - catch (InvalidCipherTextException e) - { - // Expected - } - - try - { - // Search through plaintext lengths until one is found that creates >= 1 buffered byte - // during decryption of ciphertext for doFinal to handle - for (int i = 2; i < plaintext.length; i++) - { - cipher.init(true, params); - int encrypted = cipher.processBytes(plaintext, 0, i, ciphertext, 0); - encrypted += cipher.doFinal(ciphertext, encrypted); - - cipher.init(false, params); - cipher.processBytes(ciphertext, 0, encrypted - 1, plaintext, 0); - if (cipher.processByte(ciphertext[encrypted - 1], plaintext, 0) == 0) - { - cipher.doFinal(new byte[cipher.getOutputSize(0) - 1], 0); - fail(test, "Decrypt doFinal should check output length"); - cipher.reset(); - - // Truncated Mac should be reported in preference to inability to output - // buffered plaintext byte - try - { - cipher.processBytes(ciphertext, 0, actualOutputSize - 1, plaintext, 0); - cipher.doFinal(new byte[cipher.getOutputSize(0) - 1], 0); - fail(test, "Decrypt doFinal should check ciphertext length"); - } - catch (InvalidCipherTextException e) - { - // Expected - } - cipher.reset(); - } - } - fail(test, "Decrypt doFinal test couldn't find a ciphertext length that buffered for doFinal"); - } - catch (OutputLengthException e) - { - // Expected - } - } - - static AEADParameters reuseKey(AEADParameters p) - { - return new AEADParameters(null, p.getMacSize(), p.getNonce(), p.getAssociatedText()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESFastTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESFastTest.java deleted file mode 100644 index b9dca693e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESFastTest.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.engines.AESFastEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test vectors from the NIST standard tests and Brian Gladman's vector set - * - * http://fp.gladman.plus.com/cryptography_technology/rijndael/ - */ -public class AESFastTest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new AESFastEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "0EDD33D3C621E546455BD8BA1418BEC8"), - new BlockCipherVectorTest(1, new AESFastEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000080")), - "00000000000000000000000000000000", "172AEAB3D507678ECAF455C12587ADB7"), - new BlockCipherMonteCarloTest(2, 10000, new AESFastEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", "C34C052CC0DA8D73451AFE5F03BE297F"), - new BlockCipherMonteCarloTest(3, 10000, new AESFastEngine(), - new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")), - "355F697E8B868B65B25A04E18D782AFA", "ACC863637868E3E068D2FD6E3508454A"), - new BlockCipherVectorTest(4, new AESFastEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "6CD02513E8D4DC986B4AFE087A60BD0C"), - new BlockCipherMonteCarloTest(5, 10000, new AESFastEngine(), - new KeyParameter(Hex.decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")), - "F3F6752AE8D7831138F041560631B114", "77BA00ED5412DFF27C8ED91F3C376172"), - new BlockCipherVectorTest(6, new AESFastEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "DDC6BF790C15760D8D9AEB6F9A75FD4E"), - new BlockCipherMonteCarloTest(7, 10000, new AESFastEngine(), - new KeyParameter(Hex.decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")), - "C737317FE0846F132B23C8C2A672CE22", "E58B82BFBA53C0040DC610C642121168"), - new BlockCipherVectorTest(8, new AESFastEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "0EDD33D3C621E546455BD8BA1418BEC8"), - new BlockCipherVectorTest(9, new AESFastEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000080")), - "00000000000000000000000000000000", "172AEAB3D507678ECAF455C12587ADB7"), - new BlockCipherMonteCarloTest(10, 10000, new AESFastEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", "C34C052CC0DA8D73451AFE5F03BE297F"), - new BlockCipherMonteCarloTest(11, 10000, new AESFastEngine(), - new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")), - "355F697E8B868B65B25A04E18D782AFA", "ACC863637868E3E068D2FD6E3508454A"), - new BlockCipherVectorTest(12, new AESFastEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "6CD02513E8D4DC986B4AFE087A60BD0C"), - new BlockCipherMonteCarloTest(13, 10000, new AESFastEngine(), - new KeyParameter(Hex.decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")), - "F3F6752AE8D7831138F041560631B114", "77BA00ED5412DFF27C8ED91F3C376172"), - new BlockCipherVectorTest(14, new AESFastEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "DDC6BF790C15760D8D9AEB6F9A75FD4E"), - new BlockCipherMonteCarloTest(15, 10000, new AESFastEngine(), - new KeyParameter(Hex.decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")), - "C737317FE0846F132B23C8C2A672CE22", "E58B82BFBA53C0040DC610C642121168"), - new BlockCipherVectorTest(16, new AESFastEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "0EDD33D3C621E546455BD8BA1418BEC8"), - new BlockCipherVectorTest(17, new AESFastEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000080")), - "00000000000000000000000000000000", "172AEAB3D507678ECAF455C12587ADB7"), - new BlockCipherMonteCarloTest(18, 10000, new AESFastEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", "C34C052CC0DA8D73451AFE5F03BE297F"), - new BlockCipherMonteCarloTest(19, 10000, new AESFastEngine(), - new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")), - "355F697E8B868B65B25A04E18D782AFA", "ACC863637868E3E068D2FD6E3508454A"), - new BlockCipherVectorTest(20, new AESFastEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "6CD02513E8D4DC986B4AFE087A60BD0C"), - new BlockCipherMonteCarloTest(21, 10000, new AESFastEngine(), - new KeyParameter(Hex.decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")), - "F3F6752AE8D7831138F041560631B114", "77BA00ED5412DFF27C8ED91F3C376172"), - new BlockCipherVectorTest(22, new AESFastEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "DDC6BF790C15760D8D9AEB6F9A75FD4E"), - new BlockCipherMonteCarloTest(23, 10000, new AESFastEngine(), - new KeyParameter(Hex.decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")), - "C737317FE0846F132B23C8C2A672CE22", "E58B82BFBA53C0040DC610C642121168") - }; - - private BlockCipher _engine = new AESFastEngine(); - - AESFastTest() - { - super(tests, new AESFastEngine(), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "AESFast"; - } - - public void performTest() - throws Exception - { - super.performTest(); - - byte[] keyBytes = new byte[16]; - - _engine.init(true, new KeyParameter(keyBytes)); - - // - // init tests - // - try - { - byte[] dudKey = new byte[6]; - - _engine.init(true, new KeyParameter(dudKey)); - - fail("failed key length check"); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - byte[] iv = new byte[16]; - - _engine.init(true, new ParametersWithIV(null, iv)); - - fail("failed parameter check"); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - public static void main( - String[] args) - { - runTest(new AESFastTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESLightTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESLightTest.java deleted file mode 100644 index 1c2fe6146..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESLightTest.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.engines.AESLightEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test vectors from the NIST standard tests and Brian Gladman's vector set - * - * http://fp.gladman.plus.com/cryptography_technology/rijndael/ - */ -public class AESLightTest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new AESLightEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "0EDD33D3C621E546455BD8BA1418BEC8"), - new BlockCipherVectorTest(1, new AESLightEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000080")), - "00000000000000000000000000000000", "172AEAB3D507678ECAF455C12587ADB7"), - new BlockCipherMonteCarloTest(2, 10000, new AESLightEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", "C34C052CC0DA8D73451AFE5F03BE297F"), - new BlockCipherMonteCarloTest(3, 10000, new AESLightEngine(), - new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")), - "355F697E8B868B65B25A04E18D782AFA", "ACC863637868E3E068D2FD6E3508454A"), - new BlockCipherVectorTest(4, new AESLightEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "6CD02513E8D4DC986B4AFE087A60BD0C"), - new BlockCipherMonteCarloTest(5, 10000, new AESLightEngine(), - new KeyParameter(Hex.decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")), - "F3F6752AE8D7831138F041560631B114", "77BA00ED5412DFF27C8ED91F3C376172"), - new BlockCipherVectorTest(6, new AESLightEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "DDC6BF790C15760D8D9AEB6F9A75FD4E"), - new BlockCipherMonteCarloTest(7, 10000, new AESLightEngine(), - new KeyParameter(Hex.decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")), - "C737317FE0846F132B23C8C2A672CE22", "E58B82BFBA53C0040DC610C642121168"), - new BlockCipherVectorTest(8, new AESLightEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "0EDD33D3C621E546455BD8BA1418BEC8"), - new BlockCipherVectorTest(9, new AESLightEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000080")), - "00000000000000000000000000000000", "172AEAB3D507678ECAF455C12587ADB7"), - new BlockCipherMonteCarloTest(10, 10000, new AESLightEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", "C34C052CC0DA8D73451AFE5F03BE297F"), - new BlockCipherMonteCarloTest(11, 10000, new AESLightEngine(), - new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")), - "355F697E8B868B65B25A04E18D782AFA", "ACC863637868E3E068D2FD6E3508454A"), - new BlockCipherVectorTest(12, new AESLightEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "6CD02513E8D4DC986B4AFE087A60BD0C"), - new BlockCipherMonteCarloTest(13, 10000, new AESLightEngine(), - new KeyParameter(Hex.decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")), - "F3F6752AE8D7831138F041560631B114", "77BA00ED5412DFF27C8ED91F3C376172"), - new BlockCipherVectorTest(14, new AESLightEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "DDC6BF790C15760D8D9AEB6F9A75FD4E"), - new BlockCipherMonteCarloTest(15, 10000, new AESLightEngine(), - new KeyParameter(Hex.decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")), - "C737317FE0846F132B23C8C2A672CE22", "E58B82BFBA53C0040DC610C642121168"), - new BlockCipherVectorTest(16, new AESLightEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "0EDD33D3C621E546455BD8BA1418BEC8"), - new BlockCipherVectorTest(17, new AESLightEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000080")), - "00000000000000000000000000000000", "172AEAB3D507678ECAF455C12587ADB7"), - new BlockCipherMonteCarloTest(18, 10000, new AESLightEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", "C34C052CC0DA8D73451AFE5F03BE297F"), - new BlockCipherMonteCarloTest(19, 10000, new AESLightEngine(), - new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")), - "355F697E8B868B65B25A04E18D782AFA", "ACC863637868E3E068D2FD6E3508454A"), - new BlockCipherVectorTest(20, new AESLightEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "6CD02513E8D4DC986B4AFE087A60BD0C"), - new BlockCipherMonteCarloTest(21, 10000, new AESLightEngine(), - new KeyParameter(Hex.decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")), - "F3F6752AE8D7831138F041560631B114", "77BA00ED5412DFF27C8ED91F3C376172"), - new BlockCipherVectorTest(22, new AESLightEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "DDC6BF790C15760D8D9AEB6F9A75FD4E"), - new BlockCipherMonteCarloTest(23, 10000, new AESLightEngine(), - new KeyParameter(Hex.decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")), - "C737317FE0846F132B23C8C2A672CE22", "E58B82BFBA53C0040DC610C642121168") - }; - - private BlockCipher _engine = new AESLightEngine(); - - AESLightTest() - { - super(tests, new AESLightEngine(), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "AESLight"; - } - - public void performTest() - throws Exception - { - super.performTest(); - - byte[] keyBytes = new byte[16]; - - _engine.init(true, new KeyParameter(keyBytes)); - - // - // init tests - // - try - { - byte[] dudKey = new byte[6]; - - _engine.init(true, new KeyParameter(dudKey)); - - fail("failed key length check"); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - byte[] iv = new byte[16]; - - _engine.init(true, new ParametersWithIV(null, iv)); - - fail("failed parameter check"); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - public static void main( - String[] args) - { - runTest(new AESLightTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESTest.java deleted file mode 100644 index 2c25f1f29..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESTest.java +++ /dev/null @@ -1,478 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.BufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.OFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.SICBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test vectors from the NIST standard tests and Brian Gladman's vector set - * - * http://fp.gladman.plus.com/cryptography_technology/rijndael/ - */ -public class AESTest - extends CipherTest -{ - private static final byte[] tData = Hex.decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114F3F6752AE8D7831138F041560631B1145A01020304050607"); - private static final byte[] outCBC1 = Hex.decode("a444a9a4d46eb30cb7ed34d62873a89f8fdf2bf8a54e1aeadd06fd85c9cb46f021ee7cd4f418fa0bb72e9d07c70d5d20"); - private static final byte[] outCBC2 = Hex.decode("585681354f0e01a86b32f94ebb6a675045d923cf201263c2aaecca2b4de82da0edd74ca5efd654c688f8a58e61955b11"); - private static final byte[] outSIC1 = Hex.decode("82a1744e8ebbd053ca72362d5e570326e0b6fdaf824ab673fbf029042886b23c75129a015852913790f81f94447475a0"); - private static final byte[] outSIC2 = Hex.decode("146cbb581d9e12c3333dd9c736fbb93043c92019f78580da48f81f80b3f551d58ea836fed480fc6912fefa9c5c89cc24"); - private static final byte[] outCFB1 = Hex.decode("82a1744e8ebbd053ca72362d5e5703264b4182de3208c374b8ac4fa36af9c5e5f4f87d1e3b67963d06acf5eb13914c90"); - private static final byte[] outCFB2 = Hex.decode("146cbb581d9e12c3333dd9c736fbb9303c8a3eb5185e2809e9d3c28e25cc2d2b6f5c11ee28d6530f72c412b1438a816a"); - private static final byte[] outOFB1 = Hex.decode("82a1744e8ebbd053ca72362d5e5703261ebf1fdbec05e57b3465b583132f84b43bf95b2c89040ad1677b22d42db69a7a"); - private static final byte[] outOFB2 = Hex.decode("146cbb581d9e12c3333dd9c736fbb9309ea4c2a7696c84959a2dada49f2f1c5905db1f0cec3a31acbc4701e74ab05e1f"); - - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new AESEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "0EDD33D3C621E546455BD8BA1418BEC8"), - new BlockCipherVectorTest(1, new AESEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000080")), - "00000000000000000000000000000000", "172AEAB3D507678ECAF455C12587ADB7"), - new BlockCipherMonteCarloTest(2, 10000, new AESEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", "C34C052CC0DA8D73451AFE5F03BE297F"), - new BlockCipherMonteCarloTest(3, 10000, new AESEngine(), - new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")), - "355F697E8B868B65B25A04E18D782AFA", "ACC863637868E3E068D2FD6E3508454A"), - new BlockCipherVectorTest(4, new AESEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "6CD02513E8D4DC986B4AFE087A60BD0C"), - new BlockCipherMonteCarloTest(5, 10000, new AESEngine(), - new KeyParameter(Hex.decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")), - "F3F6752AE8D7831138F041560631B114", "77BA00ED5412DFF27C8ED91F3C376172"), - new BlockCipherVectorTest(6, new AESEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "DDC6BF790C15760D8D9AEB6F9A75FD4E"), - new BlockCipherMonteCarloTest(7, 10000, new AESEngine(), - new KeyParameter(Hex.decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")), - "C737317FE0846F132B23C8C2A672CE22", "E58B82BFBA53C0040DC610C642121168"), - new BlockCipherVectorTest(8, new AESEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "0EDD33D3C621E546455BD8BA1418BEC8"), - new BlockCipherVectorTest(9, new AESEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000080")), - "00000000000000000000000000000000", "172AEAB3D507678ECAF455C12587ADB7"), - new BlockCipherMonteCarloTest(10, 10000, new AESEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", "C34C052CC0DA8D73451AFE5F03BE297F"), - new BlockCipherMonteCarloTest(11, 10000, new AESEngine(), - new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")), - "355F697E8B868B65B25A04E18D782AFA", "ACC863637868E3E068D2FD6E3508454A"), - new BlockCipherVectorTest(12, new AESEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "6CD02513E8D4DC986B4AFE087A60BD0C"), - new BlockCipherMonteCarloTest(13, 10000, new AESEngine(), - new KeyParameter(Hex.decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")), - "F3F6752AE8D7831138F041560631B114", "77BA00ED5412DFF27C8ED91F3C376172"), - new BlockCipherVectorTest(14, new AESEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "DDC6BF790C15760D8D9AEB6F9A75FD4E"), - new BlockCipherMonteCarloTest(15, 10000, new AESEngine(), - new KeyParameter(Hex.decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")), - "C737317FE0846F132B23C8C2A672CE22", "E58B82BFBA53C0040DC610C642121168"), - new BlockCipherVectorTest(16, new AESEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "0EDD33D3C621E546455BD8BA1418BEC8"), - new BlockCipherVectorTest(17, new AESEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000080")), - "00000000000000000000000000000000", "172AEAB3D507678ECAF455C12587ADB7"), - new BlockCipherMonteCarloTest(18, 10000, new AESEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", "C34C052CC0DA8D73451AFE5F03BE297F"), - new BlockCipherMonteCarloTest(19, 10000, new AESEngine(), - new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")), - "355F697E8B868B65B25A04E18D782AFA", "ACC863637868E3E068D2FD6E3508454A"), - new BlockCipherVectorTest(20, new AESEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "6CD02513E8D4DC986B4AFE087A60BD0C"), - new BlockCipherMonteCarloTest(21, 10000, new AESEngine(), - new KeyParameter(Hex.decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")), - "F3F6752AE8D7831138F041560631B114", "77BA00ED5412DFF27C8ED91F3C376172"), - new BlockCipherVectorTest(22, new AESEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "DDC6BF790C15760D8D9AEB6F9A75FD4E"), - new BlockCipherMonteCarloTest(23, 10000, new AESEngine(), - new KeyParameter(Hex.decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")), - "C737317FE0846F132B23C8C2A672CE22", "E58B82BFBA53C0040DC610C642121168") - }; - - private BlockCipher _engine = new AESEngine(); - - public AESTest() - { - super(tests, new AESEngine(), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "AES"; - } - - private void testNullSIC() - throws InvalidCipherTextException - { - BufferedBlockCipher b = new BufferedBlockCipher(new SICBlockCipher(new AESEngine())); - KeyParameter kp = new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")); - - b.init(true, new ParametersWithIV(kp, new byte[16])); - - byte[] out = new byte[b.getOutputSize(tData.length)]; - - int len = b.processBytes(tData, 0, tData.length, out, 0); - - len += b.doFinal(out, len); - - if (!areEqual(outSIC1, out)) - { - fail("no match on first nullSIC check"); - } - - b.init(true, new ParametersWithIV(null, Hex.decode("000102030405060708090a0b0c0d0e0f"))); - - len = b.processBytes(tData, 0, tData.length, out, 0); - - len += b.doFinal(out, len); - - if (!areEqual(outSIC2, out)) - { - fail("no match on second nullSIC check"); - } - } - - private void testNullCBC() - throws InvalidCipherTextException - { - BufferedBlockCipher b = new BufferedBlockCipher(new CBCBlockCipher(new AESEngine())); - KeyParameter kp = new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")); - - b.init(true, new ParametersWithIV(kp, new byte[16])); - - byte[] out = new byte[b.getOutputSize(tData.length)]; - - int len = b.processBytes(tData, 0, tData.length, out, 0); - - len += b.doFinal(out, len); - - if (!areEqual(outCBC1, out)) - { - fail("no match on first nullCBC check"); - } - - b.init(true, new ParametersWithIV(null, Hex.decode("000102030405060708090a0b0c0d0e0f"))); - - len = b.processBytes(tData, 0, tData.length, out, 0); - - len += b.doFinal(out, len); - - if (!areEqual(outCBC2, out)) - { - fail("no match on second nullCBC check"); - } - } - - private void testNullOFB() - throws InvalidCipherTextException - { - BufferedBlockCipher b = new BufferedBlockCipher(new OFBBlockCipher(new AESEngine(), 128)); - KeyParameter kp = new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")); - - b.init(true, new ParametersWithIV(kp, new byte[16])); - - byte[] out = new byte[b.getOutputSize(tData.length)]; - - int len = b.processBytes(tData, 0, tData.length, out, 0); - - len += b.doFinal(out, len); - - if (!areEqual(outOFB1, out)) - { - fail("no match on first nullOFB check"); - } - - b.init(true, new ParametersWithIV(null, Hex.decode("000102030405060708090a0b0c0d0e0f"))); - - len = b.processBytes(tData, 0, tData.length, out, 0); - - len += b.doFinal(out, len); - - if (!areEqual(outOFB2, out)) - { - fail("no match on second nullOFB check"); - } - } - - private void testNullCFB() - throws InvalidCipherTextException - { - BufferedBlockCipher b = new BufferedBlockCipher(new CFBBlockCipher(new AESEngine(), 128)); - KeyParameter kp = new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")); - - b.init(true, new ParametersWithIV(kp, new byte[16])); - - byte[] out = new byte[b.getOutputSize(tData.length)]; - - int len = b.processBytes(tData, 0, tData.length, out, 0); - - len += b.doFinal(out, len); - - if (!areEqual(outCFB1, out)) - { - fail("no match on first nullCFB check"); - } - - b.init(true, new ParametersWithIV(null, Hex.decode("000102030405060708090a0b0c0d0e0f"))); - - len = b.processBytes(tData, 0, tData.length, out, 0); - - len += b.doFinal(out, len); - - if (!areEqual(outCFB2, out)) - { - fail("no match on second nullCFB check"); - } - } - - private boolean areEqual(byte[] a, int aOff, byte[] b, int bOff) - { - for (int i = bOff; i != b.length; i++) - { - if (a[aOff + i - bOff] != b[i]) - { - return false; - } - } - - return true; - } - - private void skipTest() - { - CipherParameters params = new ParametersWithIV(new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")), Hex.decode("00000000000000000000000000000000")); - SICBlockCipher engine = new SICBlockCipher(new AESEngine()); - - engine.init(true, params); - - SecureRandom rand = new SecureRandom(); - byte[] plain = new byte[50000]; - byte[] cipher = new byte[50000]; - - rand.nextBytes(plain); - engine.processBytes(plain, 0, plain.length, cipher, 0); - - byte[] fragment = new byte[20]; - - engine.init(true, params); - - engine.skip(10); - - if (engine.getPosition() != 10) - { - fail("skip position incorrect - 10 got " + engine.getPosition()); - } - - engine.processBytes(plain, 10, fragment.length, fragment, 0); - - if (!areEqual(cipher, 10, fragment, 0)) - { - fail("skip forward 10 failed"); - } - - engine.skip(1000); - - if (engine.getPosition() != 1010 + fragment.length) - { - fail("skip position incorrect - " + (1010 + fragment.length) + " got " + engine.getPosition()); - } - - engine.processBytes(plain, 1010 + fragment.length, fragment.length, fragment, 0); - - if (!areEqual(cipher, 1010 + fragment.length, fragment, 0)) - { - fail("skip forward 1000 failed"); - } - - engine.skip(-10); - - if (engine.getPosition() != 1010 + 2 * fragment.length - 10) - { - fail("skip position incorrect - " + (1010 + 2 * fragment.length - 10) + " got " + engine.getPosition()); - } - - engine.processBytes(plain, 1010 + 2 * fragment.length - 10, fragment.length, fragment, 0); - - if (!areEqual(cipher, 1010 + 2 * fragment.length - 10, fragment, 0)) - { - fail("skip back 10 failed"); - } - - engine.skip(-1000); - - if (engine.getPosition() != 60) - { - fail("skip position incorrect - " + 60 + " got " + engine.getPosition()); - } - - engine.processBytes(plain, 60, fragment.length, fragment, 0); - - if (!areEqual(cipher, 60, fragment, 0)) - { - fail("skip back 1000 failed"); - } - - long pos = engine.seekTo(1010); - - if (pos != 1010) - { - fail("position incorrect - " + 1010 + " got " + pos); - } - - engine.processBytes(plain, 1010, fragment.length, fragment, 0); - - if (!areEqual(cipher, 1010, fragment, 0)) - { - fail("seek to 1010 failed"); - } - - engine.reset(); - - for (int i = 0; i != 5000; i++) - { - engine.skip(i); - - if (engine.getPosition() != i) - { - fail("skip forward at wrong position"); - } - - engine.processBytes(plain, i, fragment.length, fragment, 0); - - if (!areEqual(cipher, i, fragment, 0)) - { - fail("skip forward i failed: " + i); - } - - if (engine.getPosition() != i + fragment.length) - { - fail("cipher at wrong position: " + engine.getPosition() + " [" + i + "]"); - } - - engine.skip(-fragment.length); - - if (engine.getPosition() != i) - { - fail("skip back at wrong position"); - } - - engine.processBytes(plain, i, fragment.length, fragment, 0); - - if (!areEqual(cipher, i, fragment, 0)) - { - fail("skip back i failed: " + i); - } - - engine.reset(); - } - } - - private void ctrCounterTest() - { - CipherParameters params = new ParametersWithIV(new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")), Hex.decode("000000000000000000000000000000")); - SICBlockCipher engine = new SICBlockCipher(new AESEngine()); - - engine.init(true, params); - - SecureRandom rand = new SecureRandom(); - byte[] cipher = new byte[256 * 16]; - byte[] plain = new byte[255 * 16]; - - rand.nextBytes(plain); - engine.processBytes(plain, 0, plain.length, cipher, 0); - - engine.init(true, params); - - byte[] fragment = new byte[20]; - - plain = new byte[256 * 16]; - engine.init(true, params); - - try - { - engine.processBytes(plain, 0, plain.length, cipher, 0); - fail("out of range data not caught"); - } - catch (IllegalStateException e) - { - if (!"Counter in CTR/SIC mode out of range.".equals(e.getMessage())) - { - fail("wrong exception"); - } - } - } - - public void performTest() - throws Exception - { - super.performTest(); - - byte[] keyBytes = new byte[16]; - - _engine.init(true, new KeyParameter(keyBytes)); - - // - // init tests - // - try - { - byte[] dudKey = new byte[6]; - - _engine.init(true, new KeyParameter(dudKey)); - - fail("failed key length check"); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - byte[] iv = new byte[16]; - - _engine.init(true, new ParametersWithIV(null, iv)); - - fail("failed parameter check"); - } - catch (IllegalArgumentException e) - { - // expected - } - - testNullCBC(); - testNullSIC(); - testNullOFB(); - testNullCFB(); - - skipTest(); - ctrCounterTest(); - } - - public static void main( - String[] args) - { - runTest(new AESTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESVectorFileTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESVectorFileTest.java deleted file mode 100644 index fa0a6aae7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESVectorFileTest.java +++ /dev/null @@ -1,258 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.AESFastEngine; -import com.fr.third.org.bouncycastle.crypto.engines.AESLightEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * Test vectors from the NIST standard tests and Brian Gladman's vector set - * - * http://fp.gladman.plus.com/cryptography_technology/rijndael/ - */ -public class AESVectorFileTest - implements Test -{ - - private int countOfTests = 0; - private int testNum = 0; - - protected BlockCipher createNewEngineForTest() - { - return new AESEngine(); - } - - private Test[] readTestVectors(InputStream inStream) - { - // initialize key, plaintext, ciphertext = null - // read until find BLOCKSIZE= - // return if not 128 - // read KEYSIZE= or ignore - // loop - // read a line - // if starts with BLOCKSIZE= - // parse the rest. return if not 128 - // if starts with KEY= - // parse the rest and set KEY - // if starts with PT= - // parse the rest and set plaintext - // if starts with CT= - // parse the rest and set ciphertext - // if starts with TEST= or end of file - // if key, plaintext, ciphertext are all not null - // save away their values as the next test - // until end of file - List tests = new ArrayList(); - String key = null; - String plaintext = null; - String ciphertext = null; - - BufferedReader in = new BufferedReader(new InputStreamReader(inStream)); - - try - { - String line = in.readLine(); - - while (line != null) - { - line = line.trim().toLowerCase(); - if (line.startsWith("blocksize=")) - { - int i = 0; - try - { - i = Integer.parseInt(line.substring(10).trim()); - } - catch (Exception e) - { - } - if (i != 128) - { - return null; - } - } - else if (line.startsWith("keysize=")) - { - int i = 0; - try - { - i = Integer.parseInt(line.substring(10).trim()); - } - catch (Exception e) - { - } - if ((i != 128) && (i != 192) && (i != 256)) - { - return null; - } - } - else if (line.startsWith("key=")) - { - key = line.substring(4).trim(); - } - else if (line.startsWith("pt=")) - { - plaintext = line.substring(3).trim(); - } - else if (line.startsWith("ct=")) - { - ciphertext = line.substring(3).trim(); - } - else if (line.startsWith("test=")) - { - if ((key != null) && (plaintext != null) - && (ciphertext != null)) - { - tests.add(new BlockCipherVectorTest(testNum++, - createNewEngineForTest(), new KeyParameter(Hex - .decode(key)), plaintext, ciphertext)); - } - } - - line = in.readLine(); - } - try - { - in.close(); - } - catch (IOException e) - { - } - } - catch (IOException e) - { - } - if ((key != null) && (plaintext != null) && (ciphertext != null)) - { - tests.add(new BlockCipherVectorTest(testNum++, - createNewEngineForTest(), - new KeyParameter(Hex.decode(key)), plaintext, ciphertext)); - } - return (Test[])(tests.toArray(new Test[tests.size()])); - } - - public String getName() - { - return "AES"; - } - - private TestResult performTestsFromZipFile(File zfile) - { - try - { - ZipFile inZip = new ZipFile(zfile); - for (Enumeration files = inZip.entries(); files.hasMoreElements();) - { - Test[] tests = null; - try - { - tests = readTestVectors(inZip - .getInputStream((ZipEntry)(files.nextElement()))); - } - catch (Exception e) - { - return new SimpleTestResult(false, getName() + ": threw " - + e); - } - if (tests != null) - { - for (int i = 0; i != tests.length; i++) - { - TestResult res = tests[i].perform(); - countOfTests++; - - if (!res.isSuccessful()) - { - return res; - } - } - } - } - inZip.close(); - return new SimpleTestResult(true, getName() + ": Okay"); - } - catch (Exception e) - { - return new SimpleTestResult(false, getName() + ": threw " + e); - } - } - - private static final String[] zipFileNames = { "rijn.tv.ecbnk.zip", - "rijn.tv.ecbnt.zip", "rijn.tv.ecbvk.zip", "rijn.tv.ecbvt.zip" }; - - public TestResult perform() - { - countOfTests = 0; - for (int i = 0; i < zipFileNames.length; i++) - { - File inf = new File(zipFileNames[i]); - TestResult res = performTestsFromZipFile(inf); - if (!res.isSuccessful()) - { - return res; - } - } - return new SimpleTestResult(true, getName() + ": " + countOfTests - + " performed Okay"); - } - - public static void main(String[] args) - { - AESVectorFileTest test = new AESVectorFileTest(); - TestResult result = test.perform(); - System.out.println(result); - - test = new AESLightVectorFileTest(); - result = test.perform(); - System.out.println(result); - - test = new AESFastVectorFileTest(); - result = test.perform(); - System.out.println(result); - - } - - private static class AESLightVectorFileTest extends AESVectorFileTest - { - protected BlockCipher createNewEngineForTest() - { - return new AESLightEngine(); - } - - public String getName() - { - return "AESLight"; - } - - } - - private static class AESFastVectorFileTest extends AESVectorFileTest - { - protected BlockCipher createNewEngineForTest() - { - return new AESFastEngine(); - } - - public String getName() - { - return "AESFast"; - } - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESWrapPadTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESWrapPadTest.java deleted file mode 100644 index f5f883d28..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESWrapPadTest.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.Wrapper; -import com.fr.third.org.bouncycastle.crypto.engines.AESWrapPadEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * This is a test harness I use because I cannot modify the BC test harness without - * invalidating the signature on their signed provider library. The code here is not - * high quality but it does test the RFC vectors as well as randomly generated values. - * The RFC test vectors are tested by making sure both the ciphertext and decrypted - * values match the expected values whereas the random values are just checked to make - * sure that: - *unwrap(wrap(random_value, random_kek), random_kek) == random_value.
- */ - -public class AESWrapPadTest - extends SimpleTest -{ - - private final int numOfRandomIterations = 100; - - public AESWrapPadTest() - { - - } - - private void wrapAndUnwrap(byte[] kek, byte[] key, byte[] expected) - throws Exception - { - Wrapper wrapper = new AESWrapPadEngine(); - - wrapper.init(true, new KeyParameter(kek)); - - byte[] cipherText = wrapper.wrap(key, 0, key.length); - if (!areEqual(cipherText, expected)) - { - fail("Wrapped value does not match expected."); - } - wrapper.init(false, new KeyParameter(kek)); - byte[] plainText = wrapper.unwrap(cipherText, 0, cipherText.length); - - if (!areEqual(key, plainText)) - { - fail("Unwrapped value does not match original."); - } - } - - private void wrapAndUnwrap(byte[] kek, byte[] key) - throws Exception - { - Wrapper wrapper = new AESWrapPadEngine(); - - wrapper.init(true, new KeyParameter(kek)); - - byte[] cipherText = wrapper.wrap(key, 0, key.length); - - wrapper.init(false, new KeyParameter(kek)); - byte[] plainText = wrapper.unwrap(cipherText, 0, cipherText.length); - - if (!areEqual(key, plainText)) - { - fail("Unwrapped value does not match original."); - } - } - - private void wrapWithIVTest() - throws Exception - { - byte[] kek = Hex.decode("5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8"); - byte[] key = Hex.decode("c37b7e6492584340bed12207808941155068f738"); - byte[] expected = Hex.decode("5cbdb3fb71351d0e628b85dbcba1a1890d4db26d1335e11d1aabea11124caad0"); - - Wrapper wrapper = new AESWrapPadEngine(); - - wrapper.init(true, new ParametersWithIV(new KeyParameter(kek), Hex.decode("33333333"))); - - byte[] cipherText = wrapper.wrap(key, 0, key.length); - if (!areEqual(cipherText, expected)) - { - fail("Wrapped value does not match expected."); - } - wrapper.init(false, new ParametersWithIV(new KeyParameter(kek), Hex.decode("33333333"))); - byte[] plainText = wrapper.unwrap(cipherText, 0, cipherText.length); - - if (!areEqual(key, plainText)) - { - fail("Unwrapped value does not match original."); - } - } - - public String getName() - { - return "AESWrapPad"; - } - - public void performTest() - throws Exception - { - // test RFC 5649 test vectors - byte[] kek = Hex.decode("5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8"); - byte[] key = Hex.decode("c37b7e6492584340bed12207808941155068f738"); - byte[] wrap = Hex.decode("138bdeaa9b8fa7fc61f97742e72248ee5ae6ae5360d1ae6a5f54f373fa543b6a"); - - wrapAndUnwrap(kek, key, wrap); - - wrap = Hex.decode("afbeb0f07dfbf5419200f2ccb50bb24f"); - key = Hex.decode("466f7250617369"); - wrapAndUnwrap(kek, key, wrap); - - wrapWithIVTest(); - - // - // offset test - // - Wrapper wrapper = new AESWrapPadEngine(); - - byte[] pText = new byte[5 + key.length]; - byte[] cText; - - System.arraycopy(key, 0, pText, 5, key.length); - - wrapper.init(true, new KeyParameter(kek)); - - cText = wrapper.wrap(pText, 5, key.length); - if (!Arrays.areEqual(cText, wrap)) - { - fail("failed offset wrap test expected " + new String(Hex.encode(wrap)) + " got " + new String(Hex.encode(cText))); - } - - wrapper.init(false, new KeyParameter(kek)); - - cText = new byte[6 + wrap.length]; - System.arraycopy(wrap, 0, cText, 6, wrap.length); - - pText = wrapper.unwrap(cText, 6, wrap.length); - if (!Arrays.areEqual(pText, key)) - { - fail("failed offset unwrap test expected " + new String(Hex.encode(key)) + " got " + new String(Hex.encode(pText))); - } - - // test random values - SecureRandom rnd = new SecureRandom(); - for (int i = 0; i < numOfRandomIterations; i++) - { - int kekLength = 128; - boolean shouldIncrease = (rnd.nextInt() & 0x01) != 0; - if (shouldIncrease) - { - kekLength = 256; - } - kek = new byte[kekLength / 8]; - rnd.nextBytes(kek); - int keyToWrapSize = RNGUtils.nextInt(rnd, 256 / 8 - 8) + 8; - byte[] keyToWrap = new byte[keyToWrapSize]; - rnd.nextBytes(keyToWrap); - wrapAndUnwrap(kek, keyToWrap); - } - } - - public static void main( - String[] args) - { - runTest(new AESWrapPadTest()); - } -} - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESWrapTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESWrapTest.java deleted file mode 100644 index 09d08b6e3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/AESWrapTest.java +++ /dev/null @@ -1,260 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.Wrapper; -import com.fr.third.org.bouncycastle.crypto.engines.AESWrapEngine; -import com.fr.third.org.bouncycastle.crypto.engines.AESWrapPadEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestFailedException; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * Wrap Test - */ -public class AESWrapTest - extends SimpleTest -{ - public String getName() - { - return "AESWrap"; - } - - private void wrapTest( - int id, - byte[] kek, - byte[] in, - byte[] out) - { - wrapTest(id, kek, in, out, false); - } - - private void wrapTest( - int id, - byte[] kek, - byte[] in, - byte[] out, - boolean useReverseDirection) - { - Wrapper wrapper = new AESWrapEngine(useReverseDirection); - - wrapper.init(true, new KeyParameter(kek)); - - try - { - byte[] cText = wrapper.wrap(in, 0, in.length); - if (!Arrays.areEqual(cText, out)) - { - fail("failed wrap test " + id + " expected " + new String(Hex.encode(out)) + " got " + new String(Hex.encode(cText))); - } - } - catch (TestFailedException e) - { - throw e; - } - catch (Exception e) - { - fail("failed wrap test exception " + e.toString()); - } - - wrapper.init(false, new KeyParameter(kek)); - - try - { - byte[] pText = wrapper.unwrap(out, 0, out.length); - if (!Arrays.areEqual(pText, in)) - { - fail("failed unwrap test " + id + " expected " + new String(Hex.encode(in)) + " got " + new String(Hex.encode(pText))); - } - } - catch (TestFailedException e) - { - throw e; - } - catch (Exception e) - { - fail("failed unwrap test exception.", e); - } - - // - // offset test - // - byte[] pText = new byte[5 + in.length]; - byte[] cText; - - System.arraycopy(in, 0, pText, 5, in.length); - - wrapper.init(true, new KeyParameter(kek)); - - try - { - cText = wrapper.wrap(pText, 5, in.length); - if (!Arrays.areEqual(cText, out)) - { - fail("failed wrap test " + id + " expected " + new String(Hex.encode(out)) + " got " + new String(Hex.encode(cText))); - } - } - catch (Exception e) - { - fail("failed wrap test exception " + e.toString()); - } - - wrapper.init(false, new KeyParameter(kek)); - - cText = new byte[6 + out.length]; - System.arraycopy(out, 0, cText, 6, out.length); - - try - { - pText = wrapper.unwrap(cText, 6, out.length); - if (!Arrays.areEqual(pText, in)) - { - fail("failed unwrap test " + id + " expected " + new String(Hex.encode(in)) + " got " + new String(Hex.encode(pText))); - } - } - catch (Exception e) - { - fail("failed unwrap test exception.", e); - } - } - - private void heapIssueTest() - { - byte[] key = Hex.decode("d305ef52a6b9e72c810b821261d2d678"); - byte[] ciphertext = Hex.decode("d2b2906d209a46261d8f6794eca3179d"); - - Wrapper aes = new AESWrapPadEngine(); - aes.init(false, new KeyParameter(key)); - try - { - byte[] result = aes.unwrap(ciphertext, 0, ciphertext.length); - - fail("incorrect pad not detected"); - } - catch (InvalidCipherTextException e) - { - // ignore - } - } - - public void performTest() - throws Exception - { - byte[] kek1 = Hex.decode("000102030405060708090a0b0c0d0e0f"); - byte[] in1 = Hex.decode("00112233445566778899aabbccddeeff"); - byte[] out1 = Hex.decode("1fa68b0a8112b447aef34bd8fb5a7b829d3e862371d2cfe5"); - - wrapTest(1, kek1, in1, out1); - - byte[] kek2 = Hex.decode("000102030405060708090a0b0c0d0e0f1011121314151617"); - byte[] in2 = Hex.decode("00112233445566778899aabbccddeeff"); - byte[] out2 = Hex.decode("96778b25ae6ca435f92b5b97c050aed2468ab8a17ad84e5d"); - - wrapTest(2, kek2, in2, out2); - - byte[] kek3 = Hex.decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"); - byte[] in3 = Hex.decode("00112233445566778899aabbccddeeff"); - byte[] out3 = Hex.decode("64e8c3f9ce0f5ba263e9777905818a2a93c8191e7d6e8ae7"); - - wrapTest(3, kek3, in3, out3); - - byte[] kek4 = Hex.decode("000102030405060708090a0b0c0d0e0f1011121314151617"); - byte[] in4 = Hex.decode("00112233445566778899aabbccddeeff0001020304050607"); - byte[] out4 = Hex.decode("031d33264e15d33268f24ec260743edce1c6c7ddee725a936ba814915c6762d2"); - wrapTest(4, kek4, in4, out4); - - byte[] kek5 = Hex.decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"); - byte[] in5 = Hex.decode("00112233445566778899aabbccddeeff0001020304050607"); - byte[] out5 = Hex.decode("a8f9bc1612c68b3ff6e6f4fbe30e71e4769c8b80a32cb8958cd5d17d6b254da1"); - wrapTest(5, kek5, in5, out5); - - byte[] kek6 = Hex.decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"); - byte[] in6 = Hex.decode("00112233445566778899aabbccddeeff000102030405060708090a0b0c0d0e0f"); - byte[] out6 = Hex.decode("28c9f404c4b810f4cbccb35cfb87f8263f5786e2d80ed326cbc7f0e71a99f43bfb988b9b7a02dd21"); - wrapTest(6, kek6, in6, out6); - - byte[] kek7 = Hex.decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"); - byte[] in7 = Hex.decode("00112233445566778899aabbccddeeff000102030405060708090a0b0c0d0e0f"); - byte[] out7 = Hex.decode("cba01acbdb4c7c39fa59babb383c485f318837208731a81c735b5be6ba710375a1159e26a9b57228"); - wrapTest(7, kek7, in7, out7, true); - - Wrapper wrapper = new AESWrapEngine(); - KeyParameter key = new KeyParameter(new byte[16]); - byte[] buf = new byte[16]; - - try - { - wrapper.init(true, key); - - wrapper.unwrap(buf, 0, buf.length); - - fail("failed unwrap state test."); - } - catch (IllegalStateException e) - { - // expected - } - catch (InvalidCipherTextException e) - { - fail("unexpected exception: " + e, e); - } - - try - { - wrapper.init(false, key); - - wrapper.wrap(buf, 0, buf.length); - - fail("failed unwrap state test."); - } - catch (IllegalStateException e) - { - // expected - } - - // - // short test - // - try - { - wrapper.init(false, key); - - wrapper.unwrap(buf, 0, buf.length / 2); - - fail("failed unwrap short test."); - } - catch (InvalidCipherTextException e) - { - // expected - } - - try - { - wrapper.init(true, key); - - wrapper.wrap(buf, 0, 15); - - fail("ailed wrap length test."); - } - catch (DataLengthException e) - { - // expected - } - - heapIssueTest(); - } - - public static void main( - String[] args) - { - AESWrapTest test = new AESWrapTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ARIATest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ARIATest.java deleted file mode 100644 index 2e9344568..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ARIATest.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.engines.ARIAEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class ARIATest - extends SimpleTest -{ - private static SecureRandom R = new SecureRandom(); - - private static final String[][] TEST_VECTORS_RFC5794 = { - { - "128-Bit Key", - "000102030405060708090a0b0c0d0e0f", - "00112233445566778899aabbccddeeff", - "d718fbd6ab644c739da95f3be6451778" - }, - { - "192-Bit Key", - "000102030405060708090a0b0c0d0e0f1011121314151617", - "00112233445566778899aabbccddeeff", - "26449c1805dbe7aa25a468ce263a9e79" - }, - { - "256-Bit Key", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "00112233445566778899aabbccddeeff", - "f92bd7c79fb72e2f2b8f80c1972d24fc" - }, - }; - - public String getName() - { - return "ARIA"; - } - - public void performTest() throws Exception - { - checkTestVectors_RFC5794(); - - for (int i = 0; i < 100; ++i) - { - checkRandomRoundtrips(); - } - - new MyARIAEngine().checkImplementation(); - } - - private void checkRandomRoundtrips() - { - ARIAEngine ce = new ARIAEngine(); - ARIAEngine cd = new ARIAEngine(); - - byte[] txt = new byte[ce.getBlockSize()]; - byte[] enc = new byte[ce.getBlockSize()]; - byte[] dec = new byte[ce.getBlockSize()]; - - for (int keyLen = 16; keyLen <= 32; keyLen += 8) - { - byte[] K = new byte[keyLen]; - - R.nextBytes(K); - - KeyParameter key = new KeyParameter(K); - ce.init(true, key); - cd.init(false, key); - - R.nextBytes(txt); - - for (int i = 0; i < 100; ++i) - { - ce.processBlock(txt, 0, enc, 0); - cd.processBlock(enc, 0, dec, 0); - - isTrue(Arrays.areEqual(txt, dec)); - - System.arraycopy(enc, 0, txt, 0, enc.length); - } - } - } - - private void checkTestVector_RFC5794(String[] tv) - { - String name = "'" + tv[0] + "'"; - - BlockCipher c = new ARIAEngine(); - int blockSize = c.getBlockSize(); - isTrue("Wrong block size returned from getBlockSize() for " + name, 16 == blockSize); - - KeyParameter key = new KeyParameter(Hex.decode(tv[1])); - byte[] plaintext = Hex.decode(tv[2]); - byte[] ciphertext = Hex.decode(tv[3]); - - isTrue("Unexpected plaintext length for " + name, blockSize == plaintext.length); - isTrue("Unexpected ciphertext length for " + name, blockSize == ciphertext.length); - - c.init(true, key); - - byte[] actual = new byte[blockSize]; - int num = c.processBlock(plaintext, 0, actual, 0); - - isTrue("Wrong length returned from processBlock() (encryption) for " + name, blockSize == num); - isTrue("Incorrect ciphertext computed for " + name, Arrays.areEqual(ciphertext, actual)); - - c.init(false, key); - num = c.processBlock(ciphertext, 0, actual, 0); - - isTrue("Wrong length returned from processBlock() (decryption) for " + name, blockSize == num); - isTrue("Incorrect plaintext computed for " + name, Arrays.areEqual(plaintext, actual)); - } - - private void checkTestVectors_RFC5794() - { - for (int i = 0; i < TEST_VECTORS_RFC5794.length; ++i) - { - checkTestVector_RFC5794(TEST_VECTORS_RFC5794[i]); - } - } - - public static void main(String[] args) - { - runTest(new ARIATest()); - } - - private class MyARIAEngine extends ARIAEngine - { - public void checkImplementation() - { - checkInvolution(); - checkSBoxes(); - } - - private void checkInvolution() - { - byte[] x = new byte[16], y = new byte[16]; - - for (int i = 0; i < 100; ++i) - { - R.nextBytes(x); - System.arraycopy(x, 0, y, 0, 16); - A(y); - A(y); - ARIATest.this.isTrue(Arrays.areEqual(x, y)); - } - } - - private void checkSBoxes() - { - for (int i = 0; i < 256; ++i) - { - byte x = (byte)i; - - ARIATest.this.isTrue(x == SB1(SB3(x))); - ARIATest.this.isTrue(x == SB3(SB1(x))); - - ARIATest.this.isTrue(x == SB2(SB4(x))); - ARIATest.this.isTrue(x == SB4(SB2(x))); - } - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Argon2Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Argon2Test.java deleted file mode 100644 index 65aa16a62..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Argon2Test.java +++ /dev/null @@ -1,225 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - - -import com.fr.third.org.bouncycastle.crypto.generators.Argon2BytesGenerator; -import com.fr.third.org.bouncycastle.crypto.params.Argon2Parameters; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Tests from https://tools.ietf.org/html/draft-irtf-cfrg-argon2-03 - * - */ -public class Argon2Test - extends SimpleTest -{ - private static final int DEFAULT_OUTPUTLEN = 32; - - public String getName() - { - return "ArgonTest"; - } - - public void performTest() - throws Exception - { - if (getJvmVersion() < 7) - { - return; - } - - testVectorsFromInternetDraft(); - - int version = Argon2Parameters.ARGON2_VERSION_10; - - - /* Multiple test cases for various input values */ - hashTest(version, 2, 16, 1, "password", "somesalt", - "f6c4db4a54e2a370627aff3db6176b94a2a209a62c8e36152711802f7b30c694", DEFAULT_OUTPUTLEN); - - hashTest(version, 2, 20, 1, "password", "somesalt", - "9690ec55d28d3ed32562f2e73ea62b02b018757643a2ae6e79528459de8106e9", - DEFAULT_OUTPUTLEN); - - hashTest(version, 2, 18, 1, "password", "somesalt", - "3e689aaa3d28a77cf2bc72a51ac53166761751182f1ee292e3f677a7da4c2467", - DEFAULT_OUTPUTLEN); - - hashTest(version, 2, 8, 1, "password", "somesalt", - "fd4dd83d762c49bdeaf57c47bdcd0c2f1babf863fdeb490df63ede9975fccf06", - DEFAULT_OUTPUTLEN); - hashTest(version, 2, 8, 2, "password", "somesalt", - "b6c11560a6a9d61eac706b79a2f97d68b4463aa3ad87e00c07e2b01e90c564fb", DEFAULT_OUTPUTLEN); - hashTest(version, 1, 16, 1, "password", "somesalt", - "81630552b8f3b1f48cdb1992c4c678643d490b2b5eb4ff6c4b3438b5621724b2", DEFAULT_OUTPUTLEN); - hashTest(version, 4, 16, 1, "password", "somesalt", - "f212f01615e6eb5d74734dc3ef40ade2d51d052468d8c69440a3a1f2c1c2847b", DEFAULT_OUTPUTLEN); - hashTest(version, 2, 16, 1, "differentpassword", "somesalt", - "e9c902074b6754531a3a0be519e5baf404b30ce69b3f01ac3bf21229960109a3", DEFAULT_OUTPUTLEN); - hashTest(version, 2, 16, 1, "password", "diffsalt", - "79a103b90fe8aef8570cb31fc8b22259778916f8336b7bdac3892569d4f1c497", DEFAULT_OUTPUTLEN); - - hashTest(version, 2, 16, 1, "password", "diffsalt", - "1a097a5d1c80e579583f6e19c7e4763ccb7c522ca85b7d58143738e12ca39f8e6e42734c950ff2463675b97c37ba" + - "39feba4a9cd9cc5b4c798f2aaf70eb4bd044c8d148decb569870dbd923430b82a083f284beae777812cce18cdac68ee8ccef" + - "c6ec9789f30a6b5a034591f51af830f4", - 112); - - - version = Argon2Parameters.ARGON2_VERSION_13; - - - /* Multiple test cases for various input values */ - hashTest(version, 2, 16, 1, "password", "somesalt", - "c1628832147d9720c5bd1cfd61367078729f6dfb6f8fea9ff98158e0d7816ed0", - DEFAULT_OUTPUTLEN); - - hashTest(version, 2, 20, 1, "password", "somesalt", - "d1587aca0922c3b5d6a83edab31bee3c4ebaef342ed6127a55d19b2351ad1f41", DEFAULT_OUTPUTLEN); - - hashTest(version, 2, 18, 1, "password", "somesalt", - "296dbae80b807cdceaad44ae741b506f14db0959267b183b118f9b24229bc7cb", DEFAULT_OUTPUTLEN); - - hashTest(version, 2, 8, 1, "password", "somesalt", - "89e9029f4637b295beb027056a7336c414fadd43f6b208645281cb214a56452f", DEFAULT_OUTPUTLEN); - - hashTest(version, 2, 8, 2, "password", "somesalt", - "4ff5ce2769a1d7f4c8a491df09d41a9fbe90e5eb02155a13e4c01e20cd4eab61", DEFAULT_OUTPUTLEN); - hashTest(version, 1, 16, 1, "password", "somesalt", - "d168075c4d985e13ebeae560cf8b94c3b5d8a16c51916b6f4ac2da3ac11bbecf", DEFAULT_OUTPUTLEN); - hashTest(version, 4, 16, 1, "password", "somesalt", - "aaa953d58af3706ce3df1aefd4a64a84e31d7f54175231f1285259f88174ce5b", DEFAULT_OUTPUTLEN); - hashTest(version, 2, 16, 1, "differentpassword", "somesalt", - "14ae8da01afea8700c2358dcef7c5358d9021282bd88663a4562f59fb74d22ee", DEFAULT_OUTPUTLEN); - hashTest(version, 2, 16, 1, "password", "diffsalt", - "b0357cccfbef91f3860b0dba447b2348cbefecadaf990abfe9cc40726c521271", DEFAULT_OUTPUTLEN); - - } - - - private void hashTest(int version, int iterations, int memory, int parallelism, - String password, String salt, String passwordRef, int outputLength) - { - Argon2Parameters.Builder builder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_i) - .withVersion(version) - .withIterations(iterations) - .withMemoryPowOfTwo(memory) - .withParallelism(parallelism) - .withSalt(Strings.toByteArray(salt)); - - // - // Set the password. - // - Argon2BytesGenerator gen = new Argon2BytesGenerator(); - - gen.init(builder.build()); - - byte[] result = new byte[outputLength]; - gen.generateBytes(password.toCharArray(), result, 0, result.length); - - - isTrue(passwordRef + " Failed", areEqual(result, Hex.decode(passwordRef))); - } - - - /** - * Tests from https://tools.ietf.org/html/draft-irtf-cfrg-argon2-03 - * - * @throws Exception - */ - private void testVectorsFromInternetDraft() - { - byte[] ad = Hex.decode("040404040404040404040404"); - byte[] secret = Hex.decode("0303030303030303"); - byte[] salt = Hex.decode("02020202020202020202020202020202"); - byte[] password = Hex.decode("0101010101010101010101010101010101010101010101010101010101010101"); - - Argon2Parameters.Builder builder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_d) - .withVersion(Argon2Parameters.ARGON2_VERSION_13) // 19 - .withIterations(3) - .withMemoryAsKB(32) - .withParallelism(4) - .withAdditional(ad) - .withSecret(secret) - .withSalt(salt); - - Argon2BytesGenerator dig = new Argon2BytesGenerator(); - - dig.init(builder.build()); - - byte[] result = new byte[32]; - dig.generateBytes(password, result); - isTrue("Argon 2d Failed", areEqual(result, Hex.decode("512b391b6f1162975371d30919734294f" + - "868e3be3984f3c1a13a4db9fabe4acb"))); - - - builder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_i) - .withVersion(Argon2Parameters.ARGON2_VERSION_13) // 19 - .withIterations(3) - .withMemoryAsKB(32) - .withParallelism(4) - .withAdditional(ad) - .withSecret(secret) - .withSalt(salt); - - dig = new Argon2BytesGenerator(); - - dig.init(builder.build()); - - result = new byte[32]; - dig.generateBytes(password, result); - isTrue("Argon 2i Failed", areEqual(result, Hex.decode("c814d9d1dc7f37aa13f0d77f2494bda1c8de6b016" + - "dd388d29952a4c4672b6ce8"))); - - - builder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id) - .withVersion(Argon2Parameters.ARGON2_VERSION_13) // 19 - .withIterations(3) - .withMemoryAsKB(32) - .withParallelism(4) - .withAdditional(ad) - .withSecret(secret) - .withSalt(salt); - - dig = new Argon2BytesGenerator(); - - dig.init(builder.build()); - - result = new byte[32]; - dig.generateBytes(password, result); - isTrue("Argon 2id Failed", areEqual(result, Hex.decode("0d640df58d78766c08c037a34a8b53c9d01ef0452" + - "d75b65eb52520e96b01e659"))); - - } - - private static int getJvmVersion() - { - String version = System.getProperty("java.version"); - - if (version.startsWith("1.7")) - { - return 7; - } - if (version.startsWith("1.8")) - { - return 8; - } - if (version.startsWith("1.9")) - { - return 9; - } - if (version.startsWith("1.1")) - { - return 10; - } - - return -1; - } - - public static void main(String[] args) - { - runTest(new Argon2Test()); - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BCryptTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BCryptTest.java deleted file mode 100644 index bb88d4aa7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BCryptTest.java +++ /dev/null @@ -1,153 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.generators.BCrypt; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Integers; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/* - * bcrypt test vectors - */ -public class BCryptTest - extends SimpleTest -{ - // Raw test vectors based on crypt style test vectors - // Cross checked with JBCrypt - private static final Object[][] testVectors = { - {"", "144b3d691a7b4ecf39cf735c7fa7a79c", Integers.valueOf(6), "557e94f34bf286e8719a26be94ac1e16d95ef9f819dee092"}, - {"00", "144b3d691a7b4ecf39cf735c7fa7a79c", Integers.valueOf(6), "557e94f34bf286e8719a26be94ac1e16d95ef9f819dee092"}, - {"00", "26c63033c04f8bcba2fe24b574db6274", Integers.valueOf(8), "56701b26164d8f1bc15225f46234ac8ac79bf5bc16bf48ba"}, - {"00", "9b7c9d2ada0fd07091c915d1517701d6", Integers.valueOf(10), "7b2e03106a43c9753821db688b5cc7590b18fdf9ba544632"}, - {"6100", "a3612d8c9a37dac2f99d94da03bd4521", Integers.valueOf(6), "e6d53831f82060dc08a2e8489ce850ce48fbf976978738f3"}, - {"6100", "7a17b15dfe1c4be10ec6a3ab47818386", Integers.valueOf(8), "a9f3469a61cbff0a0f1a1445dfe023587f38b2c9c40570e1"}, - {"6100", "9bef4d04e1f8f92f3de57323f8179190", Integers.valueOf(10), "5169fd39606d630524285147734b4c981def0ee512c3ace1"}, - {"61626300", "2a1f1dc70a3d147956a46febe3016017", Integers.valueOf(6), "d9a275b493bcbe1024b0ff80d330253cfdca34687d8f69e5"}, - {"61626300", "4ead845a142c9bc79918c8797f470ef5", Integers.valueOf(8), "8d4131a723bfbbac8a67f2e035cae08cc33b69f37331ea91"}, - {"61626300", "631c554493327c32f9c26d9be7d18e4c", Integers.valueOf(10), "8cd0b863c3ff0860e31a2b42427974e0283b3af7142969a6"}, - {"6162636465666768696a6b6c6d6e6f707172737475767778797a00", "02d1176d74158ee29cffdac6150cf123", Integers.valueOf(6), "4d38b523ce9dc6f2f6ff9fb3c2cd71dfe7f96eb4a3baf19f"}, - {"6162636465666768696a6b6c6d6e6f707172737475767778797a00", "715b96caed2ac92c354ed16c1e19e38a", Integers.valueOf(8), "98bf9ffc1f5be485f959e8b1d526392fbd4ed2d5719f506b"}, - {"6162636465666768696a6b6c6d6e6f707172737475767778797a00", "85727e838f9049397fbec90566ede0df", Integers.valueOf(10), "cebba53f67bd28af5a44c6707383c231ac4ef244a6f5fb2b"}, - {"7e21402324255e262a28292020202020207e21402324255e262a2829504e4246524400", "8512ae0d0fac4ec9a5978f79b6171028", Integers.valueOf(6), "26f517fe5345ad575ba7dfb8144f01bfdb15f3d47c1e146a"}, - {"7e21402324255e262a28292020202020207e21402324255e262a2829504e4246524400", "1ace2de8807df18c79fced54678f388f", Integers.valueOf(8), "d51d7cdf839b91a25758b80141e42c9f896ae80fd6cd561f"}, - {"7e21402324255e262a28292020202020207e21402324255e262a2829504e4246524400", "36285a6267751b14ba2dc989f6d43126", Integers.valueOf(10), "db4fab24c1ff41c1e2c966f8b3d6381c76e86f52da9e15a9"}, - {"c2a300", "144b3d691a7b4ecf39cf735c7fa7a79c", Integers.valueOf(6), "5a6c4fedb23980a7da9217e0442565ac6145b687c7313339"}, - }; - - public String getName() - { - return "BCrypt"; - } - - public void performTest() - throws Exception - { - testParameters(); - testShortKeys(); - testVectors(); - } - - private void testShortKeys() - { - byte[] salt = new byte[16]; - - // Check BCrypt with empty key pads to zero byte key - byte[] hashEmpty = BCrypt.generate(new byte[0], salt, 4); - byte[] hashZero1 = BCrypt.generate(new byte[1], salt, 4); - - if (!Arrays.areEqual(hashEmpty, hashZero1)) - { - fail("Hash for empty password should equal zeroed key", new String(Hex.encode(hashEmpty)), - new String(Hex.encode(hashZero1))); - } - - // Check zeroed byte key of min Blowfish length is equivalent - byte[] hashZero4 = BCrypt.generate(new byte[4], salt, 4); - if (!Arrays.areEqual(hashEmpty, hashZero4)) - { - fail("Hash for empty password should equal zeroed key[4]", new String(Hex.encode(hashEmpty)), new String( - Hex.encode(hashZero4))); - } - - // Check BCrypt isn't padding too small (32 bit) keys - byte[] hashA = BCrypt.generate(new byte[]{(byte)'a'}, salt, 4); - byte[] hashA0 = BCrypt.generate(new byte[]{(byte)'a', (byte)0}, salt, 4); - if (Arrays.areEqual(hashA, hashA0)) - { - fail("Small keys should not be 0 padded."); - } - } - - public void testParameters() - { - checkOK("Empty key", new byte[0], new byte[16], 4); - checkOK("Minimal values", new byte[1], new byte[16], 4); - // checkOK("Max cost", new byte[1], new byte[16], 31); - checkOK("Max passcode", new byte[72], new byte[16], 4); - checkIllegal("Null password", null, new byte[16], 4); - checkIllegal("Null salt", new byte[1], null, 4); - checkIllegal("Salt too small", new byte[1], new byte[15], 4); - checkIllegal("Salt too big", new byte[1], new byte[17], 4); - checkIllegal("Cost too low", new byte[16], new byte[16], 3); - checkIllegal("Cost too high", new byte[16], new byte[16], 32); - checkIllegal("Passcode too long", new byte[73], new byte[16], 32); - } - - private void checkOK(String msg, byte[] pass, byte[] salt, int cost) - { - try - { - BCrypt.generate(pass, salt, cost); - } - catch (IllegalArgumentException e) - { - e.printStackTrace(); - fail(msg); - } - } - - private void checkIllegal(String msg, byte[] pass, byte[] salt, int cost) - { - try - { - BCrypt.generate(pass, salt, cost); - fail(msg); - } - catch (IllegalArgumentException e) - { - // e.printStackTrace(); - } - } - - public void testVectors() - throws Exception - { - for (int i = 0; i < testVectors.length; i++) - { - byte[] password = Hex.decode((String)testVectors[i][0]); - byte[] salt = Hex.decode((String)testVectors[i][1]); - int cost = ((Integer)testVectors[i][2]).intValue(); - byte[] expected = Hex.decode((String)testVectors[i][3]); - - test(password, salt, cost, expected); - } - - isTrue(areEqual(BCrypt.generate(BCrypt.passwordToByteArray("12341234".toCharArray()), Hex.decode("01020304050607080102030405060708"), 5), Hex.decode("cdd19088721c50e5cb49a7b743d93b5a6e67bef0f700cd78"))); - isTrue(areEqual(BCrypt.generate(BCrypt.passwordToByteArray("1234".toCharArray()), Hex.decode("01020304050607080102030405060708"), 5), Hex.decode("02a3269aca2732484057b40c614204814cbfc2becd8e093e"))); - } - - private void test(byte[] password, byte[] salt, int cost, byte[] expected) - { - byte[] hash = BCrypt.generate(password, salt, cost); - if (!Arrays.areEqual(hash, expected)) - { - fail("Hash for " + new String(Hex.encode(password)), new String(Hex.encode(expected)), - new String(Hex.encode(hash))); - } - } - - public static void main(String[] args) - { - runTest(new BCryptTest()); - } -} \ No newline at end of file diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BigIntegersTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BigIntegersTest.java deleted file mode 100644 index e7dc6fe51..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BigIntegersTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.util.BigIntegers; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestRandomData; - -public class BigIntegersTest - extends SimpleTest -{ - public String getName() - { - return "BigIntegers"; - } - - public void performTest() - throws Exception - { - BigInteger min = BigInteger.valueOf(5); - isTrue(min.equals(BigIntegers.createRandomPrime(min.bitLength(), 1, - new TestRandomData(BigIntegers.asUnsignedByteArray(min))))); - - BigInteger max = BigInteger.valueOf(743); - isTrue(max.equals(BigIntegers.createRandomPrime(max.bitLength(), 1, - new TestRandomData(BigIntegers.asUnsignedByteArray(max))))); - } - - public static void main(String[] args) - throws Exception - { - runTest(new BigIntegersTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Blake2bDigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Blake2bDigestTest.java deleted file mode 100644 index 5550a7b1f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Blake2bDigestTest.java +++ /dev/null @@ -1,328 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.UnsupportedEncodingException; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.Blake2bDigest; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class Blake2bDigestTest - extends SimpleTest -{ - - private static final String[][] keyedTestVectors = - { // input/message, key, hash - - // Vectors from BLAKE2 web site: https://blake2.net/blake2b-test.txt - { - "", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - "10ebb67700b1868efb4417987acf4690ae9d972fb7a590c2f02871799aaa4786b5e996e8f0f4eb981fc214b005f42d2ff4233499391653df7aefcbc13fc51568"}, - - { - "00", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - "961f6dd1e4dd30f63901690c512e78e4b45e4742ed197c3c5e45c549fd25f2e4187b0bc9fe30492b16b0d0bc4ef9b0f34c7003fac09a5ef1532e69430234cebd"}, - - { - "0001", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - "da2cfbe2d8409a0f38026113884f84b50156371ae304c4430173d08a99d9fb1b983164a3770706d537f49e0c916d9f32b95cc37a95b99d857436f0232c88a965"}, - - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - "f1aa2b044f8f0c638a3f362e677b5d891d6fd2ab0765f6ee1e4987de057ead357883d9b405b9d609eea1b869d97fb16d9b51017c553f3b93c0a1e0f1296fedcd"}, - - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - "c230f0802679cb33822ef8b3b21bf7a9a28942092901d7dac3760300831026cf354c9232df3e084d9903130c601f63c1f4a4a4b8106e468cd443bbe5a734f45f"}, - - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfe", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - "142709d62e28fcccd0af97fad0f8465b971e82201dc51070faa0372aa43e92484be1c1e73ba10906d5d1853db6a4106e0a7bf9800d373d6dee2d46d62ef2a461"}}; - - private final static String[][] unkeyedTestVectors = - { // from: http://fossies.org/linux/john/src/rawBLAKE2_512_fmt_plug.c - // hash, input/message - // digests without leading $BLAKE2$ - { - "4245af08b46fbb290222ab8a68613621d92ce78577152d712467742417ebc1153668f1c9e1ec1e152a32a9c242dc686d175e087906377f0c483c5be2cb68953e", - "blake2"}, - { - "021ced8799296ceca557832ab941a50b4a11f83478cf141f51f933f653ab9fbcc05a037cddbed06e309bf334942c4e58cdf1a46e237911ccd7fcf9787cbc7fd0", - "hello world"}, - { - "1f7d9b7c9a90f7bfc66e52b69f3b6c3befbd6aee11aac860e99347a495526f30c9e51f6b0db01c24825092a09dd1a15740f0ade8def87e60c15da487571bcef7", - "verystrongandlongpassword"}, - { - "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918", - "The quick brown fox jumps over the lazy dog"}, - { - "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce", - ""}, - { - "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923", - "abc"}, - }; - - public String getName() - { - return "BLAKE2b"; - } - - private void offsetTest( - Digest digest, - byte[] input, - byte[] expected) - { - byte[] resBuf = new byte[expected.length + 11]; - - digest.update(input, 0, input.length); - - digest.doFinal(resBuf, 11); - - if (!areEqual(Arrays.copyOfRange(resBuf, 11, resBuf.length), expected)) - { - fail("Offset failed got " + new String(Hex.encode(resBuf))); - } - } - - public void performTest() - throws Exception - { - // test keyed test vectors: - - Blake2bDigest blake2bkeyed = new Blake2bDigest(Hex.decode(keyedTestVectors[0][1])); - for (int tv = 0; tv < keyedTestVectors.length; tv++) - { - - byte[] input = Hex.decode(keyedTestVectors[tv][0]); - blake2bkeyed.reset(); - - blake2bkeyed.update(input, 0, input.length); - byte[] keyedHash = new byte[64]; - blake2bkeyed.doFinal(keyedHash, 0); - - if (!Arrays.areEqual(Hex.decode(keyedTestVectors[tv][2]), keyedHash)) - { - fail("BLAKE2b mismatch on test vector ", - keyedTestVectors[tv][2], - new String(Hex.encode(keyedHash))); - } - - offsetTest(blake2bkeyed, input, keyedHash); - } - - Blake2bDigest blake2bunkeyed = new Blake2bDigest(); - // test unkeyed test vectors: - for (int i = 0; i < unkeyedTestVectors.length; i++) - { - - try - { - // blake2bunkeyed.update( - // unkeyedTestVectors[i][1].getBytes("UTF-8")); - // test update(byte b) - byte[] unkeyedInput = unkeyedTestVectors[i][1] - .getBytes("UTF-8"); - for (int j = 0; j < unkeyedInput.length; j++) - { - blake2bunkeyed.update(unkeyedInput[j]); - } - } - catch (UnsupportedEncodingException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - byte[] unkeyedHash = new byte[64]; - blake2bunkeyed.doFinal(unkeyedHash, 0); - blake2bunkeyed.reset(); - - if (!Arrays.areEqual(Hex.decode(unkeyedTestVectors[i][0]), - unkeyedHash)) - { - fail("BLAKE2b mismatch on test vector ", - unkeyedTestVectors[i][0], - new String(Hex.encode(unkeyedHash))); - } - } - - cloneTest(); - resetTest(); - testNullKeyVsUnkeyed(); - testLengthConstruction(); - } - - private void cloneTest() - { - Blake2bDigest blake2bCloneSource = new Blake2bDigest(Hex.decode(keyedTestVectors[3][1]), 16, Hex.decode("000102030405060708090a0b0c0d0e0f"), Hex.decode("101112131415161718191a1b1c1d1e1f")); - byte[] expected = Hex.decode("b6d48ed5771b17414c4e08bd8d8a3bc4"); - - checkClone(blake2bCloneSource, expected); - - // just digest size - blake2bCloneSource = new Blake2bDigest(160); - expected = Hex.decode("64202454e538279b21cea0f5a7688be656f8f484"); - checkClone(blake2bCloneSource, expected); - - // null salt and personalisation - blake2bCloneSource = new Blake2bDigest(Hex.decode(keyedTestVectors[3][1]), 16, null, null); - expected = Hex.decode("2b4a081fae2d7b488f5eed7e83e42a20"); - checkClone(blake2bCloneSource, expected); - - // null personalisation - blake2bCloneSource = new Blake2bDigest(Hex.decode(keyedTestVectors[3][1]), 16, Hex.decode("000102030405060708090a0b0c0d0e0f"), null); - expected = Hex.decode("00c3a2a02fcb9f389857626e19d706f6"); - checkClone(blake2bCloneSource, expected); - - // null salt - blake2bCloneSource = new Blake2bDigest(Hex.decode(keyedTestVectors[3][1]), 16, null, Hex.decode("101112131415161718191a1b1c1d1e1f")); - expected = Hex.decode("f445ec9c062a3c724f8fdef824417abb"); - checkClone(blake2bCloneSource, expected); - } - - private void checkClone(Blake2bDigest blake2bCloneSource, byte[] expected) - { - byte[] message = Hex.decode(keyedTestVectors[3][0]); - - blake2bCloneSource.update(message, 0, message.length); - - byte[] hash = new byte[blake2bCloneSource.getDigestSize()]; - - Blake2bDigest digClone = new Blake2bDigest(blake2bCloneSource); - - blake2bCloneSource.doFinal(hash, 0); - if (!areEqual(expected, hash)) - { - fail("clone source not correct"); - } - - digClone.doFinal(hash, 0); - if (!areEqual(expected, hash)) - { - fail("clone not correct"); - } - } - - private void testLengthConstruction() - { - try - { - new Blake2bDigest(-1); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("BLAKE2b digest bit length must be a multiple of 8 and not greater than 512", e.getMessage()); - } - - try - { - new Blake2bDigest(9); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("BLAKE2b digest bit length must be a multiple of 8 and not greater than 512", e.getMessage()); - } - - try - { - new Blake2bDigest(520); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("BLAKE2b digest bit length must be a multiple of 8 and not greater than 512", e.getMessage()); - } - - try - { - new Blake2bDigest(null, -1, null, null); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("Invalid digest length (required: 1 - 64)", e.getMessage()); - } - - try - { - new Blake2bDigest(null, 65, null, null); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("Invalid digest length (required: 1 - 64)", e.getMessage()); - } - } - - private void testNullKeyVsUnkeyed() - { - byte[] abc = Strings.toByteArray("abc"); - - for (int i = 1; i != 64; i++) - { - Blake2bDigest dig1 = new Blake2bDigest(i * 8); - Blake2bDigest dig2 = new Blake2bDigest(null, i, null, null); - - byte[] out1 = new byte[i]; - byte[] out2 = new byte[i]; - - dig1.update(abc, 0, abc.length); - dig2.update(abc, 0, abc.length); - - dig1.doFinal(out1, 0); - dig2.doFinal(out2, 0); - - isTrue(Arrays.areEqual(out1, out2)); - } - } - - private void resetTest() - { - // Generate a non-zero key - byte[] key = new byte[32]; - for (byte i = 0; i < key.length; i++) - { - key[i] = i; - } - // Generate some non-zero input longer than the key - byte[] input = new byte[key.length + 1]; - for (byte i = 0; i < input.length; i++) - { - input[i] = i; - } - // Hash the input - Blake2bDigest digest = new Blake2bDigest(key); - digest.update(input, 0, input.length); - byte[] hash = new byte[digest.getDigestSize()]; - digest.doFinal(hash, 0); - // Using a second instance, hash the input without calling doFinal() - Blake2bDigest digest1 = new Blake2bDigest(key); - digest1.update(input, 0, input.length); - // Reset the second instance and hash the input again - digest1.reset(); - digest1.update(input, 0, input.length); - byte[] hash1 = new byte[digest.getDigestSize()]; - digest1.doFinal(hash1, 0); - // The hashes should be identical - if (!Arrays.areEqual(hash, hash1)) - { - fail("state was not reset"); - } - } - - public static void main(String[] args) - throws Exception - { - runTest(new Blake2bDigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Blake2sDigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Blake2sDigestTest.java deleted file mode 100644 index e5e1a9dba..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Blake2sDigestTest.java +++ /dev/null @@ -1,311 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.util.Random; - -import com.fr.third.org.bouncycastle.crypto.digests.Blake2sDigest; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class Blake2sDigestTest - extends SimpleTest -{ - - // Vectors from BLAKE2 web site: https://blake2.net/blake2s-test.txt - private static final String[][] keyedTestVectors = { - // input/message, key, hash - { - "", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "48a8997da407876b3d79c0d92325ad3b89cbb754d86ab71aee047ad345fd2c49", - }, - { - "00", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "40d15fee7c328830166ac3f918650f807e7e01e177258cdc0a39b11f598066f1", - }, - { - "0001", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "6bb71300644cd3991b26ccd4d274acd1adeab8b1d7914546c1198bbe9fc9d803", - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "172ffc67153d12e0ca76a8b6cd5d4731885b39ce0cac93a8972a18006c8b8baf", - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "4f8ce1e51d2fe7f24043a904d898ebfc91975418753413aa099b795ecb35cedb", - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfe", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "3fb735061abc519dfe979e54c1ee5bfad0a9d858b3315bad34bde999efd724dd", - }, - }; - - public String getName() - { - return "BLAKE2s"; - } - - public void testDigestWithKeyedTestVectors() - { - Blake2sDigest digest = new Blake2sDigest(Hex.decode( - keyedTestVectors[0][1])); - for (int i = 0; i != keyedTestVectors.length; i++) - { - String[] keyedTestVector = keyedTestVectors[i]; - byte[] input = Hex.decode(keyedTestVector[0]); - digest.reset(); - - digest.update(input, 0, input.length); - byte[] hash = new byte[32]; - digest.doFinal(hash, 0); - - if (!areEqual(Hex.decode(keyedTestVector[2]), hash)) - { - fail("BLAKE2s mismatch on test vector ", - keyedTestVector[2], - new String(Hex.encode(hash))); - } - } - } - - public void testDigestWithKeyedTestVectorsAndRandomUpdate() - { - Blake2sDigest digest = new Blake2sDigest(Hex.decode( - keyedTestVectors[0][1])); - Random random = new Random(); - for (int i = 0; i < 100; i++) - { - for (int j = 0; j != keyedTestVectors.length; j++) - { - String[] keyedTestVector = keyedTestVectors[j]; - byte[] input = Hex.decode(keyedTestVector[0]); - if (input.length < 3) - { - continue; - } - digest.reset(); - - int pos = (random.nextInt() & 0xffff) % input.length; - if (pos > 0) - { - digest.update(input, 0, pos); - } - digest.update(input[pos]); - if (pos < (input.length - 1)) - { - digest.update(input, pos + 1, input.length - (pos + 1)); - } - - byte[] hash = new byte[32]; - digest.doFinal(hash, 0); - - if (!areEqual(Hex.decode(keyedTestVector[2]), hash)) - { - fail("BLAKE2s mismatch on test vector ", - keyedTestVector[2], - new String(Hex.encode(hash))); - } - } - } - } - - private void testLengthConstruction() - { - try - { - new Blake2sDigest(-1); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("BLAKE2s digest bit length must be a multiple of 8 and not greater than 256", e.getMessage()); - } - - try - { - new Blake2sDigest(9); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("BLAKE2s digest bit length must be a multiple of 8 and not greater than 256", e.getMessage()); - } - - try - { - new Blake2sDigest(512); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("BLAKE2s digest bit length must be a multiple of 8 and not greater than 256", e.getMessage()); - } - - try - { - new Blake2sDigest(null, -1, null, null); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("Invalid digest length (required: 1 - 32)", e.getMessage()); - } - - try - { - new Blake2sDigest(null, 33, null, null); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("Invalid digest length (required: 1 - 32)", e.getMessage()); - } - } - - private void testNullKeyVsUnkeyed() - { - byte[] abc = Strings.toByteArray("abc"); - - for (int i = 1; i != 32; i++) - { - Blake2sDigest dig1 = new Blake2sDigest(i * 8); - Blake2sDigest dig2 = new Blake2sDigest(null, i, null, null); - - byte[] out1 = new byte[i]; - byte[] out2 = new byte[i]; - - dig1.update(abc, 0, abc.length); - dig2.update(abc, 0, abc.length); - - dig1.doFinal(out1, 0); - dig2.doFinal(out2, 0); - - isTrue(Arrays.areEqual(out1, out2)); - } - } - - public void testReset() - { - // Generate a non-zero key - byte[] key = new byte[32]; - for (byte i = 0; i < key.length; i++) - { - key[i] = i; - } - // Generate some non-zero input longer than the key - byte[] input = new byte[key.length + 1]; - for (byte i = 0; i < input.length; i++) - { - input[i] = i; - } - // Hash the input - Blake2sDigest digest = new Blake2sDigest(key); - digest.update(input, 0, input.length); - byte[] hash = new byte[digest.getDigestSize()]; - digest.doFinal(hash, 0); - // Create a second instance, hash the input without calling doFinal() - Blake2sDigest digest1 = new Blake2sDigest(key); - digest1.update(input, 0, input.length); - // Reset the second instance and hash the input again - digest1.reset(); - digest1.update(input, 0, input.length); - byte[] hash1 = new byte[digest.getDigestSize()]; - digest1.doFinal(hash1, 0); - // The hashes should be identical - if (!areEqual(hash, hash1)) - { - fail("BLAKE2s mismatch on test vector ", - new String(Hex.encode(hash)), - new String(Hex.encode(hash1))); - } - } - - // Self-test routine from https://tools.ietf.org/html/rfc7693#appendix-E - private static final String SELF_TEST_RESULT = - "6A411F08CE25ADCDFB02ABA641451CEC53C598B24F4FC787FBDC88797F4C1DFE"; - private static final int[] SELF_TEST_DIGEST_LEN = {16, 20, 28, 32}; - private static final int[] SELF_TEST_INPUT_LEN = {0, 3, 64, 65, 255, 1024}; - - private static byte[] selfTestSequence(int len, int seed) - { - int a = 0xDEAD4BAD * seed; - int b = 1; - int t; - byte[] out = new byte[len]; - - for (int i = 0; i < len; i++) - { - t = a + b; - a = b; - b = t; - out[i] = (byte)((t >> 24) & 0xFF); - } - - return out; - } - - public void runSelfTest() - { - Blake2sDigest testDigest = new Blake2sDigest(); - byte[] md = new byte[32]; - - for (int i = 0; i < 4; i++) - { - int outlen = SELF_TEST_DIGEST_LEN[i]; - for (int j = 0; j < 6; j++) - { - int inlen = SELF_TEST_INPUT_LEN[j]; - - // unkeyed hash - byte[] in = selfTestSequence(inlen, inlen); - Blake2sDigest unkeyedDigest = new Blake2sDigest(outlen * 8); - unkeyedDigest.update(in, 0, inlen); - unkeyedDigest.doFinal(md, 0); - // hash the hash - testDigest.update(md, 0, outlen); - - // keyed hash - byte[] key = selfTestSequence(outlen, outlen); - Blake2sDigest keyedDigest = new Blake2sDigest(key, outlen, null, - null); - keyedDigest.update(in, 0, inlen); - keyedDigest.doFinal(md, 0); - // hash the hash - testDigest.update(md, 0, outlen); - } - } - - byte[] hash = new byte[32]; - testDigest.doFinal(hash, 0); - if (!areEqual(Hex.decode(SELF_TEST_RESULT), hash)) - { - fail("BLAKE2s mismatch on test vector ", - SELF_TEST_RESULT, - new String(Hex.encode(hash))); - } - } - - public void performTest() - throws Exception - { - testDigestWithKeyedTestVectors(); - testDigestWithKeyedTestVectorsAndRandomUpdate(); - testReset(); - runSelfTest(); - testNullKeyVsUnkeyed(); - testLengthConstruction(); - } - - public static void main(String[] args) - throws Exception - { - runTest(new Blake2sDigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Blake2xsDigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Blake2xsDigestTest.java deleted file mode 100644 index 163fbb169..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Blake2xsDigestTest.java +++ /dev/null @@ -1,2690 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.Blake2xsDigest; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class Blake2xsDigestTest - extends SimpleTest -{ - - // https://github.com/BLAKE2/BLAKE2/blob/master/testvectors/blake2-kat.json - private static final String[][] xofTestVectors = { - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "99" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "57d5" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "72d07f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "bdf28396" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "20e81fc0f3" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "53d87da652c6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "dea6abdba2b385" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e8ef785d84bed985" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "8564786ae17558a034" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "8fe7cf0bedfc5c8a25c4" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "ced64dbdb850b8d9238544" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "a61e711081c80de67b0f5cd3" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "ca84913682c32af70a5a762e96" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "b3051e87aeb0e2f29d4197ea1001" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "f1db5e2f2bde30d08125a67d718b3a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "541e57a4988909ea2f81953f6ca1cb75" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "58910f890077e12ec101610597195ddc0e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "42a2b79173ee4f554baafe870efdd11d0bef" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "ab2133a08e937af16b521a09a83c5b25fe39fb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "839d21a3030d13c2f59fea3634d8394cfa97c7d4" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "0a0eb5cddef7a827d7d3ba947e55c04d5d74ae4780" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "5fbfa41a06fabac5349e39701e79be5ee7d74195ac94" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "58ff07c4812f286cfb69bae047742a1fe519c5a886f3a5" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "653a88f2458217a42ebb0cff862076dfff08ebdcef917bd2" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "4f64ff718d4a02663a64d61ef7a3a0b8a9e0d201c310931f32" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "5980b25c906286f0850b2349b0ab1b6fdff051aac85814648c64" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "89a4ae162416824f35ef116369d155b2d941df8a3d3f6dbba2279e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e72beb4a6524fdfe06fb519edd634e62bfac05dc26e73d7da4e6b105" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "34fdfab2a60eb77a4b30e0a14d1b90c4d3fed0284b6ca4503d1e87729d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "f0fe72dcc5a7aa3cd3ba068e14395b1998db37f922593dd6f340b3831ce3" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "ca46fb7d84d726f5011c00c379ef2fb625151c0a1f416e62c9da2aa14c33cb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "91cab802b466092897c7639a02acf529ca61864e5e8c8e422b3a9381a95154d1" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "0253f5487d927a5d35d0089ad9cab2d7515b65d332e870c78d1229d1c584bec3d5" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "38524415a7ecc9d09128cbd0999bb76847fc812148b5a432548e4e500720b356c803" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "4607a9e4ac70b3b61c47c44f9e5d05450bc356f2a323a9d2d213525ef2ad2905f82f79" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "c8ab4ac86f91ab339c79bec70920cdf382f7cffa279a80687a5c27cf691cc92777120c3e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "de63da44e818a837a9ccb7d339ae9e68bb4632eb34ad5dcc2223de7b8c1dca50a3739ff8ea" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "ad5a3ff34c717f1ea06334e074e30b4c57053501566d4889beb32933bc6dabd01f74d17fd3ec" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "845a8fcb16cc5459868f5200a811f511c84caf7fd7f6de2010c162c1eaeca1f3f135b14c4de356" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "5ee53a681ccf1bb9d65359e2dd5daa377ce9f54096678a67390c2c9db5e797eabe13fc0ca5d4037c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "ed2230ff3817d2ba55e65dc137a3ea9865e436355ac542ca0ee71bfb70e0f48f61f5a0099dbb6df616" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "29be3322662c65b7cceecbdaf27e6f65f93cf41bf27fe5dc8c29891297892bdf1adc948026ef20b6c29c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "82c496d4ed8b6cca197c25bd2fc6924c35ae9a23fd555cf12456cb24850124b1b8dce9a1badf1983f16cc5" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "c80125ad9d202db1fcbd9a4c7ec3857eb5578b20ef54cf71197954a45df5b5d246bbcfac43f19ae3aaf7b212" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "6d25dcdaba3b133747de6c4fae478a6feee65c70b6ca904768796aba08a056071d2853b8375cad2911fdfff20e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "ce14b4f4f327941684be16178f86c3cc1382c326909d3577748c672d6a80253c7a563ff36c409d647997cf1039a6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "62c256d6561b46b0cc6567b188ce615aadeb4b51880e16f2a268cbe3eb37b97d1136089d892b5dda8f65d1e418eda9" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "02a06f6949c942ddcd8a659faa3492a12f22ed44cfd58de5e4312ad33b1af337655d2b292f9e4802b5ea1ad0f2f9a2be" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "c9eb45d0a7430548d96f1033a0e0c62e150c0a105b53de8b7288ec74349ed6d329b60abeb64053cbd13c97404f0b1a8a9b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "253d1710e74d36ee28918880220468da1be23678579bee544a671094dd05cdc658752585bdcb8d943c5dd008531ada11a813" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "8ac3361542a33bd1ddbaa83ceb37113e391803b46824e91a81862f8867420b78dcadc8967ca6645084db367f811001471c17c0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "cdc6b82553314ed27d442d6445a97667ec94337ee913d7a6f6f83ac197286e93ad455be6e5346a3369ed7a5c03152f4e452b1773" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "74d8b9c28a80e3d2f9add23c1700a0a8677c6833c969f8337375411d0f2514757bb6dddbcb1ace7e0046fe3668f941860c9f624811" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "1a801c80e2e74bcccd583037b6b2228c8bca8444a3ce7d3c47aac3647842c204c1f3997e2f0f8b2b3d63b27a9f845e392bb273497dbf" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "4641d3f104a6d384d04c7a92712c02a7c1df543cddd80ad88252113c155b344530fe1602f50f0325f61669daa4b7dbb6ed5e1e3229ff37" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "b79a894d9e95b0d71b78810f7ad18fbeb4bd3d84843b585195e3cdee4021a9ba3f0e6e1b960356afcf607fe3b5eab448dcf512fc5b0929fb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "3e89fd9a7daf87bc75088c756067afb8da003e746553603338e0ef5aadf804267448c74e8ad014cde658708e5707976e8311881bbdd2fd3415" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "d74c6b60df37362d218396f411d1ee7d7e34cb502ea637e9c9c10523f8f687c13a9b32d704fd49045f22c1c4b9d0576b3eb51f5f2b2e234703a0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "5e428a29f184b93022812c39485c770cde5c3b4596c0d4e714054187a4bab511193458f7b618d64e2debbd8d5b5680b602326ed760cc5d48c5fc84" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "04147c14a73752961ae870b0ab6c3704e29c8534be4b3063adbf1430eee5f144a57bd003afce1fc1fbf6f926a34c504203ecd113ca3f2de3744238a2" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "8f54504e449e743a4308fb215d250a08f0541d376f8bec5f4d7afb609326795416a168084f62c187eac40f036603e8426d306a05df36b5e91a1733813a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "76c564a9a5960016b9e588d4fcad94a4b9afe77172edeff7cfbc25b2d08277225fd50250a05a3281f677adfdd96777351bd895fd289137dffd8588907deb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "25981b7d6af3c87840639621acd46ce4bce8612fe7f081cca25b72a569c81c498606deaf781f89b07534625336563e19c6b2c467033bd04b55561251f8521a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "57aa5c761e7cfa573c48785109ad76445441de0ee0f9fe9dd4abb920b7cb5f608fc9a029f85ec478a130f194372b6112f5f2d10408e0d23f696cc9e313b7f1d3" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "150a3e311efb3299d0b9ca333526bdb96a0584f00b52f4e723407cc332a9d5f0f64f426fec8717ae03eaebf1b52401956595bd6e56543a53517be104be99745e51" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "6add9e23840ca283a12f0b695a39631e5e068c27abb35edf351b19e542ec30d956b3a978df34155941e11b8182f71a57f3f4edad8dc8913b3e3830989ebdcaaf3952" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "9878a842d17d75bae411967da45e1e23c395a714192d424a4a082c5ffd8745c5d872a841d827865fd4586c668798117d65b293ed2950427610cb9c908bb961699a9585" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "65f1a8874e3563170d4f8c81a52fe1b27d5137056e95ff03ccc97a1c658f29fedf0f3debaa39452f14821b2ce06d349f89f6aec7340e79727dfe4609b7d08c1b5f3b591e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "0d1d71883a5d82addb706c677a054c03be97972392fce88b9dfc676fe83662c2d8a310f1ea00acc7bf1303b324bccc7bd7c9b8ec0f0d3e33d6e31311ad96357b144078b0bb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "b85aeb30fd301c182b980ec09dc99caf533e7ec86f35580004b6741aec28d4ca416d13eaaf1c87758f1eb3a70525932129f65528a790983b012a7620db68d7858b48f9e999d6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "bc3c10e1a08de16ce26134f363843f9243caf3bd1dcf445cfca839ee55cb5ca5f8994acd13509609578dd39d6b3c89901bf129a5bff17ffa1bb506ad7f63d0c18a570b8953a488" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "d37cb91bdca013430f38c914d1ef18b68dc38e5c6013cf8e357048df2c86261a0f3301bbe436362bd81059c1f315cff45a9091f1e1d84141f63ff92f2c56a6ba11fe3db17cff3377" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "52704d061557de8f2debc6cfb71616bd6ea10eef41523670f87e8f8acc673fd3100b063b95f8bca943b3eb98984f908142d6da9e040aaf93cd711191d00ac48fa56e4669d2e7e5b548" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "2c0981b3580aed2add3f7c0167f04221b376819ff5406034a41c261ec5969ff248b7a0ce2a6c9f01f1ec80b7d98c148a3a9f842c626354576c9e6cd0588aa129cc9360e9aaa8d4c58bf4" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "1b9b51a0e20a02922fabb2a99f11c9ab0111ceda3e20433b25caf010190aba37789c996947cff081d0c6332bf2a780d90c1ccaaa05ebe9a2f186e30b210f9859ace8bc9fe84bb5aa512e8e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "8489919afae8ad867c55bddcb43868a089cdb5ed7b8fe0a3dadddbd12cf6ac1d608741d76881c085b4542fb5e82959860b4d617fcff1e627cc89910a8d7cf848dd6b0b70c9870005b8be5ea7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "2b820effcb8312b6c05f1013d61327f84c1f11c5b8834a7e59820bbb8ccf77990d0190fe70f62bed946605d82e66ed4c68236c9aa39d9a88fe668331dacc607a3dc4a30365e9a185bf294e94ce" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "481f56240d0aab02b669e7e595041ea59851a8372b375bd1131e39cbdcd76e73734dd5838ae8ae655c2ef513af9bce364b103911defd332da64a1fe9a11011195e4a71c11e8eb57d82d0457b0346" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "b57d1fa9332b7a22fd6cb3348733c2883f4a99f4a6fe22239dea9320a458f062a391e240044d19105b81f3c08dc9ecc5a9f86bc884cc1bad649b9cd5ce12a1f0a73bcfb5c1c32dbcbd75a74f5df617" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "f59fdea0a8b6b99202c455194f5bb65e56fb45d34500c37a7e73470bd1175714969b608cb7507e8fa1b9e39dc82b1582b3cd4b193e1f518f016a7251b6f52ff4b1d217758715b739eee27b1c9a2aed11" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "56fe4e7c41e9ff59c48b6200d17e6f9eb30b6d4d18154bab7db9aaf206b667e937cd3d4ae23916dfb9f1485ef68c1aef8fe7a661c6a5fb9cb8034364821641b6ee9d76bd4cc378a454435a98c71e47ef8f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "c7233615cf8b9d6871fdd7c0024f5ef629e00b2e0c0a19abdcc7b789ff1493d187ebad63b651eca605f8295b29f01364422527a15176754c332f3cf566fd2fbcccfee0bb33d9305e7b8660f81f3e8f6d42ca" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "c1bca6f43d40a287f596e4730e27fcf56ab9b841aef9e4daa4e244846f2036689cb319520b93a43aac9e9238ffc256f26e7e5860873cb3404417099eb8147a5e12a094c3d9a758ac989c0c2baeb1e719c2a432" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e3b82e4cceec32977767241c1b1e8504ba76018162de5cea14a19c5f06875a32fff9e53a047e68416b8dc6bcb9e991487b81b76e58428cb33f92f637965f9ee00ec57923019e702c7ba3a8b3c1b7049f3bccdeba" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "1489fc59f0b16c2f6bf4a78b6cb71a4c12e0a9e02567edb6a14ec2dfc512687113a709d7e4457a8d03c9d3b1a6cd77a0d50ec5aaab94d48d366e976e7f3dec356ea32ec0561bea07ce8a4204911619ebe54152c73b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "7cb2babff9c15db475ee00db87804d984fdc3be81272a60f8286b7ccfc4294841908c56c7268e80356b566582ba457614e392f58613c4059b184e085b0caf4e81aef8ab67a2220c068151ae100c9a323792d7f49e477" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "508f70ce1e4450291f690e2172944e5008dc6bfc494f891a8c79c012351ff160357b39c69027859bd0d6ca7d329ef4c5779e8f3cfd5921ce9c7170038821e4ff03f5279a01156299cc5227eb8a81cae310d4c7ca52e7cb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e534d9fd2632c0d64a3df145048bc674ea0f01af879a26f252a4b0cf406d8bc4c2f134a86443228b667ec1c0c1babb2b04775b064a3994965cd6080913036ed387483fc9295930fe9ebb1da87adcccbca8318fd2b1d14e29" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "deed43ef976409050873e966a722922bd2b61bf11cff0064b5458b9eaaf9bac20846b7f20606d84b0429bc1a0c00df5b742cec643d44659b3243cf42217e6abc84d01cd326139120f96c92f625a08dcdf193639bc5756e29f9" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "00b322e73e6eae7de84425961f11b9736806bafaddf0495274552328c6b1dbc9c88227de05e8348c04b9fdd9e9898fe69065cad8f884e4bf1a2eb821ad0a3eb4b49cee2ef299a0051976b28af1d3d16777233b75db6b9004cdbc" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "9d3a5ca80e99eefe49eee987132c73bb973260869149ecf8b167a7a4424939f48c5acfce848232f49372aff6ff09908f943768a5b87bc30594ad6272f63b5ec2fb46e742700767d4663f82a1ac88e060ee87dd30ecc27115f52df1" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e068a4c054cf8b757ac81d216c961f221276e1753148fc9202f83f258bd2877d192e324784fabe600a2dcb53996d67aee8ee9964b9020e2bf458daa4e9494a193f3446daf087899d71c52688a14c05f5ebb6811ca0fad85003aaefe2" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "0d4ea1a13a2cb5e403caf018e5c529dcf0fb8b1fa625e150fa46383c45fc25e51725e946f09b93877ae2058de3577e996637817a3332c46842089ceef2dc9a4f52f14edd2f10fe56d11477a4eb06e559d4636c4f06019be3911426d1b3" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "8de5e14a26cf4c758fd43b30b71fab2a77480ee98faccc95488849a49fb983362f883e5c75d6e6515063c15194f3fe9fada18b91b8ccf0b3ced07c410d8eda5f0956a1fe9340b5a3dacc10c2f1b5f4a9c751a65361f21273a11e571829cc" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "bfec8b58ee2e2e32008eb9d7d304914ea756ecb31879eb2318e066c182b0e77e6a518e366f345692e29f497515f799895983200f0d7dafa65c83a7506c03e8e5eee387cffdb27a0e6f5f3e9cb0ccbcfba827984586f608769f08f6b1a84872" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "291a233932dca80d3a4ff11f06c056b8c7e9de2a99c4c28c666965ef6c075b8d90017608ac7074b7e4831536f5811ccf97f47ec39660ee1de01e31161cbfaeb575a45413df6a9a69767763a4578c23d1d697d7b8673d2b2dabb05dbd506c7c62" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "967c76e3814a1a2fe4ab811b8e0ec56b54dd67f37947bc3554adcd143d8ff17f0f11b5736d512dd8966bad9c4e4c2aae5835ef5d0baff5c6a034e58e3eafacaaa0d0ba4489dd78f06449754b25688fd9e50a191bab8ca6dea5e59c08aa07f2947b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "4ea13e136028596e6e0ffbcd2aa8f177d2e40abb7a5efc95a66b0113eab8eb48c7e0af7a7499eeb6e04b341a229f24fb5b9c6ab444288d32a9489e9c9abc6bbad1fcf406adeff9b14e29bc60dc0307094ad8e6b1b6151d7dc185c2a6b2f2c0465798" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "61aa1f4d4e2cdf23bd547f425b52cdac799ff437ea49adbd5a81f0801f640881a09569fbc8b6c91ea2c5538f518e054b5ea75dd074a8285b5869b109646408621b64f6a902ae061192f0dc25a172361508c945e218d1e42182abc21eab8d2b00c8e308" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "5e3f0046de3d99d5de3d01ef2947b812714e09af342d9ea03311565a748ac0842540e0504aa8a54d4c7563bd8948d36177d88cc7b14777b2c7930252d4ec1c1a0fa0e21ff2889f41615c9b828b179c4778f314751cc58fbe386bb6cc48b1a729cafd9f2f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "37238968e530a2c072632186f8c54f271d15f43d2bb2a5541914a9d771a7d22a2e718992f74534da17f126e1616c39788bb4a8196e49da93ff4c6300b0d873de6b1effa0af995f534ff4c5c079324e66b18d3c2a87b632541a39c1353a6e2c0cf5b594d4e0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "88623f66c92f3993a309c6ecdafd29815c8b9ac1757290ca3a5f5694932e57acf70fdd83c595858b3331afae7de0884859ecf11b28f84ec8794fb16a136ae0cc9a4360f64a9dc6e8cc5160e8f11e2d2243e927e1479bae5afb82d192b44e59971357a5cb14ab" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e8b11e720b0870db776a8f682b85c865144ffae5a7ab7849bbd0cd9077e5f64d4ee4aec0b25d06ff5d2ad528b1248df90a3dc8cc189cec026b22910d57d756b12153362001920c3f82d102f910eafdd34b1a50e9b99b019107e764b5b8eeda5b465c755d684489" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "690501ac0b21e40128f36be64fd19919dbfb4e0edcf01df9a4d946f1660d3c81b896e77fdb74ef601e44b4af6e1a0f6aead0fca6328542dc7c99d230ca97b905bcbf2dbe0bbc6a73f062d555fe2579cd3e658ddb9a6959467f64fc02344e42cecbfe1c10740f3b6e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "672a69beeb960495361d80ce9bdc3c348b8a747ae83399cb648a720ab7596a8c2db14f924c0960355988189d6aa437e87c3ef3cf3a716d49a045a4fa8dcc7731925f1d5e66f8c0e644d9b4746f5f27d2361269c1313f8badcb38d74ece67d4de7dae120dd9f8291393" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "739c7ea259cebc61598b9630de10c1217eb32a1107933b8929ffbe71e664c266f5733b94843a57f92f57af363ff73ba91022d92183ea368ed26a7bb27162b66651ccb4c3fd417b0ed195d2b7f1323396c49d82f5fd17c60962f795705c3f8262cacff82a587d49c25b37" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "fc80be54afb6a6dbfa21744fa588249e6532572e70236ccc6170f5abfee2e7806104f2ec507782d93efbe7b9f7b098588bfc2f62879df7b05929523015cd5720ef452c244ec212bd21ecc3e1a15932858dc6a55b6888947c067865f0c34f7e8b78b76c8f18c28e1a0b81d0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "7dfa64ccdeec6811f6f67a899511d693b999cfafe705a9cdf0458273ad314d2580e01d6975a476beb67e9cffd48da875aa9faabc555968ce2f3ad0b1d9526c986b78fd86b8abc36e281de1e4258ba5521240ac7734990de7299e51063344d9bf9fc1a47d8a9b0c4b9243e7b8" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "c4d84255d5a7ebb77d632d59f998decbac3d031464653146adf5e78475910cc049fc0101fabed376bd8440bfdffd83d80c27081d531b9fcc3e732248dca2c3bf6007da725c0787ba07269b05034a953a2df682c962e1441c96024966ee6663853f8c3ac88e80bc6117b7f68483" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "9003bcbe5e928e28827eeb435f311730e8ab0e7d1f2bb615f4258e591c625d28301ea72520079c40455a9464e4811599ceeedb913071f5c9c8b4486079108e0916282668799441c4901b72d5a57da1f72b65a1512a23c4c0c88857ada847d75c39f3e925100ef0bdde49f5127083" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "1c1ce518a470f751be5abc5c95e797809b40c83f5002c69c3e34b2eb52e9eabd4202539d821e98e8510733e26dad712527ff04e17d37f9172c58e4af94524fdf0bdd55126cce429c7ec91293d073a4e3d33b33a8bb198b2bac7113799cac70df1d860db405b78a0bac420976a6f6d6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "23e5ac8c6331d772e7b2bdd3f0b6fe57df95bee52645013072f076835a3393547d454d67f3f228d1cc2d1e969a80879c241f68273477ae65a6cf6e5194e5ad6cdb2881b74fc0a3e31263669bf5f1fb70890c681c5e1d12eee43b44141e9b95d0180c11aa95c0e513a96861bc3944cc31" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "51f3254390ba613dad1b4288b6b40f8615e047e1ae85b7eca3d1e8fddddb5ef0555c1db8683fd889fc304c62c70eef2ea4c21c2192f6097a996d421b8b6f730cf829ac14f82b45c64c299831e8015039a10314896517297c4c48a91d0914a6da1eb7951e29d0ec63f3fde0c98e24bf7ab5" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "75168cde1904184c2cc845ecdef73f69fa67a709cda969853fe8644c44cf8674f13c3a399509f1671568edeb936ef60a450c282aef04086bded69d0696df84b00c3d3477ad51d5483cdade2eddf8093de0aef19761f7af4f6182bf48e848b422088a22ab38eb331c8908a2ad28956e4824b2" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "d8f6542eaa90aebbc9d24c28e29c229ea4cc6a775aa8146e98cf6929160d90786fd1168e5e81aa91246e4175b06a383f3cf61a6d832b91c13ca2ebfd88f659e351da333fb25ded1fc44df314cb42897cb56ed6544fe556d4e6a658fead6154b3a1cae3e50be2c81f2f86a326515078fb8cc910" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "2be8d7128e0200e78ccd7cf6e61a8786b62809b2a17fc3b333387b2205794fef2b6836b19eb9600b8de93aed934191b3e2c291954244d46e87774c465f96b46ff46093d66d6ca1ac4176e9e59c6ea649ea174ac197043f6b2b39ab3397218e78bc2bd79071bb4ab3532d304bac5c5e47730dec36" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "835a085c2f477b537c8d5ff4dd439f2794f8cb3bc1d787fe30b3ff9c590c3d3df6f4b903238c482c63e24b448fcb347b73821089496fd7587f4b9f23ef73c615060c9282fd67f8f012869ffebc12521cb745dc318b07b48dc02aa8b5a512aed4e346919b3ee4836cbdaffef1b3dabdb01bcc7eb636" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "6c626640d1496181b0c161e28ccf741598e521d9187e8ac1a648bf7128dafea2562a6e9010f2dd8fbe561f158a0d1eed7c7f1ac2cd208b7cfa2c352939227a12da50018c54cc44a7146ac79d5d847897a69cd64e22f252abbb506d141d3a8393b38a3a3cd99096a3d10037de1feb6404b6c5072c3d98" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "295ccefe2bd4e68d533fe402c8e6477ad00a3cba55aa1c99b7a9bf31f0d021d761607d27312fb099784a456efbaad30fbddd354df45c328838c423f169888c3e7ac7dd9f9052ea356aa46171156ddc645dd2d9801aa23ca832c8a19c5c2fbef040b66fcc579bd73e92e0a1052519452392c94b50176012" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e635d9a82e5fa5af49561bae9abf31ce5c2fb85c1d3ed819f2aec39019bd637d66595ed7be4d1eec75d2f97ee0bf41b441624667e0e7a727e4aedb3c306c6903aba306b88074d2c9ae6787c14003fb76408efb90b0827538f5099ea35baf2a1d7c874ab38804efe51a925aa852a9b4e776e21fe913518afb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "92e056584b2767dc7a5f4f4d0837c034d962eb36e97a590fa3386b106a58e238842923b8e688d6034e7c1466cb26f2b09a5378117a8fbf3fc08398070fcb4ab8d0ca0b4ef197a4252ecb5eccca097d32cb036c8ece264a45f9f7d4b0ab945fd95286ed3714b9979b0575226fc52c979fc26cfa8d3d23e6b327" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "d826daae45241b3e5b24e9049a4f86c454b50c5de06e2dc70605acc8da4712f9391ba7a8ea90449c368590881ddcdb2d37775004ca032aa8861453704c9afc42a77553d24f664db7798b25667e9b5e3d04287a35fd6e604feb70a2f8d03de083a364e7711687eddca8c3b73e0134b940b0a42f9631a74f39cf1f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "8cf01578e2d2cf15680485db397ee230e4d04171c45fd8d0c65555128f6a13b8dd28cfd7d90807ff4f71ab9ef5384bc8160c49a23b19a541658d7b8f8c43aa98f09af0fc0668da332b1b8f9590a5a5b46fe9058bacf25157892705130d8004dde4eeab3255214776a2d9b2368755b20574b37524f15e300e0aa093" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "16ce0a26a1985633c5f9c653bf4da9853b301b08c321165e20ab38762efc7952352556f91d109779485cab6100294f3d59269b99082037fd5e48a125523c95d5ec4e8339d3eaccc67d9bf37c7e82c0962d72532b0448a4497d312524ee2f92b44a6763de12996164821f0f11db66031b1247cb4cc1dcfbc366b93c88" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "b145e964233d8c74eded80b6c625de7efe274142c26ae9140a762bfbd31bf543eb8e52c65fe0c96dec46a02c08a8fac0aa564f0abdfe6ce629d5e191ea159165f351982d51f0d64ea434a1e7e789ffef38ecb8756485cbc2614de9b80e1172fd2c4be05ae5b7dc76182f8d9ba29106e5ed4f8d610c7708fc97eccade92" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "c96773d31fb8c6f02fbf2a9f4f4ff74234e26808d7162678d25c931309209c3b568fc2c69b5d97a00ae7378702b344644fe9c4b0f9e44fe01ee219a3471866ee1fafa8b00265a10dccd1b3f676562ffe2fe43bee82c4f7b5ff5e04dfd4e23de75b6ee35dfaf01c716c0db1c848a781d04978bba749d347b6e85c5334b74a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "87776d4b3be82f3eef9a88f8135a005e4c8efb34d51d182efc358af1b4287b46c8c16a6307fc57dbdd7af3af57c3f3670a310e65c69ff7c91b2a75bfe622dc860cb6384459eafa243d0d6cc768add9bf5145e6ad393777d745f285ef4e96f2238da3f7416b049958cd55019850982843315038cb97f788be3aadbf283ef956" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "4d1f33edc0d969128edb16e0756c5b1ef45caa7c23a2f3724dab70c8d068cfbfc4ee15ca2fa799b1eb286c2298036faec73d3cac41b950083e17ef20ddff9d55aa8b4d0365c6dd38d5ddea19ebfa2cb009dd5961320c547af20f96044f7a82a0919126466bad6f88f49b0342fd40f5c7b85206e77d26256c8b7ff4fedf36119b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "9339bc4d2c29865f64d1b93b1e29314bc26b78d53b69873ef54205b3891155683f2d8199eb9c8bb37becb7ec02d126b730cc4310c9c70785fb819551beb509ec14f2f7cef1deb83a8c9fae4511f94d48ed38f8a444b73630cd433ed8e6022211286a2df8193dbaa1f57b38ff84d6ac2945a575dfd4804b538cbd33800f488f254a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "c4018d36d2f84fe2e1f726181caf1952f3501b4b4ababe525c76d8436c9e79d18094a3f7726f3bdced6781f1626e90ee3b230bb4862e5497129bb58b40d6717c7f25ca7d96f80b1f37273105acc9dbd30f15fc0c5b81f465e2f596948a00aefb9d976eef60669e1770cdb6beabd2ba112622734c8659eb87f0aa08c034d462a0267d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "03a44e84603f79ebdeef6680447ded2bdd5a640549f4ed6cc493ddec1006d0535481417bb8ce221e1b3b2535cd0223630e2f96a8e47f44da8a998c2766be89b2e245033a1bf1fc15f506825964e6c6a9c6c5eebf06b1fec66b8322d1425755aabe7391ca9f5c59cfe0c14095036b141f864c01a5dff04b8fdfb7de2b88d6c31f8c684f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "181870851c94b7b02629c99ed1bdf55a20412534c5101918cdb36525364b1e7d0f7eb2b4f549be88bfec9eabe45be9e4bc3d8495258b83c6107c995c85e1f5ec84bbb8bd43f58ae98d13854ea7de75e51a5f73e24bff4e6dd850878b3b7f8948ff99924b9706bec23fa613634abe2191023d01d463ea7f6f4019f1eb4af6e74832008e69" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "9b8d7205ace31b13e544de5f65ec17fa2ce350c8bd32e68aea7b22cfdba9e0181b8db8dc961a279f3441e2f86543e0ef8de65b89d28eeac748fb65a2b5c13466ca94fd45c425f8146c4fa12c6705e6230b0a0ea060fafeeb43907087682d26a465fcf7f21ac52f1351f73b45d75ece0680d27db1be924af3a92adc38a9efec2963b6882b8b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "60ddbc9c10494d540b04627b30dbceefa1331bfed86ea30407c99fb18a50f5afe58a7f73544f6c70b3034825111fdd139dfc3e0c3c00ee2f1960fee71284332f727efa6187a4d131d4271e23948a2c2092b24fc0b366ecb11ab464bc85e2c779fd3d9f2b68e62ee59d9b86debfdd96cac33b2628a5a966c26b0602e242ed4053737a3db0e83d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "27e3bca4fccfae88c9a7a7f43c0b72a302b626cdf32eb70122e9cdbc100be2d29d945098f5d74354b4f90a66e938ed6eea3ed9cadc24a1b08d12e731150b327f0f53ad43fdaa9ba76785c03fcb9b2995cc2ea67009a0ce10e92f9ed9fab54c09b3f90b0fb9db2545edb9088f93a547333fff31dec6000120914baf6b6ad7feba9ceee614beed11" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "71028d445c4d77fa30c5c58057b4d233ad2e12ee640d484177e20c635fd1ebc150d1a3e4d855b7910623492a6828c215d5d1a9f39a4ff3f4e6c98c98068fb1f3b4ce319658fdc764854b95928bf0315a81a0f0a022b3d2bd285f22b16b1613b52590399f1b993589ff2f8997c4d9eabda69c9f3b8a925ac9b4942b380c6fe0ccc95f1b4e3d8cf336" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "8533108fe06b8ffadb5b8618d03486db657bc32221488b7b629d6ea2e24c1e1de3755edb971c1db135bb38e0cc943bc2b3aae2369b3019b98b5a92dbe122b35dfbef0620685d5a808f21c31704e7296f207dfda914fad3a903d8142c623a83a0f55dbd0313bbca2c2831c8e4f02b10bef62ef321644836b3b5224a0eb68e84f25742450b10f9c59bed" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "45a62940d954283daa40a17b89a8d89f383ecd3a888d009b31d96f48bb5a656e4d6870062b41ff33d0b7dc7893b3a480f2d2c4c909b18d50365451e7e56c6305d26e357cf51665bda819c1f64b59dfe87123755523ff969934f5900d2f5e69da3189c118ac2bc1c0438f14b1a37d2227801ac6895a3c54dbab0faf77e9b1b8eea879c9dcbfbb7dbcfaef" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "03f992e29cff3059d46ae559186581b67954e6efa73d7a8aa26ed3e453828c3e8ca5031a988dbd680648f5775b0484a09d0ec953c49c3f44bbeeafec5d7c0820e6c04cabab144d66e2076f1dc8ffda96fdd292edad65a671c440a2810bd0c86e9608173ebde1d193f2fc738e1482cabea306208b9eae348113be4855d5aa322ea604597cc0793488b65cea" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "f3a30064a77618fcb495df57dd45d498e7fc9edf91e6c41fb76ab296201f6b9eecff62f5a3aa6309e38d02bff0548238dc7a54bb1c51f89500c8cd07bb8da92a7659cfb12b175f6417eff25d811c930b029c543c4cd0f849e77cacf476f3bc690a169e1dbc5a60c407cf206074980d265a44231a9afe10aa679b542f63397019011e6fdc0316f658dd10a4d6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "ab3cfed6234f8bba8918664f83d266b3876ad57575032b3260c3cbba740ef1530db08f0f5e9f1718d5bf1f177922407ed746455736f21016994e0b447258234921f0f373974ba0e17f04f0aabdf7e7a33d180e474fb259191450ba590e225e9d7fcdd7fa5d4b3eea4f836444e31ecea28727d215709ba33bf6f2fe31305689600a314dffc81f99afdc1f63010f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "fcc8d836915a460569d081121755425439a95a85f635b8b1087b55abf43c1ae3af7350de02a0d11443315e5b46cd2dc135c5a2522801ced212bbe05c7c595ce3cf30b9bca9a34082b270b42c02b12e3c570524a9f7724ff0adfb2a134cfc70b6da98c375f197cd1a0f56c792695a88272ab3c30fbc3d46cd391303812e3db840e594f59b25e21007fbb7e259ad2c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "7664b3954ecad281dc23e0dac62536a4512076afd536addfc74d2ccf9742e80abd6a45dbdecccbb951e41b5f9dc4b5c10fa2734a0ff4b247f237950367a3e2f1ee00f75813eb6c3d6da4383ab908333fc123d5570a43319587d9625516122104e5691a7c6e9244ab7785846e13da5bd0e15568eea2d491cf202a0253a25209389b27c817c22c5ff3da99520cd71290" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "ed5ee508aab550984e5c58cbdefab0b5161a4455f2d4eb0cfb633dc2fe88144504e294af91dc830604a0c6be4583b97d054fd2d11c431292e52e559206bac1a447b4267a93740c7fc50973a6569772589286593164262056ddd60e6cde4fcd7798cfcbe4761ceed93c68f9075c6f1d5ded991974c2c75a8057eeeb73eeb07de5dfdfde32af4f69fa1476209f38003cdc" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "5a1c93e287f1e01a6e832e7c0c23522db04758c67faf12f8900cbfdf48cd62fdd0e5f1c1de85c921104164e35ff970ae0f047ec1ffdc84934cb869d4f944cbe010061b6e1f04fcc67eb1fe73a267c9e2cc784937b70ccc9bc210ce12c52c1a4c6e944d212d8a7789f7fb28e0633f299bfbb69bc967a464cf18610c695029f14a9049fafd3d876b68c9e3abdb4f829ee2cb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "70de86a6b3d9cd1d9b61084e7008b948afa2beda8e6171618260533d5f55bde09d454add55d6c6419467a57e48fa5ff16ffe852d5d650659310e3d56da10d0bea2d3ca1ed3557ea2ee5cd9a1067f3415a628aa0c174234ae0636e662b51bf5d1d0d066f5900e7464ab741bc69d3fec621dc610748271a672862aaf3c553fe4ca2ed9ba4f57f1e27953e3167fd1d9c3e4c30e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "2bb9490c3f07c77e4cc4db3b10e57e6606920d0ae01bf3a7b68a3d29b327ba9f5d7389fb0636d1494c3cb95d27122cfbcd9ae960fa0fadcbb123927f93599a24be52a01be80f5763597b8c52268ae553f5f6a90894573cd0a8876ee1035a65ff5a739c8abd8f115cab980d369d68b266b7a34d75f9c18b2efe3742e3e398ab6c70448f670354a8b486fa916bbff492fc98daab" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "deaf859404fc6e48c66cff9bc437eed861b45dabdbe625af4a82353f426a040050ed9235c0798a40930714df30bb796b64e9ad0df4350e196390aba4b0a10a6cae34007414a5880c5c2ce672c2b36a0e7d2622d677b74348ce07eb3cbb1c5a9c568063d8da555a64a0ba4b126a0e9d9f9ccde4cfca6d206f54c022f7518b8dda9d26d31a7dc9a2afcc3abf70ee5b0fcef9bf669f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "f875ef68c13c5a982637b84eb21a11e6f57ffab07bbc11e5326fea005326cb27c6f70e99347d5bf3b303639c260193c1b7d15de51da7e661e2ee4d08d5022d918d0bf1f3a4572d8003a8a4afb821f6dd03c2bc189391f25b2e425b743282f1371d209b61cce95092a2aedfabcc842fcfdef7a0b33473992e13fe0d6da31b41976597aebd26657407ede2d7c51ab1dfad8d44e66b86" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "9f46e27edb697d90398d02620b06ac8d49a3f66f0cfb02b9c628e70bfa0bda51eb024376fbcec59d8517f1e896557349d22ec78038b66a9a16460b8941005336bff96caa32e195abded0d31de0f4c8ab234d994979dc2b53476460abf5136b6b7fe6489793c14c48daab353208e150c43f7b1c7d659d6f8b5bf2fc3663335495e9aa47537afa5b5173aebde200f26705b6f1f3efc4be" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "35a3235938ed1312e8d79120615daa622cb5d24bb84efaa84dfd8daad79311ce6ebd52af7c8ea8dfc3ab72f49ede51d5b62f538e6cc84127a0eefa20c558961c644ea09c913cfc8550173109deb8554e0a418351073d5bda8f13cecdc71f32efa4e8c96ff5b30f663c7a4112f4b6b6afd6ab8daba9e2c7ac604a7e4b00cb52cce8ed10bca0cd6a6d1842b59867ca9e7f36ad678d28ec5a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "b3a70cd849fb5978199d363881831cc9df46c940d405360faa294e36e8ebcbbfdd8a672dca3b3195eb86b1a0817e537f853ee599ef3058692bcf5dcccd37118fdd42d50c524bc96ba7c6d2deedfe062a32b7ac93a20a8bd3ef20fb7a1766db25313390838e6a08e01cc932dc8b4410efdbb02aa4d53cd88d1b5fa0ba564b6e764aa417833f52e0a3ac46b42f4da1ddce5a35e070e0e02343" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "090c351eadfa98ea2843c39c0f1f6c6bc1800cf17359ae22e7a8a24960ddf137666e1cb45eaa675bd01175e81110f54c775ba952e3de3784987c96b92bd9fd349c7f120de13553366f621e7437a08e374612dae5f9f2cf9081c6761bf287c7a3af39963f06a345f1a8f7a8b04d360836f172bcc2f4b3aa2c6754a60b1bd49d42747561b3fef35501581f606777e6530c446daa462a4f7ccf83" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "01cba0c30285c6963c3bd9455713eb330bb887289c2a71ef7755e64cc0067810f120a1becf6a0dd45eb8c31ddb2befae75bbe7b4fa7dca9417455b92b6adb7118a36bed55b379f66d9bf4423ec928f14ff644019a6b9bbef69cc013f717b9a385ada55c87c06dd6b3474020edeef23188d0ccbc5d758e61eb00a20f9f52f309f2a8ba45f49db93170e61c239eb8bbc3c89b0b925c1c87a099aad" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e13f2c5aff51c441fc9aaf48aa45bfa2afc7c517104b6b7d50a9c4fa40ddd0595bb06541ec709c685aaea4c77ac37afb266f3510ac0c8c8891b4904a065ff9f7dd11de4bb758f6f2f5b16370a3ebc5890ec75b69a2c014bc9c67598c7e094c8820858e34c0d2150996dbd1c3de69f53dbfae0283412d27680428437ec1d5dfa444c5a553851bde66ef3377019c06f93d36e9b7e540e09ed223c948" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "84d5ae7fab040456d5b60a49db84184c6522c671eae6d715432d5b92da30fa8d17ca6fd8e10f00dc0a06fd7bc0fd3c1b00e6308b0c2615b20aa1a65d8ac905238c0520774181ffbdf4767eb2971813de6ecb07baad256ae3dbcb1b73d90afd0f5de22ee1e4be79541bcf4eb887ce1f904c3f32a868b289a76e43214ec171bc1639b51132a1f6b0db60c835761b6106115d81aecbc385114d56372891" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "5fe779f861e709fe51ba04ef56aeab3865b758ddd56caec49d268eb04ccf2cfbd83075286011ba7af59b8c50f81d978b029b541a5a5023c86533e1d25c4db5ec4f9b4ccadade8f4332fb62dd5f41cc0756adb4662c4b9063c7bca3dac7719082080e07de40956a4f3922b0271d6227115eb634639383608693bde9942fbeb4c0a76c1efa407946ad440556f489800d92eca6a7c73beacdac79e7fc551a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "be6ba46b695d0b8a24d4886e3a49caa510bed696d342a842bc51c0d015b9b737f299516ec27d3082a8c87fcc92bd50efa4a3aae7ca140bff820e5a849fa02b421fc0647a09f5a0f01bcc31c966fefab1e136b0c6d1fe1bfdb24a436f7a84d3905a88dbe18ceda4ea4923ad4b2b42ecf1923678f3d0bcca46c20c4a8edaed8f76e27ebeeff5d3fb3831de0b0de469e73968f94adb172c50eed38cb058ea62" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "a00bc425de55c2d030ac39dcce74083b56f809c1f1f8e3398fd68f4139a083ea7261f872378aafcfa6bb45b720101c9be64eef0eb2097a1c4f66ce4b56df65b144ba74267ace2c0dc80076d5d3e6e8a9acd70f21e7e743422acfc148be0088db05ef5575f9eaf5a1bcfaa468142b8f2c4a62ab3247571dc2481254ff030ca298dee37a4500845ee322378324ae2f635f4891e2d46f1f9c71ca307e5243d056" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "5f57318fca8c3a3b590e0205a5f5d314c15fd2ae751ba7befb91c4f898205f3f2701651e23f941c274b9228a39b598b33405f4a75e9d6600f1192e4f06f81edeb7f619ecc4e82b161f0cf9c8d37e68c7139ca9d653ee34a43419205caa61d14ab51f28b7c8e393dca8d6fdfdbd796d7f84ec0f3f33ebadeec67dbf7afe134c37f2bfc24a8ec47e0536361a87c8ac238e42c0baa9eebb9d576548c847f78f3f78" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "61237c1ea7a82566fc6f76a1d3d78eec3b3181de76065da39f4bd1da971e40e3011334c225e66ef4d4ff50e49b331ac39b00c91f985aec227d43f7e0eeee40c2668328201bc663039851fcf757e1c757f27f831a983b1050ac1e669c6a1f4cb42fd76c40f76cf0f4bb889ea36c02890f0d2adaa009d47169a9a8b4d1bdfb2e107c7b3b2bc907c368c59ab37ef54f84c4488ab75901995ac8430c27be15934f0de6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "24c443acf04ee19b20fae2268582993fbd142d22ad75a777647201116bd8c123334f6e0e847b3030af1482f7cd2cd2ccf5425683172094cda8e73e33cdc9991ca69e3285b9387beabf00c370ceb47db606aeae4b958636dd0937ce857cbdedbe31cb67a33eedcf2c51dccf620e20d8dd9f35718dbd208d865f1459e4cf3946e0a9b4e60ad0c450ba81d73d892b0cd595a52f4e07b6f740bb957e7768a9f32bc154ab" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "7ba4f3ed6000a2117982962ffd84e932de959aee244a8096778264fdbec4d04ddacda8a73c5728b04f0571ce5b9ec482a9ecf50b21133418f644262d9794601e7f2398629122b5b888d6af02ecb42d2e41238e0082fb2d47636f2aaa6cdb7d3be5eacdd4d4912f1b307e49572f1d657038ca83d1a9c456bc3bb6faf851687e5cdf4977984a44050413b5fd2c4272c2a3448fcda152e2c306a98d738ba1f8a21fcbf57a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "9b16ea160c255452b6baf3c4e5caf627c1f4e8663da9c9036f048860d31f0918075e3eda569254422b0295ff3afa152e4df0f99de21bac416e028e2a32e52896179f18bce7be2c5ecce28625222dcfaf2cc503ac4768df7bf04cd38d6dfcf1f1c4233051ae9843de7ac552203cbe0afcdee913ced89103a986af7fec428f9f93167a4218d5745cdcf57c6de15bcac08ce8a8de8b03ad9ebde73978a6486f7e1b90d1123e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "1dc2f82fc83a973eba60ee0ca1ad7a50fc50e9db3fc530378865b9abd4101198d6017a40777839dbc6313ecf35b7b727e0311226fa865d73a43cd28a400d8b35408d789b2249b7a8e5df452d50c6a3c28fcaadb58b222261be49aeee3667e0ba7c5f2726e31cd5bffd125231116baee18bdf7727ce3bcc0c31e1cf600635623881a944d14d514e1becd9bd0d823b41a93ae969396db22411172efdcb73593fc8cf80071f2c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e8c00940d825a6117d59d922221e01e2dfc2fcb47bcba06a72f09e8f5969bf988aee8a4035fc97d4ba4a0d4629c06912c908b90611c1cf4c580f8bd3345fd8b155c64dd747a9c21017146d620913979ece6df5a610d12ebb9ef30724586655ea7a11e45ed51a58f7705db538dd075a6a5ff70239e88a8d8da0817da0318aa57f637b522c50418da50d0710ece7e3b36331eb1147094ea8321659e6cfbfb90e92f10e90c3a73c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "8e9c1aee76744af025ba3f5bf630c13af132ab7c55230c8adbd20b214f204494f08035d9cf1beaa30a3f8522eabb88d02d5558e7f43c27b58c56dec5bf67812055a99bfca881e86f0024ef84501eb63bd5af849a134de4dabccb087a6cafe0426ff0d03de8cdcea2af83746f94b33eba2dcf4de7775d6a4db8d0ccb0d789e11b9bc3586e82e31a265cb26f82ef705139a5464118072af13f494f1b9a07bbbdb19dd596fdcac414" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "44753f6011c68059b5fdbaf6156e158221b5f1a544225844b33f3d4509efe0d4185a670627c3652b4f6427b583ebc5d941da2a801111a12d8d46ab1c0fde95c91e538be2e86954be14d3e7ae33d04029102e4267f3e2f099fb76f6801ff19f26b5ba07c29ab74cf1e3f3e3bdff363699dcfa7a32e3ffda3419bd22691cc64167f66a3c999714144e1079e6ff0472dc218d11274c061d92d97ee5ac1e02c104d1313a1ce3272326d3" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "f6a4be7b99c42b72c4e03cef4ac7420b445fb0720804df5f58d284e16cf27ae905dcd5e53f2ac1cc19d62c762fc9906cd45a0a5720dce51692285118f80dcd0cfa4008730a49c69aa259cf9221f2a992c21617e5fb361b03cffe6bdc283866d4f4823abbf43f02dd4d9351f1e37cbabe3eba1438dce281d6b87fcdcc88f4d6c2473d479467e13a5a1e94d1fcc32b9932c5f28ada66615d1f8c7e6e9170b06ff1c1041eaa4ca838edf7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "894491aeccd8edcceb6a6cb3c7722b2959cc591f8443b1efbc19a459d84c77183b2439e594e644b5b66091059fe372cc41c98ee01e2b83242ed2379dc97cb7f9d75fa146b36dfa9f923f2e5093b19fa4beb18d844af8926338f458d458f7452075bd0882e70570fc9b74cb61fa4fc2d50f8aeba4ee7d1dfaa4cdd44134c751ef6dd04d06f4892256472a09b9cf68919769c3b1ccd75c3b89b7f122d9b5c37d8745caaab703a32113afe7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "0ba47fc6ad5364ed20dba3638480fd26ab35fcc2da8220e971f3849235d6e706f291e08736bd2edb5de04299bf2fbb97d9fea02456244540821a7ecd0f3b87a7819e054fb14130c92245b72b8b8b4e5a0d3a0cbf513a75aeb398e2c5842553c947297603cc733021608451a615cde713099a4b4d1ab26b6a322932d1fd6a99c0285b7c44103c7ee80499db0716160382db8fea1b5caea9aeaaf1d940dedf185b903dfc2764bae972005fe0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "9f80b7abc0af99d288971d6a3bd35dc802e7975eeb854bc16dc0d7a2b4c41607fca9d2628d042d65d7a2bdabde5912ab36b293932c12f02f8c97d2623fd4b660a559de3ebfe58ef90f5cb5dd9515f5d21157825803f32aeaf2c1700ff8d084c0b7bcc70ac7f29090ad8c218375624d58f2ce789ab0b345da99ad17a47279d3e8a001f337e5fa7278c26554c673a7bac334efb258471c4156974cd1b54749a49000cc7459fb3983b4258e1f0a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "c254b38aaed704cce241ac2308490d469aa01403a44fa44987e3a33a94f51a9b762d02ea54967a8ba351812a6662463e82fcc4ee07af0862113e01c3f6d513b292dd02ae0e3afcc8584b559b930a27f877443d9443afa119db7cee8c632e18f186df0b907e8e3f3267f48a5a44232b720cc9330720e93a31cfbdab14718453cd5eac89beac73c996b6175bae2e91eda40e47625b286d42993fcac967e8320d7cb013a84427df4e30d23abe9cfe" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "abc8df1ef3606c517f5a2d8623e5cd0325504ebfc670da56ca01a570cf3840416b24f21091a68a536e162cc7ed7922869b7ab30283e57f5eeb60b778a06a8c5d6c6d10c91fe5cd37ce47669b785b11a3e1ae824eb9dbc4857a3ecfe0d1aeedeb103688daa07c4e01eb3e12507fcbdf1522fc5a186afbd858cfe8a453278c78285271c303a82417afa3d1893e09b4d2d1146c715cd226292af1ef2ad968ac7e491c127129d106677336767f25597c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "dcb3db73e478b5957276b1c6b16b1cb26d6679d4ce009ee6e5f4dff8ac135296f3ceeb80426d5bffac0324e927d7f77e31d011737e7460cb1f19b8c8aed25a786ebd8b521524c5faddfa009c6799778b48c50075d43db1dbdb891715f038595c597380a8d02baa3f06c58bf3d610148ef84c7bfc610455b63c1a8acc9e834cc079bdc9452bf5a1964c75776f33ce648d71b99a3a97f776938fd76314296a892973f1ac73cfd778eb130bb7aacab4b1" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "b390160aab430ba9fd39956bc2cffbb81e85f83323840c665cb3c8534dcbba46769ace43b21a0e0f6808b22cbe2e64075c5ee4aeb9f6588cf377a7f10f824aa48e9c3ff93c2ab1ee3bf2149ec9d51783af44d50d49f5801f5e30183b4a18ee99496357201602cfb7cdc6c68ea95bdb858dcef3f4333e304183f139811c853ce1397deadea3875036c72d4e018f8443763e5679bbf177b6d6f9295a9f0079dd6f3d33d523481b44d5abf432fb5cc372dc" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "eb380ddac0f8e07171d05759fac1dc71a22448e1453ff2430f82944743457b56a6c5228f6d14408d703cdb89305c5d67efd1c8cc9b0b145e51784edab2beab0021dce4a93fd4113cbdd7c7a33a6a77028228eb6b2a6750dfd2f842769da9692b8f1da6f9ce58ed56a63a666be97912f464ff57d3214889b7d66394b759caa18e57266b63bef3002a8a32d1138ff033e8f078d88b2f01b800e3f1181acb82460b8352b6736b3f122f02f416fd4aa40ec98c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "b480f56a66f51cb1385dec327ce586e81d3d9143a7301dce4bc593035080d6c2e1f0cb256bfaa082f68edd8542c0e0166464021dd2a5d721e9f6ce79d05208c348d9c892beecda78200ff67d61a96d7d2df1eb5426d41d5cca0ae3b25e896a914360db473c96899b923fd850a03770923473fded07c0b82cfa2e8c6f9aeca4f266829ebd10a07c1662d2ab1f2986eb9ebc33559958db46a89d46c7dee617caf1740f5e3022458d5cb0b8476381ed6ec8abc7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "a91a2d8ecb6485fa780adb7dab9679ac17f2b269306589e1eff3bd7842c2e004795ba3367ab5e6bad584159a6e6c063d64c0338cdb19f89eba55059992b02258f27fbbe1b5b748810a6d00cb365e08a493b98159a169616b8ff88f7e67e7ddb6502e03481a2c601852ed0b6651fb8963af760fdac36edd4fdcce1529b2c3800af3e63ab6bb013864b49950f04a3c784f0e84db4a1f58aa8b4a437b86673d124caa8534afff3fc5be3f5d5f16ba6f862ab5b9e7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "214b8e934e70e2e9ed6ca65e198bca56c84f498fc642b5add5b709b62544171a4d57f82d70d1fbb5cd4359379aadd8dbf274da265ea78302d66f130aa5593ab968a64f596e5f72093ccc3e5473e2de5cb4378823e6282e93d52fbdc4217cb1f942da7e5fdbae8c5ccd44c59fde24128bbcc3436bb6e43fa6d7bacb7a8714f693f1348dedbb024a8c22e164e0e7804a51bfb316569c3fde1b771fb2af9a648d949cd701cbab36a5bcd87c6923428301f3d64f5231" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "a2efa708dda81f8ef989f37cb10cf344a8a91548cffbab474041b59c5ebcebf34355e38de9e3b853201b3a4547762b9d10bfbdb52d8230c057fe84177b7790f488204d401fb8dc35fda836cbd549d504c47487ca1ed4fe80f327acd84a43e228c43c811070d74b788a3ea7b39b4a908bf9a17098fe36723f994b0d4cf2390ad430b979a5a48b89e1b7069656f806d53ded32cd256e3d3ad0ec09738b822aba507c16d15f2f4b748fd050b7984654e597d9b30c63eb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "1c8e20f3bb00f4d30a8b6d53458ff0b13032bdae6bbf1c99389d32069284dba2e82e068205583bf493de4cbf873ddb0018d866d4543e480b7f3040be117f526e99dc60a60bd84c3ebca8331dc2c126304369420c5c98d00f55d753cf7a993d58962093fae8460f2af2e495908bbe8276c50c11d15dd7ce09dfa35a49bdb6c1b0679f4abc2645034d9b61e07f29af79239dc2a47bd04157ccb5e77011f8dda9f75ed06e1fcb6b87b18a0d02a2648d91f6800ddd041a85" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "34a6209350420b4fe7eb859cbc21e7323f73921819f03529de3051d248f5ba3d73694eac76ef6e3281c51755ca6d625f6f840b181e18ef1f227669603e7f65875891639111d996314dc4b6e5a2dd18a8fa2da32ee3fc1514a44b3b105d291f3d49990d2a1c904921685b9f713c484fa1787608c735bccaeb4ceccd3e799960354444cdce5d9880a3100ca285560d2b9d3842391f60ef89126a58a0af453b1dd0d8ee44d253a99fbcc9f5b0ccd7b80cd2488a57bb4b23d8" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "85aecb151295bb3b7c992aa4c2534701e6ec0c9893d9bc8b95716262497411d9592b4f061357e7de7d03b0bf213c0c371c513e12fdf5d0fcaddf8b4b801a261082731dd269ab64e436dbade46152669a945bc51b9fb583cf287c76af8f236b2b44c85649066d2f46ad699435c3c3e954a9e85503537d70f34c06c5aa7c5e0cff11d2cf37c9ce6e883c837d7873a0b152470b26e21c82fb36c300a5e0bb62c81d09444d0967f0e8e8533d69660686f2c7fe2cc6f28478e231" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e7eaea666eda1ad214069ebe8acc8c01e7fcaea21ac8bc4922c686f8f256741f6b29c00fba4e9556b056e3c1ee55d75f06d946d77450c5398e17844ded4f7276693bbe9109bfe9507f42bced1971b3b03f3d70f25f0f99e29d82969bcf1bb663e4c4ae2a04882e05baa2f9c34c029b700c745705581cc5dcef33472cf2319aad0d1d37d92add19e20c88168475463969ca10c5e37cdee346482edbd9133636ad18690070fa7313fa39a7b8656b3e67340d386bd91eb2069262" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e0d3cae4de4bb434d22e779d992c671825b2af5209a236d0d82fe8103d21bf4519401ce2cd4c2852a8aa63f4aa29c8533ac9cb280bf39c92e5813208f563e7b3b88393f611175e99bdf22abc75e2cb175e5bcc9e0f614766e8c9f61b675899e701fad79ddc1f84c18649e50795305667bd22f1bc5dabf914ef207770c99ce3d802ff9afb36c829e5eb34c3218aa3ac47381da335d6dd1757c92af01f51b45d1f7b08a2ce50586474171acaa36927b10752268bc727b057f7c14d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "3d237d5b4e1fd29c6677c0fe437bc6624165b3a6e3ca157258dede30d0a59346a57b49ae0cb049324d5c6f289e91de76ffb29395a79e4937a74fdaefa65ea2513a487b8b50675954b72c9d551b0de89ef39c5596e678bae4b5b1cbeebf86e6818555fe886c624fa37f645120973fc92f4f83b263fe6d3e6eb4896d3bbdb8840c01a5f96d9213ac0400cb39e045ebbdbae00179afb31b77823a1ca3fae079d2cc4b09fb0525aec2ea5421e2c4b5ff9e2c881a29b49f9868d15a5dc4" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "89a8c115681b38ec1fef2137fe0dc1c76d53d042820536455233743830fb08a9d601fd1f3d796a08472687e457cad3166dd4781fa3ec0ade3ba31ba38a528932f0c6a1727d012631f649e50c76b983873217fc3c397c39ad8661c0f818222c55b35d0679b8ff13ff66235ad5bbb64c2eaa2891e400d443c687ddba429c2ec038c080785510cf999e0d2bf4e3918b27ec209145e0176dd533ff69876e4ac57438ec45ff3574a8e03afddf802e946385a158505526c1f6f6d816db2d3b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "f3f8196eeb035d4d2d9a0312f962190af5451a245a04ca77d2f7201c57a34f81332822730fb68bbe9c7876fe5b2dfbd56734110a9cc550419643ad094dda17171fcb06437e69e76c6614f4b90acfa3767093ad1eaeb5ddd3ea30769efdae090545eb74c482559c9c08e78231b0f235402a339eaf72c1c3f202a456d9a954e3187325bdaec1cee4a436e65a7ba401596a88c8b116470cadf8143f1cf0206eb7fea09fbe13178e30c7522218d80cb5146550f94c0f7085011bbea616c82a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "17790b069543cc3116bf84983c6fda6b6782d48bea79f4359f194a0a91f071fc9dff793af64302ff581d60905ca0e0ec07e16bb1af54d30bbe2ad2f522611d6d164ca85274041ab0a041f78a066480f19cb44ef88980febb1108513654b06480350fb68923b64b3c06c749d9da05430a0b4440105c44653e808a8557f59ac721c99aea7edf76b3bb3f1abebb4a7e55babf42cdc03c91135b48ff1554e57a96f07ed9bab8e6f529c93c6ccfa6961a591d8d05d7a9ef4d333b7722d2b29b08" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "86e0a5f8f3e995dae42d2e73d87438cf139f4bc42bdffe97dbf8fc26939f1454a254fdcd56882b3f552fa30b25ca62d0315fa49f1d5d42020b68bfc7bdb20fd4957ed50a533b2be720a8af438e68f174cbfee6817f3f0b3be2bfa365ab51942dab2b321def065c20cda6c7b1a7aa6fc3a1f1d6b4185880491601507ae2a0fa9686b40aaf0524705b760e15d9db822bbca58fba45f6c2d1b33fe49381120dec862d3940a3b145106125e3e99068beda1b073e5f03d38f6973e5969a4bab896e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "0459375f9886f055105cb34a109eb44de838bd5e14812f0719a40593aa1bd3c76c8339b7ad90d934d23f1b2aef5aca6f795c4e0132fb1e2d0702fb044f4724fb33e75c5a5d5af60501bec7c873349b1b8bb756ff7a816088ed08fd1a1e79830396d3f73f4656da870a5c1c0aa238c024ed490ec93e0e410c9312b96b5a64313e3d404c6236c655c9d9ad5df6b64e2149bc62f0173f33df60840f44386f4726ce15ee50fbaa0aedf1c384225413889f68571e578412bc6f6897081848fb7df0cc" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "1cc2c138b0cec83dddb572024356c6a05b456b889f69a8dd2cd8007fe7a23715b567fd6f646c0282b5c5d5360c0e1dc04fa45f69010eaaff42385ba85fd8d343bd1f6d2ac4556fc35ef57394473652f468bc28a0911eeca4234cf0f5e15d5b61a5c8e6340e974835aa8d5e36c63cfafb67bc1388d94e2a57f37056ff1925401f3ea9b497ce7750af79d45a8bbfe9cffd0597a0ad17cbffaa0f90451ac25ed14e807e4ec68e0100373a9d951d094c43308ebc195aae1c68067e1308bbc6144d0464" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "464d0ed294396d610f6b6ce100a876c0ef5b6d3193b746e2152cf437c422a2ab89abca1af36d2d585ddca437e43f9b045c129147820b0ec937d75f5051bb70c528ad9d419a38c9062d665a111e738e44ee9ec9c0f06e566c7267b05f8bb824854d4441c4cd3ba152002c4425e42e9e67926ee8f152f4b76f8bedf50855bfffb23780f02897765571a66b22c3b91fb115ecbd8f6b60b47761cb89d776d8376fd7a7ec9f267e4a27c0339d05812fb98e332100c3540d26a13d1122c09ab64acd30092f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "8b18cb31351dc0e00052722e236ab7c57c35c6ffff24a1dc28a56854f48ededdb067315234f6b25308a45c8fd9cd8130ecb24cb5ab0b1719796681fcbb4fd007f92c7d946545a0ac340f7e641cf3647756e08a96d4bd3396b691c9701b149c0c3859fcc922c76d2e827b5717198f015644301acfd2629840a0196e00e9f50477fc561dc69c8df6322d05e922212f2a5d5436701bc3256cad9d868cbd3ca4616938c8cb0e6dca03d2acec7709aa0dbb82b558b912f7e18283fcf13b7e32a992b222f341" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "f9962f0b9c6d5628577fcbc108d5708c2ecdc65c157ebabadfc68350cd0734d8ce6277544f39b16438f3b29b8265bfe421eec22f854e7ce8c0d165ddb38ecc523d895704764dfe263303a72db9aec08b1aaf5edba746b585fad6af8b7c61c7753cf9f1fa6121959842bcf74566cbd18bb8471bcf438cc3080feaca7891d326e627de7fb0f104851f1afcd832c3031366406953581540eddb0834dc79964facab1e7b8a45a3c64c6726e3057f82c22c674cc09f41bac59aaf3f7c727f4cee52306f91fe4f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "fd7af4e31d0f692bd74c4089e0af8890a933800b04521d59bb8c24bacc43e96193fea4475bd67419153362b83e54d235d7c7816d4027197e73ec1474dd2d7d003c1297eaf6ea80586d748cc52f1719b73f66cd6174c09c12524f960cd4d4bc26d066020d2ead9af8210bb78eebcb7e480604a1eeb15cb5e3df95f8d701b2d3ebb0b5b06822e157f09fd5a12fbf6af1762ff5cc9a7bb780237fe572eeb9fc4f52ea8b3494b1690fa5809819af4680070d25081dc00bf531710a13d8b661fbeef104ce7bce72" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "7a366aa68ea6dd5eaf6820ad9ac4a4863a3e67dd54d1d54b13f4bc88043398a5bac0c735750e5d3d65c157f97cd981aa1ea489f58d6ddd187fd18b8c65bcc3f36e22f564c64786254f319e25bdfd3edfd9d9cb744e7d36115788ca119b892ab4bffba4b467eeb7be8bfaaa09d902143765622351126e1d9707929350701875d512a762d28ec4d9e506d946078be66c6f57b9f5f21d8121bb339e9688b52a7ec1af7c4d0755026a531b73cb940c512d28d3421a302d83acd915ff2fc3c2a45ad5ebd91db7168b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e29fdaf8cae1f2aceb376d53f550170e5d18c44b3083c835340ed6079f312c7d1776824a4604d7967efda33b3824f106abfaf08f359555a24b78dc8ed6787186b8650a19adf64a8a7bd3d8598d9fb4699d3c8df6007086b03141a78aed1fab1ba46d4ad57d6b165dd2a405a6725e50d7bf0114728d1f81eb542abc72ebf499bf795f58f8bd0805b15fabd16de34bc646a7199e2df0e80064a9aef599c9d60884a6503fb9cc50efbc6e46d6dc1c8992978b9cd67b6d61b779c99e98d01c4c84a258a3318e57672a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "da61658788de4b16bc6eae4d9999785448e4055e730629275d1dadd048ac007440ec203f593c4e790cf9bdeba07ac926ab4310c5d6c196fa62dd239b22074bffa535fa1e9616bf7ceed9ecd56b7b6ec1d1d6f88c8672fc4087db0488cb0313642599682a5cbfdb7b79cbff91b4bcf76ad8f779d9fc2fa8fb95c4123775c7c0ffaea19dc28f310aa40cf734b8de7aea233c18b40ce01a851d0e208017e4a8f36c74d344a41dce80b6b180699021bbb13670c2c6025681b730c5f2ea581923f900c9e42baa2d5e0a38" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "31f1b58b087a656bd501b6b89b95e87ec36db90469b3ca02e8bc2b2f2493ccaa9dee81e8877f41a846b717ab550bf3ddc60438d747520f28ce4c30db9ed6be0e5062e5bd4aeeda7c42b94792247b383423cc24dc84613b1c8c892fd3c926267a1f6b290619be07126a34a442b860980967844138155bdf8fc4869115fc65fecd28b16bba47b4651e8bb586c1189dbb7d557124e04943ef79754beffdfe63ef9151610abbfd7b9696b98a6af7f5af088a6ce6ab23ec7533b7ce2942ec61bf9baedab3f3768205ebc85b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "77b6b031b61fa2a66115ba10bdbce0922cc3a5fa29a1410dd5e7021182389319800c3c2e3587af3629ae821366ccd5fa498960786814c3a2263a7b912d2ee866a35a51fdce1df8c7b9c6a86659bd6d2a05d665fb0b6f39582f26d648420abdc1f0404739b0502f85ce9b0d034d51a3eeabc562a8900ecee65dec28e111befc3c62ef8f928e707cdd2ec76068f3d347eeb0f062f6abd23e7c0cbd50061fd462dbf07bec30ef13ced3e5c65d2d8913495680a71a80275c0ca20d7a693a3b25f8c96beb78dabfdc55b8ab57" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "5169d680a74be335c0bbfa5f28985595b9d23b4a7101f92d11332ed5938b578900c18b6c2cd6676bf3bdf93121b6537d3aa97b3856b2fda9dabcb1a01f7eec7bdb8239dc8e6aed00f08bce422ad6b834670c847684669c84739ee2e26baca9703db038b92b943bd9ce0f8fb2711e79f8722115e6d7b8eb9b5cbc2b7e318fdae83edf3dc24b400b1907c8b8450c6b31bc975ed4303c9bcaf84b4003077f7c39514244434f7ed1b691ec9bf4c01005e14f40e1818ec376cac21d60f3986dba064f48655a5ca9a9f6045957db" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "1681227674cf4bc7124559c7c3409caa4eaec0f895a35693d454e44d79166bd93d29fafb5750c4235609d8a6545b19685a3049466c1e9a01e79221ff4d045390d3493186d116eef714a26e79dbc38a84d2b44b5909524d123ee2a1db6c5fb8d97f6d9776acd3a77210107c2853780225d49b8aebd00486eca5f469d0fb4ede6a7bb72ff92d778357b25053307db21b4f394c120c42712d52fb2ab3f803b276d5d81619a94560bfa0dbbad76a88f6527e453ee3eae3cd0dad3e9be3bbda9277a167d4de833f2a0876f13032a0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "1ff6e40a736e0aab47957a8f9631e7b7740645cc10e00ad4f1e95837bd45dc95f44d63139c28351c80432d195e8970222544d7b9f31b29cfde5bda467b814ff381b0af02ddfca8199f18aceb656eaf34df471918b5280c0c5e08ad17dafbbd22627febdf9e62ab1fc0beea3f3732ea166b4715733ec2c68262c09103ee96b062a0d112af1e800cff59b970101626bf3af5ec665d9de91467101e8a261dc733fef971639ada5b8c7679efc6a83cd6195fe5ee933efac81e8f83d0fcc4147f6dd7ddb35c1d0a17395f3309c4328e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "b44f695a21679104c2ee1662abff4f654712c990c2b8a89141481e5f33757484a2b921e822c5f37e5703cdbca480df2813163bab64fe5f7ee2958c6e08d2296908cd2aec4b66055f4d64d39967fed56f1074365d1d0e973cf10cb6b8b872ce0debe7658d75d73a4295d858b316559f9ddd9c4adae98143d990880dcac0b8f2c803a6162f0627bc18e8b43c0ccc1475fd03c51b39a64d93e7d60bc63de383598833fc248b5daf8c124ecbe9c39e1be8cd9c0e5c453936b1370177720f2d0b76078088ae483018ae6d5432b4324aa2" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "dde2dbfa04b50b16c03e7134981e2a947f49fd05ca06c25d3dce5203bdb17a281af45a291f9e0c3a463468f90415322bb4e61ef0016f47f169e0cdbd4dd88b352f6f27c12ddb9705a1269529eae07f3d34f6ec9fd5ac8eaaf3f20fb1961c188a771163c50778dcf452ea52b17723399d3f8a02967b0e27cfa61ac1c90adb585d6fa504f646e3d08c9abd695405563ea08b0163c6a4f91c88f7b0321e4393e234a355e3fc83a5245ca46cc6236e6f053d854360a7bf379f521acee6b6f54deda7b2fe233208d75ae77db9d1d827afe0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "fd0e4876256b31547b3bc1a2c2def5c417a5d3fb2c3771946784705528611d0bd60b1b5bedf3ee074875b6c8f38f57eac0323d85842dc3980c133f785379ae98fc732cdf733e7600b0cdd895b15ef0a280a01171fc7be87995047e70f8f4a1556e4cd7f0cbe0afd63fea4e51d5b8ee613ce38241e6f6e9e25c577cc8ad7dc914c0f26314a6a629cfd85d364ee73db9e888036fcad410478b563590aa10324d0b7d95618d36210fe8d086808b09fe52939f629d0e083ef6b03c1bc46b7e57779649f5f2b5f9f2e7f99d4017d1c20de6ce" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "6cfb70ed1c1ba261bb608217a062828357f228007518657378d4c633b5f15a54946cdf4a25f3466860339b42ad84b2a13553a8c7e49999716d7c8bace66ba68bb499d7840c622fa93245bf144b0bad70bdc16a27ec9bfafa92a1a58e846c3565d1309a29a371fcc2105e50b769f4fb620d839f042fde48e72a01e5889154f0572e31b7d6caa4326f393cba00100404c38ba6150465cb181aa29d4031d3e2ec3f09310caf4dd0bea9bc5527aa0161e41ddd923c4c0885dfcfc08ff92e85c703901dfe0ab233066a3d2d41a282d77fb767bc" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "8cd5d164a2b79c9e78b6235e49e62a174b7318c8c5b9a1e56e344951ee03daceab43c7ad9240e6ace541a052a1f500145b4dbd6590bba86f094f0b0696650c64be3ed6d041acd8ea6b0a32082eaf396faadcf0ef1880eb8ac2fbfd82b41f4755f02e970061328a7c8d93de8043d6d8df00e0e3527ae796738be6a76513e12af27807e981d152aa64892a1290c5d28636b4f7917cd0b7c4cb84fc00f4b9687e195cf77a52cc14bc1f5881a02f2a118d2296f7a254ac1a6d566ce4c04e91e42c398ae305e406db300dc3a9d450a390958fc62a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "a7a88b8862ac6d4895b627d2b4ca88f144781d69f64da7ff294b92b1f398c8740f94664c8262d5f1a47ec35cb2442fd91f5a0e74317782c2dbd861022945447313d7e5d17f930ab9f7e546dbc02e5df9f07629baf206fac4c3a5bd8de1d4172fb99bd2423b67c9e6c16d5648d3a95554996fd9d8ffb8a0dea44cf70e9f3976c53187e3f54810bafc49ea8164f77e8f0e6b1207445940b82f7a2ba783d9bfa1bd19cf847d7d6a5eb5989433c7aee0356a021b0701ffce133cf2242560b451abfc240d23ab2584de14bc727537a7b5fd582c4322" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "a3dead87fa53514025d8523b2ebcd89c7136c51788a8828c4ab62cf129e39a13f0ebaa2c990e621511bb6e8c1f948c4ea4775ae68263f368d7a7d52346a2fb45fb098d7009d46ea17078b8a0ae8a6cdc2368e6df793f5362bda3ec1d88959ae4aaf665d6d755902c908bba2ee95a38f59a5bfa9564103b95789f31f293c8766c51d8f41fb598581dc1503a8904b6efb74071c9fc7f5d6028a609bd4780f283867eb71e5754d1459d70f5393a5da9a2e0f90492bba2264b3db26cb4294082a8d98cabeba6733e5081a8d026f8a490858d8855d239" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "cbed99581a74de8d52bd80a970cec4fad1deba42a37496c7a584dfe75f1f883e1810b2efe18d59b6d92d800d1a0290b956fb35f8f8c9ba0878e0e5d477fa1d4d3fa0d7a835a25cdf9282ad93dafdfd90a28d7314d42b4724cfa495a599eeeb501a719168e38dc82200a593ae3f34920eca33a0224f511247a733f03ffaf1ebf476ad3645c3f1807bfc01619dfaf8731405d5efa106df774c0f3f018f8a545def065578651b01c33dfa5643d4a1b03dc9953bc943ea097f1a616002400e1cc4241084f63acb935561e0d3ba0ed5e487ffb3cded6a5b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "cebc668bc2e2f5089abfd20f1e15167f923a3d8514839eba2d6321f91f4cc7045ccb9d07f77bcb4872e42984e54b78f2e1c5fa66882c34d0369342b78d05443001b6eb97943f80d90689f140343b7b8b7e0eb2b5aa41d270c6cca1062c11b3cc6e0801e62213cece8860aace2a94176702f5e5f3ee31cb09e8c5b18d5d1e99a66492b115f11eb951e78b268e19009ff509605c66cc319d38ac0402c20d384c3ae4772b8d3aa4ad03dd19a639d5dd4a7e88307d68cb7bc13d768f1bfd7724cb2da50812e77a516ed36a1666b23ad3c5d8c80f4a94b9f2" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "1241811d00320b1ba7c370bfef2e3f423caa0680c22d17674db382617ec02be7c360bfadf95329ddae76919208bfe6f138b45885a5cc54e9fa46096707625c8b6a9b2be1e29428a98177a8c7d703969fc6f34c7b4cbcd316b7515b23502d0eedff8dad2d918b2673089160ce5bfbf1a03fa43bded3b7c006fe23af584a577b6518238706cc1ba6d0f462bc3f62e68948dd2332fe3ab624df9662cde869cdff1b8785a08af7f14aaee0217ca2e29b3e1679acdd25ff50958aaef05c13797bbe4992ba77c3091320c5e1b237decb7131a1eab79dfd636260" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "f175fe4bb81904142c7bbf271a3133444b8fde748d151672c471392458238dfd84cb643715705e2f21d7193ba52e06b81f6644a8733eaf71aaa9b24be772e6491b68717d6755b4af4e45f43cf88f874fca71a01e559d4a5a1f60c321d3e0ea0a8854b8d51ce7f8febebfade0edcf04a74f3c21814061cc7e9e5a48a40c49778a803a0eae7449f73512016f272784e32a4cc78c8d0f30ce3832b7e2d324bdd7b0c3d09ca49c654348760d261c55b56cb7767535ea925af2f0159780bdc8906c57abcc6319f2a5e9f16bf6729bc6e919311e5948aaffd84e89" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "8923aa7bc888549a47f405f61f09cfd235a9126250566506b7576d1c65a7e49dc76553f1921a4d1e1458c35bb032d4d804e421d8e19d9ee0dc80fe4de1f06d183c3ce60709df1726450532ad082275bd2552233bce9b15324dd1211d939c0ade85a16b5618754c6bfbba9dc15e79c2e69d375918a5301d8fca2fc5fb0dd02d71490575192497f769967c5c5a15a3552109d862c5ea21170db9a660418dafc942982d56a46181ec290c6fe9322738f00ccd0dab2bb825e557e39d61662409609b5d06676e9801ee7826076a665dbc9a0b65c17fc48d6223cfda" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "4dd761fd488c41c89c1998a95dcfae35c7907221195c6747aaada8e37b900d6c2f1a69e874a088dc2a7f01c31c64d877fe0a970716446135af511380276a51b067ef6a4ab914765a36444add895d4586a941bd1ba8db907487159a968bb8cf2f4457585b331cdaed2dd327b972c5aa71eca959add6dde4ad0b97f82bee9dd5ce457b0bb3b6da042068f6ff2bb8c20d8459d44172dcfd6139215a42aca13ebeec835357d3e7e01b1a684a4089c1e502cb655331acda4cd2f1c748ec2d86c8841f7606cb13271710ae816d62c3e7e4e35c968cd608f54bad127074" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "af5d2912543cf85417cc243ce775ca86d09a3463a6f6caa554834cab060d88dd18678dc22c46c99529709afa2499e37d58e345a72d40dec191ac1035b9eb6cdb85c41e6d5935574b9600e3b6acbf9292d237b410827e3e4ba40023141e19372bce972e16561983a0a2d06b5659224a8cfb4fdc253311a7c7c3b08d34db27c5118f5423ebc5d0503dba6ffc8653b5d0be4e82e3b0d3cac1f5b2a5efac448849c42d775fb659b041dbc793c0b64a58e884410d6aaf69e3d7bcd7bf500e61ef66f16f77ad1b4c3f009206577196be081b7aee014f4d62cebfb6d058e8" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "1317d1f48092dff2f78bacd0ca292e7a36839ed52d7bf1e0e729ff800372456a544ece4e740443652b67dc697e316009b3dcecbf9cc471193dfac3935c81f928744770a8b250159f44de9461f068d024927d5d8a4aebd2061fe015927ae67658aa48209aadd2115de5d02fb55fc5b4c274c7c9f2dbe218116fdc235e37d07a9fc5747da978c4fbee1244e5210ddbda05984f0e3dbc5b63359d2c928051a4d5ce6cd3857b6864ad1dec588ceb6306328f925f195a05aacf53d9340427f5fd433289fa0320f073417e68f356e4e6e5fb6b8a2a467af8fd51f4092afc10" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "3dc8e8ad7119b010d186e1238acb4bbaf33a2d93852ba91f733611e981df6597a87226f6c6d41edac6981d12e7642daa82c0490fd150b8d57f790630716b188af8285925fc0ff8457b4aa93963adfbdebacb8ba89fc4281bc56e4562a632e030f47093a7a44ec563c23dd6556cdedf899a2d3c1298f63e7959716981f82743b3f4d8cca371c7881550fb30bde8b7feba2e80d0ed5ec63e166d0ef17ddf8db2cf8cfe983d88eb40b0b10e0c9a9eeb38b220f7e013bb952c86b5ad11fc570f525c0125e01302a28ed8b1a97cc79edb87846a8e596c4d28f5018f2387a1ef" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "3a2f35477d7056e9ffd101691d80926ae1595c6fc618be62d6b24eed1922c1fdf10dc62d019a29b87440f3f3311dd90d0155e726eb96c3a49d985e9bf719e1480ecb4f4460d16cac29aa64b77e58d9a414160ed5f90ef0811c161c4e860a2ac705c988ac3567b1e63de780781b61ca6e8f16087a89e5304ceb7a68506ffa692194130eb82d1a458cf0057cb4a08346ace3076c72728c4e7abab4bf0add26d33eec3709a7644bc2c7cc355a10887f245f92fc049d733dfd1a87d2b67c9ee12ea4545cb84df60f3d8ffe209b7ac2fb3aada065acd7138d3680e36802f671f0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "b8d04609ff91f7dd457592d183d5482fe26f2862069011c5255d4c265c7906b55c72d2befd472309430fed0664b39cb67d16fcc622ada4976e2ff23c39910f85566473ab6bf0f5a8e1315310a2789ceddda80cae84f48f7a2d6c75df0277b5424d2c54c20209a9cf298f94d43b7769ada163ad1b4c2497e6a2406d41af3cbf11d233b882a46ee9195ad7f511b3de6369fc65e34ed54715681bbf8afefb337fc2f26adadecb429fda383b56a2529cfc7aec86b6377dbc17d03557d61f5410c106672d3a553c36e2a3722663f47d75c4c45595a9e7579d058aea1b35a5caa836" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "7d2f8d13222f1aafc0a47689010713d019feede3b1fdfad25def42550cbe918f5f4829787413a3606f854e0d431c6b2761d53f92786e969965d06700a39945adbdc17972b0ce501ddc5c6dd4b489944611ccbb9e62134d98fea9ef5bb6b5f7a684d971bc09e21fe6b40828199864516bc0b00323767a6d9506c8e3aa47c7676feaa60c820d70d0d8bfb7c3b7abb8d47eadf3beca782c79f6cb469c7c8c3340c14896b3489cb950fd23c4439a72f5c8a9589efcefb85bc786ee32124030a1c6d346011ef105cddbb398a6fef999cd19b04fcbbc6427cc385e8399d2611f0f3e65" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "723898ccebd8d2746ce9e3796d429462fe9e34cec7fd6c863e3d90c4f51eced7e241365ff428161a6762544675b6c805e6cc04c625f4d727e6e2e596c501ca5d9baab86c7b4d04fe4da505acd3e2d34b477ece7339b2064ae9f8d991d4f21de6273fb32fdd789df450b3d10e8961a5061290af31ea4f240a512da433fcead2c0908f9a020a0167fa45b7575e65f4febdd63ae251953afc407de50c5ed5da15384a16b5bbd86ff3514cd1f7cf2902cb7192dadd848987929121b051da8de022239c01e8b8f40379c0970e31ba98859bc5349637fcae05c8a50ea7c00fa3300b1af6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "6433591eaca79f1bb52aef15dbaea5e19f2b29312e594ac58702c3f96c297d87ca6ee2bffa2f961f41814c410b763125ec7a412e0621f32fd4b0fe2e17ac262c75780bd43877c56c413c2a6bd8c119ea73baf2cb821d46b7684f81101d3ed0429b6a94ad91742f7bd51b11bf4c12e5547c30e870f8e407bb5ffbdb96b10f901430eaf3e650b69b7802e93ec2c75d05183fb905f21d590e79617e4d08838a1ca126cb47d7e80a55253444682b49543b97146e71a96ddab190821a3007b28b55785442259bb2ade35e0cfe11e994f3894b7f3f5fceb341734e6b52d7e22b22f678f283" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "7d7e6bca9da076e7e833dd86bcb7d86fa305755e46e252eb201982fa3a3bd7fbd5d04d9077908a694de27a236361ea68a1f04adc231cc3856de97941ac8936152c51fe55e02be1673f315281cec9ae3b3f10f1668a84c1a96ee3f0a889c22cfeb7d6175b3bc23052971ae2e88b9be6fd5454b6256b8d62bdf617ad6cb22ad93fa02a20f1a3c29cee6447dff6806bcc7169f0b94b016c6a68f0b5a581a58d41a0cab986d4660cedcf1cc6113df7423bd486ef4e4b8f7fe33f3d82afccb9c86eea598156aedc90bdbccb75fd55c254975a193e1a6937e7a5ea0aefa94de7a9667565826c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "ac91aa5434938c1293186c76b7ae28a8437e621ac79c93b4b8145de9951f1948fd4cac58b781c3593a444b51751297db4dfd6bca2aa3452156f6bc412010da90270b09b6c5d0e4d8d836dadc2bdc35152ec6fdec7d1faedcb33868c81717100dca6bea92e08408ca6d1bbc7b68e7f71ae48f2fb2117697b9fdc4b46cccdf2d81bd6dc8c76c225ac71a49548b2f3788e47d56127a703e6705b08f4949738415b3392a701025775359ac29940a12161e554e50e6a6d5c0229039b25326ae1a61c93035f68c389ab2e88e8dce09b2f55d9291e6e640d411a543f5e97fa50eee2c10aedaf5fb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "0502fd59c54a710da5a6c4060d3573de3ad4c9a5a570722f95ccef846e5c7a574c8bb772816a6e7dd5c56331af86139fe7fbf3d7a3fb1c44c9d8579094c622b061060ef1f3dcd77163932ee6fe66af70d854e31ecfc086979416cf3e193c5dcd19ec1a9933aac0c04964981e4f76169a937bf9a454d9ca413d6a1097dee798a5f60a20b0643acb48c7514f026a9219a8d7aee6087584ac33a8c52af289699e604f2659bd7fbb45342cc3be9e7fe7564fa0332e5c2233daa9472f59d59f38369c1d153cee628fd5ba511c0f5df6deface8ad81a2864d403273175db913047b80556da8ef76e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "3d7eb388c75f23aa5a413c1aea1fcb3ba1d76123bc1834b5b973b385aa12eb0041ab55f571c7432287786ddae33539ca8777250f7f1960c973d7afbf561c274104f3c4cc033cab139247e43d98a5c814076482fe829e2eee0e302b3265676fdc82cf921935d19161ae814394cda9818f8e7c2bb4c56565790fffefa9ba86ab35816daa9bcb35f11e72637e7a6b127d084057906035914ff0ae08f71b601d755371171d249c7f87586e53cef8e175fb6312e8771ff5ead9a2f68050b8bf1add0aea7a3cd2f6d18eea57c6a7a13918cf7ebeb21113d09ce9c7a641a34b8ac22c9c164e9729ffda" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "a2a3b9a7c7f17ed8c51f8437c92e8918d0102f320227682192479a094a0cd6401d689a24f0f1f0ec7ccd7d5343391a7ef7590db47c83da0b43c133c673a679b49dacce5386a92c50880ff2803489a1ab8edf6212a155dfe8e3cdeff98cb145ddc1a9a1260385ffafb175e954d67eb5816c4da009df5a21b96a5cba8e77050220abd4f0b21f87fd44bf0354b9ea270cb8e428bd2d1822c8ae57256a413016b67894a3c38ef74bda287c2ee7aac2efbf244bea3dd1e9e94b0e1a5b18295f538253d7362e0bf0b5c090ca4b537e692bdb993e1225b23565cb281372f4d3a0ce247b96b1af1db06da1" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "42563ee8adfb99ea56890d94074a727c47d0aef5756145a92b1a41ae4cfeaa91351c88668afc1c4a715f35d265a36ffc103c5820098b13f0bb4ec0b761066aeb521a3b40dd40bacb45f58908cb2742e453c671754e85cfc43b12ac385dc1c72883260196658ae345ca16d16a08548fc8197709e3d026b7130bf6a0a74375dbfe619e64d35c2577f8e2d53eca56ae60d11551208ce41f95d19f789d909b4d9fcb52d289ed8862d5f1bfe5542b9fc68dd49d20f673b53a06e2ad6d74725e1180228a2dabf7f2089f4a974a22e91f3f413c2a4c18d7f5da95152a0338c3f406b71d760a9b2c32a5328b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "d699a03480c769b114056f7b8c1c2f4ea6013f785216a91ab9cf02df1a72625162c74979bfdbb938f76e0248f7a18c20dca243104aacefd8e8d2c9eba6ac0123f38fdc6ed1dadab1ed473097276f6c1a50d1d6fab39f2dfa8e78cc965d5875f73c703785c77e346c4ca551aa4ac0c25fd74567555209aa5bc7b7455a71f3d6cdc94a81297d1aa2901d2be9423f91e4d2c6977355910b0bb0dfad851e87bfca350e1406225dec1c514cfd2325411425c71dbfcacd4e21338980af552e5f833e4743a96130e71988005a26ecaeeac6abca9fe7aab0c8ff320ff135195532bde17cc5cc398476fa935597" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "cbc516abdb43cc8aa4d6e8c0dd28c4f8a1286d510a9ee9db7815814b635c6f17dbee4d4d18442d03faa7b21bc9756e7ab276f855d8780e2c35e0fdc4e6e1d2c7bdba75b3236e761289731461427e89ae9c36b815727740004c7aa565b9c8e52796a67a5be792c01365e6005d7bdaf71eeb26cbb67a2c503e978cc1469cf90cc5c67a0277eb78227c66c999fda6d87f6e2c8d69ca614f5335fb77333ad53bd64a904b9a588e99d5362b965fa509829bc88c5163f09ba40147e61834dab7316ff537eedbd207ab34c103c014048a33861e85d1e5384145a002b0d21cc0dcbb55ef3ebe8c595dcb910ec06e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "e63a2558d900ebbee7ecf56cfd1a20b7ed133c1476f9504fa814917cbd3057c729e38284cacdf8c6e65387be06664ffbd5dba5523186a05231c377b26ad453b8ffba3439d44ea10e4a12ab7038da3c734927d88769a00ec15d39dd2d7d2ac8bef814d06bcbf804889ef46d2ed58bfe2d0bc4a9bf10594f3c4244f7460f40eb1df72d80ef4c20ea18c2af5a059ade20d634e3d0f184a6d025ce40759ddb4de99746cbe4afe858893c2a5c2f51c19e47e2b2a36c7efef85ac7bbe63657253a2ebc0915f09f288d7c2030f24c923dfd0f29b66f8ebfdf3cfbb6f551ba7d83c068ba8144e566df37b64edbf111" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "c12bc01a2001cca9b3b2f8aa048c86a70fb6f9c0f03ee16e0dff7154d5989c0f22e0d5db0c05a0a24f85e89e1bf1c1c49a7343158fa5827a3031fad7a3b62cf69a24f9d6541984c498b758a70a91576c0209be7f83ff47b3788de21ccb1f2c5dde0d654b92ce5d6c4da20f0904a453d2dbb2f84b43ff4d8ae84432d896bf07ee1047af1a942c5e2576917a279846451e1ab36843ff1c7fee1202e1ff7d4fb14788bf4ddd7bdc050048d73d2375440575b04c83127a5a4189b926f777f24d9abe76270c4f1c64a3f9da133180a8f6f88f423134ecf7b49df41c57b6c736bcb2c896f754dbc07f6b4fc807f047" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "df5437f55443ccd7676aa471db84da24295903a87f02dd95e23aa468f6fd60be2e96d1d4366e2bb831c0f396b9b92328baaf45641a1c19339b768021f6aa823c953fefc56e7dd15805f4a3c0f83f9a21b5b3a7f81591febc8f0b1614813cc4b09df3a67dc11cb3d0f4d0399101da60b7986c1b7af3d19afa3a245a6c457332caa28e4c87be2596b6662992631d6ea8361c44f7b5f0ae991951b18fa187de224966fd074e2add2cd4e442ab18118737b75751c32b5c14afaf06318c2011b08e62c5c2bb35e48ab946a59be2ba6dadb3dc0e94b69ed0de84f02d6b5c61ffd4bc42cbf393b51760583477946b5417" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "491baaaf3061239f157fb02dda59e76f995c710d6170179821aa556264dd237e2eeb3c1b51efb94623e5603a0f0d3f0cce2b5ace1108e5c1f1edb359f5e1d65de4c99f1f48cca747adc58786515b955f65177e36f4f5c7fc696146fd4e7f7b9cb38c81b215fe08b6f034710cf9076b29dad70f8795bdb89bf4688c020fd2362feb2b6876fbdc9cf0edd250709cc7d059870f080ba9899f977007110274ebac11373578d11c93b1ff5872253aa395b1bd0b4e9da71c273dfd8c98c46d65d692c688adbd656bbcadd4ad4a5531e5ea96728afd25da0ea6c3b472bd5924aaff2b0e26ec6e0f0496f1cdd8c3c8cb34b4" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "39d12b605a6241a2a239a9cfa9936556b2d6f8d961b6165425f0a9b8c63940db014e41ad93aa9a94e68517a7553a4979a58eb24238eef54baea5384836be636b9953893114830467065ecb7b5d8b53fe8d861001f3c16e616cc5cbe0650942b40b068dc6740ba40684f837685f0581d699ec34226967223228bb73f5449d933c2fd7577b4f5feb3c98c5cc890c86e56e666b135c9ac46ca67f0ef5f4f5516beb221006b38bb37c1e8df9b549a5ba128fe168b83752c588d0ff9ddf725d31431f0ae085b5dd9f251124e0d575f9f79b6d2c28ba8d5c79a7d106c2617f77863a95fce0ff9962e6a21c4c00647ba27e8f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "c0ef3d806481d316ab62e4a75d42256f653138e6bfbfb42c398e88ee6f3d5ee2e85c5f6d407196718cda38c890111f2ca41a20238fe78903b1071591916b964e1cb15e1c357cd0f2c30aebf03a3662e14cbc1cd5bd4d58cf0054960edb9f091e3f4ed6c11a87fcdfdd84b8f5ca3ad8f1e4e5f06efd9594e1c5e5240ac9a8a373e140850d6b4eb4df20da33ce768b46a645fd73ec0fde5b799d548a12be5452492e46dba3da03fccce0cd3666ce88373ed07633024f29dc883c16245f8992b0b134e5461ad8def4922b4911e526f3e3c72b121fec0318369d1a40a4fadfa5078585494d3926b7ec6fc522fc85e3eec7aa" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "d9c78eb756dc9335fed007b1156ee7d89356291bd1808b025b7ac3bdaac8597c2a68f3d99890c04578ada7fad23125dc1fdee6e183f17c332882979913fd2610352e61f4f1b6e3c711907f4c6b5ecdd5ab5659b9788ab98e734455ba2a564215c7cd147a838e4ee02f4f35fdeb38706e64d23b8dfe3a58b0e1fa76c63038dc6aae308896bf52b9f851b76f3760f808b00e17442328f78287161dc283affb00862dd500140b86ca787bd58fd20f8425d2b5735467f723db7a0f9d1d08800ec395078a5470670056013ee95d7e59eee510fa23fe899a59594a3f823a1d62017a03bf464135c6b71f405e774c25563218b45f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "fb4504919408017da6d8a0622f6e95b9ed6b14db7841bd44f046eef98bf26bc834ecb3f4b7628ba3a53fc4d75075a25bfdc8536d014a185c0087fca9e011efe29e794b0e02719b617470fff50b02562a521e6c109a6cc183d74ab70b60ff1326255f8de02307cae03ff1bf49a771b5b311daa67cd4131004b2a1efaccd1d157c468637ea400caa891a531261b32f0fc61b241ff0fb8d1e8cf90703f80945a50dbf8edd650d43dd1c19dd4bcfdc202812f7dd5fe7d66dd39b3a9be37ecbfe1d0b3609c79cb19e49cafac783f02b9815912619cb3ccf8aaa47362bbb98f21fb48f61dfbe20d48b281fac8263b84b7c472b1719" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "0c317a9baf295d07e050e015a73f8827778973d924707c71aac3edf5e0f13bb51ad4f391b56d9b6dc204bbfc71d091d274fbb21e38317b7844a5e1cd58225279471401512a874ce6da69b364e2bad389069892057eba683f55b97ca4d18febda810eced644b6475fb00b64a4d86e81ba344a41b8b120eb63b047a45c9251c396448b07afa0315e062f40c430cae51448eaed7946cc58c7ff05917b564e6e4f99d1522be04d235659b3dc1e3f7ab0e65a5bb1cc3d26c1589e8532cb361f6bf2ef0b6b27e57569030db4e543a684c17db3dfc6bdb984834d842fd3642412ff88453d78dbd0cfd3b0771b6c0fb7ee38261cd1d103" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "3edf5d417a0d1a38a3a57e5265eb8df1542e25d90cd64292ab63713cb4a75b9c94850978fe2bd2f96f160b61c51d62eb2092d19b70c4448c2900f57f861f34425e2af6fd060c94f237fd4cccb745bee2bc47d0b4d5d8a57bd612af6109f5bb9a964bb4a6360371bec3bf851c269aad8d0f191eb7a9b77a1e98bc096a9b5586252526508a1c25cc1f6b0c1333f97c86a8799ad2ef8aa123400aa8741fe6277a2b92a6c4d4edaadc7fcae7953fbdf5ef1b499f871f66809b0d72c9b03e9b49cd5b8a91dc1c749fada0d9a4595d085f4b3e7643e239689c87a73455b31c9c5a6e0b899934408edc0dab175ce25c659c238b69e9ebbe" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "80f4ea817d4649de3f998374e11c9b41c3db5a5ac86b53031abab352171f46b893592ac5650a5218f7e54964b962b297079751c1d82bfbb9333fac445067a04473d26cf96a71c0c8092a8571d91f4413bfef40807206584d04928a5243f5ecec60e42aa3e0c83a28c8df71075d9a52ffd3519d5e40a0b20d4f4d1b21c695a249b5509a540cc0360d2906d6fddb6fa327beb9b087b1ad4d40ad435a2d589406369e7655dbd6d4f6ea340e35301b4bc02ac03ca85e55c8e50dff67718a9c1aedb6a0334bdc99f6c8b4dd52996bfd8dfca840c10aa92f6cf9d84c3994f5719fbc8d6a9592ffdada572d32aef67a9d7f9c897e08a197cb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "32d5d8e29fe1b68a49a30ef65787bf1ce003534891700ca2efe6dc4ce4b8770857130cad694451c148ed276c6843cc92597b3cd0129a043cd2d0803d82dda405b4151c5b4121bc276540c1723f4ce0f490d5ba0a4bff3a92117898d6ec362cbabd34052b6f82633f059a9f7948b46ab11cbe78d23f5a4828dfff412acf333a21cca6aacf570348a12a44c2939d360099234c2a68aff2bfc7e6fa0af55fbecbcb7d5d581a133bc46af75437147bdc42bd2cc0769098953655b2a41b5fec382ce63820ff4a447c7f62c825e68628279b8da57071a0c0a187943cfe5ac99e8447c3cb565973642115bf78cab6884cacd202d5c086ff09a5" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "2042c8097d147442b9e0787ad9efc72f0b351bcbc3e4037556a82e29a6f0015f0c8e162513c6529fcb5e1e790c789c0022e34ec0541128ee07f3597062ca54e4bc9ac6566861d0d3e93212c229a318b379f03e480776b0c57dc0053535d3c94ebe54887fd89212bc3f1814eccbe00918049f17b9db59aea0e5cba970ec6bae937cd059d0eacd3bffaa19dc1ebf5f5cd90681effe1eff986754b80c5817589abf4ca404bce5ccaa066c4753494b8620e0a796f7892c6ee8c62a44a9b40f7a098d344f09b45134583f860a3b59621aa31b96e094713406674a9974df69d206eb8efaffc9b7feda8ae5757406e5278873d68114e11dc57ee3" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "32217f6690884421cd6b0cb94884511ed0047b3a317cd2ff899b2dc866ece06ae9473018019124ab7f91918b9410a67f411ec349182c7f9dea73fad0152716d8f9910496e83fd50c56c93d5b088548071d65eae370722ac87178e62126f3a702ad323bac48bd7c238d65033c76187baabd952d6008723ecc4f492ca401b85fade1b219b31c6ede814e0ae35e1977ffd7b3b8c3b3474a3465a860ea7f27ee4b92852b09e4343772272deb760621bac6beb48143013dbe1c7ff1b7ff51cf66d02bd59e76604ad8b3374c688a05843f8af5e66465d5b5b738712e809d87587468c970e6239594720f1200b084fdd0829f282912a86d1c6360dd" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "da4830165af94ace9b01248bf2c373911096ebd83129cf6f454128c41efce7fea91156ab30a74a521e533b3ddb21b4a48de883c0ba7028420a128b3ead0a0d15d42766ce4d0607413cce1f947fa25f4a5ba29573554e68e005978d3b14ac0216ada50e02964759625bb313926f5ee7369fb3d4f50ab7e20244d2930d7f0113a44dd4b3edee72c15d57224d24b9fe9d9c1df2ef77f7566b18b6fcbb1f550f7717d4cf50b6666da197bfe2f4c3c23fe7d1ff6f770711dcc54ef9231bfa6ff455f859fb4be342e33a623723f17976f7b014ff8f50bfd2a687622dccf55e724d17337c65a1ef721c9ae68aece4906387078f058809e2a139e9755d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "1017ee9edb76500379a9eb1011cdfdb02cba68c53e47dcb2a2e29075c1b275f6a60782257b69e23e92563e8e6ef00bd99b5eac94ec223279e18422af405b0708689e8e3ae56044286c80f4de21474b4d0f8a5e525ed4394dd285abc592fd52410893a4f5b695ec9015bb3e95d9b8905ee6357122020729177042dd1b1a36f3fb33f992d4abbee44753c0d911745a186db1dfbfada785e5cfdb119217107f51e33858ddc5cfc97bafb75d838baf5e7407176db5080dfd3f4417221f0d1673db79289f16cac33e1be977f75a699658a965bb4730118202eabe34486f35664eec62610260014755d2704339ce611e759eae087b9b9ffe237bb8e88d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "5fb36a00c95a45ec6e7526c2a35189980e231aa36c2c8d6a9ccf288abe52ff56f77f01a0303d267fbed331bde0c30555e0f5a298b148fece91d802e3c33c233b535e37caef41ce16ab5df52070fdc3bcff00aefc15a552b0760769011e81aa70fb5740a3a568a15b5f72bc70564630209c5356dee3e49b1e089d97d9137f33653d81758f0a38aa53913753b5703249b5bcdd0104c86998d815951d5d0ec94685dbcf98e7fdbeae10361e9522fe87ba60c49fa6290503016cfd85a478a91fc70e9d43075b167058f1589b194296c750c6693f9dc245e9b21a483975ada00217166189b99b6c56357886e9a8063da35e9d20db24002ed36edbbd1981" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "c6942d36146678f56f4f8cec34f97448aeaeab84424cc0ea957292227287ffa954d5186f3e133eddd0d460c741dfc104f0015165e5efb7ee33043b97e55b2995b7887c49a5df5546459f445819a55edee3fc39743352b5b197095787710dd55b11f88d1155b051b97918885916a59dc8d64dc31c2e1eebd3995bf144c86849b992a35be67fa30bbba18a565b1aae21ad2738236014cbde288ecfcb910a7edbf33d41bf59fd81675a8fc0f3dce569d0662d6d565e8bcccb8528328aa75bc98e09163be1ff113af4d7e4dd514ead744117754e54b4bc85c194c2f074d3d27033011c66beb70e984ef7b675b70a9eb73a3dc0c3d626bba33a87cde4dd68" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "55f5d8c7a4fb578ae7f02e9d627b5ec4e6279aaeb1791be6a030e00f3f715eff486affd8539d41fd7517588cb6a08dc77c0a3d2ad6be11492cc950d44137c3209177ca50e5a48073a85ecac000fee2cc97c81ea4c82f9ddaec4ec479219ceffa06052d6c0fd57044b7c69c07b6c361269aa6e2fd6dec3d93cef32cd8a698af82f676f211053787b69194552d03d3db7ddc508efb6336f17541d7c18b18e93854d24644ca999495e8b321303b8dfe9eb430d251ee9e265dc838b1d201f84018fb89cca117954c7c059927e5eb8ab54afe5caf720292edfc003959fd93f945dabae0c3d56edd430894c103f579a048ba0c097a17fb4954df8acaa46026b5" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "7c4634ca8c596c5f3003986ef7a26bbae711327cc9ea020b546755ebe23e4997731fc1a9760de9e44529a8d671f99f567db7aba5d8b594ae35a61bb585cd2a950f6c216f3173614b1f96ac120085f79106732e7bb55edbfe1b525c23e4dbb117a23517ac4a89cd3d09a39b421ac1bf3f83ea763c272f3f653c3c3807130d6a998394359bc5f51047c46f77af1c738b363cd243c10d1c7a0d9db55d8e14c91bced77065d0a5c21061d181ef6fab35218aeb065b49630b9e3b29ca1d64fe21ddd2b906d9a9421eca770639084e97ca4b04cbd522a355f7e30465219a5ac869003f5c5d40401d5e049a9737081effda31c6ea9e6aaf4205c85470d5a2ca2d37" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "2953a3385e63c8bc7bf7f441756deedf21f7620528ded82100ee0639658c6b973ee4878b1ed8c7a9a755b2aefaf010855c64933c578cdf5d9b93f991ea044ff020662757901c1b6014f354f061f7274c2d912eae78601944be200be650a869219a9f67890f5d6a48ab799c3676b24009642690105b20e034c6632b36956e43d049b306b0a596d0ecc0e79cb1ff11824ea31e8d023bba757bf2597bc58e83076e1c45b2f0e9b72fa93f4423589401efa4916d2f9a82833f44e2866bcbb222ddec1b5a70ac5f78716e4389e566dff0e9c1b510eae7a3106c47eb60b8b5bab89acbe46c055a7554bb1cdfa485a891c3b548c7a5f1d38c03cdfefa5ead65031ea4" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "", - "d4a23a17b657fa3ddc2df61eefce362f048b9dd156809062997ab9d5b1fb26b8542b1a638f517fcbad72a6fb23de0754db7bb488b75c12ac826dcced9806d7873e6b31922097ef7b42506275ccc54caf86918f9d1c6cdb9bad2bacf123c0380b2e5dc3e98de83a159ee9e10a8444832c371e5b72039b31c38621261aa04d8271598b17dba0d28c20d1858d879038485ab069bdb58733b5495f934889658ae81b7536bcf601cfcc572060863c1ff2202d2ea84c800482dbe777335002204b7c1f70133e4d8a6b7516c66bb433ad31030a7a9a9a6b9ea69890aa40662d908a5acfe8328802595f0284c51a000ce274a985823de9ee74250063a879a3787fca23a6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "0e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "5196" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ad6bad" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "d8e4b32f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "8eb89056f3" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "410497c2ed72" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f0de771b375c90" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "8662db8685033611" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "9ef9f1eed88a3f52ca" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "08225082df0d2b0a815e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "0f6e84a17439f1bc97c299" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "895ec39c78d3556cefdbfabc" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "2b396b3fa90ab556079a79b44d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "abae26501c4c1d6123c0f2289111" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "bca098df9099b3f785a37ba40fce5f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "19b827f054b67a120f11efb0d690be70" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "b88d32a338fd60b58570fda228a121113b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "3f30143af1cad33f9b794576e078cc79062e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ffddb58d9aa8d38086fcdae07e6653e8f31dfc" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "abb99c2e74a74556919040ca0cd857c95ec985e9" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "71f13f89af55ba936f8a7188ee93d2e8fb0cf2a720" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "99734fdf0eef4838a7515426f4c59b800854e2fcdc1c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "579b1652aa1f5779d2b0e61868af856855020bdd44d7a7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "1383d4ab4a6d8672b4075d421a159f69380ff47e4bb518d5" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "d3fa1412712dbbab71d4c6265dc1585c8dcc73380cf807f76a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "1d57868a71e7245667780455d9aaa9e0683baf08fbaf946091c2" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ef80418fe7049c6251ed7960a6b0e9def0da2749781994b24593a0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ef91cb81e4bfb50231e89475e251e2ef2fde59357551cd227588b63f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "d7f398a5d21c3139cff0562a84f154b6953c7bc18a5f4b60491c196b6d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "0a2abc6d38f30aef253579a4088c5b9aec64391f37d576eb06a300c193a5" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "02dd758fa23113a14fd94830e50e0f6b86faec4e551e808b0ca8d00fef2a15" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "a4fe2bd0f96a215fa7164ae1a405f4030a586c12b0c29806a099d7d7fdd8dd72" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "7dce710a20f42ab687ec6ea83b53faaa418229ce0d5a2ff2a5e66defb0b65c03c9" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "0320c40b5eea641d0bc25420b7545ac1d796b61563728a4dc451207f1addeedcf860" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "460539415f2baeb626fad748dee0eb3e9f27221661160e13edf39d1b5d476ee0672400" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "02de8ffa5b9c748164f99ed9d678b02e53f4ae88fb26c6d94a8cefc328725a692eae78c2" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "348a61a0136436136910262ad67ef20644b32c15456d5fad6b1679386d0bea87cc1a2e2b5e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "24c32966c803434d48d2283482ee8f404f598cf7a17961748125d2ed1da987039b1ce00f2ba7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "bd07cb16121d3b47adf03b96c41c947beadc01e40548e0d0773e61780d48d33a0e2a675ca681a6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "a35844e34c20b4b9371b6c52fac412afe5d80a4c1e40aa3a0e5a729dc3d41c2c3719d096f616f0ba" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "6df1efbb4567747fe98d218935612f8835852dde2ce3dec767792d7f1d876cdae0056fef085245449d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "48d6094af78bd38d8f4b39c54279b80ef617bc6ad21def0b2c62113b656c5d6a55aea2e3fde94a254b92" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "cd6e684759d2f19083164712c2aca0038442efb5b646594396b1fccdbd21203290f44cfdecca0373b3801b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "155dfbf26103c8354362663677fa27d0e1ce3487a821a2a7171014c1bd5dd071f4974df272b1374765b8f2e1" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "15b11067f311efa4ee813dbca48d690dc92780656bc4d4c56510523190a240180867c829a8b8b9844175a8aa23" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "9bc27953a17fb84d5eabe95b4ea6bc03ea450274abccfb6f3938ded8560fb59662459a11a86b0e0f32fbea6bb1f8" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "03b78fb0b34fb8662accdf350a6be75ace9789653ee4375d351e871f6a98ac5e782ca4b4a717665d25e49a5ae25d81" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "687e9a6fda6e2ce0e40e4d30fef38c31e3513d2892bbe85c991fc3715947e42bc49bcd079a40ed061c2c3665efe555ab" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f3886027d2049a8909e26545bd202d6a6fa2a6f815d31c7d520f705a81fa606dd695369c37aee4fa77dc645e9b05813ceb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "e4a412ccd20b97797d91ccc286904fcd17c5afe8bed0618f1af333c052c473cd327637d951c32e4af047106036a3bc8c1c45" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "92f4b8c240a28b6238bc2eabadaf2ff3c4bfe0e6c61268ace6aebdeb0691450caea4287db8b329bde96af8cdb8a0fe2f57ef2d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "e506834b3445e1a9a9b7bae844e91e0834512a06c0dc75fa4604e3b903c4e23616f2e0c78b5cc496660b4a13064bb1138edef4ff" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "27031955a40d8dbd1591f26e3c26e367a3c68f8204a396c6a4ba34b89672896d11276966a42bd516716f35ed63e442e116dbcf35da" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "646b1635c68d2328dddd5ac26eb9877c24c28390a45753a65044c3136ae2fe4fb40d09bf555271646d3dceb1ab1b7c8d8e421f553f94" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f6171f8d833743bdee7cc8f8b29c38614e1d2d8d6a5fff68bec2c0f4dd463d7941ff5c368e2683d8f1dc97119bde2b73ca412718bc8cb1" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "45db1c478b040aa2e23fb4427017079810775c62abe737e82ec0ef8dcd0fc51f521f29fe6412fff7eac9beb7bcf75f483f3f8b971e42454b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "500dab14687db3ca3dde9304af5f54194b37bdf475628af46b07bfbf6bc2b64ecef284b17f9d1d9be41794699bc0e76c2878b3a55730f7142d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "31bba2efc7b3f415c3f031d4c06bb590ae40085ad157370af30238e03e25a359c9e133212ed34b7a006f839173b577e7015a87fdff2270fafddb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "0600b3fb4b5e1ed0c8b2698ac1d9905e67e027390764821f963ad8d2b33cbc378b9c25c3ee422992d22b760222ed5697be0576d73938ae9d634ed7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "4c0ca4f177d132594a4c613bad68da24c564efa3b4da0d0a903f26534a2e09f8d799d10e78f48ccdb0203954a36c5cf1bf24c076632c2b022b041200" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "97aacf2e1b013677b2e14084f097cb1e64d7b3fa36f097e189d86dc4a263bcc46817cd1ee6ff0c7ccd9acef63201cdc0e36254e19204a7388643bb571f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "71fd6846ce7adb0843d6063546a16b79b54ad6c0f018a479a45817624fa221f63525084860559d1a0679c8d89a80701c62743ec2da8419d503f8f0cd7946" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f73dfb046def3362d6de36077dae2cee2587fe95fe0800548bb7d99737897096ba59052e0dadcc1fb0ccb5535391875328637a0376a43a4d89366758dfe3e2" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ec470d0aa932c78c5bcf86203ec0014314114765fa679c3daef214f883a17e1b4ca12f44433772a6e4ef685c904b2fc35586c6bd88f325b965968b06d808d73f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "cf601753ffa09fe48a8a84c37769991e96290e200bbaf1910c57760f989bd0c72e6128e294528ee861ad7eee70d589de3cf4a0c35f7197e1925a64d0133628d87d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f15413f7d6fc54bb55829f698da92ee42fcf58dde1aa1bd07d438ecdc32ad6bf2bcdbecc99f18ed43e81b33065af5a4ca29960ae50553e610c0bbf4153d580e73dbb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "84b1738adb9757fb9402ef7113581291136184d7ae35fe0b6a738da6acb0889d4d5bac7a957024e3709fa80c77d3859871ed1aa25cf488e438a2d24cfadce6008761dd" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "e02814bb81f250c1835a05108396b74c7878e737654bb83155e241774d04e639bbc571b413cd9349092f926c8a149a53cd33e9b63f370b6d460e504199d2e7d849db6cbe" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "aeee4a789956ec0913592c30ce4f9c544894da77ba447c84df3be2c869100e4df8f7e316445d844b31c3209abcc912f647735fd4a7136c2f35c6fda5b2e6708f5ca951b2b0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "8cfd11ca385de3c843de84c830d59278fe79b70fb5ddbfbfc1ddefeb22c329ef2f607d1d1abbd1cd0d0cc7c5d3ed922add76aadca0d2f57b66cb16c582b6f18f60aee2f7509b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "852e5ce2047d8d8b42b4c7e4987b95d23e8026a202d4567951bbbd23111e389fe33a736318546a914d2bddedfbf53846036ad9e35f29318b1f96e33eba08f071d6dc665149feb6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f225c23164979d0d13874a90ee291627e4f61a672a5578506fd3d65a12cb48a182f78350dc24c637b2f3950dc4882a5c1d5d5bad551c6f3e0093aa87e962bea51566af3791d52d65" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "5f33864d882455f8ef046aed64e2d1691e5c1555e333b0852750592e6f00d3b5ec941d0c00e99629612795d5870cf93c984b45e4464ba072a34903b400a42824ac13da28c7c1cb1959" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "7baaee7c3eb68c18c5ae1d45ba381803de34e36a52e2d7ccc9d48a297273c4d8644b473195bc23005f7a4f5ca790b1fa11f6a96e585e635513f11745dd97a69c1222204ab28d3c7735df" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "d0a2a3fc450ef9af7ae982041feb2842901026467d87839c33b4a9e081ea63d5be60ae99ca6e42393ded45255b8f42886f87ba0310572d9f0d8b5a07ff4b6bae1f30559a844983cc568560" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "3aa4164462b3e7044c35b08b047b924790f6d5c520b1df4305b5d41f4717e81f0cd4bccb9a5a6594773832b8707443adde4047caaed2293f92234df257df54ed275a9658fab483d0576d33a9" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "c8b4239fd7f1b893d978268f77f6505b5775d89090374322d40083b0f4c437423f670ca213f7fe05c61069725da2561646eefaea597ac48e293fbad44c2872046857e56d04a426a84008cefd71" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f94839a7024c0a16971271b6727c081770110c957b1f2e03be03d2200b565cf8240f2873b0426042aaea996a1784fadb2b27f23bc1a521b4f7320dfbed86cd38d75141365ba9b443defc0a3b4078" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "8af934fdc8b3376ca09bdd89f9057ed38b656bff96a8f8a3038d456a265689ca32036670cb01469cc6e958cc4a46f1e80d700ae56659828a65c0456b8e55f28f255bc86ce48e44377bf1f9970b617d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ada572989e42f0e38c1f7c22b46bb52a84df8f7b3b773c9f17a5823e59a9725248d703efb4cb011abc9474e8e711666ed3cfa60db48480a8160615dfabad761bc0eb843d2e46299c59b61a15b4422fdf" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "b11f1ea52a7e4bd2a5cf1e234b7c9eb909fb45860080f0a6bdb5517a37b5b7cd90f3a9e2297f995e96c293189b807a7bf6e7633bebbc36674544db5f18dd33020aeaf50ee832efe4d3d053873fd31ce3b9" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "e54b006cd96c43d19787c1ab1e08ea0f8922bdb7142e748212e7912a1f2c0a4fad1b9f5209c30960b8b83ef4960e929b155a8a48c8fb7ce4326915950cede6b98a96b6f1ecb12715b713985dacd1c1180413" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ee2c2f31a414ccd8f6a790f55e09155fd50aac2a878f9014f6c6035cae9186f90cdef0b7adf3e207c3d24ddfba8cd321b2e9228b02a1182b6973da6698071fce8cc0a23a7bf0d5aefd21ab1b8dc7818549bba3" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "6d6810793bad6c7efe8fd56cac04a0fb8717a44c09cbfaebce196a80ac318c79ca5c2db54fee8191ee2d305b690a92bd9e2c947a3c29342a93ac05796484638787a184e4525e82aeb9afa2f9480caebb91014c51" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "91e4694366cff84854872667fd168d2d42eca9070cdc92fca9936e8361e7266931f418450d098a42686241d08024dd72f0024d22ba644bd414245e78608942321ff61860ba1245f83c88592dc7995c49c0c53aa8a9" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "608aa620a5cf145f4477694407ccd8faa3182465b29ae98d96a42f7409434c21e4671bcae079f6871a09d8f2965e4926a9b08277d32f9dd6a474e3a9fb232f27fc4235df9c02abf67f7e540ca9ddc270ee91b23a5b57" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "c14f75e92f75f4356ab01c8792af13383e7fef2ffb3064de55e8da0a50511fea364ccd8140134872adccad197228319260a7b77b67a39677a0dcdcadfb750333ac8e032121e278bdcdbed5e452dae0416011186d9ebf29" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "03fcb9f6e1f058091b11351e775184ff2cd1f31ee846c6ea8efd49dd344f4af473f92eb44eba8a019776f77bb24e294aa9f962b39feecf7c59d46f1a606f89b1e81c2715ac9aa252e9ce941d091ffb99bb52404961794cf8" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "11e189b1d90fcfe8111c79c5351d826f5ec15a602af3b71d50bc7ed813f36c9a682520984ae911669d3c3036223a53176794c7e17929efab2b1c5b500f24f8c83d3db5d1029c5714c6fd34eb800a913985c218071677b9885c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "69f8f5db3ab0321a708ab2f4234645dade6bfda495851dbe7257f2b72e3e8378b9fa8120bc836b737a675271e519b4712d2b56b359e0f2234ba7552dd4828b939e0542e729878ac1f81b6ce14cb573e76af3a6aa227f95b2350e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "be734d78fae92cacb009cc400e023086bc3a3a10e8ca7cb4d553ea85314f51383660b8508e8477af60baf7e07c04cc9e094690ae12c73e5f089763201b4b48d664b94b4f5820bd1540f4a84100fdf8fce7f6466aa5d5c34fcbab45" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "d61b77032403f9b6ea5ad2b760eb0157545e37f1712ec44d7926ccf130e8fc0fe8e9b15570a6214c3899a074811486182b250dc97ebdd3b61403614d935cd0a61c0899f31b0e49b81c8a9a4fe8409822c470aacfde229d965dd62f51" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "c31bd548e36d5fae95ed8fa6e807642711c897f0fcc3b0d00bd317ed2bca73412064618c6a84a61c71bce3e963333b0266a5656571dcc4ba8a8c9d84af4bdb445c34a7aef445b15d77698e0b13c436c928cc7fa7acd5f68867e8132993" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "9903b8adab803d085b634bfae2e109dd247a7d6249f203403216d9f7410c36142df8fa56fb4d6f78136eef5817bad5ea3608439bb19336628c37d42db16ab2df8018b773baedafb77278a50926370b48bd81710203c7abc7b4043f9a1751" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "4dadaf0d6a96022c8ce40d48f460526d9956da33260e1770315ead420da75b122c762762aa3ddc1aef9070ff2298b2304cf90443318b17183b60778f3859b141053e5827decfff27ff106a48cfdb0371d0ef614fc7400e860b676df3176d1a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "314dda800f2f494ca9c9678f178940d2284cb29c51cb01ca2019a9bede0cdc50f8ecf2a77e238b884867e78e691461a66100b38f374c4ccac80309641533a3217eca7e6b9a9af01c026201f0afaec5a61629a59eb530c3cb81934b0cb5b45eae" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "4658b7500951f75c84e4509d74047ca621009835c0152f03c9f96ca73beb29608c44390ba4473323e621284be872bdb72175628780113e470036265d11dfcb284ac04604e667f1e4c1d357a411d3100d4d9f84a14a6fabd1e3f4de0ac81af50179" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "491f877592837e7912f16b73ee1fb06f4633d854a5723e156978f48ec48fbd8b5e863c24d838ff95fa865155d07e5513df42c8bb7706f8e3806b705866475c0ac04bbe5aa4b91b7dc373e82153483b1b03304a1a791b058926c1becd069509cbf46e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "231034720c719ab31f7c146a702a971f5943b70086b80a2a3eb928fa9380b7a1ad8773bfd0739142d2ad6e19819765ca54f92db5f16c1df5fa4b445c266215a92527bd4ef50ed277b9a21aee3fb7a8128c14ce084f53eac878a7a660b7c011eb1a33c5" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "3366860c77804fe0b4f368b02bb5b0d150821d957e3ba37842da9fc8d336e9d702c8446ecafbd19d79b868702f32405853bc17695873a7306e0ce4573cd9ac0b7fc7dd35534d7635198d152a1802f7d8d6a4bb07600fcdaacfaa1c3f40a09bc02e974c99" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ccbbbe621f910a95835f5f8d74b21e13f8a4b03f72f91f37b5c7e995aa3cd5539508d5e234e77a4668a42c239b2d13ef0e55ecf85142055e3f8a7e46320e21324a6b88e6c823ac04b485125c2aa59b61476481208f92ea4dd330cb18777c1cf0df7cd07893" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "87faf0e49e7e5ab66ee3147921f8817867fe637d4ab694c33ee8009c759e7d707f44c69c1b9754e2b4f8f47b25f51cd01de7273f548f4952e8efc4d9044c6ea72d1d5857e0ffeb3f44b0c88cb67683401cfb2f1d17f0ca5696641bef28d7579f68d9d066d968" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "38c876a007ec727c92e2503990c4d9407cea2271026aee88cd7b16c4396f00cc4b760576adf2d683713a3f6063cc13ecd7e4f3b6148ad914ca89f34d1375aa4c8e2033f1315153189507bfd116b07fc4bc14f751bbbb0e752f621153ae8df4d68491a22430b309" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "87d636a33dbd9ad81ecd6f3569e418bf8a972f97c5644787b99c361195231a72455a121dd7b3254d6ff80101a0a1e2b1eb1ca4866bd23063fe007310c88c4a2ab3b49f14755cd0ee0e5ffa2fd0d2c0ea41d89e67a27a8f6c94b134ba8d361491b3c20bacac3d226b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "b021af793badbb857f9a353e320450c44c1030fce3885e6b271bcc02e6af65fdc5be4dc483ff44bd5d539ed1e7eb7efe3001252e92a87df8227ace601047e101c871d29302b3cb6c6f4639078afc81c4c0f4c2e04688612ecf3f7be1d58ea92894a5dab49b949f2089" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "c5c1f2fbf2c8504a686b615278fc6221858d401b7fe790b75fb6bca6885cdd128e9142bf925471ee126f9e62d984de1c30c9c677eff5fdbd5eb0fa4ef3bff6a831056cea20fd61cf44d56ffc5bda0e8472ecdc67946d63c40db4ba882bc4dfa16d8ddac600570b9b6bf3" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "88f8cc0daeaeaea7ab0520a311dff91b1fd9a7a3ec778c333422c9f3eb0bc183acc80dfefb17a5ac5f95c490693c45666ec69234919b83244003191bad837aa2a237daeb427e07b9e7aa6ca94b1db03d54ee8f4fe8d0802cb14a6599005eb6326eefe5008d9098d40aa851" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "2eb6b1a58e7fe39ff915ac84c2f21a22432c4f0d260380a3f993310af048b11647f95d23adf8a746500833ee4e467fb52ea9f1039519fa58bcb0f1d0151558147b3c92b83730aba0e20eeeea2b75f3ff3ad79f2f8a46cbbadb114a52e32f018342aeeaf827e03ad6d583bbce" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "3ba7dcd16a98be1df6b904457709b906cbf8d39516ef107006c0bf363db79f91aaae033466624d30858e61c2c368599963e49f22446e4473aa0df06e9c734e183a941510d540536377072334910e9cef56bc66c12df310ecd4b9dc14207439c1da0ac08bdd9be9f2c840df207e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "a34a7926324ea96867dac6f0dba51d753268e497b1c4f272918c7eb0e34120be65b7b5ba044d583141ec3ea16fcedae6197116b16562fb0706a89dc8efd3ba173ccd0fd7d84d480e0a3dda3b580c326aa1caca623879b0fb91e7d173998889da704eda6495023b5ad4c9ad406298" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "5ef97d80b90d5c716322d9ba645a0e1b7a403968258a7d43d310320f60f96235f50e9f22cac0ad239636521fa0607d2f471051b505b371d88778c46fe6787d47a91a5bec4e3900fe6ed22918226fc9fbb3f70ee733c369420612b76b5f55988d757c891d7005d17ee55783fe506202" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "140d2c08dae0553f6a49585fd5c217796279152b2e100ebde6812d6e5f6b862b2a3a484aed4d6226197e511be2d7f05f55a916e32534ddcb81bdcf499c3f44f526eb515cc3b6fa4c4039ad251253241f541558bba7413ca29318a414179048a054104e433c674ca2d4b3a4c181878727" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "29fdfc1e859b001ee104d107216b5299a792d26b2418e823e0381fa390380d654e4a0a0720ba5ff59b2ff22d8c4e013284f980911dcfec7f0dca2f89867f311ced1ac8a14d669ef1114504a5b7626f67b22ecd86469800f1575543b72ab1d4c5c10ee08f06159a4a3e1ae09937f12aa173" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "52dfb643832a598a10786a430fc484d6370a05356ee61c80a101dbbcfac75847fba78e27e537cc4eb918eb5ab40b968d0fb23506fee2ad37e12fb7534fb55a9e50902b69ceb78d51db449cbe2d1fc0a8c0022d8a82e2182b0a059035e5f6c4f4cc90278518e178becfbea814f317f9e7c051" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "d32f69c6a8ee00ca83b82eaf82e312fbb00d9b2f6202412a1ffc6890b4509bbbeda4c4a90e8f7bca37e7fd82bd23307e2342d27aa10039a83da55e84ce273822740510e4ec239d73c52b0cbc245ad523af961994f19db225212bf4cc160f68a84760233952a8e09f2c963be9bb1d71ca4bb265" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "d1e603a46aa49ee1a9ded63918f80feca5fc22fb45f659fd837ff79be5ad7faf0bbd9c4ba91628ee293b478a7e6a7bd433fa265c20e5941b9ea7edc906055ce9799cbb06d0b33ae7ed7f4b918cc082c3d4a1ac317a4acec175a73cc3eeb7cb97d96d24133a29c19375c57f3a4105519846dd14d4" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "b45ac88fac2e8d8f5a4a90930cd7523730733369af9e39bf1ffb833c01108952198301f4619f04b9c399fef04c214bad3358999967c474b67a7c06457a1d61f9466489ed5c0c64c6cdc83027386d6263491d18e81ae8d68ca4e396a71207adaaa60997d0dca867065e68852e6dba9669b62dc7672b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "d5f2893edd67f8a4b5245a616039ffe459d50e3d103ad4675102028f2c497ea69bf52fa62cd9e84f30ae2ea40449302932bbb0a5e426a054f166fdbe92c744314cc0a0aa58bbc3a8739f7e099961219ec208a8d01c1ae8a2a2b06534bf822aaa00ca96218e430f0389c69c7f3fd195e128c38d484ff6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "37279a76e79f33f8b52f29358841db9ec2e03cc86d09a335f5a35c0a31a1db3e9c4eb7b1d1b978332f47f8c3e5409d4e443e1d15342a316f442e3bfa151f6a0d216df2443d80cbcf12c101c51f2946d81161583218584640f4f9c10de3bb3f4772bd3a0f4a365f444777456b913592719818afb26472b6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "a46d252a0addf504ad2541e7d992cbed58a22ea5679980fb0df072d37540a77dd0a1448bdb7f172da7da19d6e4180a29356ecb2a8b5199b59a24e7028bb4521f3281313d2c00da9e1d284972ab6527066e9d508d68094c6aa03537226ef19c28d47f91dddebfcc796ec4221642ddf9de5b80b3b90c22d9e7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "060c18d8b57b5e6572dee194c69e265c2743a48d4185a802eaa8d4dbd4c66c9ff725c93667f1fb816418f18c5f9be55e38b7718a9250bc06284bd834c7bd6dfcd11a97c14779ac539629bcd6e15b5fca3466d14fe60d8671af0fb8b080218703bc1c21563b8f640fde0304a3f4aeb9ec0482f880b5be0daa74" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "8f2f42bc01acca20d36054ec81272da60580a9a5414697e0bdb4e44a4ab18b8e690c8056d32f6eaaf9ee08f3448f1f23b9844cf33fb4a93cba5e8157b00b2179d18b6aa7215ae4e9dc9ad52484ad4bfb3688fc80565ddb246dd6db8f0937e01b0d2f2e2a64ad87e03c2a4ad74af5ab97976379445b96404f1d71" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ccb9e524051cca0578aa1cb437116a01c400338f371f9e57525214ad5143b9c3416897eae8e584ce79347297071f67041f921cbc381c2be0b310b8004d039c7cc08cb8ff30ef83c3db413f3fb9c799e31cd930f64da1592ec980cc19830b2a448594cb12a61fc7a229e9c59fe1d66179772865894afd068f0942e5" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "3eb5dc42172022ab7d0bc465a3c725b2d82ee8d9844b396913ceb8a885323dbbbf9ef4ed549724cc96d451ea1d1d44a8175a75f2a7d44bb8bfc2c2dffed00db0328cfde52bf9171f4025770abbe59b3aefd8151c480bafa09f613955fd571e5d8c0d4936c670d182cf119c068d420ded12af694d63cd5aef2f4f6f71" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "20ea77e58e41337ad63f149ed962a8210b6efa3747fe9bea317c4b48f9641f7145b7906ed020a7ae7d2ee59435392edc32aee7eff978a661375af723fbd440dd84e4a152f2e6ef66f4ab1046b22c77ac52717de721dfe39aa8ba8cd5da27baca00cc1fffe12c52382f0ee83ad1418f4c6a122effaf7471e1e125d7e7ba" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "95c662b835171fa23f948c3c3ed27bab9b3c367bbfe267fe65f8037a35b50cd7fc6030bfce4000425ef646c34793f0762635ae70487a0216ef7428da622be895d1b6040423246511c2370d6876a5c5d2df8bbd48fb14f787b632ad2c1f5a927fdf36bc493c1c8606accfa52de33258669f7d2d73c9c81119591c8ea2b0ef" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f708a230675d83299cc43167a771602d52fa37cbc068ef9128ef60d186e5d98efb8c98798da619d2011bf4673214f4a4c82e4b11156f6292f6e676d5b84dc1b81e7cc811b0d37310ac58da1bfcb339f6ba689d80dd876b82d131e03f450c6c9f15c3a3b3d4db43c273c94ed1d1bd6d369c4d30256ff80ea626bda56a6b94ea" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f8417766ce86b275f2b7fec49da832ab9bf9cb6fdfe1b916979ae5b69176d7e0293f8d34cb55cf2b4264a8d671370cb595c419c1a3ce5b8afa642208481333522005fbe48cdc700e47b29254b79f685e1e91e7e34121784f53bd6a7d9fb6369571bba992c54316a54e309bbc2d488e9f4233d51d72a0dd8845772377f2c0feb9" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "3479e04efa2318afc441931a7d0134abc2f04227239fa5a6ae40f25189da1f1f313732026631969d3761aea0c478528b129808955be429136eeff003779dd0b8757e3b802bdff0f5f957e19278eabad72764aa74d469231e935f4c80040462ab56094e4a69a82346b3aeb075e73a8e30318e46fdaec0a42f17ccf5b592fb800613" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "03df0e061fa2ae63b42f94a1ba387661760deaab3ec8ffabcaff20eeed8d0717d8d09a0eafd9bde04e97b9501ac0c6f4255331f787d16054873f0673a3b42ce23b75a3b38c1ebcc04306d086c57a79d6095d8ce78e082a66c9efca7c2650c1046c6e0bbce0b2cba27c3824333e50e046e2a7703d3328ab3b82c9d6a51bc99b9516ff" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "76b488b801932932beefffdd8c19cf5b4632306e69e37e6a837e9a20c8e073bcadd5640549faa4972ebd7ee55cb2425b74cb041a52dd401b1a531beb6dfb23c4cfe74bc84f034156c8f55050ca93236eb73c4e2595d9fbf93dc49e1ec9a31705359732dda73f737ec4274e5c82626dc4ec929e5e2c7a2f5f5fb666181922bd8be575e3" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ff17f6ef13abc0426b03d309dc6e8eeb822300f7b87eff4f9c44140a424098fd2aef860e5646066d22f5e8ed1e82a459c9b9ad7b9d5978c29718e17bff4eeefd1a80ba48108b551e62cd8be919e29edea8fbd5a96dfc97d01058d226105cfcdec0fba5d70769039c77be10bd182bd67f431e4b48b3345f534f08a4beb49628515d3e0b67" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "95b9d7b5b88431445ec80df511d4d106db2da75a2ba201484f90699157e5954d31a19f34d8f11524c1dabd88b9c3adcdba0520b2bdc8485def670409d1cd3707ff5f3e9dffe1bca56a23f254bf24770e2e636755f215814c8e897a062fd84c9f3f3fd62d16c6672a2578db26f65851b2c9f50e0f42685733a12dd9828cee198eb7c835b066" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "010e2192db21f3d49f96ba542b9977588025d823fc941c1c02d982eae87fb58c200b70b88d41bbe8ab0b0e8d6e0f14f7da03fde25e10148887d698289d2f686fa1408501422e1250af6b63e8bb30aac23dcdec4bba9c517361dff6dff5e6c6d9adcf42e1606e451b0004de10d90f0aed30dd853a7143e9e3f9256a1e638793713013ebee79d5" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "02aaf6b569e8e5b703ff5f28ccb6b89bf879b7311ea7f1a25edd372db62de8e000219afc1ad67e7909cc2f7c714c6fc63ba341062cebf24780980899950afc35cef38086ee88991e3002ae17c07fd8a16a49a8a90fc5540be0956dff95390c3d37629949de99920d93096eb35cf0427f75a6561cf68326e129dbeffb8772bfdce245d320f922ae" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "70752b3f18713e2f533246a2a46e38a83cc36dfccec07c1030b5204cba4432700735a8cee538b078d281a2d0262110381c5815a112bb84404f55af91652bd17502dd75e4910e062943d8a736ae3eecdfdd8e3f83e0a5e2ddeeff0ccbdadaddc95391310fc657a59724f7e6560c37dc1d5bb5db40170190f04a274c864ade9687c0f6a2a48283177a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "01f3c1333b44077c518cc594d0fb90c37651fb7b2442e71fc0a5611097f1cf7bcfaf11c8e0ac1b1cab54afba15bb9332df6bc64d8032368e3f686c8324b0114e0979dad78a5ccd3fff88bbe89eef89c4be586ca092addef552ed33224e85d8c2f4fba85ac7735f34b6aa5ae5299154f861a9fb83046b0e8fca4db32c1343e02676f283975f43c086cf" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "509283ebc99ff8d87902fa00e2d2a6fa239e335fb840dbd0fdbab6ed2d95e8275402523f7ce9a2fabd4b6c9b533288fbe914bde84365a204711d0977a7d698f4614385984dd4c137e4820035dd6737da364edff1bb62283e87a8c7ae8637314fe9b5777ec4ec21276dafedb2ad5ee1aa0ac99e34a6c01c055c8a239fd28681607f65143082cd4553c529" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "c17e417e876db4e123c631f7136b8a85bfd6ce66a69180d0cd5ecfd6f037bb1c7bd7908d51f2c485bf9e92c0e1799ee5f6ab834ee481f5eb1a8020205adb4d0f90126d4e7c2c859c5a5f644bdfa9c649ff4f168e834de6f9769429732099d46d0af506ab86c6fd92175159bbc05c75db8e1fa867e6030d64250008d64c857c47caec3dc8b2ffb384d0193e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "950988fbe9d62a66f5f2c492bc8dc944a78eb3796ec37ba94b6a81a9d402ccad03cd8497fff74c5f4a03081c5fecec48574fecb21c1de261332c23108195d3f6a96ff8e433a1a30eda53dd5bb414973334f8cde5510ff759f7c17046cbb5acd8e8c4a6eecf2a9121ec3fc4b22c4daa72678194ce809024cd45c4ebb9ccdb6f854205cdb624f0787480d8034d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "552a212c403b473741da8e9c7b916d5e5e9bcc9949021ae1ca1ed46b7d4a98addbb604d9fff56175b7e0367db26c9635fa7813653dc8d610befdd09ec41e99b192a716106f4299eec8b940863e5a59cf26cdc2cd0c3017f9b4f215812bed15f69e77edf672178e13c55580982f01fcc2fa131ec3d736a55d56504c545f4be50fee83f1263e4d3f3c877cc6242c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "b00c4283dd3d9cd26e44bd97cede6c771cb14f2571b51cfdaae4309560ffd165da025a1bbd31096c3aa8286e2d6dcc3e681b8d01f2c5064ea26dfd0b5156b7a7f5d1e046c5bd1628f8fdae24b03bdf7cf7366900cc013a8cbed9d7f5937c914b08f8c27683b956e1279812d04288515333fc6aba3684dde2292951f0610649d90fe61606630fc6a4cd383649252c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f6e79457bb6d0884dd223be2cf5ae412a1ed425f1e4012f75951b096aea3b9f3581f9013bcae1aff2d3fc1e5c7e06f24af6d53c2c5c238b71c71cc670b05a7ee5204400026a5c4e5ddec3ad96771e49fae4b0f75ec58049ad9d972e5749a32d90f847f1ed2a1bab83db181e541cf5c8adb6b29ecc64dc25add491d408d3eb3ddcb013de7f5ffb6de9dd7ff300a5fc6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "fe1d71e1d5efa3f712d23216ee8ee9139e66bd648b83efc02cdb4d45a28cf36759ff190a84d14d9471477abefb5aea4111110336143dd80cf81e02f268120cc07d746538f968e9876bff8358d390f5b8e7eafa61ecd236cedaf276bd61865fdd3424988201dcdeda2e3e0c33c9e3b3670125dd1049106cc6df5695fb2dca443233ff440f265bbff055483bac1e859b83" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "4c80163562872a965dedd8725652906156ada6e9d999027d96f49289edb92f9ef043e9d7c3377e091b27f85275499454af32317535997fb4aaeaf93565ad481ff7d45d2abddd4df4b60f71a6923ec30496c6ae534dc5427107ab4c5e656a322c7ab058d4c13ec0ebafa76576560697ac98f84aa4a554f98ec87134c0d7dca9184cf70412a324aac91823c0aca02537d197" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "fdd58c5ffe88665beb7073c8f4c22472f4bc9390cdd27a42622ca55978b000ab7579f795d4de0dfcaf521b8268980ef1d20277b07567985c0fd5030784ad6c32541ac24e99ab706105a2255fc32935c0fce6fdad9bb224d94ae4eae2a3ff08836618a3adf193630647bce1952b69da4de360f59da303519278bfd39b733cf66820a5e9e971b702f45998b69a0889f4bec8ec" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ff38b15aba3794e2c81d88003e045ac6cbfc9f4833cdf896cefd8ac0c88674727ad9a9fcb9ef36574deea480e6f6e8691c8390ad73b8ea0eb3665c914b0d886546948e67d7987eea248b5feb52346ffdd965d5c835144c3bc63daf325e74b11267e32e58a914ae4521a668839d9445fececa49c5fba41f9e171698bbc7c6c97fa163a377a96456958d6e1d74f91ada56a30df8" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f048c19328d60b4e59ed76940415b2c84c23883198bba5699efb0a1774ad5da6d15390c7b55d77d66f37448fe08107f42a5336408d5322f4b630e3275865fc66dccab39f6e13fabc133e5a441fe352d81c7cd9a25f145a6e2e2417d3b0bbc79eafcd7ad688c02011fd268dd44ac3f4f87b37a84a46fd9e9975962fba92c9a3486deb0c45f6a2e044df4bb79f0feeea432c5008b0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "1b3e5fe6f113cce28a6f8d6f7809d3cec398cabffe9ff2ff10a7fec29a4ee4b54186063fd5307a2be393c9ecd75a37620bdb94c9c18da69b658579676ec90351d10dc33a7cb3b75798b1234f9f684d4a73a0fab2df3d5d6fdb1c1b1514d0935c1f2dd21486f91c2595b2f8f8a500ff443b9305270fb6f3da7961d9316d4ed6a135a31c4a3611d40e6585bbb34f498cd5b9a5d92676" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "740db337baa12b16897f17a85fa5685acc85e48338867f8ac9c0198dd650f5dfa7c17725c1262c72207e365c8aa45ffaab6470a0e5afefbfc3bb702a9766064f28cc8b796878dfdd3ca9d0216c14941438fc541fb5be0a13d29a996c5c985db4f630df067a5626db5dcd8df3a2bff17dc446e46e4079b8815da4318cb228c7722684e2a795a0ca56f500ea51951a6a385385d886f678" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "1465f2d578d167faa017fe8f763ce3cc8dc1e8371d774ed2a8803f12585296ee71a1f2253dd16b717a81f91f0f3641018a0111182b4e65d884b0a3d0292631ad807cdccc88bdeecb476e76f72b5246a630aff6e2401fa9570f85acb73ccb4e19ef04a932a03d7b7985dbe1e5bb410df517fe362321469e6f8b0e0cef6c31d7aa8ec06aa220620d66cc0e133fdee963589b12320fc9678e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "80c051952fa6f3ef6af0f1759ec3e83c8eb91abee1de360bfa09e74b05af2475a0dbf8f9135aa25892919bbe0515898cfb6f88abc9e1891f2b2180bb97370f578973d55c13c35edb22ed80647c2a7e2884d1ccb2dc2f92d7b6ec5843ade13a608a31190ce965bde97161c4d4af1d91ca9962053f9aa51865bdf04fc23fa35a6fc3c8e888941263a26ed66c2dd0b29b2325dfbd1227c5091c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "9c1e2a1aed6406052eed12b4495365f2f80e9c9645473f3549b607f20910bcd16dc3a4b173ac8d128129cdb7c76ebbc8e9a2a1ba0d822c66b367e790a69ac71f0a60ed4bff0e979148e3f3ee6607c76dbc572ee5ff17c27e4b52adebb4bedddff517f591a1977299c7cb01106f1453b098d29848ba3751c816215bb0d090c50f9e445b41b2c49d4eec83b92ce6c269ce835fd279e7cbbb5e47" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "466abda8944d0329d2975c0f2e2afc901f117887af301881f63b714f49a2f692fa63a8871fc0b301fe8573dc9b2689880cd8969e5072c57671e0633b041481dab25e65c9de404af033a11a8070c8ab70ca6d465318501afdd9940c7efbe1bb6d49581c222fad251dba4ee0a98efe22a3c4f74da05844523b30bbad6b080ac8df70a02da80bc9d477dfb869adb211e209a316d5dd1fd89a6b8f8e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "0e89a873e07799ba9372fc95d483193bd91a1ee6cc186374b51c8e4d1f40dd3d30e08f7feecfffbea5395d480ee588a294b96304b04f1ee7bbf6200cc8876395d1db3ac813e1019bb68d27204e514fe4a61ad2cbd1782dca0e38b5538c5390bca626c5895b745cfca5dac636fd4f37fed9014ab46ae1156c7789bbcbb956ff7ee5ce9effa560731d26783dc6ae8bddd53a5d28133614d0ddeddd9c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "fdde2b80bc7a577ef0a6c03e59512bd5b62c265d860b75416ef0ce374d544cbb4e3a5dbd31e3b43e82975090c28bc77d1bdec907aeceb5d1c8b71375b6d631b84a46153f5f1d195bfcb2af6f597a9cdc83782c5bbbb58c5188a87ebf375eee5212fa52523820a83106e8ecd52bedd60d95cd646159774389c07e1adcaa6b6f649408f33399ec6e507d61659696b3dd249996892d5986b654d94ff337" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f5d7d66929afcdff04de30e83f248e69e89604daea782e1d82d8032e91a95c1d6fb2f5578f79b51be4397e4cd7cbc608ce143fdddbc6fb6c43ffdd394a7df0124353b919aeeac025f3eb11ff246c3b9657c1a947fc534ce48e18feffada8797037c6bc7e2d9a9e2e019fe65627b3feb28e446473e3bd413047a2587f0be6a103403cb3c33fdc212dca14d8e386aa511c22308e632f5f9528dbabaf2deb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "332990a8dba55f977bc814436cf386ebbf10cb487a5f6ce83e13741bac670c6810284fbbe4e303547ef411e964fae82854e8c13cf56979b89ecfedd337aad78260060122d13dfbbf8497acb2066ed89e30a1d5c11008bd4d145b5ec353956310536304d8b8bba0793baec6d8f3ff49718a56e6694f8122078265cf5731d9ba61292c1219a1affb3679576d4998290aba3684a205c3469d40761a5c4e96b2" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "efbdff285027610f03182009c89b953f19721cfcdb8accd74bab6ec4bdf3f555ab902cb0dd91284269d140638aaabd211748aa4da3b18cddc653b57e461b9ad8491807c535c08fe97d89eb587c6af19ca152e72479626ab764e8b62da89fefc8354c75a44851f985746d78715a5a92798dac1a4222be27897b3f0aa63d596aa7378545f49b259aa8518c3def8a2ec8f7aa956c43668c8717052035a7c36b47" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "0eea9bb83bdc324fd21b03669aa922fbebc448e7d25e210294c07862cfa6e061731dfb67b4810633f4dbe2130d90fa1c65843af436e74219d213c4458dcac1c48ec4541fc6e3b7918ab2bc621aedda53658050900c3865ca57cd5dfa1d28576827401956d2dd8b861fa90ab11bb0b544ded9bd3d62e3278ed484e17db8f2d5dc5ea4d19a0e15134ba6986714c2b22c59c2f0e517b74eb92ce40d2f5b89e6d79f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "25da9f90d2d3f81b420ea5b03be69df8ccf05f91cc46d9ace62c7f56ead9de4af576fbeee747b906aad69e59104523fe03e1a0a4d5d902352df18d18dc8225855c46fefeec9bd09c508c916995ed4161ee633f6e6291cb16e8cac7edcce213417d34a2c1edea84a0e613278b1e853e25fb4d66ff4c7ee4584e7f9b681c319c874d43502534e8c16a57b1ae7cc0723783807738a55b661e617ee285bdb8b845607f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "a76b6f81372df09322098868d469fb3fb9beafc5edb32c674974ca7032966aaca5b5c9bffef87bfe626bd8e33d1c5f054f7d5acd3b91ff95324d1ae39eb905b9f2694fe5cb03486cee86d2f661a751b0e6c716a61d1d405494c2d4e32bf803803dc02dba2c06eecf6f97fb1f6c5fd10cfc4215c06d627c46b6a16da0854e4c7c873d50aa1bd396b35961b5fa31ac962575230c07c369f8fbc1ff2256b47383a3df2a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f9db613812f2259972d91b1598ffb166031b339913925ee385f03b3b35dc4b2f1ae78a3c3d99c6ff6a07be129ce1f4b8d994d24988d7fbd31f20535d36ab6bd0592cfb4f8c1ed9244c7fa8a3c46e91272a1a40c6cfcf261c5658476c59793bf1a3775086e41a0492f88a31e2d9d1ce75cf1c6b4b928b3545d838d1de6b61b735d921bcf72e4e0615e9ff969ef76b4b947026cb016e2660ba39b0c4c953369a52c210de" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "e601c7e75f80b10a2d15b06c521618ddc1836fe9b024458385c53cbfcedd79f3b4239598cd7b9f72c42dec0b29dda9d4fa842173558ed16c2c0969f7117157317b57266990855b9acbf510e76310ebe4b96c0de47d7f6b00bb88d06fad2c2f01610b9a686079f3ed84613ba477922502bc2305681cd8dd465e70e357534503b7cbc68070ad16d9c51de96ccf0aae1599299331c5655b801fd1dd48dddf6902d0e9579f0c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ee5ff4ca16d1bde59ffaf2d064eac9141c1d8f120ea2bda942b7956ba3effc5f1e725a3b40b0b9223a14d7a50df1681d14ca0e0eda7bb09c428fa3b2701f83a7a3e139485a118f6287d266dbc7fe68c87b35becabc7782537c79cb8165bdc40cc103d7b6d4b627fafa0e4113f92341ab90ceab594bfae20dadbfafd401684584598941f1ffb8e23dc8a04ecd15376cda6d849fe0dfd177538c62413622d172d9d46e05c450" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "1daca80db6ed9cb162ae24aae07c02f4126f07cd09ecee8e798fa1bc25c26c644333b63731b4ebc3f287f2318a820c32a3a55fc976576bc936f7384e2553d2891e3771ff24dd4c7f0256906460a8f12d30ed2b23583a0259cb00a9065a757d654d6e4603e7c7eb4a8426b527ae8a849d9350e9094b890367df3e8b23ad2df4d7dcce416bd8ea3badd037f53f7b07c02e5926515f196d62aeb9b8b14c863f067fc12c5dfc90db" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "27ff4e58a34ff1fcd66855d014ea17889a3cf0021a9fea3fabfd5b270ae770f40b5439e00c0d26bd9766f6fb0b4f23c5fcc195edf6d04bf708e5b0bced4f5c256e5ae47cc5651e51cd9fe9dc5d101439b9bc5cc24f76a8e8847c72686e2af1ce7098ad7bc104dad00c096a6d48b6453322e9cd6773fb91fb1eabd05dc5185a9aea07a2f64c6fea9897681b4428aaffe1fe5fd3e8ceb890b12169ec9d51eaabf0ca3d5ba415770d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "75e2fb56327983b04f640717be8cba6fef3655b4d8e5539587d6478356ec397efaed818b8425d052778eb30ef0dee656c52c2aeab079ed496ae4441a365f2130432c87ba757e25b4511656ad15e2eff84d342331fd2814d1f1d11af65d98a424c115ba183437c0d0aa55f5c44b8685028a47d89d0d36a0f20aed510c366ab338f074a941b404fb349caaec821e0850a627777cc8f5abce6b509290027a2a28ff1db62a5ed2f95fc6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "c6ae8b6a060917cd498aa7874ad44baff73efc89a023d9f3e9d12c03d0b7f5bcb5e24e1bc2ab2f2c67b9a9d36ff8beb51b5affd4a3510361001c80642955b22ea4bf28b81a5affe5ecdbabd8d17960a6af3825a4522fe76b3d720b5d06e66bff5379d7a8de1f5cc3e7bb75163a854d77d9b3949bf904b6c4e568682f0dab7f217f80da7303cfdc9a53c17b6b51d8ddff0ce49541e0c7d7b2eed82a9d6be4aec73274c30895f5f0f5fa" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "606c9a15a89cd66a00f26122e33ab0a08c4f73f073d843e0f6a4c1618271cfd64e52a055327deaaea8841bdd5b778ebbbd46fbc5f43362326208fdb0d0f93153c57072e2e84cecfe3b45accae7cf9dd1b3eaf9d8250d8174b3dade2256ecc8c3acc77f79d1bf9795a53c46c0f04196d8b492608a9f2a0f0b80294e2abe012dc01e60af94323c467f44c536bf375cddbb068c78432843703dd00544f4fff3eaa1a5a1467afaae7815f80d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "88b383cb266937c4259fc65b9005a8c190ee6cc4b7d3575900e6f3f091d0a2cefa26e601259ffb3fd03083270eb63db1ffb8b4515ec454d12f0944f8f9f6869eedc2c5f1689766a748d74e79ad83ff6a1639aefdec6109342dead31e9cead50bcc00c5b2206e8aaa47fdd01397b141880490174141a1e6e19268378c1b54a84aba60ca711fd72f7df88e120dfea2caa140085a0cf73342f3c588b7edfb5b5e5ccabd68a32364746d92d536" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "dc0b293f1ba02a326743509f41efdfeeac1efc45137ac03e397a3273a1f586a0190cfb4ea96d6c13ca692a4de6de905c8338c3e29a04cbae76272f568b9d795cea5d758106b9d9cff6f80ef650d6b7c428ea3946c3acc594907fe4227ed68faf31f2f6775f1be5139dc0b4d73ed6308fa226b9077561c9e4c7a4df68cc6b819b0f463a11b9a09682ba99752c4db7aea9beac1d9279f2c2675d42b551d27aa2c1c34125e32f2f6f45c35bca45" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "5d801a7413311e1d1b19b3c321542b22e2a4ccbe340545d272abede9223741d9835a0fc80cc9da97a13f8bb4110eb4ad71093efba165b1edad0da01da89d86726e0d8e42ae003b4b50297d233c87da08406f0e7fc58ba6da5ee5ba3d2d7142cbe6632734eb2e7b7863c15cc82198ee8f9a0ae0b7f93bdbda1ed269b3824d5d3c8e78513815b17a4c0cc8c9706b9c77423a309ae3fd98e1e05cdbe9e2577834fd71f964301b10b66c316a2d8f2c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "2fd32a2bc15a9e96a100624404fd0a4e54ba9f8c0543d8ccf7c5c2e35f5e8c3c11dfd497320aa903900a4ca55a2b323b3ac4a7cfcd01bf0b448db8829072bee6b77c3d7bec2e1d8b414d907288d4a804d2379546ef2e2dc628269589164b13fceb32dba6fd5d48a956ce0b5c3eb28d894a95af58bf52f0d6d6cbe51317152744b4ccfc918ed17fa6856478d580b389016b772e1d02e57d2217a204e25361d91d4845a3fa20fefe2c5004f1f89ff7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f537b437662759bef8bd64368536b9c64fffbddc5e2cbdad465c3966b7f2c4bc5b96767ef40a1c144a4f1cd49edc4cc5b57e7eb30d9b90108f6fd3c0dc8a8808b9e0bd13aa3d661c4863637c5e4ba286553694a60bef18801299ae349df53a355051dcc46a7d003c4aa613808f430e9db8ca7dfe0b3f0a4c5ab6eb306aeb53e11a01f910064fbe6ca78b2a94fac34a2602f73de3f275953e13ff5c6bb5c39b82321ead17ec0f8ecc479e6afbc926e1" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "1dd9fb7d5b5d5074971e69300720014deba6fbdb942bd29704cdfcd40fa5281d2a1b9f5b776183e03ff99c29587f10e8d325cb49c5c93e94f5132741b92c4086eec1374dea5c1e772cbb230c7b31f3e962eb572be810076bdb926b63732522cdf815c3ab99bbc164a1036aab103cac7b823dd21a911aec9bc794028f07b7f839bae0e68211286441f1c8d3a35b281fd321312577bbda04f643ecb2a74ec4527bb5148dbccbeba749f5ea19b6072366ba" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "5bd63737449de2d20ca63943953338ecf4cdd6cd0a726241adb04376385a809cc6ba0f3482a310746fbc2cd5eb214f03a14cdc548777fb0d048d659cd75a962e490c4fe47affc2430a34b10275e4c76752a115aae3a24d4fb4fad89ce4d79d65de10292f3490bfdaeabfae08ed51bda6ec8230e66cb07ddbeec26e3ef68dd71c852900659fcf0c963f4574ffe4626a33db9abf0873dde68b21138498b81e8cc44d354be4073615889a7ddff633b5447d38" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "a683ec8250506571f9c640fb1837e1ebb06f123e745f95e521e4ea7a0b2b08a514bbe5bdfd316903d1d6a05f5a143d94dab61d8a3a146ab40b2d6b72df2f0e945875a8aa7051ed115975f6f1567cfcbf04c5e11e3a7027b8e179ba00739181ba10b028e3df7259d0712f4a6cef96469ff737865b85fee2c2db02a6423e32505381e18a1e0b4ce3c7998b8d6b1b5e09c3a280b85486d0984c9e193b0ad2043c2bc4ad04f5b00a73956715937eebf6b3e27afc" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "4df9d160b8e81c42930c48956fcb46b20b6656ee30e5a51dd6317876dc33e0160d31280fc185e58479f994991d575a917073b4439919c9ac49b6a7c3f985211d084c82c9d5c5b9a2d29c5699a22e79de3958d7b0e856b9aa97493cd4563aaa04fa3977a9bb89e0bc06a82296bdc76d20c8d393770176d648712454305fdfcf4e117d05acb5a5b006a9f8d0dc66dca708c4e4103ca825d2331750685c44ce3d9b3e753455580f4d6ac4533edeeb02cebec7cc84" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "67bb59c3ef5ee8bc79b89a673e331e581215076cc36b68f517ca0a74f74efafe9dcc240e6d8ca4b21019c27d6c9289f4419b4f218eeb39eb741c5ebebfe0ed2f6faeec5e8c477acf71907990e8e288f4d4049111779b0635c7bbec16b76493f1c22f645745fdac2b383679fee573e4f47af45ee08d84f63a5ace4ee1c06fa41e2e6e14b7bc392e38426813087a3a461efc62ed1941dc8f1728a2bdc04fde72a0b786558783c84abd4bd100e4926979a0a5e707b1" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "d341147169d2937ff2373bd0a9aefa77968ec8f0d993c6f9881eb174a1911e05cdc45993cb86d149a754bbe321ae38363f9518c50dd3faf087ffeeeb6a058b226ccab7858c00ba6de0e8f4d034b1d27508da5cc473f3a413189ee6fd912d7750486912944d4dc34405ce5ccc3885fb0aabcb922bcfa9081d0ab84c288022bd501235a835eb2e1124ed1d48fd4f8682da8e7919321031326502273375625c4e3a7282b9f53452195e53c6b4b57cd5c66f621bed1814" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "27e7872a54dfff359ea7f0fca256983f7600236e716e111be15a1fe72eb66923ea60038ca2953b0286447dfe4fe853ca13c4d1ddc7a578f1fc5fc8598b05809ad0c64a4363c0228f8d15e28280837a16a5c4dadab681e28968ae17934639fbc124bc59212138e494eecad48f6546c38366f1b7b2a0f56f579f41fb3aef75dc5a0958b25deaa50cb7fd1c69816aa9a51874a98e57911a33daf773c6e6166cecfeec7a0cf54df01ab4b931984f54424e92e08cd92d5e43" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "13dcc9c2783b3fbf6711d02505b924e72ec6736131159017b966dda90986b97522bf52fd15fc0560ecb91e2175322334aaaa0097e1f3777c0be6d5d3de18ed6fa3444133486068a777443a8d0fa212ca46994944555c87ad1fb3a367db711c7ebd8f7a7a6dbb3a0207de85851d1b0ad2f4149bdd5a5ba0e1a81ff742df95edee850c0de20e90dd01753137cb8f2c64e5e4638ceb893a3879ae2c049aa5bce44d56bf3f325b6c5029b2b8e1b2da8de7d4e48ca7d8f6fbdc" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "9ca875115b109eab538d4ec7023600ad953cacdb49b5abe263e68b48eafac89a15e803e838d048d9625972f271cc8f36344bed7bab69abf0bf05979a4cfff273b82f9961626509765fcb4b4e7fa48212bcb3ab2b1f2dd5e2af768cba6300a813514dd13e4d269e3d36548af0cacdb18bb2439ec9459f6d847d39f5598304ec46a26d75de1f9f0c2a88db915bd26e45e1f1e68c5b5b50d1890e97a3803c36755f026863d14176b8b57f42e91d3ff37787f9b38e333e9f0433" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ec006ac11e6d62b6d9b32ebe2e18c002353a9ffd5dfbc5161ab887770ddd9b8c0e19e5321e5bc105add22e473050b71f0399327c7eba1ef809f8667c1f4e2c7172e10e753705e9a083f5bce88d77521225ecd9e89f1e1caed367fb0275dc28f620fbd67e6b176c9ae5d2659e6ec662116c9f2bbca3a93043233a4861e0688db6dc1800f752c5d58aa5033c250c891d9126e534ed921a9026eb333333fa8292059b8b446f336ca6a0cb4c7946b6aea3831653122f154a4ea1d7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "23deadc94481ce28188f3a0ca3e85431964cb31b60fabf381e6bd45ef0332bd4dde774b0281d317dc2e7d0c298fcf8625fa734126968df8b68ef8a35c325d84ba4fc53936ff3ffdd8838d2a8cabf8a9cac54aa444ed9875944e55994a22f7fa8538b1e983b57d9215fac5c0052029644044e790ce2f5044655608c1d7ad3bb862203ba3aba3b526606f273d342ed5721648e3f600942d3f7546f679161436389d879dd8094e1bd1b1e12cde15cd3cda4c30a40835665e4e5cf94" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "94701e06340114f9cf715a1fb659988d33db59e87bc4844b1500448960af757b5282f6d52967a6ae11aa4ecfc6818c962b084c811a57724f5d401191567f24ce917e4f8c3963474fdc9d2c8613c16f62446448b6da6eeae54d672825ed7606a90e4611d0e318ff00566862c955b636b5e81fec3362e8672ad2a6d222a515cf410482836deba092a51a4d464dfbbab35c50a33437ac16a88256e9e23ddd3c827cc58d3e5000ee90b12e4c5175c5733662d4848ae0d406c2f0a4f498" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "735b0758d5a331b2304f01081172eb95ae4115de651b1a6693c5b9543de33df25d9f421dbaeca033fc8bff57313b482778005aa9fdcbca65c643da2f3320e34197868eec3848ff3c70d7ac7d910fc332e9a359f892ae01641be253013b554a0d3f249b3586b1857e5a0f9482ebd91432a852b221f4287a6e81ed24e8064645d5b28ab9a13b26cc1420ce73dbc47b31acf8a871601022ce23bc443b1222ce9a037a2fe5226295feb4efd4fd671338f459ae146032697cf82fc55c8fbf" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "c48d94f14549352790079fee69e3e72ebaa380510e3581a0824066413e7044a36ad08affbf9b52b21963d2f8e092ff0ac1c973c423ade3ece5d3bca852b894675e8173290529226939c24109f50b8b0d5c9f762ff10388833d99bea99c5ef3ebb2a9d19d2231e67ca6c9056d8834730605897426cd069cbeb6a46b9f5332be73ab45c03fcc35c2d91f22bf3861b2b2549f9ec8798aeff83ceaf707325c77e7389b388de8dab7c7c63a4110ec156c5145e42203c4a8e3d071a7cb83b4cd" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "553e9e0de274167ecdd7b5fc85f9c0e665be7c22c93ddc6ec840ce171cf5d1d1a476743eb7ea0c9492eac5a4c9837c62a91dd1a6ea9e6fff1f1470b22cc62359474a6ba0b0334b2739528454470f4e14b9c4eeb6fd2cdd7e7c6f97668eebd1000bef4388015630a8332de7b17c2004060ecb11e58029b3f9575040a5dd4e294e7c78e4fc99e4390c56534a4e933d9a45460f62ffaaba25da293f7765cd7a4ce78c28a85013b893a0099c1c128b01ee66a76f051dc1409bf4176e5afec90e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "dea8f97c66a3e375d0a3412105ed4f0784f3973ec8c57b4f553d3da40fd4cfd39761de563ec96a9178804641f7ebbee48caf9dec17a14bc8246618b22e683c0090259e3db19dc5b6175710df80cdc735a92a990a3cfb166461ae713adda7d9fa3c4cf9f409b1467f3cf85d2141ef3f119d1c53f23c0380b1ebd728d7e932c535965bca41a414b6ea5bf0f9a381e098d282a554a25ce41980d7c7be75ff5ce4b1e54cc61e683f1dd817b8e2c1a430d7f895e5e7af13912cc110f0bbb95372fb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "9dfda2e2f732867e60ed2b5fa99ab88eb82dc7a54334d02031258beef75fa4bd6962a1083b9c29e4eeb3e5ab8065f3e2fc732675b8d7705c16cfb4ef7305eb58120f1af5ddc55872a2cbde3a48661a0598f48f63e2e9aadc603545e2b6001748e3af9e86e1830af7b84ffd3e8f16679213d37cac91f07af0af02b37f5ed946ef5c955b60d488acc6ae736b10459ca7dabeacd7dabcfd656511ac913174f6d99327be59befe3e463a49afbb5235f0ce2840588c6edfbaaba00a4211c0764dd638" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ddcd23e8b9dc8889b8599c721e7f8ecc2cbdca03e5a8fd5105f7f2941daec4e2906c654210bdd478374ddee43ee749a920ee91872e057a1157d384dcd111266221b3c79774476b4862fe450704ff2c5353e9a936cac87c96515c28ed4c830335a55d084cb5873c5fd2dd907f3266d8eb7bf13b6dd7cd4966982a0949efd8e428dae13daee549e01cc3c226211d6307823f742c5ef2155601a4644c46eddd603d4abd959c6d242e427768df3b1e22d87971df58a1564b38311a897c85b497a72556" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "39016647acfbc63fe55a74598bc1956eaf4e0cb49d532c5d8323fc6a3f15a0231597f06eafd74ad245e672bf6b21e4da503cb5bf9d15e9038ef354b38807564d91f38b4258378ccd9b9420a1562d7136196822a1291c913d83c4cd99fd8d420990c72cdc47607124de21da8d9c7f472fdcc780379f186a04da93cd87628abf323c8dadcd7fb8fbade37d7d2b5c9f9fc524ff77494c98f42f2158a6f68c906105ca9e8bb2df463863cfc1e9008d8344f55c4e3203dde6699b59812d49ce1279fa1c86" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "02cff7567067cbca5911664c6bd7daaf484181edd2a771d0b64566c3ab08d382e83932cdd7b4dbf86c9cdd1a4c353a511e68afb6746a507a9cd385c198246f4543d606c6149a5384e4ff54c1b90d663dc7a4b91aeac3cf716db7ca6f9a1914e3a33efe82e7ccc4215999c0b012782402db4726db1d7d1c73571d45739aa6fcb5a20eeb54a84d5f99902a8d356cbf95f34c9c28c8f2badfbc08c69233514493c0c04963268c88bc54039ab2999c7b06cba405936dfc43b48cb53f62e18e7ff8ff3f6eb9" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "5764812ae6ab9491d8d295a0299228ec7146148ff373241a510faee7db7080706a8dada87938bf726c754e416c8c63c0ac617266a0a4863c2582412bf0f53b827e9a3465949a03dc2db3cb10b8c75e45cb9bf65410a0f6e6410b7f71f3a7e229e647cbbd5a54904bb96f8358adea1aaa0e845ac2838f6dd16936baa15a7c755af8029ef50aed3066d375d3265eaaa38822d11b173f4a1de39461d17d1629c8df7334d8da1b6401daaf7f34b2b48d6556ae99cd29ed1073926bcda867421832a4c36c7095" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "4df3043cf0f90462b37d9106e67366d112e4938c4f06abae97869531af89e9feebce0812dffe71a226de5dc36be652e26ef6a4be47d9b2db5cdd43809a565e4fc0988bfe82037c505dd276b757b785203249fd083fb474a25acccc9f38dc5164ff9097e05989aa6e280739a755231f93670e7226e22046914c155bf33d135b3f736ccca84cc47ae643215a054b54b7e13ffcd7ad73cced9279dc3210b80700fcc757acfb64c68e0bc4da05aac2b6a99d5582e79b303c88a7ac4dd8ed4289516bba0e243527" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "bf041a11622715426c3a755c637d5f478dd7da949e50f05377bf333f1c62c671ebdbf9467d37b780c25f7af9d453fc67fafb2f065a3f9f15d4c3561eeaa73fa6c813bf96dcf02430a2e6b65da8d174d2558110dc1208bdcb7898e2670894c0b9e2c894da3b130f57a90ec8ea1bffd27a37b4da4645c546b2b141db4e2c919154dac00e78dd3eb6e4445974e3bb07905982da35e4069ee8f8c5acd0efcfa5c981b4fd5d42da83c633e3e35ebdc959bd14c8bacb52212b4334f94aa64d2ee183861db35d2d8a94" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "a170ceda0613adc9c3a1e427f07beacf3b16ed69fb42b6bc09a38d803f632ad2929dba215b85683b74e2feb1d18fe17d0ea0db84d1be4e2e73476917a2a4cff51d6eca7c5e82232afde00dd2286a4c20eb09800b4d5d80e7ea35b6965b9792d99e399abda8cf32174ae2b7414b9bdb9d63e148f7357635a7310b130c939593cd3479164724011966c4232142df9966f09422f34f20b30af4b640a2c6d3dd985fe0ba3dfa9083cbb9b8dfe540ff9f6c608d18481213040768ef33300d773f9890c724ead320a1e7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "929477e9c2d0bbad3429a0e0de776695255013108261dc6404cb09828770e274d8bb650a50e490dfe917fc2047b0f8ee72e105927d9fa70523c727778cbf6ae876d641ad562938c870d12f2e047bb78920739dba0c3f8ce1fb77589623a5f1625f5d6ab81940c7dfc3dc3a641d82b2813629bab8282999317d6b93842334f123fb4693a9c2c9d8ba9bfc746642dfbd045cd2021b272eab7358aa954d453da53fc5392dfa7eb881f6f53809b692d27f3366595ff403289efcc691e118b4744a1147071d8909bef1e8" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "3e98bb14fff5bdf7db38a3960dc55ca7d02333daed8712cca13dd5bffd114636559279db72554cc0a0ee1f7e15557d77cab0f2f1131f94fe698db81be38300a856a5eca85e5cf915fb7b6f38ccd2f27350e62cc30ce10ffe835118be3d435d2342ed3d06199b7e20c8e34d68902f0ab8745bd8b7d5b863d525c1f5906d2dca598db8a0f1e67736182cac15677579c58b8c670cae1be3e3c882153b2aa2988933e579ec2d6dbb00c671da64443dfc027dee6dfc3233c99758304570a982bf9b2eb59ccd70d0b54c4b54" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "aa12c7fa50ffdc2811c1872e4bee15f43e6909212385c872eb489f7e06dc1787043f56126f8373bdfa4b3f61405c73dd4dfd3f40aa5cd207e8520849c26f67716a46c0989a99efff42f24e0736e327af8e607c401a1bac77341e9a78c91e35d55b2457bdd5317a405a1fcf7a2a23de68ef92b65819e8aa3807c545361dfc9fe89125123492da958dc313cb5d03cb4b192c54ac6b27fcbc498652f5ed36b587bb74942b3ad453a8d79e5ddc06ebf806dad5046b73251064582ef5777dc530f8701701761884783fdf197f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "83e615cf6e17a29e63945710b548a6d9935850eec69830841e26cb6071e908bf72c87cf079ffb34c5eb1a390def72d004a9488224a18e189aa1092a0f1135712834d257a53dc1d0e2c6417d8f472ff13b181910f4c93a307420d44beec8875d5219a3160b8e921434ddf3f71d68db1c1d5c39d68edb7a604792f8b4e31ecda7895c99fc7031a5b98a22009c1da005ac8fd2da0b5d742743f5712d12fd76d11a18e487776ce21ca0d6e5ab9ca6d8c394c321b91c14e291399a642721361811a73b7392e8603a3004e7060bf" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ae1a8f7bfe4b1a0fa94708921dadb2c20b938239d7b9a2c7c598528f20f49764d322ebe85a5b2ea15563cf2f2304baf55d6607c52e2e1160859dcb7af6d7856899eada0e9128a180d3de6fed9334ba52b80c5c362d5591a0ec30f86d37a399927eb1c53076a12d26775522c511c83eb5b7abc2a00bd2dfd5627a8febba53d85f9b74c4b7f0c862ddb0d9298899b646b774d6cc23e4e23ab47174fccd34499253996d5e0917210e2f6daa1685f89f2f1fdfd5509ebc38191d539ecfb54ff0f5bbe6ef36ea35d425af6462f518" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "1d033e06be253ab800c8176d3a9650ab2a5bcaa03e11ea95fb9ab3834b41eb0d1b2bcecfe219364c3104ef65a8d692bd77c798548b7d9a8faf7f5172db24ec7c93006d6e9839368291b8277a82c034a3731f1b2e298d6e0282ec8a7902e4f844d132f1d261d171375c646065e201849f2df73e3748d853a3122c2206aac92fea448500c5418ecfb3d80e0e6c0d51f85831ce74f6c659cc291f5348a1ef8b949f1b2a753633e382f40c1bd1b2f44748ea61127b6f568255ae25e1da9f52c8c53cd62cd482788ae430388a92694c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "104bc838b16a641749dcf73c57b207ea3bcc84381170e4ca362065a3d492e892b426a1f4fd82f69461d1ce1f3aaf8fc291ea30d6667e7e1aea4c44f7d52a5fa6d34709e6658483260ff5da76bfb74e7d194ad40dcac00daf0e45e74db4bc2248100a8b256b257278c3c98f1f2e3a80cdb812352aaf4155b3a4033999fb9fe7f506994fcf3a8db31e9e5ca8ef8c2e9c6326ca5b0803724ba641950eca877fe6ed6afc2e014651c56d0e6a61eaff7c5ed0b861d4bebe42904c0a568c26aa8abb2e97da2bfb40f14eafb6bf16cd208f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "5b92e4a175437d0a53eb10de2c56401720b11715a034459ebf506c3fd6534b5e817a0f09deac4bcfd353301d8d031b1331582ac09189b48e6ccea444655866c4bbd123d45ebabb774f877cf12d33b84cfca4a6a94f3f98869fcf2bbb6cc1b964c2438c2f348bcdf9001dce60a4706d20c169a040baa61cbeb0b8e58d505e6e3739ab03e110ae7efdf91347474033defbd1e86af322ec6456d3394699ca7ca6a29a70d9b10a38fe666eab2858bfe12dacb31568549c826c15af5b6fddf779954351be1872f04e53db7b3b5fbf61fd18" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "401cc7bd9f8227efaed70dad83fc8db3bd38efc166f0f11ab142c565c68ba9db680423a3d698b6f3476ef440051fd20b93f6a2ed045825567df5a65e3f62e4442ec396ad260a16a13a1dee46c7e8d88bdd7edf223ab76a9a787c1f4fe9925c051a4ca0e77a0e78baa29f36d193c862fd3a60653f544ea9e3f75f2f553891be8c1fb882f6a6aad118f576f3c2793efc67221b37a45ab6137434f6228cb002fc137b91fb8572c757f00736879453d64a8a868c131810ffdad9e9d028d132157ecb1da675d54047d19b27d3258c9b1bca0a" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "c20cf0354982ca6a19d9a4dbf78f810934db2373941a12c263adefa61a5f385c859bc47028829c531dc25ccc0004c7510e707175a102ec3c4b4c933e3f52033e67476ff5f864c446c042a21e6037f7798363d20267891b965879fde80af6b59d77862e3a229af01b7ac78b578e94bd9f9b073c38a627c1864df0083aabb17024bdab6c3c0f0f73d31d59480523a2f23b78baa0385c15f290114305d7f98786b7dbc17a8c2aad97448e8ea389e68ef71091a6a9735ac12ca5497b9171da11a93c28d3273f58b74e2e46279d3ce9d0b20d19" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "e2365c2754073b511f16a1881ff8a537541ca7362ae7b84223d3c7d1d49d03a37d6d05dd2b819af9705c015dacc9dda83474eb14b7d5fce6e8a8f8c58e870149338d320e5ae476da6749af45e65ffed550d225a39dc74ffd93ba7da476985d6f44e90fc8e82454496260458431804d802fe804d825f611772f9710667377adfb1a11e4275bcecb42175c515f6a9439a359824f82cc9d480954364e6693099a821ace362e6c7ecbe68be8823bb5b49b4f23ad81b64139e3b63d9d4d298a842f013ef0d91ce7915ee8f816c70ba2aa3994216f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "9c43944676fe859327096f82049cf69e48b98715878400fdf2805e0d5ee642e6cc9c43739f418b701348a033c5cb96bf8702fcd2fac9be58262a843c1e4155ed8a1724b6ebf7cce659d88a95a0c54deb2d7d9574a45219b6419ee173d1d8fad3ace47c962b349abe1048565df85bbd0eb9b11698258c23598023a00fdd26573e41951452027125c6e894a97736ecd63fd15b29a55d8dd9dab7e2e18f541a2e341890a61b7c896e7dc67aa82f3479dacd4a8ec7558d40c34d9ae4060e13718d676c2450258d83de8a86e012813693098c165b4e" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "1c707c29582d98a0e99639211102f3f041660ca03ad0939fe3855b8c1b22d6a9b8673c93e3eabc0ab231509b2b0d73c76a290a363943d12d2ff0ea30c6dd54eda753767effe04cabb4c3966388fa4c83a1906a0f48519a5fba9aeb585e0f8c45d6123a75ebe98fd1d0272f733a3925119481a321fe7509346c05128302851ba17a137f956f184e057a305e79a148727a5926de6854eb0314d5492fd735fa773d99ea34c95ca7546bd3a3aa8e66bcc6d860cec3d35d0e2165d5fbe8be99b6e7967df6693e5a6243e94c9c4a2528ae6305cbeca209" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "8f1e88103ffa378f062cade0ec509bec99a5c73fb273e79dbef24abf718ac26ac23dfd2b8932038ed3cb9637b71643c161142019f45b25b4fa4c52356737a27027e805ec635154327a66bfe64efc6285cca98c34edc7fb6c0766970a545342cf840aec0a5ba1dd3c6949be4fe97b0f8c8186de07536fd9074db34d09b2f08af9dcf9424d6edbf9cd044102c0e5dc35aff78c36d079dbd2c500e19c8c985ae2abaf6b2a20716bb719754a8840ce97632116c4d0b0e3c83ccca27f11c4204b76b5d6cfe6348a9615d8e4af53500dc4c2cabf12ec8c76" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "b9a0c28f1a6156992c103a84655fc6e654fa6e45e45819513afa797024717c00cc195994512fd53ecd1e12dac4d2448e0c40308382312084d2111f7db147b2e6589ce6d977f6115f629508167df8f45bac98abd49f6b272bcc4fd874dd5e29fb6daceb2d727a2a892194cfb9269eda00626ac89b4e74bd29b21e9f6ef18cb69889a02d4f0a06a2e5718899c1dc3b051c2cfa29653e782f87fefa478e6465bf5ff27f8b6abdb500077aac97100bd955ec535a587d66f23354be51cd8170289344bac9451f74e8aee3639f7c09981f4885e018912324d7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "456844a34ae1074246f8f71eeef2010ec8733265bed7c1cc60043d770edfa320cbd4284a94be2574337e16d27f125074ebd7e99031f7abb4547b9540a7b0b5148ef501b550dd929f3dfe39ac65519f563e9254424aaafa05b1d37c16c771882e9e25d4906ac58603da749adf686932cd73d81e2658134fe69294c7a521d257eaf2110c667fc9d6f09b52d24b93910e532184eeb96eae9d9c9750ac3c39e79367431ac1af7011172d0a8be46a31010219a0310a733068c589bfc4748f3626aa4ff8d355cc893d05111c287c9992e95ad47481a6c42d6eca" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "c5c4b9900b9727bdc24baa544cad5faf8340be6b3759361f53889f71f5f4b224aa0090d875a00ea7116772117dbefc3a81c6950ca7ceeae71e4ba975c50d61fec82e6d9448d3a0dfd10bb087bdf0673e3e19fa2aaa7e97eebf71f11b86034fcf5a61240c71444ac3da15ef09b27b3523d37d309e8722380f835c1aee4a767bb027ec0674040853e5b53d6a31657f51acff6d2487860becd5ce695696cfe5937f4a0217b69e01cc6facc24dfe5f5230b8692a0b718e3b3c789d682db36101795a9a5f8bbb838c3679be72f7941a1db180135347d0a884ab7c" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "1781df2fedd2c39137854737d054cd3ed16b0ade411e41d97888ac900fdb46d9ae26b3d2dd07e118fd57eabd0dfd03a55793c76420666444865371adffc9b2f35068a0d70f9cfda1ac27ccb4beff4ffa5b8bb8bddac843386675c38a181fd0d935d6d51b25d78e7ff4ecef27a9853c0f0d2879c395ed1c4883987d123890d04f851c3e042e1164c68c0d503de16816f4b0e554236e5f4c339ea11d01ce652f6208f78f457a2417a97c0a6a240f443262def4b6763abf53e597bf1a28f907dc7cbdc751a234ea7d75710ad5ab0c37e8e9805102a375abd44011" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "8963552ad1e729ead07750df599d734157aaa4bcdcac17e8eb19b4f99cdb162686ff433137aa4e8a0cc8df0053999196262115aec326cf37567d9ba4760e0ad21d5763977f1ab9b35c0fc667890fa87fc946ceb776a811b5adc69446bfb8f5d9908029dc5aa38db816e4a4e8f98e5a48cf0a01627031c5bd1ced8bc1940dcafe4ae2f1199b186468eafc07e96a89d95dc18ef0fed3eda5b58ce58f221a47ba5311313cc680367eeb058fafc7bcadce5f520b6371489d9e529278ae6ee2650a85aed82896879038bbd9aa8d685fc9528943ccf2235cdf69a86464" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "23ceae3008085134433f5de4b47bafe0f443d443491e6cd47b216dd2dcc3da65239515a6e6b9beb9a939ae9f1f1f5e11f88326475e0962f319d9bf75ddfb4a46e7cc3f799d7547f3c0b2e089018b75787b82ea1a7295e7411f4852f94c94170e98bb0647923b8eb7d184038e56560da46085540cbfef82b6b577c445d038f6c93fbfdfc96ab3a0191d20a57b8610efb4cc45cd95198198e6f80ac46b0601511885f650eb00992605be903bcb46cd53c360c6f86e476c4c9ca4ad052eb572bbf26eb81dd9c73bcbec137aea6ee27aa97dadf7bef733fa1555019dab" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "c0fd31e82c996d7edef095cccfcf669accb85a483ea9c59f368cc980f73da7202a95c5156c34192ae4ebf773c1a683c079b17ac9d08b4265b4054fcddaf6666ca50f38f1a2ef2497459a68c06837363a526e850ecfbd223f55dba67db017eadb7a9139abb5bf3854834478b838aafa16c5ee90ea52fb2f7b8db2bcefb85b06fc455c2b6c27d0af9a49dbf2f313bf2599370637393e7972b31d8bf6759f3e6115c618e672831f84d76ba1879c754144e1df4d56b1e264b1797dcb8ab165040c8d20b931071081d7f74fbff590bdc8e888e71acc6a720270da8db7c821" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "936fdab91fba396e4a8754a97a04ba333daadc29885c9d0c8fea3387165278f4974e468fea57f2bfd8428c4d0f010833283db73735d39de0c0cb5898d0c06c0ecd05f61098935cb6130a8da60d1a6c2ecfe420f972263fff5a631b09e81c837183c5528bb1c740b36fc39cb082f3383c2b4afb25d04ad1d1f4af63dcf26a0bf5a647cd2e35a51cc119c4dc5031f5715b3bfa1f2b92de06bdac0d670fdd30980f32c51f3936b51e5db6b95a8d36279da5faa4c4e454f2b7e54e9f488071011c7f6f9b63da260a2e46d796d36c9a9dcae88085806a10a77bbb670d475778" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "a55fe162b287bd6eebd6cf7e7aeea8672322d924ae42c7404ff89aedb98943f3755d2889bca488cc7000e6e9b8e7a0ef289273cd29c44cc600e330d1775e3cb767f12150e1615dca8c3f67466463a3ca993a1b788cf67a7a35b95dfff954206eb5ea1e1bf7fb06482a551625b5c9fd9a86e8414c8cf79d3a14104a153cbe04aac5172aa4c4a89349f5856c4262dd1d7317a7544c9afbbed449e7dcc2b58d9df6c9c9ed3883e42e80f5c2433550f30e73c7bce0fccdd880adc19282a392dae26a0108e7faf168cfc15937aeb046d60712603286b8ddfb27916b79242d56f1" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "2bd6976592408cdbc4e41dcd3ecfbb786775ddedef914d9058e6753f839fdfe15b17d549dbc084aa6cdf3befa0158aa84c5d58c5876144fd7e6c41ab7d42419d0dd353732e0e6d3fafc4f5626c07433390a4fd467197e85b5de7e2cf1c26cc575356adedcc0740008523b503df12ff571387726c5ccb280376d19cbacb1d7ce7aab8b13292c6a8b8881e949cbf6d4610d16ebba1d46cdb8d0459596e0aa683d0307bd926e14de19b9bfeaefa29d91b82248604673a455520cbb64eef3f38cfad8e126a3b1cfa1aaba53a784c8ae0c50279c0ecdab54095d36f67ace9b8ebbb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "71913ae2b1c8729ed6da003c24a1d4f96e28d7faf55ca14ee0b2865282b9b61103ce6ee0b00b00aacf2081adedea5616f9dfd22c6d6d4f5907bcc02eb33edf92de0bd479794f51246d9b612b4543f6ff633c4fc83bfa6144c9d26721cdc690a3d5a8db54d8bc7873bfd32924eeb502810732b5ac2f1852bb021c401d26c39aa3b7eb09083093a9e89bf889b53383b5af61110aca1b9fdf38908c7d5a184fc5f46b3423a66a2749feb8de2c541c563987278dbd0513d99b732411012b5b75e385510de5f6839c3797dc094c9501d5f0504b06b43efb6e746f2129ca189c1da424" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "9d048a83294de08d3063d2ee4b4f3106641d9b340a3785c076233686dd3382d9064a349c9eaa78028d35652078b583e3f708e036eb2ced3f7f0e936c0fd98f5d0f8aa91b8d9badef298bd0c06843831279e7c0c67ca7e572f552cfdd984c12e924c08c13aeec6f7e13d161785546ebfd794b5d6a92a4744e52c4cab1d0df93b9468be6e264e8cfcc488f9c3c1817cbe501f4b9cc5999483b7433aea777226b25273a6ef2331b5f3b6db8091591e8e276015da3ef78bb2ee0526ffe23def2d8d193cbe594e8ced1f3d216fcedae2a1eb288da82e34cf98aebc28def658ee0849ae7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "3251c96cbf82ee2e5264528c0b6cdfc23d20e1eb2d6441b5d62f0fd24c692a0d45a8bc8aac32884b7141ac0f4f113ec9fc7f6b4db3d696374177f9a42d602ca471275b928f639105a55b846da9ac7274cc37de8c38541f6895f94d72a81e117844b46601c201f7189b935a96e42505f2098ac985d92dfe86349a706ef6325b3c2e4060ced3c453e68ed09e043bcc75846b80118dc53530248da250fb57922d0afa53a7b2c89161aa4fa372a46b2a8e1307741cecedf585d2f998a9d496763800b6965c38a5d8aa566c709f13699c8185ab4fd8fdc8b824f4dd6d1c255b4788f50574" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "2de31dbc8a012254586f3229d3524fc529554e98850d30acdfc11406bba6a142029126ac165ee90b2de7509fc3571a8ee12e16b05054eb8baea879d135b39627f0d8331be3e66bc720c2096ce74e437daebf3bc53d8f2ccc228c3256d3edb6e9ae7c354a0c9350e6d663a9a30630bf9da3d96b96608a2a171ae28105714058b6c4b38a36c56561c4612c32aad25c65b7fb6faa4e4ecd44ebf9b2fad42ff9a807cda2581614fd30d41a7436069399b8d4f062a37a5bd4066a93d541fa5797a7d3e7dc9c4c40f0bbf5256f71613240f9ef128b3423eacaf428ada06b6a531f835281e4f3" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "07dadee629a08223dcd7ec441287b4c5e26347451d9c003e3a8496b4ea313b51126283a6720d7851e24423d9c9c818b4601247178f38a61f45fd4c8596d79529d416834226666a2c8552bbc901cc5cc3406a18fc88077fea52e1b620748553052ab7788c0d025b095b736fbe714cb3a968ec16b5917652eba2d7cf32ef3140d6c27b25d053e9786d24cd09a5306a0ef55e46201faa6196a91084267d7a7b5ca57c2efdeb2cb97d682d2a191b915553c8933f1d1b7faf0b4a1d83ef611f1e44438bc1c3d860fbfd12b5f26e5a6889a31ce26ae6a55c7a563b5816d113423ef3f25fa9befc" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "1d94166bb387526d519c4ce150221954da8930f66765fe6a5504e30a69962d595cfdd07a82c003843598864261f053bdb6f5086d516c261e089caa89990f0967605768ae9200bdfe4dcd7b77a93265cb33d9851a2a1036113c732bf3f37534530641300f0620de5c16101e16f4baf39d9fcbfcb01c52afce0992c329d8dbb438c314eee995c5020611d6f889e06b8a032785cba9a415580dbf752b5e510523c89f478cc6f047bd926f51e4a965c9749d1e76379c0e7e5b56803893bafaa4d2892b4c52f143b2fa777cd1035ea418684b8019df084f9a3f1f768753096621f342895c510d01" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "fc0073f199ed8a1d6edc8e7bdf182670003108d82b283aba82326e856f8de378987a03d0fe8d2041440fd29d51c63796aab44090d2b14ee00859b3a08cbe88f724badcd3c401226c5db8b307b8deea5be305412b080e9f99cf79d6d08d3646f347a7afebb62912e3e246e2e726f9aec5c101d916e47f984507b1d65d313697256c77da7eca3bc5811c87bee02a2826cefff0d92bae989609aaf95d70561b40d98474c37277c884aed887a1606d206b11e8a8a71d1f1d19319557b57351228ff0404be700a6cc56c0a30f3d4b7a0a046463fdaf19e7d5f59e155f378e35baa33db1e881f2207f" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f42a6a91278d6a076feba985b1cf4ce0af1fa9d6d039c136e8971e665ff088a10b6b9a379a6f5526fc5957773a0ccb8972a4a19be0745ac13937030a54b18dee4f4c5df47a58a33a7516b90e646e5da999166ab0e52f457f7c9b7e391836a687eaae37b377e59a4c995ab0c57162c307ab951a9ba6590f429cd27250e7010eb794ec1b1ec35f8aad189b2fd3e8aff24d93601d91a4884e6f84b02757ce7620a02901519fccfda52f68ad6df709d112a9c25d66bcbb9622806427ca8b8d346b6db05874bde800cde9cf17df4b05baab0f133febd1ebbb053b49c109a7f5b1f864a304d10288e2f0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "bbcefaf4a0739509f8a2f831c954071aac52e60cfa882a867b8b910dcf7edf92e1c0692bb027bc378c460a01cb6ecc8f2a012dd84ee5a678cd497b1457b6d393421fbee98ff544fc7eba24cbc3aae506254d9a2d74dde74437ce4c8a69010718506bf4c5943342a942e5e2d3406a3016280b6e37954c5d5e763346251afb0b746cad68cac757f9df765e092518729cfb9a5e76300c124e708ca33591a369767ffb63933cb72fba67beb2223d98984d0b75eb5d1a38615913747b520b3d613c715c0c77d2987bb88f3c419bcc5d38573cf4a8a4f550b2d876f05ca252d88c70a561d869a5018b32f7" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "dc2437010cb05d9cab2af5c275e1d2acd627ce19fb86355df91fb8d059e60d591663c8eb077d48388c9a321057a98136f49f0098348d9f29d808936f98bb1787c7ac75fb14f6076dfd2de5b59b1fa4848cabaa9a99a091dc24b561911c392ecdbe53f4adae82b852d830adea3a10490c908e337ce0a6d12354ce05a37ad3a06696b66820af8a1f67e6287533fd6f38a5f6ad1c6b078c08baf2c37d2683af01e6a5b33796c8ae48935a888f9bd265f4f11a4e27c433b8b1c9afd140bcd21a07e24378ad6badde8e47c57e3340f49e2406e8d49afadd65eaaa4c3d078c27d7e42118cb86cd248100a356" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "6c290db326dd3152e6fa9b9c0cd7d49e50a0221b96e32f5f34a8cb7d0c2edd3e937a7d025d6999b7b468add4d6894d8f7aceaabc18f4d9c171f1fe95ea1ae8570382a8450fbc595d95b1f51d24e1abc2970b0e1d20ca40aa21bdfb3656adf2f19882eda606f5ef1c03174e1d94c8d12f0fee8dce6852f42a364eeafa27a7971d4379405db8e46baac4d685b969238e5df06292a6c790bf1994a051b038e1d8db91e1bc4804f32443781c34a552ed2e8100cea374e77af56ba0e11c45990d3ba68df9087b1f4968cbcbb1c42f99b7267c76af926ff3134e093df28fab039cad420c6b70f2d9b5e678c155" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ac724a22ebabaedbbb052953e3c264a4b6440f313bad501cdc1484b64f33402a2230898776db5c818c28035ffae6ea24abd04b7159e42159833903a0c23a7c564f7645e49ddedb748fd9e51bd6cbf2eced98caaa35226970f003ce1fd260ac5795e096f1c04aebf8fd36e5e2adeea929b5e963a3cb71d6b55c85bb7d3a2b03a7e74b4416de8fa68950168d7c3ae8ed2e29bad1e8a182a7c5418e5d564373163778cd3c34e9d320eb1a60480a8f98b12e0026cbd7752e6079812e3767d9f55f3f10b8c214a6eceb2a58954091a06b33862af171a9b60bf2c6a44e8766e6c56e98092c56f2a8510f6d05c103" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "8c70114f7cffb375c2b9a06e27297a5c32418b2daf68af5bbedcc7106edbc070e764bf40c1f8eb15079e2ab77f898afff3490108ed9afb7ea9cb05df41d263be0e42d2321d3d2656622d7bd232bf68d37375fe7314b09cba66f19c8b59424198ee69e7a9f3de0ecce0685127807ce336fa479ccaf7aa1ebc4e406271ce6c4923ec36093516498cc227f9218869346c80ba5ae83e023aca0ae2bc86b5bf5d115a4616b6587cb869d92f8c780ab70d5766de07a204af5e1c8dbba622516d2e911b36c82e4687e4d258ea616c07f76ff0baa376c8d5975cffac0b25817f779ae3ce88b72eb47e378484ce999bf0" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "0733d59f041036398233fd47a84b93f6778ae5259ef5d62aa3b9faedec34c7edb570c18b2a5d2c4c55cf656d98a1ae396d45a3b746b7ad6f07312c3d05d1a50ffa90bcdcdba105e25b7b0c52664223f8c2476925d46dc6ea2406ded7d0b0b292f6656cebcc7616cfa4b82aec68b35d1da67f6ed2bf0171849d6bb65128d8a140ea5cf97f1003f8d7093bee077be78def4f7bd2caccbf0644f26b26285225142c40038484c3bb9ba9597744f4389e76dca3eb695c33ccc621cab1fb603cb3535a0ad318d220385d5e94f8674f3d55e97e097f8d5c049e911946afbfce783819951d65d6bff4567dc951390d1aaa" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "398ddbba3dcb5642c102efa841c1fcdaf067062e7eef8e2ee0cd73d7f77e57372d6ee1a9b7b6f86ad12d575001ae71f593449cb5a476c6bfeddaa2af0f9239c1d7effdedf66ceaf413707b5ab9661a7cc0ef8cfe4d1651579c4f0f64e2d12a52653c54f2dd60864e769eab8a627c89c56ee93365d031f0d2523cb95664b1575d51b122f33c9e94de75432a690658c977b68aa5b721a393f9b9b3b612c10e920a7d510c6d8460b35f8614c42f5d2c241a01b28105aa7c1b521ac63ebbedafac6d5a38c898e8590f918a1927bc53aecc2b1c8b18d7df9107c6997d9b3fa4b0bdb1c603da619d9e75670b97a5b40f06" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "ef07bbc7c4150dd47f8c69a7989948fe831dc798b0424dcd6551bfa8e88216095a7e5d720909bf3d23526b9ba464b66ff6b63a7337c31451ab9a15f04ead809a62bb52206237de77597a730106d02d227dd6099ea9ee2a92cdc446ac3b9d024e32255adb3e9b56b561c431e0b5a721f0336f19568a5335d0ebc6c73ed8ff2c15e219477d9e4b67f2928e251f8a61a2848857e037d010806c718ab062967fd8e85f3722252957923f5f9005aae47b4b1b3fa464e3ba9df573a56055f17e903126fbbcb6cb96de92fe617c97f84ef3ba0d8f2651dc4aa80c157f372ae1bc02e5067ad076f3fe48bb72c0f3c99273f82b" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "c7076986d2333f3a6752adf11f1a9e5c6bc4755f341073cc86a9c7519c8db029d5ae833fdf3fee826ff4692c57880c5074620ea97c00f1dde1e8a0f18501627984ded4d1b5c4af35be5cc1bcc868060a49a968dc0547acde490b4c68d79924a93a986aa0ad060c7de706e8a99ce8f84a4f8707b52a8ee122b763ba580d6b1f35f6af25094c69f49247da96c836991851ad36f60bf577863d7471608a012afa7a56656abeee7cd9b4f1f4d9d13a8526c0f33cd251caf7486639e787250390e7e488e9ec311fc3d847a7266cc59bcc2bc34192554aa57cf25db10ce04bdabef3fde6db85f55195ecc2ff892b2e268ebea6" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "01789f40d42d8d3e4a416fd9ae7de78c3a30507809eda200e1afaaf8d7020cd1fad18eba62d821946f220506cf105ff0e2069a771a2c233714afa6b2f695497e4b95c9693dbb93ec4c9a14720676aa87ee31dd34e4e081756477032b4a57b328285f2cdec1b269754c474936927e93acc26012aff1bb36f30c2402aca0a9b9ce9568f5000e2c934263933b436c94f8d6589c89db7edabc5d03a8fe795fe50c5166beab64ed7c22662b984ae2c66dbe4c090b0df603b27c759278f8d66859afea3f6a8f02c2c2a2202b9fc29132256f164b5050a803b43688dc4c9ba86374a3522afba5d1a19bb3820b883aebc267627095" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "2c61944bd6a50da00ebb951d2b67d79fc6b6fb5aca83b1de3dbd7690ab756bb1e1a21051ccf1e24136ac8ccb42a2ee10be94d2cb9289d5f52b6f90e9d07a3478f36a1eb7d08c3dec52ca154fd1427ba92a4ecbe73a71bceafbd26e9a39d50821e2876d3a0c0e6e373b9795dbf72ea29cc439ff42706be798c90d4617b39c90ec84bf9fb699dc8a9a34e25d81759d6c57df45efb1d0d68aa51278564b99633ed5dc464bb7d53c5c21f798f33bcd868657ecfe75a1ed8149d394b398969ef624831b30f1458465bfd2fdf3f284f2ffc54bf2817b5fab2e02056e864f78bb6fd870c64f3609dab218f25da8060f756e45121e79" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "942fa0c68cc72f69518a3a7aac0cde45bab0e928b5cb2bd24d049fc313f74b6afa87c4e34150484f3b5200163f8a6472d04777928ecc49319539fc17d71a38090f55a74f757fe45781a3c09f08dcd3dd4c73c8533a5e00cf8a86ebe77fe45be2848574f7c5d25e9a0632a60d2dd41febdbf987d2a0487e4a4ce6ed5f49f2d741a88ecac232b1498253fa4ee8147bbd0f600abdf295e81f7570015aac5fe6ca7bb4a99bb3fc54287106d7fc1132a574af49db82a7b9a5f33e193cde527ca2176c52cdab672165e0fe5720f71ada57ee90060aa069ae2a0bfe67c1b71b17c601c3c2224bf9891bc11ba216e3ebcb51fd95b8d7cb" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "0d68cfe9c087ec116fe7572042385159cc705960f842aabad1ed1387ec1697f4413a23c6090041328fedd4b626c6eeaac5b5a71acc1fd1bb8fbd228857ac5bd045c364be7a5a26338ff04c99c4c473cf445a891db6422d1bdef4533442df171643fc36a092fabb464298e4194c9e2950884de13d113ee24160a416404c16ddc5d2476cb3fb80da543e6ed9105f6003977acb34e1fdd2cbdf7a00d5ff84350b74ac231418c0d88269d02d824802791ff42a51cc835deb9869a6023f867f82ef6dc0bfb03e6dfa835646bb18a4074773486e308aa39e532aaea4e6fb35dcada7e060f8282c371ed26d22302323d4fd142a85534671" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "45e24b167a0bbef1bd8f79dd047763d0754f36a7b623f298059d177e8ac994945c37d2c4af06f01318960301595941124592f2995af1459d854339998d3ae17534df2d9793d6e203857d02c98a0cd88991e641b3e640090ba303f87b907dca8ca462fac19ad079b2c82ea5b521ab891b10138b083b3d9fa214a8fe60d1cb3599c5d199c61a2cfb7ee2f39e5a5abad5ac4998b707545f73e92128d21803420526d2598a53bb314adf29a0ef56b94bd2221601eb53ecb8540e8fffd38fba7bd827ef255e4ef55491475c0f383a241f81c72af4e1dbf2a65cd4d18a497615aa0de2791a3511a7977a8d4d41492bfa4085f2fd4e8f751d" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "1c1bb695ae90e6e33fc1e8b2a62ab98bf835ac7193440f2351c8cdd830472b637d2fd9c9013cb83caef506abc1c4f7567706db6046b1d184579c7a9223ab1b35e32898c70a3c27628123ffcfa518612f080a2c4a9f8e0a927a47dc98307d2b48de9d5dddcb5c82f0b0e4e610d44f1baa9bbbf7f5a727134680bb7d1327b73b52d8e5e36dbb53971e99e699d79f75a3fc01316bd7012947d119d6aeb7f75b8fbf0479c03002148553fa0da450fd59d4f1bebc252caa11ed9bec5b6ef54279b5f8382b61cffc67ec03f4baa7ea476c31364b86aa8ccad9fd0818717f0ced2dd49477874b4341c602d7a1beab860eb476c7e3ce597e6926" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "7a3cd9bb2277e2c7f1134fe7233f0f7883c2db9fba80aa5742b03041de0fe589d9e5ea84470dabf41bb66816f3e33ebf19a0ca5aba1004cf971249b258ff26a98dbd0c37ec6cd574854109433357720040bafed4531e0079186b1e853e0ced35d08d27f6d732ed6e2c6651b51cc15c420a24f2dc36c16ef4b3896df1bb03b3963f9aaeb02a48eac5772abd5948c2fd0db2bb74e3351e5eabd681c4f413655bd94dec96b1544c1d5d2d1df4bdc26020d25fe81d5238de824687a5505e1fbe08d11b3924b3ccc070fd225bf01eb79e3d21f7b62a836cd3bcc11c931669c37613470e356143df87c48848a829f5e018973a5db88eb6c60203" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "3f158afd0733fcc5dfe1efc2dd4eada732f942af734ee664955bb1ba613eafd0f349e7554a14d68200c62d8f2dca2ec8b81c8350735eaf437041f78b452598825b6899560963ade66a0fc74ad01f8343d1d19c7bb327a8dc14ffdb1c42fa72b2970d9155e2da6a2e6419d4117842d826ff38ffab9617307a0283d3ea28c8104ad9a6e087bb750ed1d10fd8f7100b1663682e979d80e43968c33d9eff66f4d1344e583ee521e78d0a2193c0577516b978339c143bfc689bc744bbc4a9163063de82c9706384b6b385e54666c86b34f23c1e25be293af06092ca31d857e11e5b2caf0d19dd3afbe85380878eda76d718b4bb869c67e044e242" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "a177af4387b9bfa3d59e97ee7b0ff5f4ae4a326fd9204c8d28831a67fcc385ee6c4828247b16d11aea9bb8cd9e6c4d2876c6b2fa6d5041ad39e1b04039071e29c4d86417e7eac4fc7d3823958a021823e2c880a757dfbcd0c8196371db5bbfac15e4d1a0596508b6d26f8c4a664924c95082d173f817995b44c4285d625d9b2f56c86632fe1295c5a8a7a3760028072bcb07bc245a705e7174d06b9d5c0c8ca495b9ac218f1921fa63f2db3fd148f07545366d008fb5aead7497d902b91fbaa39669929d4ae9d07df8557f1f0aed7b51252f10c6606e5ff3ede1327530ca356b4896ecf14bf7322d77fddfbe28d52f6de7f66eeb81704c87e2" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "01a15b9018e35cc342c926b01d03ad9db4993a6bf92e0555969fee90033f28f3ec234c1268b11b040dfa0770d4ceb39edfeb8ee6a589f4eebcc08d2d1b0a1a52953aa26eb44fdf4a2743c3dacb212a0c0f325572f645f53027b6f3c0c55abaeb1b0918c89bedcb5028f094d743ea354f8ff553c45f111a8fd5a14a4e5c835164747d302472e19a67da04b4c8e39756a9d248ce14d1ed43de75aca86850f2455eccd4639b2af035bb3f504cc9065d091c1c47e036083cb3fc50bf39292b11737c7ce0b49673ba93981de304dc65a671775b6ff927e3ff93850b214fffb5792105a4bdc81354d5b09e84afbdd1792b8fb4e9d0ae3dad2492b03282" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "24f07ae31279ceed18ec6d35990f21200934ad6b132c6c62e82fe92a40a0e60a5bed10720eff5a1f728971888682772b2d9060d4fee88f37d0824e7384dddcc549475f0e1a44eda4804778b62febe46e04657a20577ee70acb3425e334881eebd8ddf714ae8c527ea747e3367de384e595a43b299b6bb3f6b0a4716cf90038e0f75a47d5057d7fcc3c8a8f9224992c67f8ae0d3251ea09a24aed9ce57ab637f6b3cbb7083df62b6287f64d0877984c4249d113bdb2b07865082aa24cd7ec07061b17de320f51f29f25b82d7073d369cf2dbf96310c0c311997911b2cc02f606f9cd99663c57e78499192a2a78f9c9fa67013e0f9817287faa69b22" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "4aeb32bf9d050f10bea18d9f71b4afea7bd08550e574e7d50df234c7413668b297b6721d7a0f0bdcdcceb2f55adddea28cd59bd44be0c5ec067039e428706caae11f565d961ad6e7f4c51b0aed6d05cc5b8d826c4b9c39daefb6c7da46dce619a359dc9ce215a215218fa8d54ee0b4f301b6c201c7c2c5f7cb1c6e0cb76ba6c6e8f63ef7a5213d550b0d0857fa0ff9e3e38e497161617413ac066e2fa539520233193a5cb7baa0c2cb20b45e56bfed2c40a9544d1f230dd0cd6d4976e7cf51da8a13200c3957c0154c8237b2931ce19b824963ac576ea49b548cc6aa85c47796b470fb2c6308d88f390bb13607e294c84a838b2713b14ca6a5e8bcee" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "77e607478be5502432230c913d9ec82f967d87c0ee169a74076f989648853eca693277287f8a5b306bc94dfdbf64ca5cb5dfc0bc498589d51a691b8d57d4b0a9ee247d038fe1b5571183be3e75c37045bf1235863ff1b84b208c10e7f1a5ba54ff36af5b2870129867164d013e0a6d2cc067a3509bba2f46390302c80b651cf590ef69aad8effd94cab28a9b44be6a38b58cfc47c9c725d6fa467894163383b6873d10d263b1cbbad932ded59ab503920267ac026726f794a335a88f6ef564f8968c6fa6f5d3ea161eb6062ca349b9a0e4038273399cfa297a6b07ceda1ebaa99c9de2d935ee230a08c5a488ad46f3393243371d40916b8063cac9da63" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "50957c407519951bd32e45d21129d6b83436e520b0801ec8292d79a828106a41583a0d607f853dc4410e0a1427f7e873455a75df065cfc6eef970f7e49d123b346976460aadd91cf513c140c356442a84656904a8b1d708dc6089db371c36f4fe059c62302eaab3c06c0cb3b429961f899dcf99798464b8571a440cac7a52b495f32417af6bc8f58adc63647531f804b4e96273b29b42434c1236bde80ba3744fef7b1d11c2f9db332b35bc25123338ac9a0796aac213c9709b3c514ea7ecd80e22d3d8a74f28c8194418a6e1ff30714d0f5a61c068b73b2ba6cad14e05569b4a5a100da3f91429d6e3ffee10ceea057845ec6fc47a6c5125b22e598b2dc" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "f2273ec31e03cf42d9ca953f8b87e78c291cb538098e0f2436194b308ce30583f553fccb21ae6c2d58f3a5a2ca6037c1b8b7afb291009e4310a0c518e75314c5bb1e813bf521f56d0a4891d0772ad84f09a00634815029a3f9ad4e41eafb4a745e409ef3d4f0b1cf6232b70a5ce262b9432f096e834201a0992db5d09ffa5cbc5471460519a4bc7cdc33ae6dfe6ffc1e80ea5d29813136406499c3514186ced71854a340701519ef33b6c82ca67049ab58578ff49c4c4fbf7d97bfec2ecd8fbefec1b6d6467503fea9d26e134e8c35739a422647aaf4db29c9a32e3df36e5845791fdd75a70903e0ce808313a3327431b7772567f779bbaee2e134c109a387" - }, - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - "5784e614d538f7f26c803191deb464a884817002988c36448dcbecfad1997fe51ab0b3853c51ed49ce9f4e477522fb3f32cc50515b753c18fb89a8d965afcf1ed5e099b22c4225732baeb986f5c5bc88e4582d27915e2a19126d3d4555fab4f6516a6a156dbfeed9e982fc589e33ce2b9e1ba2b416e11852ddeab93025974267ac82c84f071c3d07f215f47e3565fd1d962c76e0d635892ea71488273765887d31f250a26c4ddc377ed89b17326e259f6cc1de0e63158e83aebb7f5a7c08c63c767876c8203639958a407acca096d1f606c04b4f4b3fd771781a5901b1c3cee7c04c3b6870226eee309b74f51edbf70a3817cc8da87875301e04d0416a65dc5d" - } - }; - - public String getName() - { - return "BLAKE2xs"; - } - - private void testBlake2xsTestVectors() - { - for (int i = 0; i != Blake2xsDigestTest.xofTestVectors.length; i++) - { - String[] vector = Blake2xsDigestTest.xofTestVectors[i]; - byte[] input = Hex.decode(vector[0]); - byte[] key = Hex.decode(vector[1]); - - Blake2xsDigest h = new Blake2xsDigest(vector[2].length() / 2, key); - h.update(input, 0, input.length); - - byte[] out = new byte[vector[2].length() / 2]; - h.doFinal(out, 0); - if (!areEqual(out, Hex.decode(vector[2]))) - { - fail("BLAKE2xs mismatch on test vector ", vector[2], Hex.toHexString(out)); - } - - out = new byte[vector[2].length() / 2]; - h.update(input, 0, input.length); - Blake2xsDigest clone = new Blake2xsDigest(h); - - h.doOutput(out, 0, out.length); - if (!areEqual(out, Hex.decode(vector[2]))) - { - fail("BLAKE2xs mismatch on test vector after a reset", vector[2], Hex.toHexString(out)); - } - - byte[] outClone = new byte[out.length]; - clone.doFinal(outClone, 0, outClone.length); - if (!areEqual(out, outClone)) - { - fail("BLAKE2xs mismatch on test vector against a clone", - vector[2], Hex.toHexString(outClone)); - } - } - } - - private void testLengthConstruction() - { - try - { - new Blake2xsDigest(-1); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("BLAKE2xs digest length must be between 1 and 2^16-1", e.getMessage()); - } - } - - private void testOutputOverflow() - { - Blake2xsDigest h = new Blake2xsDigest(1); - byte[] out = new byte[2]; - - try - { - h.doFinal(out, 0, out.length); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("Output length is above the digest length", e.getMessage()); - } - - h.doFinal(out, 0, 1); - } - - private void testBlake2xsUnknownLength() - { - final long maxNumberOfBlocks = 1024 * 1024; - Blake2xsDigest h = new Blake2xsDigest() - { - public long getUnknownMaxLength() - { - return maxNumberOfBlocks * 32; - } - }; - - byte[] buf = new byte[32]; - for (int i = 0; i < maxNumberOfBlocks; i++) - { - h.doOutput(buf, 0, 32); - } - - try - { - h.doOutput(buf, 0, 32); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isEquals("Maximum length is 2^32 blocks of 32 bytes", e.getMessage()); - } - } - - public void performTest() - throws Exception - { - testBlake2xsTestVectors(); - testBlake2xsUnknownLength(); - testLengthConstruction(); - testOutputOverflow(); - } - - public static void main(String[] args) - { - runTest(new Blake2xsDigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BlockCipherMonteCarloTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BlockCipherMonteCarloTest.java deleted file mode 100644 index fb99ed1c0..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BlockCipherMonteCarloTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.BufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * a basic test that takes a cipher, key parameter, and an input - * and output string. This test wraps the engine in a buffered block - * cipher with padding disabled. - */ -public class BlockCipherMonteCarloTest - extends SimpleTest -{ - int id; - int iterations; - BlockCipher engine; - CipherParameters param; - byte[] input; - byte[] output; - - public BlockCipherMonteCarloTest( - int id, - int iterations, - BlockCipher engine, - CipherParameters param, - String input, - String output) - { - this.id = id; - this.iterations = iterations; - this.engine = engine; - this.param = param; - this.input = Hex.decode(input); - this.output = Hex.decode(output); - } - - public String getName() - { - return engine.getAlgorithmName() + " Monte Carlo Test " + id; - } - - public void performTest() - throws Exception - { - BufferedBlockCipher cipher = new BufferedBlockCipher(engine); - - cipher.init(true, param); - - byte[] out = new byte[input.length]; - - System.arraycopy(input, 0, out, 0, out.length); - - for (int i = 0; i != iterations; i++) - { - int len1 = cipher.processBytes(out, 0, out.length, out, 0); - - cipher.doFinal(out, len1); - } - - if (!areEqual(out, output)) - { - fail("failed - " + "expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - - cipher.init(false, param); - - for (int i = 0; i != iterations; i++) - { - int len1 = cipher.processBytes(out, 0, out.length, out, 0); - - cipher.doFinal(out, len1); - } - - if (!areEqual(input, out)) - { - fail("failed reversal"); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BlockCipherResetTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BlockCipherResetTest.java deleted file mode 100644 index 80788fed5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BlockCipherResetTest.java +++ /dev/null @@ -1,206 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.AESFastEngine; -import com.fr.third.org.bouncycastle.crypto.engines.AESLightEngine; -import com.fr.third.org.bouncycastle.crypto.engines.BlowfishEngine; -import com.fr.third.org.bouncycastle.crypto.engines.CAST5Engine; -import com.fr.third.org.bouncycastle.crypto.engines.CAST6Engine; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESedeEngine; -import com.fr.third.org.bouncycastle.crypto.engines.NoekeonEngine; -import com.fr.third.org.bouncycastle.crypto.engines.RC6Engine; -import com.fr.third.org.bouncycastle.crypto.engines.SEEDEngine; -import com.fr.third.org.bouncycastle.crypto.engines.SerpentEngine; -import com.fr.third.org.bouncycastle.crypto.engines.TEAEngine; -import com.fr.third.org.bouncycastle.crypto.engines.TwofishEngine; -import com.fr.third.org.bouncycastle.crypto.engines.XTEAEngine; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.GOFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.OFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.OpenPGPCFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.PGPCFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.SICBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test whether block ciphers implement reset contract on init, encrypt/decrypt and reset. - */ -public class BlockCipherResetTest - extends SimpleTest -{ - - public String getName() - { - return "Block Cipher Reset"; - } - - public void performTest() - throws Exception - { - // 128 bit block ciphers - testReset("AESFastEngine", new AESFastEngine(), new AESFastEngine(), new KeyParameter(new byte[16])); - testReset("AESEngine", new AESEngine(), new AESEngine(), new KeyParameter(new byte[16])); - testReset("AESLightEngine", new AESLightEngine(), new AESLightEngine(), new KeyParameter(new byte[16])); - testReset("Twofish", new TwofishEngine(), new TwofishEngine(), new KeyParameter(new byte[16])); - testReset("NoekeonEngine", new NoekeonEngine(), new NoekeonEngine(), new KeyParameter(new byte[16])); - testReset("SerpentEngine", new SerpentEngine(), new SerpentEngine(), new KeyParameter(new byte[16])); - testReset("SEEDEngine", new SEEDEngine(), new SEEDEngine(), new KeyParameter(new byte[16])); - testReset("CAST6Engine", new CAST6Engine(), new CAST6Engine(), new KeyParameter(new byte[16])); - testReset("RC6Engine", new RC6Engine(), new RC6Engine(), new KeyParameter(new byte[16])); - - // 64 bit block ciphers - testReset("DESEngine", new DESEngine(), new DESEngine(), new KeyParameter(new byte[8])); - testReset("BlowfishEngine", new BlowfishEngine(), new BlowfishEngine(), new KeyParameter(new byte[8])); - testReset("CAST5Engine", new CAST5Engine(), new CAST5Engine(), new KeyParameter(new byte[8])); - testReset("DESedeEngine", new DESedeEngine(), new DESedeEngine(), new KeyParameter(new byte[24])); - testReset("TEAEngine", new TEAEngine(), new TEAEngine(), new KeyParameter(new byte[16])); - testReset("XTEAEngine", new XTEAEngine(), new XTEAEngine(), new KeyParameter(new byte[16])); - - // primitive block cipher modes (don't reset on processBlock) - testModeReset("AES/CBC", new CBCBlockCipher(new AESEngine()), new CBCBlockCipher(new AESEngine()), - new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); - testModeReset("AES/SIC", new SICBlockCipher(new AESEngine()), new SICBlockCipher(new AESEngine()), - new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); - testModeReset("AES/CFB", new CFBBlockCipher(new AESEngine(), 128), new CFBBlockCipher(new AESEngine(), 128), - new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); - testModeReset("AES/OFB", new OFBBlockCipher(new AESEngine(), 128), new OFBBlockCipher(new AESEngine(), 128), - new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); - testModeReset("AES/GCTR", new GOFBBlockCipher(new DESEngine()), new GOFBBlockCipher(new DESEngine()), - new ParametersWithIV(new KeyParameter(new byte[8]), new byte[8])); - testModeReset("AES/OpenPGPCFB", new OpenPGPCFBBlockCipher(new AESEngine()), new OpenPGPCFBBlockCipher( - new AESEngine()), new KeyParameter(new byte[16])); - testModeReset("AES/PGPCFB", new PGPCFBBlockCipher(new AESEngine(), false), new PGPCFBBlockCipher( - new AESEngine(), false), new KeyParameter(new byte[16])); - - // PGPCFB with IV is broken (it's also not a PRP, so probably shouldn't be a BlockCipher) - // testModeReset("AES/PGPCFBwithIV", new PGPCFBBlockCipher(new AESEngine(), true), new - // PGPCFBBlockCipher( - // new AESEngine(), true), new ParametersWithIV(new KeyParameter(new byte[16]), new - // byte[16])); - // testModeReset("AES/PGPCFBwithIV_NoIV", new PGPCFBBlockCipher(new AESEngine(), true), new - // PGPCFBBlockCipher( - // new AESEngine(), true), new KeyParameter(new byte[16])); - - } - - private void testModeReset(String test, BlockCipher cipher1, BlockCipher cipher2, CipherParameters params) - throws InvalidCipherTextException - { - testReset(test, false, cipher1, cipher2, params); - } - - private void testReset(String test, BlockCipher cipher1, BlockCipher cipher2, CipherParameters params) - throws InvalidCipherTextException - { - testReset(test, true, cipher1, cipher2, params); - } - - private void testReset(String test, - boolean testCryptReset, - BlockCipher cipher1, - BlockCipher cipher2, - CipherParameters params) - throws InvalidCipherTextException - { - cipher1.init(true, params); - - byte[] plaintext = new byte[cipher1.getBlockSize()]; - byte[] ciphertext = new byte[(cipher1.getAlgorithmName().indexOf("PGPCFBwithIV")) > -1 ? 2 * cipher1.getBlockSize() + 2 - : cipher1.getBlockSize()]; - - // Establish baseline answer - crypt(cipher1, true, plaintext, ciphertext); - - // Test encryption resets - checkReset(test, testCryptReset, cipher1, params, true, plaintext, ciphertext); - - // Test decryption resets with fresh instance - cipher2.init(false, params); - checkReset(test, testCryptReset, cipher2, params, false, ciphertext, plaintext); - } - - private void checkReset(String test, - boolean testCryptReset, - BlockCipher cipher, - CipherParameters params, - boolean encrypt, - byte[] pretext, - byte[] posttext) - throws InvalidCipherTextException - { - // Do initial run - byte[] output = new byte[posttext.length]; - crypt(cipher, encrypt, pretext, output); - - // Check encrypt resets cipher - if (testCryptReset) - { - crypt(cipher, encrypt, pretext, output); - if (!Arrays.areEqual(output, posttext)) - { - fail(test + (encrypt ? " encrypt" : " decrypt") + " did not reset cipher."); - } - } - - // Check init resets data - cipher.processBlock(pretext, 0, output, 0); - cipher.init(encrypt, params); - - try - { - crypt(cipher, encrypt, pretext, output); - } - catch (DataLengthException e) - { - fail(test + " init did not reset data."); - } - if (!Arrays.areEqual(output, posttext)) - { - fail(test + " init did not reset data.", new String(Hex.encode(posttext)), new String(Hex.encode(output))); - } - - // Check reset resets data - cipher.processBlock(pretext, 0, output, 0); - cipher.reset(); - - try - { - crypt(cipher, encrypt, pretext, output); - } - catch (DataLengthException e) - { - fail(test + " reset did not reset data."); - } - if (!Arrays.areEqual(output, posttext)) - { - fail(test + " reset did not reset data."); - } - } - - private static void crypt(BlockCipher cipher1, boolean encrypt, byte[] plaintext, byte[] output) - throws InvalidCipherTextException - { - cipher1.processBlock(plaintext, 0, output, 0); - if ((cipher1.getAlgorithmName().indexOf("PGPCFBwithIV") > -1) && !encrypt) - { - // Process past IV in first block - cipher1.processBlock(plaintext, cipher1.getBlockSize(), output, 0); - } - } - - public static void main(String[] args) - { - runTest(new BlockCipherResetTest()); - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BlockCipherVectorTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BlockCipherVectorTest.java deleted file mode 100644 index 9d4719b6b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BlockCipherVectorTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.BufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * a basic test that takes a cipher, key parameter, and an input - * and output string. This test wraps the engine in a buffered block - * cipher with padding disabled. - */ -public class BlockCipherVectorTest - extends SimpleTest -{ - int id; - BlockCipher engine; - CipherParameters param; - byte[] input; - byte[] output; - - public BlockCipherVectorTest( - int id, - BlockCipher engine, - CipherParameters param, - String input, - String output) - { - this.id = id; - this.engine = engine; - this.param = param; - this.input = Hex.decode(input); - this.output = Hex.decode(output); - } - - public String getName() - { - return engine.getAlgorithmName() + " Vector Test " + id; - } - - public void performTest() - throws Exception - { - BufferedBlockCipher cipher = new BufferedBlockCipher(engine); - - cipher.init(true, param); - - byte[] out = new byte[input.length]; - - int len1 = cipher.processBytes(input, 0, input.length, out, 0); - - cipher.doFinal(out, len1); - - if (!areEqual(out, output)) - { - fail("failed - " + "expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - - cipher.init(false, param); - - int len2 = cipher.processBytes(output, 0, output.length, out, 0); - - cipher.doFinal(out, len2); - - if (!areEqual(input, out)) - { - System.out.println(" got " + new String(Hex.encode(out))); - - fail("failed reversal - " + "expected " + new String(Hex.encode(input))); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BlowfishTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BlowfishTest.java deleted file mode 100644 index d2918f324..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/BlowfishTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.BlowfishEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * blowfish tester - vectors from http://www.counterpane.com/vectors.txt - */ -public class BlowfishTest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new BlowfishEngine(), - new KeyParameter(Hex.decode("0000000000000000")), - "0000000000000000", "4EF997456198DD78"), - new BlockCipherVectorTest(1, new BlowfishEngine(), - new KeyParameter(Hex.decode("FFFFFFFFFFFFFFFF")), - "FFFFFFFFFFFFFFFF", "51866FD5B85ECB8A"), - new BlockCipherVectorTest(2, new BlowfishEngine(), - new KeyParameter(Hex.decode("3000000000000000")), - "1000000000000001", "7D856F9A613063F2"), - new BlockCipherVectorTest(3, new BlowfishEngine(), - new KeyParameter(Hex.decode("1111111111111111")), - "1111111111111111", "2466DD878B963C9D"), - new BlockCipherVectorTest(4, new BlowfishEngine(), - new KeyParameter(Hex.decode("0123456789ABCDEF")), - "1111111111111111", "61F9C3802281B096"), - new BlockCipherVectorTest(5, new BlowfishEngine(), - new KeyParameter(Hex.decode("FEDCBA9876543210")), - "0123456789ABCDEF", "0ACEAB0FC6A0A28D"), - new BlockCipherVectorTest(6, new BlowfishEngine(), - new KeyParameter(Hex.decode("7CA110454A1A6E57")), - "01A1D6D039776742", "59C68245EB05282B"), - new BlockCipherVectorTest(7, new BlowfishEngine(), - new KeyParameter(Hex.decode("0131D9619DC1376E")), - "5CD54CA83DEF57DA", "B1B8CC0B250F09A0"), - }; - - BlowfishTest() - { - super(tests, new BlowfishEngine(), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "Blowfish"; - } - - public static void main( - String[] args) - { - runTest(new BlowfishTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CAST5Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CAST5Test.java deleted file mode 100644 index a74ad9647..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CAST5Test.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.CAST5Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * cast tester - vectors from http://www.ietf.org/rfc/rfc2144.txt - */ -public class CAST5Test - extends CipherTest -{ - static SimpleTest[] tests = { - new BlockCipherVectorTest(0, new CAST5Engine(), - new KeyParameter(Hex.decode("0123456712345678234567893456789A")), - "0123456789ABCDEF", - "238B4FE5847E44B2"), - new BlockCipherVectorTest(0, new CAST5Engine(), - new KeyParameter(Hex.decode("01234567123456782345")), - "0123456789ABCDEF", - "EB6A711A2C02271B"), - new BlockCipherVectorTest(0, new CAST5Engine(), - new KeyParameter(Hex.decode("0123456712")), - "0123456789ABCDEF", - "7Ac816d16E9B302E"), - }; - - CAST5Test() - { - super(tests, new CAST5Engine(), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "CAST5"; - } - - public static void main( - String[] args) - { - runTest(new CAST5Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CAST6Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CAST6Test.java deleted file mode 100644 index ccb541387..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CAST6Test.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.CAST6Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * cast6 tester - vectors from http://www.ietf.org/rfc/rfc2612.txt - */ -public class CAST6Test - extends CipherTest -{ - static SimpleTest[] tests = { - new BlockCipherVectorTest(0, new CAST6Engine(), - new KeyParameter(Hex.decode("2342bb9efa38542c0af75647f29f615d")), - "00000000000000000000000000000000", - "c842a08972b43d20836c91d1b7530f6b"), - new BlockCipherVectorTest(0, new CAST6Engine(), - new KeyParameter(Hex.decode("2342bb9efa38542cbed0ac83940ac298bac77a7717942863")), - "00000000000000000000000000000000", - "1b386c0210dcadcbdd0e41aa08a7a7e8"), - new BlockCipherVectorTest(0, new CAST6Engine(), - new KeyParameter(Hex.decode("2342bb9efa38542cbed0ac83940ac2988d7c47ce264908461cc1b5137ae6b604")), - "00000000000000000000000000000000", - "4f6a2038286897b9c9870136553317fa") - }; - - CAST6Test() - { - super(tests, new CAST6Engine(), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "CAST6"; - } - - public static void main( - String[] args) - { - runTest(new CAST6Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CCMTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CCMTest.java deleted file mode 100644 index a5ae696ea..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CCMTest.java +++ /dev/null @@ -1,305 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.modes.CCMBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.AEADParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * First four test vectors from - * NIST Special Publication 800-38C. - */ -public class CCMTest - extends SimpleTest -{ - private byte[] K1 = Hex.decode("404142434445464748494a4b4c4d4e4f"); - private byte[] N1 = Hex.decode("10111213141516"); - private byte[] A1 = Hex.decode("0001020304050607"); - private byte[] P1 = Hex.decode("20212223"); - private byte[] C1 = Hex.decode("7162015b4dac255d"); - private byte[] T1 = Hex.decode("6084341b"); - - private byte[] K2 = Hex.decode("404142434445464748494a4b4c4d4e4f"); - private byte[] N2 = Hex.decode("1011121314151617"); - private byte[] A2 = Hex.decode("000102030405060708090a0b0c0d0e0f"); - private byte[] P2 = Hex.decode("202122232425262728292a2b2c2d2e2f"); - private byte[] C2 = Hex.decode("d2a1f0e051ea5f62081a7792073d593d1fc64fbfaccd"); - private byte[] T2 = Hex.decode("7f479ffca464"); - - private byte[] K3 = Hex.decode("404142434445464748494a4b4c4d4e4f"); - private byte[] N3 = Hex.decode("101112131415161718191a1b"); - private byte[] A3 = Hex.decode("000102030405060708090a0b0c0d0e0f10111213"); - private byte[] P3 = Hex.decode("202122232425262728292a2b2c2d2e2f3031323334353637"); - private byte[] C3 = Hex.decode("e3b201a9f5b71a7a9b1ceaeccd97e70b6176aad9a4428aa5484392fbc1b09951"); - private byte[] T3 = Hex.decode("67c99240c7d51048"); - - private byte[] K4 = Hex.decode("404142434445464748494a4b4c4d4e4f"); - private byte[] N4 = Hex.decode("101112131415161718191a1b1c"); - private byte[] A4 = Hex.decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"); - private byte[] P4 = Hex.decode("202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f"); - private byte[] C4 = Hex.decode("69915dad1e84c6376a68c2967e4dab615ae0fd1faec44cc484828529463ccf72b4ac6bec93e8598e7f0dadbcea5b"); - private byte[] T4 = Hex.decode("f4dd5d0ee404617225ffe34fce91"); - - // - // long data vector - // - private byte[] C5 = Hex.decode("49b17d8d3ea4e6174a48e2b65e6d8b417ac0dd3f8ee46ce4a4a2a509661cef52528c1cd9805333a5cfd482fa3f095a3c2fdd1cc47771c5e55fddd60b5c8d6d3fa5c8dd79d08b16242b6642106e7c0c28bd1064b31e6d7c9800c8397dbc3fa8071e6a38278b386c18d65d39c6ad1ef9501a5c8f68d38eb6474799f3cc898b4b9b97e87f9c95ce5c51bc9d758f17119586663a5684e0a0daf6520ec572b87473eb141d10471e4799ded9e607655402eca5176bbf792ef39dd135ac8d710da8e9e854fd3b95c681023f36b5ebe2fb213d0b62dd6e9e3cfe190b792ccb20c53423b2dca128f861a61d306910e1af418839467e466f0ec361d2539eedd99d4724f1b51c07beb40e875a87491ec8b27cd1"); - private byte[] T5 = Hex.decode("5c768856796b627b13ec8641581b"); - - public void performTest() - throws Exception - { - CCMBlockCipher ccm = new CCMBlockCipher(new AESEngine()); - - checkVectors(0, ccm, K1, 32, N1, A1, P1, T1, C1); - checkVectors(1, ccm, K2, 48, N2, A2, P2, T2, C2); - checkVectors(2, ccm, K3, 64, N3, A3, P3, T3, C3); - - ivParamTest(0, ccm, K1, N1); - - // - // 4 has a reduced associated text which needs to be replicated - // - byte[] a4 = new byte[65536]; // 524288 / 8 - - for (int i = 0; i < a4.length; i += A4.length) - { - System.arraycopy(A4, 0, a4, i, A4.length); - } - - checkVectors(3, ccm, K4, 112, N4, a4, P4, T4, C4); - - // - // long data test - // - checkVectors(4, ccm, K4, 112, N4, A4, A4, T5, C5); - - // decryption with output specified, non-zero offset. - ccm.init(false, new AEADParameters(new KeyParameter(K2), 48, N2, A2)); - - byte[] inBuf = new byte[C2.length + 10]; - byte[] outBuf = new byte[ccm.getOutputSize(C2.length) + 10]; - - System.arraycopy(C2, 0, inBuf, 10, C2.length); - - int len = ccm.processPacket(inBuf, 10, C2.length, outBuf, 10); - byte[] out = ccm.processPacket(C2, 0, C2.length); - - if (len != out.length || !isEqual(out, outBuf, 10)) - { - fail("decryption output incorrect"); - } - - // encryption with output specified, non-zero offset. - ccm.init(true, new AEADParameters(new KeyParameter(K2), 48, N2, A2)); - - int inLen = len; - inBuf = outBuf; - outBuf = new byte[ccm.getOutputSize(inLen) + 10]; - - len = ccm.processPacket(inBuf, 10, inLen, outBuf, 10); - out = ccm.processPacket(inBuf, 10, inLen); - - if (len != out.length || !isEqual(out, outBuf, 10)) - { - fail("encryption output incorrect"); - } - - // - // exception tests - // - - try - { - ccm.init(false, new AEADParameters(new KeyParameter(K1), 32, N2, A2)); - - ccm.processPacket(C2, 0, C2.length); - - fail("invalid cipher text not picked up"); - } - catch (InvalidCipherTextException e) - { - // expected - } - - try - { - ccm = new CCMBlockCipher(new DESEngine()); - - fail("incorrect block size not picked up"); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - ccm.init(false, new KeyParameter(K1)); - - fail("illegal argument not picked up"); - } - catch (IllegalArgumentException e) - { - // expected - } - - AEADTestUtil.testReset(this, new CCMBlockCipher(new AESEngine()), new CCMBlockCipher(new AESEngine()), new AEADParameters(new KeyParameter(K1), 32, N2)); - AEADTestUtil.testTampering(this, ccm, new AEADParameters(new KeyParameter(K1), 32, N2)); - AEADTestUtil.testOutputSizes(this, new CCMBlockCipher(new AESEngine()), new AEADParameters( - new KeyParameter(K1), 32, N2)); - AEADTestUtil.testBufferSizeChecks(this, new CCMBlockCipher(new AESEngine()), new AEADParameters( - new KeyParameter(K1), 32, N2)); - } - - private boolean isEqual(byte[] exp, byte[] other, int off) - { - for (int i = 0; i != exp.length; i++) - { - if (exp[i] != other[off + i]) - { - return false; - } - } - - return true; - } - - private void checkVectors( - int count, - CCMBlockCipher ccm, - byte[] k, - int macSize, - byte[] n, - byte[] a, - byte[] p, - byte[] t, - byte[] c) - throws InvalidCipherTextException - { - byte[] fa = new byte[a.length / 2]; - byte[] la = new byte[a.length - (a.length / 2)]; - System.arraycopy(a, 0, fa, 0, fa.length); - System.arraycopy(a, fa.length, la, 0, la.length); - - checkVectors(count, ccm, "all initial associated data", k, macSize, n, a, null, p, t, c); - checkVectors(count, ccm, "subsequent associated data", k, macSize, n, null, a, p, t, c); - checkVectors(count, ccm, "split associated data", k, macSize, n, fa, la, p, t, c); - checkVectors(count, ccm, "reuse key", null, macSize, n, fa, la, p, t, c); - } - - private void checkVectors( - int count, - CCMBlockCipher ccm, - String additionalDataType, - byte[] k, - int macSize, - byte[] n, - byte[] a, - byte[] sa, - byte[] p, - byte[] t, - byte[] c) - throws InvalidCipherTextException - { - KeyParameter keyParam = (k == null) ? null : new KeyParameter(k); - - ccm.init(true, new AEADParameters(keyParam, macSize, n, a)); - - byte[] enc = new byte[c.length]; - - if (sa != null) - { - ccm.processAADBytes(sa, 0, sa.length); - } - - int len = ccm.processBytes(p, 0, p.length, enc, 0); - - len += ccm.doFinal(enc, len); - - if (!areEqual(c, enc)) - { - fail("encrypted stream fails to match in test " + count + " with " + additionalDataType); - } - - ccm.init(false, new AEADParameters(keyParam, macSize, n, a)); - - byte[] tmp = new byte[enc.length]; - - if (sa != null) - { - ccm.processAADBytes(sa, 0, sa.length); - } - - len = ccm.processBytes(enc, 0, enc.length, tmp, 0); - - len += ccm.doFinal(tmp, len); - - byte[] dec = new byte[len]; - - System.arraycopy(tmp, 0, dec, 0, len); - - if (!areEqual(p, dec)) - { - fail("decrypted stream fails to match in test " + count + " with " + additionalDataType, - new String(Hex.encode(p)), new String(Hex.encode(dec))); - } - - if (!areEqual(t, ccm.getMac())) - { - fail("MAC fails to match in test " + count + " with " + additionalDataType); - } - } - - private void ivParamTest( - int count, - CCMBlockCipher ccm, - byte[] k, - byte[] n) - throws InvalidCipherTextException - { - byte[] p = Strings.toByteArray("hello world!!"); - - ccm.init(true, new ParametersWithIV(new KeyParameter(k), n)); - - byte[] enc = new byte[p.length + 8]; - - int len = ccm.processBytes(p, 0, p.length, enc, 0); - - len += ccm.doFinal(enc, len); - - ccm.init(false, new ParametersWithIV(new KeyParameter(k), n)); - - byte[] tmp = new byte[enc.length]; - - len = ccm.processBytes(enc, 0, enc.length, tmp, 0); - - len += ccm.doFinal(tmp, len); - - byte[] dec = new byte[len]; - - System.arraycopy(tmp, 0, dec, 0, len); - - if (!areEqual(p, dec)) - { - fail("decrypted stream fails to match in test " + count); - } - } - - public String getName() - { - return "CCM"; - } - - public static void main( - String[] args) - { - runTest(new CCMTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CMacTest.java deleted file mode 100644 index 2410d7732..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CMacTest.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.AESFastEngine; -import com.fr.third.org.bouncycastle.crypto.engines.BlowfishEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESedeEngine; -import com.fr.third.org.bouncycastle.crypto.engines.RijndaelEngine; -import com.fr.third.org.bouncycastle.crypto.engines.Shacal2Engine; -import com.fr.third.org.bouncycastle.crypto.macs.CMac; -import com.fr.third.org.bouncycastle.crypto.macs.CMacWithIV; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * CMAC tester - Official Test Vectors. - */ -public class CMacTest - extends SimpleTest -{ - private static final byte[] keyBytes128 = Hex.decode("2b7e151628aed2a6abf7158809cf4f3c"); - private static final byte[] keyBytes192 = Hex.decode( - "8e73b0f7da0e6452c810f32b809079e5" - + "62f8ead2522c6b7b"); - private static final byte[] keyBytes256 = Hex.decode( - "603deb1015ca71be2b73aef0857d7781" - + "1f352c073b6108d72d9810a30914dff4"); - - private static final byte[] input0 = Hex.decode(""); - private static final byte[] input16 = Hex.decode("6bc1bee22e409f96e93d7e117393172a"); - private static final byte[] input40 = Hex.decode( - "6bc1bee22e409f96e93d7e117393172a" - + "ae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411"); - private static final byte[] input64 = Hex.decode( - "6bc1bee22e409f96e93d7e117393172a" - + "ae2d8a571e03ac9c9eb76fac45af8e51" - + "30c81c46a35ce411e5fbc1191a0a52ef" - + "f69f2445df4f9b17ad2b417be66c3710"); - - private static final byte[] output_k128_m0 = Hex.decode("bb1d6929e95937287fa37d129b756746"); - private static final byte[] output_k128_m16 = Hex.decode("070a16b46b4d4144f79bdd9dd04a287c"); - private static final byte[] output_k128_m40 = Hex.decode("dfa66747de9ae63030ca32611497c827"); - private static final byte[] output_k128_m64 = Hex.decode("51f0bebf7e3b9d92fc49741779363cfe"); - - private static final byte[] output_k192_m0 = Hex.decode("d17ddf46adaacde531cac483de7a9367"); - private static final byte[] output_k192_m16 = Hex.decode("9e99a7bf31e710900662f65e617c5184"); - private static final byte[] output_k192_m40 = Hex.decode("8a1de5be2eb31aad089a82e6ee908b0e"); - private static final byte[] output_k192_m64 = Hex.decode("a1d5df0eed790f794d77589659f39a11"); - - private static final byte[] output_k256_m0 = Hex.decode("028962f61b7bf89efc6b551f4667d983"); - private static final byte[] output_k256_m16 = Hex.decode("28a7023f452e8f82bd4bf28d8c37c35c"); - private static final byte[] output_k256_m40 = Hex.decode("aaf3d8f1de5640c232f5b169b9c911e6"); - private static final byte[] output_k256_m64 = Hex.decode("e1992190549f6ed5696a2c056c315410"); - - private static final byte[] output_des_ede = Hex.decode("1ca670dea381d37c"); - - private static final byte[] general_input = Strings.toByteArray("The quick brown fox jumps over the lazy dog."); - - public CMacTest() - { - } - - public void performTest() - { - BlockCipher cipher = new AESFastEngine(); - Mac mac = new CMac(cipher, 128); - - //128 bytes key - - KeyParameter key = new KeyParameter(keyBytes128); - - // 0 bytes message - 128 bytes key - mac.init(key); - - mac.update(input0, 0, input0.length); - - byte[] out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k128_m0)) - { - fail("Failed - expected " + new String(Hex.encode(output_k128_m0)) - + " got " + new String(Hex.encode(out))); - } - - // 16 bytes message - 128 bytes key - mac.init(key); - - mac.update(input16, 0, input16.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k128_m16)) - { - fail("Failed - expected " + new String(Hex.encode(output_k128_m16)) - + " got " + new String(Hex.encode(out))); - } - - // 40 bytes message - 128 bytes key - mac.init(key); - - mac.update(input40, 0, input40.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k128_m40)) - { - fail("Failed - expected " + new String(Hex.encode(output_k128_m40)) - + " got " + new String(Hex.encode(out))); - } - - // 64 bytes message - 128 bytes key - mac.init(key); - - mac.update(input64, 0, input64.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k128_m64)) - { - fail("Failed - expected " + new String(Hex.encode(output_k128_m64)) - + " got " + new String(Hex.encode(out))); - } - - //192 bytes key - - key = new KeyParameter(keyBytes192); - - // 0 bytes message - 192 bytes key - mac.init(key); - - mac.update(input0, 0, input0.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k192_m0)) - { - fail("Failed - expected " + new String(Hex.encode(output_k192_m0)) - + " got " + new String(Hex.encode(out))); - } - - // 16 bytes message - 192 bytes key - mac.init(key); - - mac.update(input16, 0, input16.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k192_m16)) - { - fail("Failed - expected " + new String(Hex.encode(output_k192_m16)) - + " got " + new String(Hex.encode(out))); - } - - // 40 bytes message - 192 bytes key - mac.init(key); - - mac.update(input40, 0, input40.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k192_m40)) - { - fail("Failed - expected " + new String(Hex.encode(output_k192_m40)) - + " got " + new String(Hex.encode(out))); - } - - // 64 bytes message - 192 bytes key - mac.init(key); - - mac.update(input64, 0, input64.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k192_m64)) - { - fail("Failed - expected " + new String(Hex.encode(output_k192_m64)) - + " got " + new String(Hex.encode(out))); - } - - //256 bytes key - - key = new KeyParameter(keyBytes256); - - // 0 bytes message - 256 bytes key - mac.init(key); - - mac.update(input0, 0, input0.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k256_m0)) - { - fail("Failed - expected " + new String(Hex.encode(output_k256_m0)) - + " got " + new String(Hex.encode(out))); - } - - // 16 bytes message - 256 bytes key - mac.init(key); - - mac.update(input16, 0, input16.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k256_m16)) - { - fail("Failed - expected " + new String(Hex.encode(output_k256_m16)) - + " got " + new String(Hex.encode(out))); - } - - // 40 bytes message - 256 bytes key - mac.init(key); - - mac.update(input40, 0, input40.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k256_m40)) - { - fail("Failed - expected " + new String(Hex.encode(output_k256_m40)) - + " got " + new String(Hex.encode(out))); - } - - // 64 bytes message - 256 bytes key - mac.init(key); - - mac.update(input64, 0, input64.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k256_m64)) - { - fail("Failed - expected " + new String(Hex.encode(output_k256_m64)) - + " got " + new String(Hex.encode(out))); - } - - // CMAC with IV - // 16 bytes message - 256 bytes key - mac = new CMacWithIV(new AESFastEngine()); - - mac.init(key); - - mac.update(input16, 0, input16.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output_k256_m16)) - { - fail("Failed - expected " + new String(Hex.encode(output_k256_m16)) - + " got " + new String(Hex.encode(out))); - } - - // CMAC with IV - // 16 bytes message - 256 bytes key - mac = new CMacWithIV(new AESFastEngine()); - - mac.init(new ParametersWithIV(key, Hex.decode("000102030405060708090a0b0c0d0e0f"))); - - mac.update(input16, 0, input16.length); - - out = new byte[16]; - - mac.doFinal(out, 0); - - if (areEqual(out, output_k256_m16)) - { - fail("Failed - got " + new String(Hex.encode(output_k256_m16))); - } - - if (!areEqual(out, Hex.decode("9347a60c64061b9ff2a92522ca8e08fc"))) - { - fail("Failed - expected " + "9347a60c64061b9ff2a92522ca8e08fc" - + " got " + new String(Hex.encode(out))); - } - - testCMac(new DESedeEngine(), keyBytes128, input0, output_des_ede); - - testCMac(new RijndaelEngine(), "2b7e151628aed2a6abf7158809cf4f3c", "682b9b57e769cc63231cf778c5c76646"); - testCMac(new RijndaelEngine(192), "2b7e151628aed2a6abf7158809cf4f3c", "2a11b6bdd1e4f8b6127c2960859ae73ede59c7200d77ff45"); - testCMac(new RijndaelEngine(256), "2b7e151628aed2a6abf7158809cf4f3c", "316d1df4084ada3e10b26266ae1fdae170a9d824ab37e981f06227c80c80fddd"); - testCMac(new BlowfishEngine(), "2b7e151628aed2a6abf7158809cf4f3c", "875d73b9bc3de78a"); - testCMac(new DESEngine(), "2b7e151628aed2a6", "3cc3a242585e49f9"); - testCMac(new Shacal2Engine(), "2b7e151628aed2a6abf7158809cf4f3c", "794b2766cd0d550877f1ded48ab74f9ddff20f32e6d69fae8a1ede4205e7d640"); - - testExceptions(); - } - - private void testCMac(BlockCipher cipher, String keyBytes, String expected) - { - testCMac(cipher, Hex.decode(keyBytes), general_input, Hex.decode(expected)); - } - - private void testCMac(BlockCipher cipher, byte[] keyBytes, byte[] input, byte[] expected) - { - Mac mac = new CMac(cipher, cipher.getBlockSize() * 8); - - KeyParameter key = new KeyParameter(keyBytes); - - mac.init(key); - - mac.update(input, 0, input.length); - - byte[] out = new byte[mac.getMacSize()]; - - mac.doFinal(out, 0); - - if (!areEqual(out, expected)) - { - fail("Failed - expected " + Strings.fromByteArray(Hex.encode(expected)) + " got " + new String(Hex.encode(out))); - } - } - - private void testExceptions() - { - try - { - CMac mac = new CMac(new AESEngine()); - mac.init(new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); - fail("CMac does not accept IV"); - } catch(IllegalArgumentException e) - { - // Expected - } - } - - public String getName() - { - return "CMac"; - } - - public static void main(String[] args) - { - runTest(new CMacTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CSHAKETest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CSHAKETest.java deleted file mode 100644 index 029190fb5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CSHAKETest.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.CSHAKEDigest; -import com.fr.third.org.bouncycastle.crypto.digests.SHAKEDigest; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * CSHAKE test vectors from: - * - * https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/cSHAKE_samples.pdf - */ -public class CSHAKETest - extends SimpleTest -{ - public String getName() - { - return "CSHAKE"; - } - - public void performTest() - throws Exception - { - CSHAKEDigest cshake = new CSHAKEDigest(128, new byte[0], Strings.toByteArray("Email Signature")); - - cshake.update(Hex.decode("00010203"), 0, 4); - - byte[] res = new byte[32]; - - cshake.doOutput(res, 0, res.length); - - isTrue("oops!", Arrays.areEqual(Hex.decode("c1c36925b6409a04f1b504fcbca9d82b4017277cb5ed2b2065fc1d3814d5aaf5"), res)); - - cshake = new CSHAKEDigest(128, new byte[0], Strings.toByteArray("Email Signature")); - - cshake.update(Hex.decode( - "000102030405060708090A0B0C0D0E0F" + - "101112131415161718191A1B1C1D1E1F" + - "202122232425262728292A2B2C2D2E2F" + - "303132333435363738393A3B3C3D3E3F" + - "404142434445464748494A4B4C4D4E4F" + - "505152535455565758595A5B5C5D5E5F" + - "606162636465666768696A6B6C6D6E6F" + - "707172737475767778797A7B7C7D7E7F" + - "808182838485868788898A8B8C8D8E8F" + - "909192939495969798999A9B9C9D9E9F" + - "A0A1A2A3A4A5A6A7A8A9AAABACADAEAF" + - "B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF" + - "C0C1C2C3C4C5C6C7"), 0, 1600 / 8); - - res = new byte[32]; - - cshake.doOutput(res, 0, res.length); - - isTrue(Arrays.areEqual(Hex.decode("C5221D50E4F822D96A2E8881A961420F294B7B24FE3D2094BAED2C6524CC166B "), res)); - - cshake = new CSHAKEDigest(256, new byte[0], Strings.toByteArray("Email Signature")); - - cshake.update(Hex.decode("00010203"), 0, 4); - - res = new byte[64]; - - cshake.doOutput(res, 0, res.length); - - isTrue(Arrays.areEqual(Hex.decode( - "D008828E2B80AC9D2218FFEE1D070C48"+ - "B8E4C87BFF32C9699D5B6896EEE0EDD1"+ - "64020E2BE0560858D9C00C037E34A969"+ - "37C561A74C412BB4C746469527281C8C"),res)); - - cshake = new CSHAKEDigest(256, new byte[0], Strings.toByteArray("Email Signature")); - - cshake.update(Hex.decode( - "000102030405060708090A0B0C0D0E0F" + - "101112131415161718191A1B1C1D1E1F" + - "202122232425262728292A2B2C2D2E2F" + - "303132333435363738393A3B3C3D3E3F" + - "404142434445464748494A4B4C4D4E4F" + - "505152535455565758595A5B5C5D5E5F" + - "606162636465666768696A6B6C6D6E6F" + - "707172737475767778797A7B7C7D7E7F" + - "808182838485868788898A8B8C8D8E8F" + - "909192939495969798999A9B9C9D9E9F" + - "A0A1A2A3A4A5A6A7A8A9AAABACADAEAF" + - "B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF" + - "C0C1C2C3C4C5C6C7"), 0, 1600 / 8); - - res = new byte[64]; - - cshake.doOutput(res, 0, res.length); - - isTrue(Arrays.areEqual(Hex.decode( - "07DC27B11E51FBAC75BC7B3C1D983E8B"+ - "4B85FB1DEFAF218912AC864302730917"+ - "27F42B17ED1DF63E8EC118F04B23633C"+ - "1DFB1574C8FB55CB45DA8E25AFB092BB"), res)); - - doFinalTest(); - longBlockTest(); - - checkSHAKE(128, new CSHAKEDigest(128, new byte[0], new byte[0]), Hex.decode("eeaabeef")); - checkSHAKE(256, new CSHAKEDigest(256, new byte[0], null), Hex.decode("eeaabeef")); - checkSHAKE(128, new CSHAKEDigest(128, null, new byte[0]), Hex.decode("eeaabeef")); - checkSHAKE(128, new CSHAKEDigest(128, null, null), Hex.decode("eeaabeef")); - checkSHAKE(256, new CSHAKEDigest(256, null, null), Hex.decode("eeaabeef")); - } - - private void doFinalTest() - { - CSHAKEDigest cshake = new CSHAKEDigest(128, new byte[0], Strings.toByteArray("Email Signature")); - - cshake.update(Hex.decode("00010203"), 0, 4); - - byte[] res = new byte[32]; - - cshake.doOutput(res, 0, res.length); - - isTrue(Arrays.areEqual(Hex.decode("c1c36925b6409a04f1b504fcbca9d82b4017277cb5ed2b2065fc1d3814d5aaf5"), res)); - - cshake.doOutput(res, 0, res.length); - - isTrue(!Arrays.areEqual(Hex.decode("c1c36925b6409a04f1b504fcbca9d82b4017277cb5ed2b2065fc1d3814d5aaf5"), res)); - - cshake.doFinal(res, 0, res.length); - - cshake.update(Hex.decode("00010203"), 0, 4); - - cshake.doFinal(res, 0, res.length); - - isTrue(Arrays.areEqual(Hex.decode("c1c36925b6409a04f1b504fcbca9d82b4017277cb5ed2b2065fc1d3814d5aaf5"), res)); - - cshake.update(Hex.decode("00010203"), 0, 4); - - cshake.doOutput(res, 0, res.length); - - isTrue(Arrays.areEqual(Hex.decode("c1c36925b6409a04f1b504fcbca9d82b4017277cb5ed2b2065fc1d3814d5aaf5"), res)); - - cshake.doFinal(res, 0, res.length); - - isTrue(Arrays.areEqual(Hex.decode("9cbce830079c452abdeb875366a49ebfe75b89ef17396e34898e904830b0e136"), res)); - } - - private void longBlockTest() - { - byte[] data = new byte[16000]; - byte[] res = new byte[32]; - - for (int i = 0; i != data.length; i++) - { - data[i] = (byte)i; - } - - for (int i = 10000; i != data.length; i++) - { - CSHAKEDigest cshake = new CSHAKEDigest(128, new byte[0], Arrays.copyOfRange(data, 0, i)); - - cshake.update(Hex.decode("00010203"), 0, 4); - - cshake.doFinal(res, 0); - } - - CSHAKEDigest cshake = new CSHAKEDigest(256, new byte[0], new byte[200]); - - cshake.update(Arrays.copyOfRange(data, 0, 200), 0, 200); - - cshake.doFinal(res, 0); - - isTrue(Arrays.areEqual(Hex.decode("4a899b5be460d85a9789215bc17f88b8f8ac049bd3b519f561e7b5d3870dafa3"), res)); - } - - private void checkSHAKE(int bitSize, CSHAKEDigest cshake, byte[] msg) - { - SHAKEDigest ref = new SHAKEDigest(bitSize); - - ref.update(msg, 0, msg.length); - cshake.update(msg, 0, msg.length); - - byte[] res1 = new byte[32]; - byte[] res2 = new byte[32]; - - ref.doFinal(res1, 0, res1.length); - cshake.doFinal(res2, 0, res2.length); - - isTrue(Arrays.areEqual(res1, res2)); - } - public static void main( - String[] args) - { - runTest(new CSHAKETest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CTSTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CTSTest.java deleted file mode 100644 index debd14668..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CTSTest.java +++ /dev/null @@ -1,218 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.BufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.SkipjackEngine; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CTSBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.OldCTSBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.SICBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * CTS tester - */ -public class CTSTest - extends SimpleTest -{ - static byte[] in1 = Hex.decode("4e6f7720697320746865207420"); - static byte[] in2 = Hex.decode("000102030405060708090a0b0c0d0e0fff0102030405060708090a0b0c0d0e0f0aaa"); - static byte[] out1 = Hex.decode("9952f131588465033fa40e8a98"); - static byte[] out2 = Hex.decode("358f84d01eb42988dc34efb994"); - static byte[] out3 = Hex.decode("170171cfad3f04530c509b0c1f0be0aefbd45a8e3755a873bff5ea198504b71683c6"); - - private void testCTS( - int id, - BlockCipher cipher, - CipherParameters params, - byte[] input, - byte[] output) - throws Exception - { - byte[] out = new byte[input.length]; - BufferedBlockCipher engine = new CTSBlockCipher(cipher); - - engine.init(true, params); - - int len = engine.processBytes(input, 0, input.length, out, 0); - - engine.doFinal(out, len); - - if (!areEqual(output, out)) - { - fail("failed encryption expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - - engine.init(false, params); - - len = engine.processBytes(output, 0, output.length, out, 0); - - engine.doFinal(out, len); - - if (!areEqual(input, out)) - { - fail("failed decryption expected " + new String(Hex.encode(input)) + " got " + new String(Hex.encode(out))); - } - } - - private void testOldCTS( - int id, - BlockCipher cipher, - CipherParameters params, - byte[] input, - byte[] output) - throws Exception - { - byte[] out = new byte[input.length]; - BufferedBlockCipher engine = new OldCTSBlockCipher(cipher); - - engine.init(true, params); - - int len = engine.processBytes(input, 0, input.length, out, 0); - - engine.doFinal(out, len); - - if (!areEqual(output, out)) - { - fail("failed encryption expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - - engine.init(false, params); - - len = engine.processBytes(output, 0, output.length, out, 0); - - engine.doFinal(out, len); - - if (!areEqual(input, out)) - { - fail("failed decryption expected " + new String(Hex.encode(input)) + " got " + new String(Hex.encode(out))); - } - } - - private void testExceptions() throws InvalidCipherTextException - { - BufferedBlockCipher engine = new CTSBlockCipher(new DESEngine()); - CipherParameters params = new KeyParameter(new byte[engine.getBlockSize()]); - engine.init(true, params); - - byte[] out = new byte[engine.getOutputSize(engine.getBlockSize())]; - - engine.processBytes(new byte[engine.getBlockSize() - 1], 0, engine.getBlockSize() - 1, out, 0); - try - { - engine.doFinal(out, 0); - fail("Expected CTS encrypt error on < 1 block input"); - } catch(DataLengthException e) - { - // Expected - } - - engine.init(true, params); - engine.processBytes(new byte[engine.getBlockSize()], 0, engine.getBlockSize(), out, 0); - try - { - engine.doFinal(out, 0); - } catch(DataLengthException e) - { - fail("Unexpected CTS encrypt error on == 1 block input"); - } - - engine.init(false, params); - engine.processBytes(new byte[engine.getBlockSize() - 1], 0, engine.getBlockSize() - 1, out, 0); - try - { - engine.doFinal(out, 0); - fail("Expected CTS decrypt error on < 1 block input"); - } catch(DataLengthException e) - { - // Expected - } - - engine.init(false, params); - engine.processBytes(new byte[engine.getBlockSize()], 0, engine.getBlockSize(), out, 0); - try - { - engine.doFinal(out, 0); - } catch(DataLengthException e) - { - fail("Unexpected CTS decrypt error on == 1 block input"); - } - - try - { - new CTSBlockCipher(new SICBlockCipher(new AESEngine())); - fail("Expected CTS construction error - only ECB/CBC supported."); - } catch(IllegalArgumentException e) - { - // Expected - } - - } - - public String getName() - { - return "CTS"; - } - - public void performTest() - throws Exception - { - byte[] key1 = { (byte)0x01, (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x89, (byte)0xAB, (byte)0xCD, (byte)0xEF }; - byte[] key2 = { (byte)0x01, (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x89, (byte)0xAB, (byte)0xCD, (byte)0xEF, (byte)0xee, (byte)0xff }; - byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 }; - - testCTS(1, new DESEngine(), new KeyParameter(key1), in1, out1); - testCTS(2, new CBCBlockCipher(new DESEngine()), new ParametersWithIV(new KeyParameter(key1), iv), in1, out2); - testCTS(3, new CBCBlockCipher(new SkipjackEngine()), new ParametersWithIV(new KeyParameter(key2), iv), in2, out3); - - // - // test vectors from rfc3962 - // - byte[] aes128 = Hex.decode("636869636b656e207465726979616b69"); - byte[] aesIn1 = Hex.decode("4920776f756c64206c696b652074686520"); - byte[] aesOut1 = Hex.decode("c6353568f2bf8cb4d8a580362da7ff7f97"); - byte[] aesIn2 = Hex.decode("4920776f756c64206c696b65207468652047656e6572616c20476175277320"); - byte[] aesOut2 = Hex.decode("fc00783e0efdb2c1d445d4c8eff7ed2297687268d6ecccc0c07b25e25ecfe5"); - byte[] aesIn3 = Hex.decode("4920776f756c64206c696b65207468652047656e6572616c2047617527732043"); - byte[] aesOut3 = Hex.decode("39312523a78662d5be7fcbcc98ebf5a897687268d6ecccc0c07b25e25ecfe584"); - - testCTS(4, new CBCBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(aes128), new byte[16]), aesIn1, aesOut1); - testCTS(5, new CBCBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(aes128), new byte[16]), aesIn2, aesOut2); - testCTS(6, new CBCBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(aes128), new byte[16]), aesIn3, aesOut3); - - testOldCTS(4, new CBCBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(aes128), new byte[16]), aesIn1, aesOut1); - testOldCTS(5, new CBCBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(aes128), new byte[16]), aesIn2, aesOut2); - testOldCTS(6, new CBCBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(aes128), new byte[16]), aesIn3, aesOut3); - - byte[] aes1Block = Hex.decode("4920776f756c64206c696b6520746865"); - byte[] preErrata = Hex.decode("e7664c13ff28c965b0d2a0e7ec353706"); // CTS style one block - byte[] pstErrata = Hex.decode("97687268d6ecccc0c07b25e25ecfe584"); // CBC style one block - byte[] pstErrataNonZeroIV = Hex.decode("571f5108c53fe95ab52df783df933fa3"); - - testCTS(7, new CBCBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(aes128), new byte[16]), aes1Block, pstErrata); - testCTS(8, new CBCBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(aes128), aes1Block), aes1Block, pstErrataNonZeroIV); - testOldCTS(9, new CBCBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(aes128), new byte[16]), aes1Block, preErrata); - - byte[] aes128b = Hex.decode("aafd12f659cae63489b479e5076ddec2f06cb58faafd12f6"); - byte[] aesIn1b = Hex.decode("000102030405060708090a0b0c0d0e0fff0102030405060708090a0b0c0d0e0f"); - byte[] aesOut1b = Hex.decode("6db2f802d99e1ef0a5940f306079e083cf87f4d8bb9d1abb36cdd9f44ead7d04"); - - testCTS(10, new CBCBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(aes128b), Hex.decode("aafd12f659cae63489b479e5076ddec2")), aesIn1b, aesOut1b); - - testExceptions(); - } - - public static void main( - String[] args) - { - runTest(new CTSTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CamelliaLightTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CamelliaLightTest.java deleted file mode 100644 index 1d748d603..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CamelliaLightTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.CamelliaLightEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Camellia tester - vectors from https://www.cosic.esat.kuleuven.be/nessie/testvectors/ and RFC 3713 - */ -public class CamelliaLightTest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new CamelliaLightEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "80000000000000000000000000000000", "07923A39EB0A817D1C4D87BDB82D1F1C"), - new BlockCipherVectorTest(1, new CamelliaLightEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "6C227F749319A3AA7DA235A9BBA05A2C"), - new BlockCipherVectorTest(2, new CamelliaLightEngine(), - new KeyParameter(Hex.decode("0123456789abcdeffedcba9876543210")), - "0123456789abcdeffedcba9876543210", "67673138549669730857065648eabe43"), - // - // 192 bit - // - new BlockCipherVectorTest(3, new CamelliaLightEngine(), - new KeyParameter(Hex.decode("0123456789abcdeffedcba98765432100011223344556677")), - "0123456789abcdeffedcba9876543210", "b4993401b3e996f84ee5cee7d79b09b9"), - new BlockCipherVectorTest(4, new CamelliaLightEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "00040000000000000000000000000000", "9BCA6C88B928C1B0F57F99866583A9BC"), - new BlockCipherVectorTest(5, new CamelliaLightEngine(), - new KeyParameter(Hex.decode("949494949494949494949494949494949494949494949494")), - "636EB22D84B006381235641BCF0308D2", "94949494949494949494949494949494"), - // - // 256 bit - // - new BlockCipherVectorTest(6, new CamelliaLightEngine(), - new KeyParameter(Hex.decode("0123456789abcdeffedcba987654321000112233445566778899aabbccddeeff")), - "0123456789abcdeffedcba9876543210", "9acc237dff16d76c20ef7c919e3a7509"), - new BlockCipherVectorTest(7, new CamelliaLightEngine(), - new KeyParameter(Hex.decode("4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A")), - "057764FE3A500EDBD988C5C3B56CBA9A", "4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A"), - new BlockCipherVectorTest(8, new CamelliaLightEngine(), - new KeyParameter(Hex.decode("0303030303030303030303030303030303030303030303030303030303030303")), - "7968B08ABA92193F2295121EF8D75C8A", "03030303030303030303030303030303"), - }; - - CamelliaLightTest() - { - super(tests, new CamelliaLightEngine(), new KeyParameter(new byte[32])); - } - - public String getName() - { - return "CamelliaLight"; - } - - public static void main( - String[] args) - { - runTest(new CamelliaLightTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CamelliaTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CamelliaTest.java deleted file mode 100644 index 5fa699e3b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CamelliaTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.CamelliaEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * Camellia tester - vectors from https://www.cosic.esat.kuleuven.be/nessie/testvectors/ and RFC 3713 - */ -public class CamelliaTest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new CamelliaEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "80000000000000000000000000000000", "07923A39EB0A817D1C4D87BDB82D1F1C"), - new BlockCipherVectorTest(1, new CamelliaEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "6C227F749319A3AA7DA235A9BBA05A2C"), - new BlockCipherVectorTest(2, new CamelliaEngine(), - new KeyParameter(Hex.decode("0123456789abcdeffedcba9876543210")), - "0123456789abcdeffedcba9876543210", "67673138549669730857065648eabe43"), - // - // 192 bit - // - new BlockCipherVectorTest(3, new CamelliaEngine(), - new KeyParameter(Hex.decode("0123456789abcdeffedcba98765432100011223344556677")), - "0123456789abcdeffedcba9876543210", "b4993401b3e996f84ee5cee7d79b09b9"), - new BlockCipherVectorTest(4, new CamelliaEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "00040000000000000000000000000000", "9BCA6C88B928C1B0F57F99866583A9BC"), - new BlockCipherVectorTest(5, new CamelliaEngine(), - new KeyParameter(Hex.decode("949494949494949494949494949494949494949494949494")), - "636EB22D84B006381235641BCF0308D2", "94949494949494949494949494949494"), - // - // 256 bit - // - new BlockCipherVectorTest(6, new CamelliaEngine(), - new KeyParameter(Hex.decode("0123456789abcdeffedcba987654321000112233445566778899aabbccddeeff")), - "0123456789abcdeffedcba9876543210", "9acc237dff16d76c20ef7c919e3a7509"), - new BlockCipherVectorTest(7, new CamelliaEngine(), - new KeyParameter(Hex.decode("4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A")), - "057764FE3A500EDBD988C5C3B56CBA9A", "4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A4A"), - new BlockCipherVectorTest(8, new CamelliaEngine(), - new KeyParameter(Hex.decode("0303030303030303030303030303030303030303030303030303030303030303")), - "7968B08ABA92193F2295121EF8D75C8A", "03030303030303030303030303030303"), - }; - - CamelliaTest() - { - super(tests, new CamelliaEngine(), new KeyParameter(new byte[32])); - } - - public String getName() - { - return "Camellia"; - } - - public static void main( - String[] args) - { - CamelliaTest test = new CamelliaTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ChaCha20Poly1305Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ChaCha20Poly1305Test.java deleted file mode 100644 index a9eafd960..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ChaCha20Poly1305Test.java +++ /dev/null @@ -1,433 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.macs.SipHash; -import com.fr.third.org.bouncycastle.crypto.modes.ChaCha20Poly1305; -import com.fr.third.org.bouncycastle.crypto.params.AEADParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.Times; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class ChaCha20Poly1305Test - extends SimpleTest -{ - private static final String[][] TEST_VECTORS = new String[][] { - { - "Test Case 1", - "808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f", - "4c616469657320616e642047656e746c" - + "656d656e206f662074686520636c6173" - + "73206f66202739393a20496620492063" - + "6f756c64206f6666657220796f75206f" - + "6e6c79206f6e652074697020666f7220" - + "746865206675747572652c2073756e73" - + "637265656e20776f756c642062652069" - + "742e", - "50515253c0c1c2c3c4c5c6c7", - "070000004041424344454647", - "d31a8d34648e60db7b86afbc53ef7ec2" - + "a4aded51296e08fea9e2b5a736ee62d6" - + "3dbea45e8ca9671282fafb69da92728b" - + "1a71de0a9e060b2905d6a5b67ecd3b36" - + "92ddbd7f2d778b8c9803aee328091b58" - + "fab324e4fad675945585808b4831d7bc" - + "3ff4def08e4b7a9de576d26586cec64b" - + "6116", - "1ae10b594f09e26a7e902ecbd0600691", - }, - }; - - public String getName() - { - return "ChaCha20Poly1305"; - } - - public void performTest() throws Exception - { - for (int i = 0; i < TEST_VECTORS.length; ++i) - { - runTestCase(TEST_VECTORS[i]); - } - - outputSizeTests(); - randomTests(); - testExceptions(); - } - - private void checkTestCase( - ChaCha20Poly1305 encCipher, - ChaCha20Poly1305 decCipher, - String testName, - byte[] SA, - byte[] P, - byte[] C, - byte[] T) - throws InvalidCipherTextException - { - byte[] enc = new byte[encCipher.getOutputSize(P.length)]; - if (SA != null) - { - encCipher.processAADBytes(SA, 0, SA.length); - } - int len = encCipher.processBytes(P, 0, P.length, enc, 0); - len += encCipher.doFinal(enc, len); - - if (enc.length != len) - { - fail("encryption reported incorrect length: " + testName); - } - - byte[] mac = encCipher.getMac(); - - byte[] data = new byte[P.length]; - System.arraycopy(enc, 0, data, 0, data.length); - byte[] tail = new byte[enc.length - P.length]; - System.arraycopy(enc, P.length, tail, 0, tail.length); - - if (!areEqual(C, data)) - { - fail("incorrect encrypt in: " + testName); - } - - if (!areEqual(T, mac)) - { - fail("getMac() returned wrong mac in: " + testName); - } - - if (!areEqual(T, tail)) - { - fail("stream contained wrong mac in: " + testName); - } - - byte[] dec = new byte[decCipher.getOutputSize(enc.length)]; - if (SA != null) - { - decCipher.processAADBytes(SA, 0, SA.length); - } - len = decCipher.processBytes(enc, 0, enc.length, dec, 0); - len += decCipher.doFinal(dec, len); - mac = decCipher.getMac(); - - data = new byte[C.length]; - System.arraycopy(dec, 0, data, 0, data.length); - - if (!areEqual(P, data)) - { - fail("incorrect decrypt in: " + testName); - } - } - - private ChaCha20Poly1305 initCipher(boolean forEncryption, AEADParameters parameters) - { - ChaCha20Poly1305 c = new ChaCha20Poly1305(); - c.init(forEncryption, parameters); - return c; - } - - private static int nextInt(SecureRandom rand, int n) - { - if ((n & -n) == n) // i.e., n is a power of 2 - { - return (int)((n * (long)(rand.nextInt() >>> 1)) >> 31); - } - - int bits, value; - do - { - bits = rand.nextInt() >>> 1; - value = bits % n; - } - while (bits - value + (n - 1) < 0); - - return value; - } - - private void outputSizeTests() - { - byte[] K = new byte[32]; - byte[] A = null; - byte[] N = new byte[12]; - - AEADParameters parameters = new AEADParameters(new KeyParameter(K), 16 * 8, N, A); - ChaCha20Poly1305 cipher = initCipher(true, parameters); - - if (cipher.getUpdateOutputSize(0) != 0) - { - fail("incorrect getUpdateOutputSize for initial 0 bytes encryption"); - } - - if (cipher.getOutputSize(0) != 16) - { - fail("incorrect getOutputSize for initial 0 bytes encryption"); - } - - cipher.init(false, parameters); - - if (cipher.getUpdateOutputSize(0) != 0) - { - fail("incorrect getUpdateOutputSize for initial 0 bytes decryption"); - } - - // NOTE: 0 bytes would be truncated data, but we want it to fail in the doFinal, not here - if (cipher.getOutputSize(0) != 0) - { - fail("fragile getOutputSize for initial 0 bytes decryption"); - } - - if (cipher.getOutputSize(16) != 0) - { - fail("incorrect getOutputSize for initial MAC-size bytes decryption"); - } - } - - private void randomTests() throws InvalidCipherTextException - { - SecureRandom random = new SecureRandom(); - random.setSeed(Times.nanoTime()); - - for (int i = 0; i < 10; ++i) - { - randomTest(random); - } - } - - private void randomTest(SecureRandom random) throws InvalidCipherTextException - { - int kLength = 32; - byte[] K = new byte[kLength]; - random.nextBytes(K); - - int pLength = random.nextInt() >>> 16; - byte[] P = new byte[pLength]; - random.nextBytes(P); - - int aLength = random.nextInt() >>> 24; - byte[] A = new byte[aLength]; - random.nextBytes(A); - - int saLength = random.nextInt() >>> 24; - byte[] SA = new byte[saLength]; - random.nextBytes(SA); - - int nonceLength = 12; - byte[] nonce = new byte[nonceLength]; - random.nextBytes(nonce); - - AEADParameters parameters = new AEADParameters(new KeyParameter(K), 16 * 8, nonce, A); - ChaCha20Poly1305 cipher = initCipher(true, parameters); - byte[] C = new byte[cipher.getOutputSize(P.length)]; - int predicted = cipher.getUpdateOutputSize(P.length); - - int split = nextInt(random, SA.length + 1); - cipher.processAADBytes(SA, 0, split); - cipher.processAADBytes(SA, split, SA.length - split); - - int len = cipher.processBytes(P, 0, P.length, C, 0); - if (predicted != len) - { - fail("encryption reported incorrect update length in randomised test"); - } - - len += cipher.doFinal(C, len); - if (C.length != len) - { - fail("encryption reported incorrect length in randomised test"); - } - - byte[] encT = cipher.getMac(); - byte[] tail = new byte[C.length - P.length]; - System.arraycopy(C, P.length, tail, 0, tail.length); - - if (!areEqual(encT, tail)) - { - fail("stream contained wrong mac in randomised test"); - } - - cipher.init(false, parameters); - byte[] decP = new byte[cipher.getOutputSize(C.length)]; - predicted = cipher.getUpdateOutputSize(C.length); - - split = nextInt(random, SA.length + 1); - cipher.processAADBytes(SA, 0, split); - cipher.processAADBytes(SA, split, SA.length - split); - - len = cipher.processBytes(C, 0, C.length, decP, 0); - if (predicted != len) - { - fail("decryption reported incorrect update length in randomised test"); - } - - len += cipher.doFinal(decP, len); - - if (!areEqual(P, decP)) - { - fail("incorrect decrypt in randomised test"); - } - - byte[] decT = cipher.getMac(); - if (!areEqual(encT, decT)) - { - fail("decryption produced different mac from encryption"); - } - - // - // key reuse test - // - cipher.init(false, AEADTestUtil.reuseKey(parameters)); - decP = new byte[cipher.getOutputSize(C.length)]; - - split = nextInt(random, SA.length + 1); - cipher.processAADBytes(SA, 0, split); - cipher.processAADBytes(SA, split, SA.length - split); - - len = cipher.processBytes(C, 0, C.length, decP, 0); - len += cipher.doFinal(decP, len); - - if (!areEqual(P, decP)) - { - fail("incorrect decrypt in randomised test"); - } - - decT = cipher.getMac(); - if (!areEqual(encT, decT)) - { - fail("decryption produced different mac from encryption"); - } - } - - private void runTestCase(String[] testVector) - throws InvalidCipherTextException - { - int pos = 0; - String testName = testVector[pos++]; - byte[] K = Hex.decode(testVector[pos++]); - byte[] P = Hex.decode(testVector[pos++]); - byte[] A = Hex.decode(testVector[pos++]); - byte[] N = Hex.decode(testVector[pos++]); - byte[] C = Hex.decode(testVector[pos++]); - byte[] T = Hex.decode(testVector[pos++]); - - runTestCase(testName, K, N, A, P, C, T); - } - - private void runTestCase( - String testName, - byte[] K, - byte[] N, - byte[] A, - byte[] P, - byte[] C, - byte[] T) - throws InvalidCipherTextException - { - byte[] fa = new byte[A.length / 2]; - byte[] la = new byte[A.length - (A.length / 2)]; - System.arraycopy(A, 0, fa, 0, fa.length); - System.arraycopy(A, fa.length, la, 0, la.length); - - runTestCase(testName + " all initial associated data", K, N, A, null, P, C, T); - runTestCase(testName + " all subsequent associated data", K, N, null, A, P, C, T); - runTestCase(testName + " split associated data", K, N, fa, la, P, C, T); - } - - private void runTestCase( - String testName, - byte[] K, - byte[] N, - byte[] A, - byte[] SA, - byte[] P, - byte[] C, - byte[] T) - throws InvalidCipherTextException - { - AEADParameters parameters = new AEADParameters(new KeyParameter(K), T.length * 8, N, A); - ChaCha20Poly1305 encCipher = initCipher(true, parameters); - ChaCha20Poly1305 decCipher = initCipher(false, parameters); - checkTestCase(encCipher, decCipher, testName, SA, P, C, T); - encCipher = initCipher(true, parameters); - checkTestCase(encCipher, decCipher, testName + " (reused)", SA, P, C, T); - - // Key reuse - AEADParameters keyReuseParams = AEADTestUtil.reuseKey(parameters); - - try - { - encCipher.init(true, keyReuseParams); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isTrue("wrong message", "cannot reuse nonce for ChaCha20Poly1305 encryption".equals(e.getMessage())); - } - } - - private void testExceptions() throws InvalidCipherTextException - { - ChaCha20Poly1305 c = new ChaCha20Poly1305(); - - try - { - c = new ChaCha20Poly1305(new SipHash()); - - fail("incorrect mac size not picked up"); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - c.init(false, new KeyParameter(new byte[32])); - - fail("illegal argument not picked up"); - } - catch (IllegalArgumentException e) - { - // expected - } - - AEADTestUtil.testTampering(this, c, new AEADParameters(new KeyParameter(new byte[32]), 128, new byte[12])); - - byte[] P = Strings.toByteArray("Hello world!"); - byte[] buf = new byte[100]; - - c = new ChaCha20Poly1305(); - AEADParameters aeadParameters = new AEADParameters(new KeyParameter(new byte[32]), 128, new byte[12]); - c.init(true, aeadParameters); - - c.processBytes(P, 0, P.length, buf, 0); - - c.doFinal(buf, 0); - - try - { - c.doFinal(buf, 0); - fail("no exception on reuse"); - } - catch (IllegalStateException e) - { - isTrue("wrong message", e.getMessage().equals("ChaCha20Poly1305 cannot be reused for encryption")); - } - - try - { - c.init(true, aeadParameters); - fail("no exception on reuse"); - } - catch (IllegalArgumentException e) - { - isTrue("wrong message", e.getMessage().equals("cannot reuse nonce for ChaCha20Poly1305 encryption")); - } - } - - public static void main(String[] args) - { - runTest(new ChaCha20Poly1305Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ChaChaTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ChaChaTest.java deleted file mode 100644 index f338161e5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ChaChaTest.java +++ /dev/null @@ -1,403 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.crypto.engines.ChaChaEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * ChaCha Test - *- * Test cases generated using ref version of ChaCha20 in estreambench-20080905. - */ -public class ChaChaTest - extends SimpleTest -{ - byte[] zeroes = Hex.decode( - "00000000000000000000000000000000" - + "00000000000000000000000000000000" - + "00000000000000000000000000000000" - + "00000000000000000000000000000000"); - - String set1v0_0 = "FBB87FBB8395E05DAA3B1D683C422046" - + "F913985C2AD9B23CFC06C1D8D04FF213" - + "D44A7A7CDB84929F915420A8A3DC58BF" - + "0F7ECB4B1F167BB1A5E6153FDAF4493D"; - - String set1v0_192 = "D9485D55B8B82D792ED1EEA8E93E9BC1" - + "E2834AD0D9B11F3477F6E106A2F6A5F2" - + "EA8244D5B925B8050EAB038F58D4DF57" - + "7FAFD1B89359DAE508B2B10CBD6B488E"; - - String set1v0_256 = "08661A35D6F02D3D9ACA8087F421F7C8" - + "A42579047D6955D937925BA21396DDD4" - + "74B1FC4ACCDCAA33025B4BCE817A4FBF" - + "3E5D07D151D7E6FE04934ED466BA4779"; - - String set1v0_448 = "A7E16DD38BA48CCB130E5BE9740CE359" - + "D631E91600F85C8A5D0785A612D1D987" - + "90780ACDDC26B69AB106CCF6D866411D" - + "10637483DBF08CC5591FD8B3C87A3AE0"; - - String set1v9_0 = "A276339F99316A913885A0A4BE870F06" - + "91E72B00F1B3F2239F714FE81E88E00C" - + "BBE52B4EBBE1EA15894E29658C4CB145" - + "E6F89EE4ABB045A78514482CE75AFB7C"; - - String set1v9_192 = "0DFB9BD4F87F68DE54FBC1C6428FDEB0" - + "63E997BE8490C9B7A4694025D6EBA2B1" - + "5FE429DB82A7CAE6AAB22918E8D00449" - + "6FB6291467B5AE81D4E85E81D8795EBB"; - - String set1v9_256 = "546F5BB315E7F71A46E56D4580F90889" - + "639A2BA528F757CF3B048738BA141AF3" - + "B31607CB21561BAD94721048930364F4" - + "B1227CFEB7CDECBA881FB44903550E68"; - - String set1v9_448 = "6F813586E76691305A0CF048C0D8586D" - + "C89460207D8B230CD172398AA33D19E9" - + "2D24883C3A9B0BB7CD8C6B2668DB142E" - + "37A97948A7A01498A21110297984CD20"; - - String set6v0_0 = "57459975BC46799394788DE80B928387" - + "862985A269B9E8E77801DE9D874B3F51" - + "AC4610B9F9BEE8CF8CACD8B5AD0BF17D" - + "3DDF23FD7424887EB3F81405BD498CC3"; - - String set6v0_65472 = "EF9AEC58ACE7DB427DF012B2B91A0C1E" - + "8E4759DCE9CDB00A2BD59207357BA06C" - + "E02D327C7719E83D6348A6104B081DB0" - + "3908E5186986AE41E3AE95298BB7B713"; - - String set6v0_65536 = "17EF5FF454D85ABBBA280F3A94F1D26E" - + "950C7D5B05C4BB3A78326E0DC5731F83" - + "84205C32DB867D1B476CE121A0D7074B" - + "AA7EE90525D15300F48EC0A6624BD0AF"; - - String set6v1_0 = "92A2508E2C4084567195F2A1005E552B" - + "4874EC0504A9CD5E4DAF739AB553D2E7" - + "83D79C5BA11E0653BEBB5C116651302E" - + "8D381CB728CA627B0B246E83942A2B99"; - - String set6v1_65472 = "E1974EC3063F7BD0CBA58B1CE34BC874" - + "67AAF5759B05EA46682A5D4306E5A76B" - + "D99A448DB8DE73AF97A73F5FBAE2C776" - + "35040464524CF14D7F08D4CE1220FD84"; - - String set6v1_65536 = "BE3436141CFD62D12FF7D852F80C1344" - + "81F152AD0235ECF8CA172C55CA8C031B" - + "2E785D773A988CA8D4BDA6FAE0E493AA" - + "71DCCC4C894D1F106CAC62A9FC0A9607"; - - // ChaCha12 - String chacha12_set1v0_0 = "36CF0D56E9F7FBF287BC5460D95FBA94" - + "AA6CBF17D74E7C784DDCF7E0E882DDAE" - + "3B5A58243EF32B79A04575A8E2C2B73D" - + "C64A52AA15B9F88305A8F0CA0B5A1A25"; - - String chacha12_set1v0_192 = "83496792AB68FEC75ADB16D3044420A4" - + "A00A6E9ADC41C3A63DBBF317A8258C85" - + "A9BC08B4F76B413A4837324AEDF8BC2A" - + "67D53C9AB9E1C5BC5F379D48DF9AF730"; - - String chacha12_set1v0_256 = "BAA28ED593690FD760ADA07C95E3B888" - + "4B4B64E488CA7A2D9BDC262243AB9251" - + "394C5037E255F8BCCDCD31306C508FFB" - + "C9E0161380F7911FCB137D46D9269250"; - - String chacha12_set1v0_448 = "B7ECFB6AE0B51915762FE1FD03A14D0C" - + "9E54DA5DC76EB16EBA5313BC535DE63D" - + "C72D7F9F1874E301E99C8531819F4E37" - + "75793F6A5D19C717FA5C78A39EB804A6"; - - // ChaCha8 - String chacha8_set1v0_0 = "BEB1E81E0F747E43EE51922B3E87FB38" - + "D0163907B4ED49336032AB78B67C2457" - + "9FE28F751BD3703E51D876C017FAA435" - + "89E63593E03355A7D57B2366F30047C5"; - - String chacha8_set1v0_192 = "33B8B7CA8F8E89F0095ACE75A379C651" - + "FD6BDD55703C90672E44C6BAB6AACDD8" - + "7C976A87FD264B906E749429284134C2" - + "38E3B88CF74A68245B860D119A8BDF43"; - - String chacha8_set1v0_256 = "F7CA95BF08688BD3BE8A27724210F9DC" - + "16F32AF974FBFB09E9F757C577A245AB" - + "F35F824B70A4C02CB4A8D7191FA8A5AD" - + "6A84568743844703D353B7F00A8601F4"; - - String chacha8_set1v0_448 = "7B4117E8BFFD595CD8482270B08920FB" - + "C9B97794E1809E07BB271BF07C861003" - + "4C38DBA6ECA04E5474F399A284CBF6E2" - + "7F70142E604D0977797DE5B58B6B25E0"; - - - - public String getName() - { - return "ChaCha"; - } - - public void performTest() - { - chachaTest1(20, new ParametersWithIV(new KeyParameter(Hex.decode("80000000000000000000000000000000")), Hex.decode("0000000000000000")), - set1v0_0, set1v0_192, set1v0_256, set1v0_448); - chachaTest1(20, new ParametersWithIV(new KeyParameter(Hex.decode("00400000000000000000000000000000")), Hex.decode("0000000000000000")), - set1v9_0, set1v9_192, set1v9_256, set1v9_448); - chachaTest1(12, new ParametersWithIV(new KeyParameter(Hex.decode("80000000000000000000000000000000")), Hex.decode("0000000000000000")), - chacha12_set1v0_0, chacha12_set1v0_192, chacha12_set1v0_256, chacha12_set1v0_448); - chachaTest1(8, new ParametersWithIV(new KeyParameter(Hex.decode("80000000000000000000000000000000")), Hex.decode("0000000000000000")), - chacha8_set1v0_0, chacha8_set1v0_192, chacha8_set1v0_256, chacha8_set1v0_448); - chachaTest2(new ParametersWithIV(new KeyParameter(Hex.decode("0053A6F94C9FF24598EB3E91E4378ADD3083D6297CCF2275C81B6EC11467BA0D")), Hex.decode("0D74DB42A91077DE")), - set6v0_0, set6v0_65472, set6v0_65536); - chachaTest2(new ParametersWithIV(new KeyParameter(Hex.decode("0558ABFE51A4F74A9DF04396E93C8FE23588DB2E81D4277ACD2073C6196CBF12")), Hex.decode("167DE44BB21980E7")), - set6v1_0, set6v1_65472, set6v1_65536); - reinitBug(); - skipTest(); - } - - private void chachaTest1(int rounds, CipherParameters params, String v0, String v192, String v256, String v448) - { - StreamCipher chaCha = new ChaChaEngine(rounds); - byte[] buf = new byte[64]; - - chaCha.init(true, params); - - for (int i = 0; i != 7; i++) - { - chaCha.processBytes(zeroes, 0, 64, buf, 0); - switch (i) - { - case 0: - if (!areEqual(buf, Hex.decode(v0))) - { - mismatch("v0/" + rounds, v0, buf); - } - break; - case 3: - if (!areEqual(buf, Hex.decode(v192))) - { - mismatch("v192/" + rounds, v192, buf); - } - break; - case 4: - if (!areEqual(buf, Hex.decode(v256))) - { - mismatch("v256/" + rounds, v256, buf); - } - break; - default: - // ignore - } - } - - for (int i = 0; i != 64; i++) - { - buf[i] = chaCha.returnByte(zeroes[i]); - } - - if (!areEqual(buf, Hex.decode(v448))) - { - mismatch("v448", v448, buf); - } - } - - private void chachaTest2(CipherParameters params, String v0, String v65472, String v65536) - { - StreamCipher chaCha = new ChaChaEngine(); - byte[] buf = new byte[64]; - - chaCha.init(true, params); - - for (int i = 0; i != 1025; i++) - { - chaCha.processBytes(zeroes, 0, 64, buf, 0); - switch (i) - { - case 0: - if (!areEqual(buf, Hex.decode(v0))) - { - mismatch("v0", v0, buf); - } - break; - case 1023: - if (!areEqual(buf, Hex.decode(v65472))) - { - mismatch("v65472", v65472, buf); - } - break; - case 1024: - if (!areEqual(buf, Hex.decode(v65536))) - { - mismatch("v65536", v65536, buf); - } - break; - default: - // ignore - } - } - } - - private void mismatch(String name, String expected, byte[] found) - { - fail("mismatch on " + name, expected, new String(Hex.encode(found))); - } - - - private void reinitBug() - { - KeyParameter key = new KeyParameter(Hex.decode("80000000000000000000000000000000")); - ParametersWithIV parameters = new ParametersWithIV(key, Hex.decode("0000000000000000")); - - StreamCipher salsa = new ChaChaEngine(); - - salsa.init(true, parameters); - - try - { - salsa.init(true, key); - fail("Salsa20 should throw exception if no IV in Init"); - } - catch (IllegalArgumentException e) - { - } - } - - private boolean areEqual(byte[] a, int aOff, byte[] b, int bOff) - { - for (int i = bOff; i != b.length; i++) - { - if (a[aOff + i - bOff] != b[i]) - { - return false; - } - } - - return true; - } - - private void skipTest() - { - SecureRandom rand = new SecureRandom(); - byte[] plain = new byte[5000]; - byte[] cipher = new byte[5000]; - - rand.nextBytes(plain); - - CipherParameters params = new ParametersWithIV(new KeyParameter(Hex.decode("0053A6F94C9FF24598EB3E91E4378ADD3083D6297CCF2275C81B6EC11467BA0D")), Hex.decode("0D74DB42A91077DE")); - ChaChaEngine engine = new ChaChaEngine(); - - engine.init(true, params); - - engine.processBytes(plain, 0, plain.length, cipher, 0); - - byte[] fragment = new byte[20]; - - engine.init(true, params); - - engine.skip(10); - - engine.processBytes(plain, 10, fragment.length, fragment, 0); - - if (!areEqual(cipher, 10, fragment, 0)) - { - fail("skip forward 10 failed"); - } - - engine.skip(1000); - - engine.processBytes(plain, 1010 + fragment.length, fragment.length, fragment, 0); - - if (!areEqual(cipher, 1010 + fragment.length, fragment, 0)) - { - fail("skip forward 1000 failed"); - } - - engine.skip(-10); - - engine.processBytes(plain, 1010 + 2 * fragment.length - 10, fragment.length, fragment, 0); - - if (!areEqual(cipher, 1010 + 2 * fragment.length - 10, fragment, 0)) - { - fail("skip back 10 failed"); - } - - engine.skip(-1000); - - if (engine.getPosition() != 60) - { - fail("skip position incorrect - " + 60 + " got " + engine.getPosition()); - } - - engine.processBytes(plain, 60, fragment.length, fragment, 0); - - if (!areEqual(cipher, 60, fragment, 0)) - { - fail("skip back 1000 failed"); - } - - long pos = engine.seekTo(1010); - if (pos != 1010) - { - fail("position wrong"); - } - - engine.processBytes(plain, 1010, fragment.length, fragment, 0); - - if (!areEqual(cipher, 1010, fragment, 0)) - { - fail("seek to 1010 failed"); - } - - engine.reset(); - - for (int i = 0; i != 1000; i++) - { - engine.skip(i); - - if (engine.getPosition() != i) - { - fail("skip forward at wrong position"); - } - - engine.processBytes(plain, i, fragment.length, fragment, 0); - - if (!areEqual(cipher, i, fragment, 0)) - { - fail("skip forward i failed: " + i); - } - - if (engine.getPosition() != i + fragment.length) - { - fail("cipher at wrong position: " + engine.getPosition() + " [" + i + "]"); - } - - engine.skip(-fragment.length); - - if (engine.getPosition() != i) - { - fail("skip back at wrong position"); - } - - engine.processBytes(plain, i, fragment.length, fragment, 0); - - if (!areEqual(cipher, i, fragment, 0)) - { - fail("skip back i failed: " + i); - } - - engine.reset(); - } - } - - public static void main( - String[] args) - { - runTest(new ChaChaTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CipherStreamTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CipherStreamTest.java deleted file mode 100644 index 65d4256e2..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CipherStreamTest.java +++ /dev/null @@ -1,706 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.BufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.BlowfishEngine; -import com.fr.third.org.bouncycastle.crypto.engines.CAST5Engine; -import com.fr.third.org.bouncycastle.crypto.engines.CAST6Engine; -import com.fr.third.org.bouncycastle.crypto.engines.CamelliaEngine; -import com.fr.third.org.bouncycastle.crypto.engines.ChaChaEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESedeEngine; -import com.fr.third.org.bouncycastle.crypto.engines.Grain128Engine; -import com.fr.third.org.bouncycastle.crypto.engines.Grainv1Engine; -import com.fr.third.org.bouncycastle.crypto.engines.HC128Engine; -import com.fr.third.org.bouncycastle.crypto.engines.HC256Engine; -import com.fr.third.org.bouncycastle.crypto.engines.NoekeonEngine; -import com.fr.third.org.bouncycastle.crypto.engines.RC2Engine; -import com.fr.third.org.bouncycastle.crypto.engines.RC4Engine; -import com.fr.third.org.bouncycastle.crypto.engines.RC6Engine; -import com.fr.third.org.bouncycastle.crypto.engines.SEEDEngine; -import com.fr.third.org.bouncycastle.crypto.engines.Salsa20Engine; -import com.fr.third.org.bouncycastle.crypto.engines.SerpentEngine; -import com.fr.third.org.bouncycastle.crypto.engines.TEAEngine; -import com.fr.third.org.bouncycastle.crypto.engines.ThreefishEngine; -import com.fr.third.org.bouncycastle.crypto.engines.TwofishEngine; -import com.fr.third.org.bouncycastle.crypto.engines.XSalsa20Engine; -import com.fr.third.org.bouncycastle.crypto.engines.XTEAEngine; -import com.fr.third.org.bouncycastle.crypto.io.CipherInputStream; -import com.fr.third.org.bouncycastle.crypto.io.CipherOutputStream; -import com.fr.third.org.bouncycastle.crypto.io.InvalidCipherTextIOException; -import com.fr.third.org.bouncycastle.crypto.modes.AEADBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CCMBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CTSBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.EAXBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.NISTCTSBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.OCBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.OFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.SICBlockCipher; -import com.fr.third.org.bouncycastle.crypto.paddings.PKCS7Padding; -import com.fr.third.org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class CipherStreamTest - extends SimpleTest -{ - private int streamSize; - - public String getName() - { - return "CipherStreamTest"; - } - - private void testMode(Object cipher, CipherParameters params) - throws Exception - { - testWriteRead(cipher, params, false); - testWriteRead(cipher, params, true); - testReadWrite(cipher, params, false); - testReadWrite(cipher, params, true); - - if (!(cipher instanceof CTSBlockCipher || cipher instanceof NISTCTSBlockCipher)) - { - testWriteReadEmpty(cipher, params, false); - testWriteReadEmpty(cipher, params, true); - } - - if (cipher instanceof AEADBlockCipher) - { - testTamperedRead((AEADBlockCipher)cipher, params); - testTruncatedRead((AEADBlockCipher)cipher, params); - testTamperedWrite((AEADBlockCipher)cipher, params); - } - } - - private OutputStream createCipherOutputStream(OutputStream output, Object cipher) - { - if (cipher instanceof BufferedBlockCipher) - { - return new CipherOutputStream(output, (BufferedBlockCipher)cipher); - } - else if (cipher instanceof AEADBlockCipher) - { - return new CipherOutputStream(output, (AEADBlockCipher)cipher); - } - else - { - return new CipherOutputStream(output, (StreamCipher)cipher); - } - } - - private InputStream createCipherInputStream(byte[] data, Object cipher) - { - ByteArrayInputStream input = new ByteArrayInputStream(data); - if (cipher instanceof BufferedBlockCipher) - { - return new CipherInputStream(input, (BufferedBlockCipher)cipher); - } - else if (cipher instanceof AEADBlockCipher) - { - return new CipherInputStream(input, (AEADBlockCipher)cipher); - } - else - { - return new CipherInputStream(input, (StreamCipher)cipher); - } - } - - /** - * Test tampering of ciphertext followed by read from decrypting CipherInputStream - */ - private void testTamperedRead(AEADBlockCipher cipher, CipherParameters params) - throws Exception - { - cipher.init(true, params); - - byte[] ciphertext = new byte[cipher.getOutputSize(streamSize)]; - cipher.doFinal(ciphertext, cipher.processBytes(new byte[streamSize], 0, streamSize, ciphertext, 0)); - - // Tamper - ciphertext[0] += 1; - - cipher.init(false, params); - InputStream input = createCipherInputStream(ciphertext, cipher); - try - { - while (input.read() >= 0) - { - } - fail("Expected invalid ciphertext after tamper and read : " + cipher.getAlgorithmName()); - } - catch (InvalidCipherTextIOException e) - { - // Expected - } - try - { - input.close(); - } - catch (Exception e) - { - fail("Unexpected exception after tamper and read : " + cipher.getAlgorithmName()); - } - } - - /** - * Test truncation of ciphertext to make tag calculation impossible, followed by read from - * decrypting CipherInputStream - */ - private void testTruncatedRead(AEADBlockCipher cipher, CipherParameters params) - throws Exception - { - cipher.init(true, params); - - byte[] ciphertext = new byte[cipher.getOutputSize(streamSize)]; - cipher.doFinal(ciphertext, cipher.processBytes(new byte[streamSize], 0, streamSize, ciphertext, 0)); - - // Truncate to just smaller than complete tag - byte[] truncated = new byte[ciphertext.length - streamSize - 1]; - System.arraycopy(ciphertext, 0, truncated, 0, truncated.length); - - cipher.init(false, params); - InputStream input = createCipherInputStream(truncated, cipher); - while (true) - { - int read = 0; - try - { - read = input.read(); - } - catch (InvalidCipherTextIOException e) - { - // Expected - break; - } - catch (Exception e) - { - fail("Unexpected exception on truncated read : " + cipher.getAlgorithmName()); - break; - } - if (read < 0) - { - fail("Expected invalid ciphertext after truncate and read : " + cipher.getAlgorithmName()); - break; - } - } - try - { - input.close(); - } - catch (Exception e) - { - fail("Unexpected exception after truncate and read : " + cipher.getAlgorithmName()); - } - } - - /** - * Test tampering of ciphertext followed by write to decrypting CipherOutputStream - */ - private void testTamperedWrite(AEADBlockCipher cipher, CipherParameters params) - throws Exception - { - cipher.init(true, params); - - byte[] ciphertext = new byte[cipher.getOutputSize(streamSize)]; - cipher.doFinal(ciphertext, cipher.processBytes(new byte[streamSize], 0, streamSize, ciphertext, 0)); - - // Tamper - ciphertext[0] += 1; - - cipher.init(false, params); - ByteArrayOutputStream plaintext = new ByteArrayOutputStream(); - OutputStream output = createCipherOutputStream(plaintext, cipher); - - for (int i = 0; i < ciphertext.length; i++) - { - output.write(ciphertext[i]); - } - try - { - output.close(); - fail("Expected invalid ciphertext after tamper and write : " + cipher.getAlgorithmName()); - } - catch (InvalidCipherTextIOException e) - { - // Expected - } - } - - /** - * Test CipherOutputStream in ENCRYPT_MODE, CipherInputStream in DECRYPT_MODE - */ - private void testWriteRead(Object cipher, CipherParameters params, boolean blocks) - throws Exception - { - byte[] data = new byte[streamSize]; - for (int i = 0; i < data.length; i++) - { - data[i] = (byte)(i % 255); - } - - testWriteRead(cipher, params, blocks, data); - } - - /** - * Test CipherOutputStream in ENCRYPT_MODE, CipherInputStream in DECRYPT_MODE - */ - private void testWriteReadEmpty(Object cipher, CipherParameters params, boolean blocks) - throws Exception - { - byte[] data = new byte[0]; - - testWriteRead(cipher, params, blocks, data); - } - - private void testWriteRead(Object cipher, CipherParameters params, boolean blocks, byte[] data) - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - - try - { - init(cipher, true, params); - - OutputStream cOut = createCipherOutputStream(bOut, cipher); - if (blocks) - { - int chunkSize = Math.max(1, data.length / 8); - for (int i = 0; i < data.length; i += chunkSize) - { - cOut.write(data, i, Math.min(chunkSize, data.length - i)); - } - } - else - { - for (int i = 0; i < data.length; i++) - { - cOut.write(data[i]); - } - } - cOut.close(); - - byte[] cipherText = bOut.toByteArray(); - bOut.reset(); - init(cipher, false, params); - InputStream cIn = createCipherInputStream(cipherText, cipher); - - if (blocks) - { - byte[] block = new byte[getBlockSize(cipher) + 1]; - int c; - while ((c = cIn.read(block)) >= 0) - { - bOut.write(block, 0, c); - } - } - else - { - int c; - while ((c = cIn.read()) >= 0) - { - bOut.write(c); - } - - } - cIn.close(); - - } - catch (Exception e) - { - fail("Unexpected exception " + getName(cipher), e); - } - - byte[] decrypted = bOut.toByteArray(); - if (!Arrays.areEqual(data, decrypted)) - { - fail("Failed - decrypted data doesn't match: " + getName(cipher)); - } - } - - private String getName(Object cipher) - { - if (cipher instanceof BufferedBlockCipher) - { - return ((BufferedBlockCipher)cipher).getUnderlyingCipher().getAlgorithmName(); - } - else if (cipher instanceof AEADBlockCipher) - { - return ((AEADBlockCipher)cipher).getUnderlyingCipher().getAlgorithmName(); - } - else if (cipher instanceof StreamCipher) - { - return ((StreamCipher)cipher).getAlgorithmName(); - } - return null; - } - - private int getBlockSize(Object cipher) - { - if (cipher instanceof BlockCipher) - { - return ((BlockCipher)cipher).getBlockSize(); - } - else if (cipher instanceof BufferedBlockCipher) - { - return ((BufferedBlockCipher)cipher).getBlockSize(); - } - else if (cipher instanceof AEADBlockCipher) - { - return ((AEADBlockCipher)cipher).getUnderlyingCipher().getBlockSize(); - } - else if (cipher instanceof StreamCipher) - { - return 1; - } - return 0; - } - - private void init(Object cipher, boolean forEncrypt, CipherParameters params) - { - if (cipher instanceof BufferedBlockCipher) - { - ((BufferedBlockCipher)cipher).init(forEncrypt, params); - } - else if (cipher instanceof AEADBlockCipher) - { - ((AEADBlockCipher)cipher).init(forEncrypt, params); - } - else if (cipher instanceof StreamCipher) - { - ((StreamCipher)cipher).init(forEncrypt, params); - } - } - - protected void fail(String message, boolean authenticated, boolean bc) - { - if (bc || !authenticated) - { - super.fail(message); - } - else - { - // javax.crypto.CipherInputStream/CipherOutputStream - // are broken wrt handling AEAD failures - System.err.println("Broken JCE Streams: " + message); - } - } - - /** - * Test CipherInputStream in ENCRYPT_MODE, CipherOutputStream in DECRYPT_MODE - */ - private void testReadWrite(Object cipher, CipherParameters params, boolean blocks) - throws Exception - { - String lCode = "ABCDEFGHIJKLMNOPQRSTU"; - - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - - try - { - init(cipher, true, params); - - InputStream cIn = createCipherInputStream(lCode.getBytes(), cipher); - ByteArrayOutputStream ct = new ByteArrayOutputStream(); - - if (blocks) - { - byte[] block = new byte[getBlockSize(cipher) + 1]; - int c; - while ((c = cIn.read(block)) >= 0) - { - ct.write(block, 0, c); - } - } - else - { - int c; - while ((c = cIn.read()) >= 0) - { - ct.write(c); - } - } - cIn.close(); - - init(cipher, false, params); - ByteArrayInputStream dataIn = new ByteArrayInputStream(ct.toByteArray()); - OutputStream cOut = createCipherOutputStream(bOut, cipher); - - if (blocks) - { - byte[] block = new byte[getBlockSize(cipher) + 1]; - int c; - while ((c = dataIn.read(block)) >= 0) - { - cOut.write(block, 0, c); - } - } - else - { - int c; - while ((c = dataIn.read()) >= 0) - { - cOut.write(c); - } - } - cOut.flush(); - cOut.close(); - - } - catch (Exception e) - { - fail("Unexpected exception " + getName(cipher), e); - } - - String res = new String(bOut.toByteArray()); - if (!res.equals(lCode)) - { - fail("Failed read/write - decrypted data doesn't match: " + getName(cipher), lCode, res); - } - } - - public void performTest() - throws Exception - { - int[] testSizes = new int[]{0, 1, 7, 8, 9, 15, 16, 17, 1023, 1024, 1025, 2047, 2048, 2049, 4095, 4096, 4097}; - for (int i = 0; i < testSizes.length; i++) - { - this.streamSize = testSizes[i]; - performTests(); - } - } - - private void performTests() - throws Exception - { - testModes(new BlowfishEngine(), new BlowfishEngine(), 16); - testModes(new DESEngine(), new DESEngine(), 8); - testModes(new DESedeEngine(), new DESedeEngine(), 24); - testModes(new TEAEngine(), new TEAEngine(), 16); - testModes(new CAST5Engine(), new CAST5Engine(), 16); - testModes(new RC2Engine(), new RC2Engine(), 16); - testModes(new XTEAEngine(), new XTEAEngine(), 16); - - testModes(new AESEngine(), new AESEngine(), 16); - testModes(new NoekeonEngine(), new NoekeonEngine(), 16); - testModes(new TwofishEngine(), new TwofishEngine(), 16); - testModes(new CAST6Engine(), new CAST6Engine(), 16); - testModes(new SEEDEngine(), new SEEDEngine(), 16); - testModes(new SerpentEngine(), new SerpentEngine(), 16); - testModes(new RC6Engine(), new RC6Engine(), 16); - testModes(new CamelliaEngine(), new CamelliaEngine(), 16); - testModes(new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), - new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), 64); - - testMode(new RC4Engine(), new KeyParameter(new byte[16])); - testMode(new Salsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); - testMode(new XSalsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[32]), new byte[24])); - testMode(new ChaChaEngine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); - testMode(new Grainv1Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); - testMode(new Grain128Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[12])); - testMode(new HC128Engine(), new KeyParameter(new byte[16])); - testMode(new HC256Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); - - testSkipping(new Salsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); - testSkipping(new SICBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); - } - - private void testModes(BlockCipher cipher1, BlockCipher cipher2, int keySize) - throws Exception - { - final KeyParameter key = new KeyParameter(new byte[keySize]); - final int blockSize = getBlockSize(cipher1); - final CipherParameters withIv = new ParametersWithIV(key, new byte[blockSize]); - - if (blockSize > 1) - { - testMode(new PaddedBufferedBlockCipher(cipher1, new PKCS7Padding()), key); - - testMode(new PaddedBufferedBlockCipher(new CBCBlockCipher(cipher1), new PKCS7Padding()), withIv); - - testMode(new BufferedBlockCipher(new OFBBlockCipher(cipher1, blockSize)), withIv); - testMode(new BufferedBlockCipher(new CFBBlockCipher(cipher1, blockSize)), withIv); - testMode(new BufferedBlockCipher(new SICBlockCipher(cipher1)), withIv); - } - // CTS requires at least one block - if (blockSize <= 16 && streamSize >= blockSize) - { - testMode(new CTSBlockCipher(cipher1), key); - } - if (blockSize <= 16 && streamSize >= blockSize) - { - testMode(new NISTCTSBlockCipher(NISTCTSBlockCipher.CS1, cipher1), key); - testMode(new NISTCTSBlockCipher(NISTCTSBlockCipher.CS2, cipher1), key); - testMode(new NISTCTSBlockCipher(NISTCTSBlockCipher.CS3, cipher1), key); - } - if (blockSize == 8 || blockSize == 16) - { - testMode(new EAXBlockCipher(cipher1), withIv); - } - if (blockSize == 16) - { - testMode(new CCMBlockCipher(cipher1), new ParametersWithIV(key, new byte[7])); - // TODO: need to have a GCM safe version of testMode. -// testMode(new GCMBlockCipher(cipher1), withIv); - testMode(new OCBBlockCipher(cipher1, cipher2), new ParametersWithIV(key, new byte[15])); - } - } - - private void testSkipping(StreamCipher cipher, CipherParameters params) - throws Exception - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - - init(cipher, true, params); - - OutputStream cOut = createCipherOutputStream(bOut, cipher); - byte[] data = new byte[5000]; - - new SecureRandom().nextBytes(data); - - cOut.write(data); - - cOut.close(); - - init(cipher, false, params); - - InputStream cIn = createCipherInputStream(bOut.toByteArray(), cipher); - - long skip = cIn.skip(50); - if (skip != 50) - { - fail("wrong number of bytes skipped: " + skip); - } - - byte[] block = new byte[50]; - - cIn.read(block); - - if (!areEqual(data, 50, block, 0)) - { - fail("initial skip mismatch"); - } - - skip = cIn.skip(3000); - if (skip != 3000) - { - fail("wrong number of bytes skipped: " + skip); - } - - cIn.read(block); - - if (!areEqual(data, 3100, block, 0)) - { - fail("second skip mismatch"); - } - - cipher.reset(); - - cIn = createCipherInputStream(bOut.toByteArray(), cipher); - if (!cIn.markSupported()) - { - fail("marking not supported"); - } - - cIn.mark(100); - - cIn.read(block); - - if (!areEqual(data, 0, block, 0)) - { - fail("initial mark read failed"); - } - - cIn.reset(); - - cIn.read(block); - - if (!areEqual(data, 0, block, 0)) - { - fail(cipher.getAlgorithmName() + " initial reset read failed"); - } - - cIn.reset(); - - cIn.read(block); - - cIn.mark(100); - - cIn.read(block); - - if (!areEqual(data, 50, block, 0)) - { - fail("second mark read failed"); - } - - cIn.reset(); - - cIn.read(block); - - if (!areEqual(data, 50, block, 0)) - { - fail(cipher.getAlgorithmName() + " second reset read failed"); - } - - cIn.mark(3000); - - skip = cIn.skip(2050); - if (skip != 2050) - { - fail("wrong number of bytes skipped: " + skip); - } - - cIn.reset(); - - cIn.read(block); - - if (!areEqual(data, 100, block, 0)) - { - fail(cipher.getAlgorithmName() + " third reset read failed"); - } - - cIn.read(new byte[2150]); - - cIn.reset(); - - cIn.read(block); - - if (!areEqual(data, 100, block, 0)) - { - fail(cipher.getAlgorithmName() + " fourth reset read failed"); - } - - cIn.close(); - } - - private boolean areEqual(byte[] a, int aOff, byte[] b, int bOff) - { - for (int i = bOff; i != b.length; i++) - { - if (a[aOff + i - bOff] != b[i]) - { - return false; - } - } - - return true; - } - - public static void main(String[] args) - { - runTest(new CipherStreamTest()); - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CipherTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CipherTest.java deleted file mode 100644 index 9d5de887e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CipherTest.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public abstract class CipherTest - extends SimpleTest -{ - private SimpleTest[] _tests; - private BlockCipher _engine; - private KeyParameter _validKey; - -// protected CipherTest( -// SimpleTest[] tests) -// { -// _tests = tests; -// } - - protected CipherTest( - SimpleTest[] tests, - BlockCipher engine, - KeyParameter validKey) - { - _tests = tests; - _engine = engine; - _validKey = validKey; - } - - public abstract String getName(); - - public void performTest() - throws Exception - { - for (int i = 0; i != _tests.length; i++) - { - _tests[i].performTest(); - } - - if (_engine != null) - { - // - // state tests - // - byte[] buf = new byte[128]; - - try - { - _engine.processBlock(buf, 0, buf, 0); - - fail("failed initialisation check"); - } - catch (IllegalStateException e) - { - // expected - } - - bufferSizeCheck((_engine)); - } - } - - private void bufferSizeCheck( - BlockCipher engine) - { - byte[] correctBuf = new byte[engine.getBlockSize()]; - byte[] shortBuf = new byte[correctBuf.length / 2]; - - engine.init(true, _validKey); - - try - { - engine.processBlock(shortBuf, 0, correctBuf, 0); - - fail("failed short input check"); - } - catch (DataLengthException e) - { - // expected - } - - try - { - engine.processBlock(correctBuf, 0, shortBuf, 0); - - fail("failed short output check"); - } - catch (DataLengthException e) - { - // expected - } - - engine.init(false, _validKey); - - try - { - engine.processBlock(shortBuf, 0, correctBuf, 0); - - fail("failed short input check"); - } - catch (DataLengthException e) - { - // expected - } - - try - { - engine.processBlock(correctBuf, 0, shortBuf, 0); - - fail("failed short output check"); - } - catch (DataLengthException e) - { - // expected - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CramerShoupTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CramerShoupTest.java deleted file mode 100644 index 953882212..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/CramerShoupTest.java +++ /dev/null @@ -1,147 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.agreement.DHStandardGroups; -import com.fr.third.org.bouncycastle.crypto.engines.CramerShoupCiphertext; -import com.fr.third.org.bouncycastle.crypto.engines.CramerShoupCoreEngine; -import com.fr.third.org.bouncycastle.crypto.engines.CramerShoupCoreEngine.CramerShoupCiphertextException; -import com.fr.third.org.bouncycastle.crypto.generators.CramerShoupKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.CramerShoupParametersGenerator; -import com.fr.third.org.bouncycastle.crypto.params.CramerShoupKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.CramerShoupParameters; -import com.fr.third.org.bouncycastle.util.BigIntegers; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class CramerShoupTest - extends SimpleTest -{ - private static final BigInteger ONE = BigInteger.valueOf(1); - - private static final SecureRandom RND = new SecureRandom(); - - private AsymmetricCipherKeyPair keyPair; - - public static void main(String[] args) - { - runTest(new CramerShoupTest()); - } - - public String getName() - { - return "CramerShoup"; - } - - - public void performTest() - throws Exception - { - BigInteger pSubOne = DHStandardGroups.rfc3526_2048.getP().subtract(ONE); - for (int i = 0; i < 10; ++i) - { - BigInteger message = BigIntegers.createRandomInRange(ONE, pSubOne, RND); - - BigInteger m1 = encDecTest(message); - BigInteger m2 = labelledEncDecTest(message, "myRandomLabel"); - BigInteger m3 = encDecEncodingTest(message); - BigInteger m4 = labelledEncDecEncodingTest(message, "myOtherCoolLabel"); - - if (!message.equals(m1) || !message.equals(m2) || !message.equals(m3) || !message.equals(m4)) - { - fail("decrypted message != original message"); - } - } - } - - private BigInteger encDecEncodingTest(BigInteger m) - { - CramerShoupCiphertext ciphertext = encrypt(m); - byte[] c = ciphertext.toByteArray(); - CramerShoupCiphertext decC = new CramerShoupCiphertext(c); - return decrypt(decC); - } - - private BigInteger labelledEncDecEncodingTest(BigInteger m, String l) - { - byte[] c = encrypt(m, l).toByteArray(); - return decrypt(new CramerShoupCiphertext(c), l); - } - - private BigInteger encDecTest(BigInteger m) - { - CramerShoupCiphertext c = encrypt(m); - return decrypt(c); - } - - private BigInteger labelledEncDecTest(BigInteger m, String l) - { - CramerShoupCiphertext c = encrypt(m, l); - return decrypt(c, l); - } - - - private BigInteger decrypt(CramerShoupCiphertext ciphertext) - { - return decrypt(ciphertext, null); - } - - private BigInteger decrypt(CramerShoupCiphertext ciphertext, String label) - { - - CramerShoupCoreEngine engine = new CramerShoupCoreEngine(); - if (label != null) - { - engine.init(false, keyPair.getPrivate(), label); - } - else - { - engine.init(false, keyPair.getPrivate()); - } - try - { - BigInteger m = engine.decryptBlock(ciphertext); - - return m; - } - catch (CramerShoupCiphertextException e) - { - e.printStackTrace(); - } - - return null; - } - - private CramerShoupCiphertext encrypt(BigInteger message) - { - return encrypt(message, null); - } - - private CramerShoupCiphertext encrypt(BigInteger message, String label) - { - CramerShoupKeyPairGenerator kpGen = new CramerShoupKeyPairGenerator(); - CramerShoupParametersGenerator pGen = new CramerShoupParametersGenerator(); - - pGen.init(2048, 1, RND); - CramerShoupParameters params = pGen.generateParameters(DHStandardGroups.rfc3526_2048); - CramerShoupKeyGenerationParameters param = new CramerShoupKeyGenerationParameters(RND, params); - - kpGen.init(param); - keyPair = kpGen.generateKeyPair(); - - CramerShoupCoreEngine engine = new CramerShoupCoreEngine(); - if (label != null) - { - engine.init(true, keyPair.getPublic(), label); - } - else - { - engine.init(true, keyPair.getPublic()); - } - - CramerShoupCiphertext ciphertext = engine.encryptBlock(message); - - return ciphertext; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DESTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DESTest.java deleted file mode 100644 index bbe968585..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DESTest.java +++ /dev/null @@ -1,206 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.KeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.generators.DESKeyGenerator; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.OFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.DESParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -import java.security.SecureRandom; - -class DESParityTest - extends SimpleTest -{ - public String getName() - { - return "DESParityTest"; - } - - public void performTest() - { - byte[] k1In = { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, - (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }; - byte[] k1Out = { (byte)0xfe, (byte)0xfe, (byte)0xfe, (byte)0xfe, - (byte)0xfe, (byte)0xfe, (byte)0xfe, (byte)0xfe }; - - byte[] k2In = { (byte)0xef, (byte)0xcb, (byte)0xda, (byte)0x4f, - (byte)0xaa, (byte)0x99, (byte)0x7f, (byte)0x63 }; - byte[] k2Out = { (byte)0xef, (byte)0xcb, (byte)0xda, (byte)0x4f, - (byte)0xab, (byte)0x98, (byte)0x7f, (byte)0x62 }; - - DESParameters.setOddParity(k1In); - - for (int i = 0; i != k1In.length; i++) - { - if (k1In[i] != k1Out[i]) - { - fail("Failed " - + "got " + new String(Hex.encode(k1In)) - + " expected " + new String(Hex.encode(k1Out))); - } - } - - DESParameters.setOddParity(k2In); - - for (int i = 0; i != k2In.length; i++) - { - if (k2In[i] != k2Out[i]) - { - fail("Failed " - + "got " + new String(Hex.encode(k2In)) - + " expected " + new String(Hex.encode(k2Out))); - } - } - } -} - -class KeyGenTest - extends SimpleTest -{ - public String getName() - { - return "KeyGenTest"; - } - - public void performTest() - { - DESKeyGenerator keyGen = new DESKeyGenerator(); - - keyGen.init(new KeyGenerationParameters(new SecureRandom(), 56)); - - byte[] kB = keyGen.generateKey(); - - if (kB.length != 8) - { - fail("DES bit key wrong length."); - } - } -} - -class DESParametersTest - extends SimpleTest -{ - static private byte[] weakKeys = - { - (byte)0x01,(byte)0x01,(byte)0x01,(byte)0x01, (byte)0x01,(byte)0x01,(byte)0x01,(byte)0x01, - (byte)0x1f,(byte)0x1f,(byte)0x1f,(byte)0x1f, (byte)0x0e,(byte)0x0e,(byte)0x0e,(byte)0x0e, - (byte)0xe0,(byte)0xe0,(byte)0xe0,(byte)0xe0, (byte)0xf1,(byte)0xf1,(byte)0xf1,(byte)0xf1, - (byte)0xfe,(byte)0xfe,(byte)0xfe,(byte)0xfe, (byte)0xfe,(byte)0xfe,(byte)0xfe,(byte)0xfe, - /* semi-weak keys */ - (byte)0x01,(byte)0xfe,(byte)0x01,(byte)0xfe, (byte)0x01,(byte)0xfe,(byte)0x01,(byte)0xfe, - (byte)0x1f,(byte)0xe0,(byte)0x1f,(byte)0xe0, (byte)0x0e,(byte)0xf1,(byte)0x0e,(byte)0xf1, - (byte)0x01,(byte)0xe0,(byte)0x01,(byte)0xe0, (byte)0x01,(byte)0xf1,(byte)0x01,(byte)0xf1, - (byte)0x1f,(byte)0xfe,(byte)0x1f,(byte)0xfe, (byte)0x0e,(byte)0xfe,(byte)0x0e,(byte)0xfe, - (byte)0x01,(byte)0x1f,(byte)0x01,(byte)0x1f, (byte)0x01,(byte)0x0e,(byte)0x01,(byte)0x0e, - (byte)0xe0,(byte)0xfe,(byte)0xe0,(byte)0xfe, (byte)0xf1,(byte)0xfe,(byte)0xf1,(byte)0xfe, - (byte)0xfe,(byte)0x01,(byte)0xfe,(byte)0x01, (byte)0xfe,(byte)0x01,(byte)0xfe,(byte)0x01, - (byte)0xe0,(byte)0x1f,(byte)0xe0,(byte)0x1f, (byte)0xf1,(byte)0x0e,(byte)0xf1,(byte)0x0e, - (byte)0xe0,(byte)0x01,(byte)0xe0,(byte)0x01, (byte)0xf1,(byte)0x01,(byte)0xf1,(byte)0x01, - (byte)0xfe,(byte)0x1f,(byte)0xfe,(byte)0x1f, (byte)0xfe,(byte)0x0e,(byte)0xfe,(byte)0x0e, - (byte)0x1f,(byte)0x01,(byte)0x1f,(byte)0x01, (byte)0x0e,(byte)0x01,(byte)0x0e,(byte)0x01, - (byte)0xfe,(byte)0xe0,(byte)0xfe,(byte)0xe0, (byte)0xfe,(byte)0xf1,(byte)0xfe,(byte)0xf1 - }; - - public String getName() - { - return "DESParameters"; - } - - public void performTest() throws Exception - { - try - { - DESParameters.isWeakKey(new byte[4], 0); - fail("no exception on small key"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("key material too short.")) - { - fail("wrong exception"); - } - } - - try - { - new DESParameters(weakKeys); - fail("no exception on weak key"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("attempt to create weak DES key")) - { - fail("wrong exception"); - } - } - - for (int i = 0; i != weakKeys.length; i += 8) - { - if (!DESParameters.isWeakKey(weakKeys, i)) - { - fail("weakKey test failed"); - } - } - } -} - -/** - * DES tester - vectors from FIPS 81 - */ -public class DESTest - extends CipherTest -{ - static String input1 = "4e6f77206973207468652074696d6520666f7220616c6c20"; - static String input2 = "4e6f7720697320746865"; - static String input3 = "4e6f7720697320746865aabbcc"; - - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new DESEngine(), - new KeyParameter(Hex.decode("0123456789abcdef")), - input1, "3fa40e8a984d48156a271787ab8883f9893d51ec4b563b53"), - new BlockCipherVectorTest(1, new CBCBlockCipher(new DESEngine()), - new ParametersWithIV(new KeyParameter(Hex.decode("0123456789abcdef")), Hex.decode("1234567890abcdef")), - input1, "e5c7cdde872bf27c43e934008c389c0f683788499a7c05f6"), - new BlockCipherVectorTest(2, new CFBBlockCipher(new DESEngine(), 8), - new ParametersWithIV(new KeyParameter(Hex.decode("0123456789abcdef")), Hex.decode("1234567890abcdef")), - input2, "f31fda07011462ee187f"), - new BlockCipherVectorTest(3, new CFBBlockCipher(new DESEngine(), 64), - new ParametersWithIV(new KeyParameter(Hex.decode("0123456789abcdef")), Hex.decode("1234567890abcdef")), - input1, "f3096249c7f46e51a69e839b1a92f78403467133898ea622"), - new BlockCipherVectorTest(4, new OFBBlockCipher(new DESEngine(), 8), - new ParametersWithIV(new KeyParameter(Hex.decode("0123456789abcdef")), Hex.decode("1234567890abcdef")), - input2, "f34a2850c9c64985d684"), - new BlockCipherVectorTest(5, new CFBBlockCipher(new DESEngine(), 64), - new ParametersWithIV(new KeyParameter(Hex.decode("0123456789abcdef")), Hex.decode("1234567890abcdef")), - input3, "f3096249c7f46e51a69e0954bf"), - new BlockCipherVectorTest(6, new OFBBlockCipher(new DESEngine(), 64), - new ParametersWithIV(new KeyParameter(Hex.decode("0123456789abcdef")), Hex.decode("1234567890abcdef")), - input3, "f3096249c7f46e5135f2c0eb8b"), - new DESParityTest(), - new DESParametersTest(), - new KeyGenTest() - }; - - public DESTest() - { - super(tests, new DESEngine(), new KeyParameter(new byte[8])); - } - - public String getName() - { - return "DES"; - } - - public static void main( - String[] args) - { - runTest(new DESTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DESedeTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DESedeTest.java deleted file mode 100644 index 30434c156..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DESedeTest.java +++ /dev/null @@ -1,177 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.KeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.Wrapper; -import com.fr.third.org.bouncycastle.crypto.engines.DESedeEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESedeWrapEngine; -import com.fr.third.org.bouncycastle.crypto.generators.DESedeKeyGenerator; -import com.fr.third.org.bouncycastle.crypto.params.DESedeParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -import java.security.SecureRandom; - -/** - * DESede tester - */ -public class DESedeTest - extends CipherTest -{ - static private byte[] weakKey = // first 8 bytes non-weak - { - (byte)0x06,(byte)0x01,(byte)0x01,(byte)0x01, (byte)0x01,(byte)0x01,(byte)0x01,(byte)0x01, - (byte)0x1f,(byte)0x1f,(byte)0x1f,(byte)0x1f, (byte)0x0e,(byte)0x0e,(byte)0x0e,(byte)0x0e, - (byte)0xe0,(byte)0xe0,(byte)0xe0,(byte)0xe0, (byte)0xf1,(byte)0xf1,(byte)0xf1,(byte)0xf1, - }; - - static String input1 = "4e6f77206973207468652074696d6520666f7220616c6c20"; - static String input2 = "4e6f7720697320746865"; - - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new DESedeEngine(), - new DESedeParameters(Hex.decode("0123456789abcdef0123456789abcdef")), - input1, "3fa40e8a984d48156a271787ab8883f9893d51ec4b563b53"), - new BlockCipherVectorTest(1, new DESedeEngine(), - new DESedeParameters(Hex.decode("0123456789abcdeffedcba9876543210")), - input1, "d80a0d8b2bae5e4e6a0094171abcfc2775d2235a706e232c"), - new BlockCipherVectorTest(2, new DESedeEngine(), - new DESedeParameters(Hex.decode("0123456789abcdef0123456789abcdef0123456789abcdef")), - input1, "3fa40e8a984d48156a271787ab8883f9893d51ec4b563b53"), - new BlockCipherVectorTest(3, new DESedeEngine(), - new DESedeParameters(Hex.decode("0123456789abcdeffedcba98765432100123456789abcdef")), - input1, "d80a0d8b2bae5e4e6a0094171abcfc2775d2235a706e232c") - }; - - DESedeTest() - { - super(tests, new DESedeEngine(), new KeyParameter(new byte[16])); - } - - private void wrapTest( - int id, - byte[] kek, - byte[] iv, - byte[] in, - byte[] out) - { - Wrapper wrapper = new DESedeWrapEngine(); - - wrapper.init(true, new ParametersWithIV(new KeyParameter(kek), iv)); - - try - { - byte[] cText = wrapper.wrap(in, 0, in.length); - if (!areEqual(cText, out)) - { - fail(": failed wrap test " + id + " expected " + new String(Hex.encode(out)) + " got " + new String(Hex.encode(cText))); - } - } - catch (Exception e) - { - fail("failed wrap test exception: " + e.toString(), e); - } - - wrapper.init(false, new KeyParameter(kek)); - - try - { - byte[] pText = wrapper.unwrap(out, 0, out.length); - if (!areEqual(pText, in)) - { - fail("failed unwrap test " + id + " expected " + new String(Hex.encode(in)) + " got " + new String(Hex.encode(pText))); - } - } - catch (Exception e) - { - fail("failed unwrap test exception: " + e.toString(), e); - } - } - - public void performTest() - throws Exception - { - super.performTest(); - - byte[] kek1 = Hex.decode("255e0d1c07b646dfb3134cc843ba8aa71f025b7c0838251f"); - byte[] iv1 = Hex.decode("5dd4cbfc96f5453b"); - byte[] in1 = Hex.decode("2923bf85e06dd6ae529149f1f1bae9eab3a7da3d860d3e98"); - byte[] out1 = Hex.decode("690107618ef092b3b48ca1796b234ae9fa33ebb4159604037db5d6a84eb3aac2768c632775a467d4"); - - wrapTest(1, kek1, iv1, in1, out1); - - // - // key generation - // - SecureRandom random = new SecureRandom(); - DESedeKeyGenerator keyGen = new DESedeKeyGenerator(); - - keyGen.init(new KeyGenerationParameters(random, 112)); - - byte[] kB = keyGen.generateKey(); - - if (kB.length != 16) - { - fail("112 bit key wrong length."); - } - - keyGen.init(new KeyGenerationParameters(random, 168)); - - kB = keyGen.generateKey(); - - if (kB.length != 24) - { - fail("168 bit key wrong length."); - } - - try - { - keyGen.init(new KeyGenerationParameters(random, 200)); - - fail("invalid key length not detected."); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - DESedeParameters.isWeakKey(new byte[4], 0); - fail("no exception on small key"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("key material too short.")) - { - fail("wrong exception"); - } - } - - try - { - new DESedeParameters(weakKey); - fail("no exception on weak key"); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().equals("attempt to create weak DESede key")) - { - fail("wrong exception"); - } - } - } - - public String getName() - { - return "DESede"; - } - - public static void main( - String[] args) - { - runTest(new DESedeTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DHKEKGeneratorTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DHKEKGeneratorTest.java deleted file mode 100644 index f80d665df..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DHKEKGeneratorTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.crypto.DerivationFunction; -import com.fr.third.org.bouncycastle.crypto.DerivationParameters; -import com.fr.third.org.bouncycastle.crypto.agreement.kdf.DHKDFParameters; -import com.fr.third.org.bouncycastle.crypto.agreement.kdf.DHKEKGenerator; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * DHKEK Generator tests - from RFC 2631. - */ -public class DHKEKGeneratorTest - extends SimpleTest -{ - private byte[] seed1 = Hex.decode("000102030405060708090a0b0c0d0e0f10111213"); - private ASN1ObjectIdentifier alg1 = PKCSObjectIdentifiers.id_alg_CMS3DESwrap; - private byte[] result1 = Hex.decode("a09661392376f7044d9052a397883246b67f5f1ef63eb5fb"); - - private byte[] seed2 = Hex.decode("000102030405060708090a0b0c0d0e0f10111213"); - private ASN1ObjectIdentifier alg2 = PKCSObjectIdentifiers.id_alg_CMSRC2wrap; - private byte[] partyAInfo = Hex.decode( - "0123456789abcdeffedcba9876543201" - + "0123456789abcdeffedcba9876543201" - + "0123456789abcdeffedcba9876543201" - + "0123456789abcdeffedcba9876543201"); - private byte[] result2 = Hex.decode("48950c46e0530075403cce72889604e0"); - - public DHKEKGeneratorTest() - { - } - - public void performTest() - { - checkMask(1, new DHKEKGenerator(new SHA1Digest()), new DHKDFParameters(alg1, 192, seed1), result1); - checkMask(2, new DHKEKGenerator(new SHA1Digest()), new DHKDFParameters(alg2, 128, seed2, partyAInfo), result2); - } - - private void checkMask( - int count, - DerivationFunction kdf, - DerivationParameters params, - byte[] result) - { - byte[] data = new byte[result.length]; - - kdf.init(params); - - kdf.generateBytes(data, 0, data.length); - - if (!areEqual(result, data)) - { - fail("DHKEKGenerator failed generator test " + count); - } - } - - public String getName() - { - return "DHKEKGenerator"; - } - - public static void main( - String[] args) - { - runTest(new DHKEKGeneratorTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DHTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DHTest.java deleted file mode 100644 index f172ad740..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DHTest.java +++ /dev/null @@ -1,540 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.agreement.DHAgreement; -import com.fr.third.org.bouncycastle.crypto.agreement.DHBasicAgreement; -import com.fr.third.org.bouncycastle.crypto.agreement.DHUnifiedAgreement; -import com.fr.third.org.bouncycastle.crypto.generators.DHBasicKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.DHKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.DHParametersGenerator; -import com.fr.third.org.bouncycastle.crypto.params.DHKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHUPrivateParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHUPublicParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class DHTest - extends SimpleTest -{ - private BigInteger g512 = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16); - private BigInteger p512 = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16); - - private BigInteger g768 = new BigInteger("7c240073c1316c621df461b71ebb0cdcc90a6e5527e5e126633d131f87461c4dc4afc60c2cb0f053b6758871489a69613e2a8b4c8acde23954c08c81cbd36132cfd64d69e4ed9f8e51ed6e516297206672d5c0a69135df0a5dcf010d289a9ca1", 16); - private BigInteger p768 = new BigInteger("8c9dd223debed1b80103b8b309715be009d48860ed5ae9b9d5d8159508efd802e3ad4501a7f7e1cfec78844489148cd72da24b21eddd01aa624291c48393e277cfc529e37075eccef957f3616f962d15b44aeab4039d01b817fde9eaa12fd73f", 16); - - private BigInteger g1024 = new BigInteger("1db17639cdf96bc4eabba19454f0b7e5bd4e14862889a725c96eb61048dcd676ceb303d586e30f060dbafd8a571a39c4d823982117da5cc4e0f89c77388b7a08896362429b94a18a327604eb7ff227bffbc83459ade299e57b5f77b50fb045250934938efa145511166e3197373e1b5b1e52de713eb49792bedde722c6717abf", 16); - private BigInteger p1024 = new BigInteger("a00e283b3c624e5b2b4d9fbc2653b5185d99499b00fd1bf244c6f0bb817b4d1c451b2958d62a0f8a38caef059fb5ecd25d75ed9af403f5b5bdab97a642902f824e3c13789fed95fa106ddfe0ff4a707c85e2eb77d49e68f2808bcea18ce128b178cd287c6bc00efa9a1ad2a673fe0dceace53166f75b81d6709d5f8af7c66bb7", 16); - - public String getName() - { - return "DH"; - } - - private void testDH( - int size, - BigInteger g, - BigInteger p) - { - DHKeyPairGenerator kpGen = getDHKeyPairGenerator(g, p); - - // - // generate first pair - // - AsymmetricCipherKeyPair pair = kpGen.generateKeyPair(); - - DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.getPublic(); - DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.getPrivate(); - // - // generate second pair - // - pair = kpGen.generateKeyPair(); - - DHPublicKeyParameters pu2 = (DHPublicKeyParameters)pair.getPublic(); - DHPrivateKeyParameters pv2 = (DHPrivateKeyParameters)pair.getPrivate(); - - // - // two way - // - DHAgreement e1 = new DHAgreement(); - DHAgreement e2 = new DHAgreement(); - - e1.init(pv1); - e2.init(pv2); - - BigInteger m1 = e1.calculateMessage(); - BigInteger m2 = e2.calculateMessage(); - - BigInteger k1 = e1.calculateAgreement(pu2, m2); - BigInteger k2 = e2.calculateAgreement(pu1, m1); - - if (!k1.equals(k2)) - { - fail(size + " bit 2-way test failed"); - } - } - - private void testDHBasic( - int size, - int privateValueSize, - BigInteger g, - BigInteger p) - { - DHBasicKeyPairGenerator kpGen = getDHBasicKeyPairGenerator(g, p, privateValueSize); - - // - // generate first pair - // - AsymmetricCipherKeyPair pair = kpGen.generateKeyPair(); - - DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.getPublic(); - DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.getPrivate(); - - checkKeySize(privateValueSize, pv1); - // - // generate second pair - // - pair = kpGen.generateKeyPair(); - - DHPublicKeyParameters pu2 = (DHPublicKeyParameters)pair.getPublic(); - DHPrivateKeyParameters pv2 = (DHPrivateKeyParameters)pair.getPrivate(); - - checkKeySize(privateValueSize, pv2); - // - // two way - // - DHBasicAgreement e1 = new DHBasicAgreement(); - DHBasicAgreement e2 = new DHBasicAgreement(); - - e1.init(pv1); - e2.init(pv2); - - BigInteger k1 = e1.calculateAgreement(pu2); - BigInteger k2 = e2.calculateAgreement(pu1); - - if (!k1.equals(k2)) - { - fail("basic " + size + " bit 2-way test failed"); - } - } - - private void checkKeySize( - int privateValueSize, - DHPrivateKeyParameters priv) - { - if (privateValueSize != 0) - { - if (priv.getX().bitLength() != privateValueSize) - { - fail("limited key check failed for key size " + privateValueSize); - } - } - } - - private void testGPWithRandom( - DHKeyPairGenerator kpGen) - { - // - // generate first pair - // - AsymmetricCipherKeyPair pair = kpGen.generateKeyPair(); - - DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.getPublic(); - DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.getPrivate(); - // - // generate second pair - // - pair = kpGen.generateKeyPair(); - - DHPublicKeyParameters pu2 = (DHPublicKeyParameters)pair.getPublic(); - DHPrivateKeyParameters pv2 = (DHPrivateKeyParameters)pair.getPrivate(); - - // - // two way - // - DHAgreement e1 = new DHAgreement(); - DHAgreement e2 = new DHAgreement(); - - e1.init(new ParametersWithRandom(pv1, new SecureRandom())); - e2.init(new ParametersWithRandom(pv2, new SecureRandom())); - - BigInteger m1 = e1.calculateMessage(); - BigInteger m2 = e2.calculateMessage(); - - BigInteger k1 = e1.calculateAgreement(pu2, m2); - BigInteger k2 = e2.calculateAgreement(pu1, m1); - - if (!k1.equals(k2)) - { - fail("basic with random 2-way test failed"); - } - } - - private void testSimpleWithRandom( - DHBasicKeyPairGenerator kpGen) - { - // - // generate first pair - // - AsymmetricCipherKeyPair pair = kpGen.generateKeyPair(); - - DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.getPublic(); - DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.getPrivate(); - // - // generate second pair - // - pair = kpGen.generateKeyPair(); - - DHPublicKeyParameters pu2 = (DHPublicKeyParameters)pair.getPublic(); - DHPrivateKeyParameters pv2 = (DHPrivateKeyParameters)pair.getPrivate(); - - // - // two way - // - DHBasicAgreement e1 = new DHBasicAgreement(); - DHBasicAgreement e2 = new DHBasicAgreement(); - - e1.init(new ParametersWithRandom(pv1, new SecureRandom())); - e2.init(new ParametersWithRandom(pv2, new SecureRandom())); - - BigInteger k1 = e1.calculateAgreement(pu2); - BigInteger k2 = e2.calculateAgreement(pu1); - - if (!k1.equals(k2)) - { - fail("basic with random 2-way test failed"); - } - } - - private DHBasicKeyPairGenerator getDHBasicKeyPairGenerator( - BigInteger g, - BigInteger p, - int privateValueSize) - { - DHParameters dhParams = new DHParameters(p, g, null, privateValueSize); - DHKeyGenerationParameters params = new DHKeyGenerationParameters(new SecureRandom(), dhParams); - DHBasicKeyPairGenerator kpGen = new DHBasicKeyPairGenerator(); - - kpGen.init(params); - - return kpGen; - } - - private DHKeyPairGenerator getDHKeyPairGenerator( - BigInteger g, - BigInteger p) - { - DHParameters dhParams = new DHParameters(p, g); - DHKeyGenerationParameters params = new DHKeyGenerationParameters(new SecureRandom(), dhParams); - DHKeyPairGenerator kpGen = new DHKeyPairGenerator(); - - kpGen.init(params); - - return kpGen; - } - - /** - * this test is can take quiet a while - */ - private void testGeneration( - int size) - { - DHParametersGenerator pGen = new DHParametersGenerator(); - - pGen.init(size, 10, new SecureRandom()); - - DHParameters dhParams = pGen.generateParameters(); - - if (dhParams.getL() != 0) - { - fail("DHParametersGenerator failed to set J to 0 in generated DHParameters"); - } - - DHKeyGenerationParameters params = new DHKeyGenerationParameters(new SecureRandom(), dhParams); - - DHBasicKeyPairGenerator kpGen = new DHBasicKeyPairGenerator(); - - kpGen.init(params); - - // - // generate first pair - // - AsymmetricCipherKeyPair pair = kpGen.generateKeyPair(); - - DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.getPublic(); - DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.getPrivate(); - - // - // generate second pair - // - params = new DHKeyGenerationParameters(new SecureRandom(), pu1.getParameters()); - - kpGen.init(params); - - pair = kpGen.generateKeyPair(); - - DHPublicKeyParameters pu2 = (DHPublicKeyParameters)pair.getPublic(); - DHPrivateKeyParameters pv2 = (DHPrivateKeyParameters)pair.getPrivate(); - - // - // two way - // - DHBasicAgreement e1 = new DHBasicAgreement(); - DHBasicAgreement e2 = new DHBasicAgreement(); - - e1.init(new ParametersWithRandom(pv1, new SecureRandom())); - e2.init(new ParametersWithRandom(pv2, new SecureRandom())); - - BigInteger k1 = e1.calculateAgreement(pu2); - BigInteger k2 = e2.calculateAgreement(pu1); - - if (!k1.equals(k2)) - { - fail("basic with " + size + " bit 2-way test failed"); - } - } - - private void testBounds() - { - BigInteger p1 = new BigInteger("00C8028E9151C6B51BCDB35C1F6B2527986A72D8546AE7A4BF41DC4289FF9837EE01592D36C324A0F066149B8B940C86C87D194206A39038AE3396F8E12435BB74449B70222D117B8A2BB77CB0D67A5D664DDE7B75E0FEC13CE0CAF258DAF3ADA0773F6FF0F2051D1859929AAA53B07809E496B582A89C3D7DA8B6E38305626621", 16); - BigInteger g1 = new BigInteger("1F869713181464577FE4026B47102FA0D7675503A4FCDA810881FAEC3524E6DBAEA9B96561EF7F8BEA76466DF11C2F3EB1A90CC5851735BF860606481257EECE6418C0204E61004E85D7131CE54BCBC7AD67E53C79DCB715E7C8D083DCD85D728283EC8F96839B4C9FA7C0727C472BEB94E4613CAFA8D580119C0AF4BF8AF252", 16); - int l1 = 1023; - - BigInteger p2 = new BigInteger("00B333C98720220CC3946F494E25231B3E19F9AD5F6B19F4E7ABF80D8826C491C3224D4F7415A14A7C11D1BE584405FED12C3554F103E56A72D986CA5E325BB9DE07AC37D1EAE5E5AC724D32EF638F0E4462D4C1FC7A45B9FD3A5DF5EC36A1FA4DAA3FBB66AA42B1B71DF416AB547E987513426C7BB8634F5F4D37705514FDC1E1", 16); - BigInteger g2 = new BigInteger("2592F5A99FE46313650CCE66C94C15DBED9F4A45BD05C329986CF5D3E12139F0405A47C6385FEA27BFFEDC4CBABC5BB151F3BEE7CC3D51567F1E2B12A975AA9F48A70BDAAE7F5B87E70ADCF902490A3CBEFEDA41EBA8E12E02B56120B5FDEFBED07F5EAD3AE020DF3C8233216F8F0D35E13A7AE4DA5CBCC0D91EADBF20C281C6", 16); - int l2 = 1024; - - DHKeyGenerationParameters params1 = new DHKeyGenerationParameters(new SecureRandom(), new DHParameters(p1, g1, null, l1)); - DHKeyGenerationParameters params2 = new DHKeyGenerationParameters(new SecureRandom(), new DHParameters(p2, g2, null, l2)); - - DHBasicKeyPairGenerator kpGen = new DHBasicKeyPairGenerator(); - - kpGen.init(params1); - kpGen.init(params2); - } - - private void testCombinedTestVector1() - { - // Test Vector from NIST sample data - - BigInteger P = new BigInteger("eedb3431b31d30851ddcd4dce57e1b8fc3b83cc7913bc049281d713d9f8fa91bfd0fde2e1ec5eb45a0d6483cfa6b5055ffa88622a1aa83b9f9c1df561e88b702866f17af2defea0b04cf3fbdd817140ad49c415909fc2bb2c5d160b77273e958a181bf73cf72118e1c8670d53d0e459d14d61ecb5b7c7f63a9cb019cd66aecb3a01d0402f1c18218f142653f4bc922e5baa35964b7432f311fa5a9b34e3b91582db366ad1493f25ea659540f87758ae34678dc864fb2c9d4aba18cb757285292c7d0bac73cc4632a2d54b89f2dc9656d1c50edd49dcbe2102510c70563a96f35dd8a21f0fdc5a1e23ce31fce0ee3023eafdca623508ffd2412fe4dc5b5dd0f75", 16); - BigInteger Q = new BigInteger("e90a78d5da01e926462e5c17a61ff97b09b6ac18f9137e7b99298705", 16); - BigInteger G = new BigInteger("9da3567e2f7396dd2ee4716d3477a53a47f811b2275a95ed07024d7231b739c79e88e5377479b23d460a41f981b1af619915e4d8b2dabf2cb716168d02dfb81e76048e23fff6c773f496b2ac3ae06e2eb12c39787a8244452aef404ce631aec9cf4027eefae492ce55517db0af3939354c5414e23205ae3bcd17faedecf80101fa75c619249a43b41aa15ee2d7699ee32e227b641129fe1c78b20c6655b09fa7fead338e179b4b4416c359b16e3773d141e1a876b7ee4281b61120607717f7edc8da8de42b16b54d0802d67d41fc173cd33227436f7c66bd2fe711b37fb0162543c268857414f4188f243fbf92e128388329c9f2df8db4e7808ab539891da798", 16); - - DHParameters p = new DHParameters(P, G, Q); - - AsymmetricCipherKeyPair U1 = new AsymmetricCipherKeyPair( - new DHPublicKeyParameters( - new BigInteger("e485cd4b82e82dafd35f89d40361049e6100c16b17ca156d072832319a40bf7a3f5081182397b8fbd9d33391896bb35d9cc890d8c0a9e5b642b773ce0690f1bbd4596a9604708edb9c27f45117a7395b7407b43eebd8b82bef4a925e2a93185df21fbf012ec9059a9c9efc0b64afe0505aa1864d79a2a9833863c16163b48c9fcc26a9b9e2741097bdeabc2b7208589e4154e1de7ecf77e928668b28abb8113b322c6d426701df979d47ccd50d493b7fb6f20050c3e67cb876c1550d8c8677527600eab07196213252bd9a48d5023788fdb4b65f85144cf6654e092550646be4882125b286ced6578eedc981304ff88725e4138f90a7a4a07c94105d796b038f", 16), p), - new DHPrivateKeyParameters( - new BigInteger("8a10c0be8f4efaf3019b99698bc4c102f2dac93b993d52ab10ae93f0", 16), p)); - - AsymmetricCipherKeyPair U2 = new AsymmetricCipherKeyPair( - new DHPublicKeyParameters( - new BigInteger("3e84fbbb785bbdc43881b04ec6221b69a557b8b708d72cec8627a8342787554702d5021153ff1246ba5311553f740835c4b82ebc28c5fac05ad37f6c619649750e8dc41af9176af0099f18d36ee43535e7f35fb5f70a37b25dedd87cb6035bb938531c0430cee9c5c8f4321eae72590122bff1f636dcd6a32116ea3945d23a17acc1bfd1e7ad12390e6e13b456bc4a613b1356a7ca95c2660ac5c9f064a6b9c6d584c7e23bc1ff56745d92d0efc06384b3f59125f7c0918ae3a40074d229e22d8ca7573f9fbe89bc7afb344498d6a85b823e1fa20c3d6eccdd69abafe5e43273e71b6d32aa8dc3a349ec4ae41304e6e159c2e5c4b1555a538d58b46a4c8c87d9", 16), p), - new DHPrivateKeyParameters( - new BigInteger("5cb398bfbc3f69744de1f9611e03ab97aba0c5dbe1f6d74ac60fecdf", 16), p)); - - AsymmetricCipherKeyPair V1 = new AsymmetricCipherKeyPair( - new DHPublicKeyParameters( - new BigInteger("2d6e1bb1ed6cc967027f2eb76d069369ac26f38fc87110fe55cc6487988a7d7bf2525a1b65cd02e30fcaa12d626f3b18d9191e6dcbf9fbe4b1f421dd2cb8ca804a7ca535c05bcb850561edb477eafe0a1e1e2468e89bb58899293d65cde98db5200b5eb32b1d80d4489fbab14a68f74453513658bda56067e8b41add0f13f5980ceb77c52f205e3d8b36f436ff0b313860197972de0da8b554b47091b8a69cf6ce7efd6cae6e17f090e0f71fc5332a9999cf880ff5c031132463b0eb56083885cee842f85540418b68d0250b18181b0dfb9487e39aad1d0402dc910cf679fd87d765222812ec66cf0a981f950de94b0fd1f45370bc2176748d20fe099c1f498c", 16), p), - new DHPrivateKeyParameters( - new BigInteger("9b6038b952d3491d937a41e1bf8857bd79b80a96c99783a96ff1ef93", 16), p)); - - AsymmetricCipherKeyPair V2 = new AsymmetricCipherKeyPair( - new DHPublicKeyParameters( - new BigInteger("991805c775da39e0b92dc71f212e332cbab2b62a86114836bbe091c5ba2ce12cca5011483e220c0f24bba23f24a32c2c11b966064beba99b0b21eb19c7f46b328dc30af094ec116248e6f3f856aab622da4eb36b6056d7c5a3e0a0f1c45acc24321fccd1d0e0f4503e3e3aae3748ae6adeb1b85e0f708b4877b7a8d97acab093a57820b9d861da6d919126ae1c0b2d28dccca03a1808c03d5c5b6847d5e43a70b0a07190ced3ccf419e9f790281cf4676cad5dc6c7d3591a9fde2251850e072ffbc0411d8559460303c56738a1dbf76c8dd165b62a407e8cac9455c9257016fa0c7892cbcb978489a909f74d38d10746c1d5756329607ab0479c994c5d6f30e3", 16), p), - new DHPrivateKeyParameters( - new BigInteger("2775ab7578d5c0e18d12ed02f8c38ddfe272712902ee6a256270b041", 16), p)); - - byte[] x = calculateUnifiedAgreement(U1, U2, V1, V2); - - if (x == null - || !areEqual(Hex.decode("0f028c915a5ff77f5997791b66f08261995f7b459a574d66412f00afe5af4b838da0b9a4ed371077f1160f063844bca86ae83838cce0974d130f489532a8aeee5d55df17c13a15f79f27144aa3533665a47867f3eb43feb963ac2201d2766fb62a3979c19411c94cedf2c283b59fc616fbeeca585deb726fc7002900dc300e7b9bc055261708fee0f1f9b90de4f3720b7ec85d68745f41d495f1001dd7ccbbacf42ff2edc28e33454c5c59897d9782142db3f47972e2a79f16028f5fc6cdce4c729c57e9f63b55e25e80e3663528942b79749d7d66f7d84d4c8c4e877e221a8e06c7f001cd50b008086a4b0981e5fe000b7896dee152b24ed9cdb9907a5d64f0e4225b3cba8268c45c0846a60a697218a683e1b33843cb0153d8634769882a7fef5db4653d827bd75b54dda96666944b5d836b875d76936f73520e57be069f6aba7c36d42fc07be3e7ea49d0dabfad3177aa673553ba93a990cb79df9bcd8fa979f81c75b280cb99ff8e09713546cae8dbaea1021d2c29902793d483f29c1153f432e8b00e039286b085df0260d4949703a4a7a46492d1cb586d1845182c5b5461a432c5ebe60650de40e9e25502a0dfb931c4d5e5d9b624dcab3cbb5bf7cc51e5dbf35cd7029e724840c660dd4a6014de92a2bbb8a1b6ce28f6448d28cf1975017f66bc6904d244fe91ec39e509568d1c8256fa79931875b7ab69e29e432cce"), x)) - { - fail("DH Combined Test Vector #1 agreement failed"); - } - } - - private void testCombinedTestVector2() - { - // Test Vector from NIST sample data - - BigInteger P = new BigInteger("ea40cd647d0a1d3bcbdfa721a837e4d4dfd328340892a00aa2317f2fc532fe1e185d4ef0718281959943fc949964e542310deb687f7fcc45696c829a491b7dc5c46fff01673e71d92520465b4115dbb7edaeb32ec2688d0a5a9be93a322f3023b96d5f54e02d4a72dec479f68b40caff79f810f3a5cdaa3bda9eb87151b4c0663ceef4b50ca22ac63e4ab1343978e8ec148b5523734b23aa9ca92a21ca1cbe652c9a01b1724a1b10285778287cb5bf87c45e45dc54998e5e5308c00003131be4a62add4f5acbb0c4e2229e0fccd1633e4cf024f96dcbf012e5b629394500b1b5ceb6707957bde445671ba9a1d5b9a7d1dfe2f1419d1abf236b4b49bcfd7563df", 16); - BigInteger Q = new BigInteger("aa6b31da31408f637670a1fc36ca3625a5eebea9bdcc4398124bb9a006ac21f1", 16); - BigInteger G = new BigInteger("380ad19f75e5c666aa24daf545d74c51a4374f9002de09744bc338a33a3ab2017fdeb59f1f8552125ade4dceb7094d125ffad694662e3fe924d23c7a404806631e353887bbc4bf9f892f581880975918aca5b8a7d5108b791469f2e35f0a4095ce253bec246a8cdce190507018a4f844685eb2e0ba0146d5bb2d7ff7f1c5624fa2d7f6d20834c453457eb0227c26ae5d422cde461cfe1cd2f5ff909388dcd6ccdbfb8617b54d9038c1b9b1b2f15febbd5215db893f3a8f340bd18ac74d025a63b321ec537fa5d2c04c651f0431f75bc490ddd2a846595c6d10d0a085ab3835d025a334cdb0b25c3d993fa22aecaf5f87ca417a7aa278cb765344195f2a45201b", 16); - - DHParameters p = new DHParameters(P, G, Q); - - AsymmetricCipherKeyPair U1 = new AsymmetricCipherKeyPair( - new DHPublicKeyParameters( - new BigInteger("a2c43dc18321063dac3cd7793fb3a6cc3b38cbce99f233ba295660aa6cbba1449b0783acb7da1118bd0530f022336a2bb8845ac26bb71c3647369e8aa29ef7b5ddc4a3b4fe70291c9acf1bc1ce5666a3401b885fd7b1906ed27a985efdb643464398036ed79eb1a79cd7b88c5bfa4418df6439ac2297b946f125f7086537082f2144545da570835b23f27ebd400ceae6670168fece4ce3780a59d6eebb3a76f91de308d4aa9a1617b4005b6b089af5c5247af6a5dea1693861151e0a5aaa4b86884ab2969f5bc3008f19ac54118939b2efccf307dc2e3aa675aea0d80dcaec7160408d6e12b0b041544c831b9ae3d06b5d51e2e77035f0b5439fb375a9bd7664", 16), p), - new DHPrivateKeyParameters( - new BigInteger("7b4957b799a08816f9c48c2aff5dcc0aa6ad93a765a664e67899f09d1fa8949e", 16), p)); - - AsymmetricCipherKeyPair U2 = new AsymmetricCipherKeyPair( - new DHPublicKeyParameters( - new BigInteger("5ceca3f30cb6eb8bef123518d9b569fb9df47ac54944e381da3f69ab4a3f0484e49ea8e54d87b2bcad6f78c82f9a1969b72c7b1314ccf2ff7aa857e69ae24dbbce023f8d3cfcb2b5fe942750597b1ada12b685bb12c6ddfddf0a9d2b95e0692d431f5735b71d456fabc7362581cad88ca97b69cf185ec2d6097b07a1da80291c4d93285b21604540dc1da0807009b8f708e4eb4bdd40672b875076d5f4e712b54922c6506de4280f2cf8b34d78ea59a91dd45c7eee8cd77d8640af48342ea348abed040f7dd085181bda8f9ce88cc602407ae91b4fcb051cfcff7e7479fb6e24f6b7fb013d5b3d2ccc3dc3088c331fc9644b73e1b47e3f585f97e6f2c57e9983", 16), p), - new DHPrivateKeyParameters( - new BigInteger("8f9fe1ecd00b427a211f9d52b973aad9451b5985757a2204473f06de07eb39e2", 16), p)); - - AsymmetricCipherKeyPair V1 = new AsymmetricCipherKeyPair( - new DHPublicKeyParameters( - new BigInteger("b823ca4d470c714efb57420cc50acbb56eb4a4664abb3fe233496c2a0f70e52a0af08f87490724819d8bfc10203dc62b38ee032f5e14e612e1b23d5b014359ab4fe3584f49475c9d117f9ad89511d88c79dcc284d39d722939b0b5d24ad7374af70db712344755fc54502d0ae428860f63fcdcd9537c0f89f451ada1a30676481154129de022019e5a6ac1c117820896ebd97d06db887d6fd088ab71ad0fd2f3c87a015abe428aeadee7a8a65a7b823edcf4b7d9b2faf98691126b885e5804bac1a8fa1d05c186de218816e0aa75e939b731621a424b39d19e47a81d3638ff3d663e38a802361fb9bd1e79b2f3d1f4955b3d7d63bcb373f2ee70659a270f5087", 16), p), - new DHPrivateKeyParameters( - new BigInteger("2c8c6202bb519b17361418f48ef346328db6be65b4aa6a25561e165b6958682e", 16), p)); - - AsymmetricCipherKeyPair V2 = new AsymmetricCipherKeyPair( - new DHPublicKeyParameters( - new BigInteger("dae7f69a4a318f506181bd97320777e9256dcf992057eb951585fbd5b6e22e0a57255f316315e462ee38e15a0e5c5b9fc3f6f0611929bfe681f0d093cdcda18e35e13f09d5c73cbab5f659b2c55669410e5a772b621acbfa365db6046b08bce1bac4c379ad0f2bee10eddb040645ab75d5888c93e91efdc442053e5e935541b80afa911881daa91488bceab9585facbbdb010575387eac4f6657fbdc85a37dedbfccbd9b37d671861c5853de9078bdf905f15b191f2dcc1c93ee7258dc6854a8d3882ff4f03753373305fa4a00a839c3853e128f51004a17641f37ed9035665c4a6d6240cbeefb9c36b618a50e3b75d6128f732b34d81ce8b316ddefe8c0630d", 16), p), - new DHPrivateKeyParameters( - new BigInteger("35f5bf981241cff39e43b93bf31f5612a364595a881e75315de0b42b82f0d596", 16), p)); - - byte[] x = calculateUnifiedAgreement(U1, U2, V1, V2); - - if (x == null - || !areEqual(Hex.decode("6d1eae28340c2095ab915b6655c96d23986c49e53f38de42a9c906eeeae3686744855b940de8377ad23053d923116f6dce7c91eea69714092a4e182cef01b362937c9bc66cc892948e79bac85bf0b9ee5c402c7725def46f754e5cd743e89247e84a4fe6e50b249c7aecf62114cb3beb6a0f8af8b0f3a19799c67372109fe0e01af6517d4108888cd3864b801a8566516b454219ee74b86a2e1a4cfbb2407198a1382858b947f9258404764fee9a0a99198c594fee426e04453b41051cfa22359d2b10d425142045b1a186056413203f4553ce0d7977012f1d3aa3df571f041f7422d4518da7abdf5a32bbbc86615cd2217b73719cb0b5ee5228a74ed0cb8202b862c68e46ab8282a482a9c94365e3dcb3b9b511bc65e7741f7d90f1180ef9c926ed9209cb10291d0ea472e675ac7704244723d788985aa6f5a73c83be4cdaba402453dfa572ac6d5bafb51b130556481e98a5ab5ede13364b886fbbf57f282b8f560f4ceafb2f29d953c8244aa3fea0c227a1a88e012e814267ecf36ac72793acf2ee02713d8980f30bc9231aae91a8181ed4645aa969625990cbdc7f4f646929132ef73354950c2490f91847a3350ece763a1869f6e446e4995296d4c024bf6998dd11aea59220e81e1aade984ba650150621f17e4bbca5f0f49fd21924c3a605d1e7e4fd3e32b93e1df6cd6a0d28cd9105537b513144e8ad1d3007bffbb15"), x)) - { - fail("DH Combined Test Vector #2 agreement failed"); - } - } - - private byte[] calculateUnifiedAgreement( - AsymmetricCipherKeyPair U1, - AsymmetricCipherKeyPair U2, - AsymmetricCipherKeyPair V1, - AsymmetricCipherKeyPair V2) - { - DHUnifiedAgreement u = new DHUnifiedAgreement(); - u.init(new DHUPrivateParameters( - (DHPrivateKeyParameters)U1.getPrivate(), - (DHPrivateKeyParameters)U2.getPrivate(), - (DHPublicKeyParameters)U2.getPublic())); - byte[] ux = u.calculateAgreement(new DHUPublicParameters( - (DHPublicKeyParameters)V1.getPublic(), - (DHPublicKeyParameters)V2.getPublic())); - - DHUnifiedAgreement v = new DHUnifiedAgreement(); - v.init(new DHUPrivateParameters( - (DHPrivateKeyParameters)V1.getPrivate(), - (DHPrivateKeyParameters)V2.getPrivate(), - (DHPublicKeyParameters)V2.getPublic())); - byte[] vx = v.calculateAgreement(new DHUPublicParameters( - (DHPublicKeyParameters)U1.getPublic(), - (DHPublicKeyParameters)U2.getPublic())); - - if (areEqual(ux, vx)) - { - return ux; - } - - return null; - } - - public void performTest() - { - testDHBasic(512, 0, g512, p512); - testDHBasic(768, 0, g768, p768); - testDHBasic(1024, 0, g1024, p1024); - - testDHBasic(512, 64, g512, p512); - testDHBasic(768, 128, g768, p768); - testDHBasic(1024, 256, g1024, p1024); - - testDH(512, g512, p512); - testDH(768, g768, p768); - testDH(1024, g1024, p1024); - - testBounds(); - - testCombinedTestVector1(); - testCombinedTestVector2(); - - // - // generation test. - // - testGeneration(256); - - // - // with random test - // - DHBasicKeyPairGenerator kpBasicGen = getDHBasicKeyPairGenerator(g512, p512, 0); - - testSimpleWithRandom(kpBasicGen); - - DHKeyPairGenerator kpGen = getDHKeyPairGenerator(g512, p512); - - testGPWithRandom(kpGen); - - // - // parameter tests - // - DHAgreement dh = new DHAgreement(); - AsymmetricCipherKeyPair dhPair = kpGen.generateKeyPair(); - - try - { - dh.init(dhPair.getPublic()); - fail("DHAgreement key check failed"); - } - catch (IllegalArgumentException e) - { - // ignore - } - - DHKeyPairGenerator kpGen768 = getDHKeyPairGenerator(g768, p768); - - try - { - dh.init(dhPair.getPrivate()); - - dh.calculateAgreement((DHPublicKeyParameters)kpGen768.generateKeyPair().getPublic(), BigInteger.valueOf(100)); - - fail("DHAgreement agreement check failed"); - } - catch (IllegalArgumentException e) - { - // ignore - } - - DHBasicAgreement dhBasic = new DHBasicAgreement(); - AsymmetricCipherKeyPair dhBasicPair = kpBasicGen.generateKeyPair(); - - try - { - dhBasic.init(dhBasicPair.getPublic()); - fail("DHBasicAgreement key check failed"); - } - catch (IllegalArgumentException e) - { - // expected - } - - DHBasicKeyPairGenerator kpBasicGen768 = getDHBasicKeyPairGenerator(g768, p768, 0); - - try - { - dhBasic.init(dhPair.getPrivate()); - - dhBasic.calculateAgreement((DHPublicKeyParameters)kpBasicGen768.generateKeyPair().getPublic()); - - fail("DHBasicAgreement agreement check failed"); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - public static void main( - String[] args) - { - runTest(new DHTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DSATest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DSATest.java deleted file mode 100644 index d101d7da8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DSATest.java +++ /dev/null @@ -1,725 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.digests.SHA224Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA3Digest; -import com.fr.third.org.bouncycastle.crypto.generators.DSAKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.DSAParametersGenerator; -import com.fr.third.org.bouncycastle.crypto.params.DSAKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.DSAParameterGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.DSAParameters; -import com.fr.third.org.bouncycastle.crypto.params.DSAPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.DSAPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.DSAValidationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.signers.DSADigestSigner; -import com.fr.third.org.bouncycastle.crypto.signers.DSASigner; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.BigIntegers; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.FixedSecureRandom; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestRandomBigInteger; -import com.fr.third.org.bouncycastle.util.test.TestRandomData; - -/** - * Test based on FIPS 186-2, Appendix 5, an example of DSA, and FIPS 168-3 test vectors. - */ -public class DSATest - extends SimpleTest -{ - byte[] k1 = Hex.decode("d5014e4b60ef2ba8b6211b4062ba3224e0427dd3"); - byte[] k2 = Hex.decode("345e8d05c075c3a508df729a1685690e68fcfb8c8117847e89063bca1f85d968fd281540b6e13bd1af989a1fbf17e06462bf511f9d0b140fb48ac1b1baa5bded"); - - SecureRandom random = new FixedSecureRandom( - new FixedSecureRandom.Source[] { new FixedSecureRandom.Data(k1), new FixedSecureRandom.Data(k2) }); - - byte[] keyData = Hex.decode("b5014e4b60ef2ba8b6211b4062ba3224e0427dd3"); - - SecureRandom keyRandom = new FixedSecureRandom( - new FixedSecureRandom.Source[] { new FixedSecureRandom.Data(keyData), new FixedSecureRandom.Data(keyData), new FixedSecureRandom.Data(Hex.decode("01020304"))}); - - BigInteger pValue = new BigInteger("8df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8324f0d7882e5d0762fc5b7210eafc2e9adac32ab7aac49693dfbf83724c2ec0736ee31c80291", 16); - BigInteger qValue = new BigInteger("c773218c737ec8ee993b4f2ded30f48edace915f", 16); - - public String getName() - { - return "DSA"; - } - - public void performTest() - { - BigInteger r = new BigInteger("68076202252361894315274692543577577550894681403"); - BigInteger s = new BigInteger("1089214853334067536215539335472893651470583479365"); - DSAParametersGenerator pGen = new DSAParametersGenerator(); - - pGen.init(512, 80, random); - - DSAParameters params = pGen.generateParameters(); - DSAValidationParameters pValid = params.getValidationParameters(); - - if (pValid.getCounter() != 105) - { - fail("Counter wrong"); - } - - if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ())) - { - fail("p or q wrong"); - } - - DSAKeyPairGenerator dsaKeyGen = new DSAKeyPairGenerator(); - DSAKeyGenerationParameters genParam = new DSAKeyGenerationParameters(keyRandom, params); - - dsaKeyGen.init(genParam); - - AsymmetricCipherKeyPair pair = dsaKeyGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), keyRandom); - - DSASigner dsa = new DSASigner(); - - dsa.init(true, param); - - byte[] message = BigIntegers.asUnsignedByteArray(new BigInteger("968236873715988614170569073515315707566766479517")); - BigInteger[] sig = dsa.generateSignature(message); - - if (!r.equals(sig[0])) - { - fail("r component wrong.", r, sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong.", s, sig[1]); - } - - dsa.init(false, pair.getPublic()); - - if (!dsa.verifySignature(message, sig[0], sig[1])) - { - fail("verification fails"); - } - - dsa2Test1(); - dsa2Test2(); - dsa2Test3(); - dsa2Test4(); - - testDSAsha3(224, new BigInteger("613202af2a7f77e02b11b5c3a5311cf6b412192bc0032aac3ec127faebfc6bd0", 16)); - testDSAsha3(256, new BigInteger("2450755c5e15a691b121bc833b97864e34a61ee025ecec89289c949c1858091e", 16)); - testDSAsha3(384, new BigInteger("7aad97c0b71bb1e1a6483b6948a03bbe952e4780b0cee699a11731f90d84ddd1", 16)); - testDSAsha3(512, new BigInteger("725ad64d923c668e64e7c3898b5efde484cab49ce7f98c2885d2a13a9e355ad4", 16)); - } - - private void testDSAsha3(int size, BigInteger s) - { - DSAParameters dsaParams = new DSAParameters( - new BigInteger( - "F56C2A7D366E3EBDEAA1891FD2A0D099" + - "436438A673FED4D75F594959CFFEBCA7BE0FC72E4FE67D91" + - "D801CBA0693AC4ED9E411B41D19E2FD1699C4390AD27D94C" + - "69C0B143F1DC88932CFE2310C886412047BD9B1C7A67F8A2" + - "5909132627F51A0C866877E672E555342BDF9355347DBD43" + - "B47156B2C20BAD9D2B071BC2FDCF9757F75C168C5D9FC431" + - "31BE162A0756D1BDEC2CA0EB0E3B018A8B38D3EF2487782A" + - "EB9FBF99D8B30499C55E4F61E5C7DCEE2A2BB55BD7F75FCD" + - "F00E48F2E8356BDB59D86114028F67B8E07B127744778AFF" + - "1CF1399A4D679D92FDE7D941C5C85C5D7BFF91BA69F9489D" + - "531D1EBFA727CFDA651390F8021719FA9F7216CEB177BD75", 16), - new BigInteger("C24ED361870B61E0D367F008F99F8A1F75525889C89DB1B673C45AF5867CB467", 16), - new BigInteger( - "8DC6CC814CAE4A1C05A3E186A6FE27EA" + - "BA8CDB133FDCE14A963A92E809790CBA096EAA26140550C1" + - "29FA2B98C16E84236AA33BF919CD6F587E048C52666576DB" + - "6E925C6CBE9B9EC5C16020F9A44C9F1C8F7A8E611C1F6EC2" + - "513EA6AA0B8D0F72FED73CA37DF240DB57BBB27431D61869" + - "7B9E771B0B301D5DF05955425061A30DC6D33BB6D2A32BD0" + - "A75A0A71D2184F506372ABF84A56AEEEA8EB693BF29A6403" + - "45FA1298A16E85421B2208D00068A5A42915F82CF0B858C8" + - "FA39D43D704B6927E0B2F916304E86FB6A1B487F07D8139E" + - "428BB096C6D67A76EC0B8D4EF274B8A2CF556D279AD267CC" + - "EF5AF477AFED029F485B5597739F5D0240F67C2D948A6279", 16) - ); - - BigInteger x = new BigInteger("0CAF2EF547EC49C4F3A6FE6DF4223A174D01F2C115D49A6F73437C29A2A8458C", 16); - - BigInteger y = new BigInteger( - "2828003D7C747199143C370FDD07A286" + - "1524514ACC57F63F80C38C2087C6B795B62DE1C224BF8D1D" + - "1424E60CE3F5AE3F76C754A2464AF292286D873A7A30B7EA" + - "CBBC75AAFDE7191D9157598CDB0B60E0C5AA3F6EBE425500" + - "C611957DBF5ED35490714A42811FDCDEB19AF2AB30BEADFF" + - "2907931CEE7F3B55532CFFAEB371F84F01347630EB227A41" + - "9B1F3F558BC8A509D64A765D8987D493B007C4412C297CAF" + - "41566E26FAEE475137EC781A0DC088A26C8804A98C23140E" + - "7C936281864B99571EE95C416AA38CEEBB41FDBFF1EB1D1D" + - "C97B63CE1355257627C8B0FD840DDB20ED35BE92F08C49AE" + - "A5613957D7E5C7A6D5A5834B4CB069E0831753ECF65BA02B", 16); - - DSAPrivateKeyParameters priKey = new DSAPrivateKeyParameters(x, dsaParams); - SecureRandom k = new FixedSecureRandom( - new FixedSecureRandom.Source[] { - new FixedSecureRandom.BigInteger(BigIntegers.asUnsignedByteArray(new BigInteger("72546832179840998877302529996971396893172522460793442785601695562409154906335"))), - new FixedSecureRandom.Data(Hex.decode("01020304")) - }); - - byte[] M = Hex.decode("1BD4ED430B0F384B4E8D458EFF1A8A553286D7AC21CB2F6806172EF5F94A06AD"); - - DSADigestSigner dsa = new DSADigestSigner(new DSASigner(), new SHA3Digest(size)); - - dsa.init(true, new ParametersWithRandom(priKey, k)); - - dsa.update(M, 0, M.length); - - byte[] encSig = dsa.generateSignature(); - - ASN1Sequence sig = ASN1Sequence.getInstance(encSig); - - BigInteger r = new BigInteger("4864074fe30e6601268ee663440e4d9b703f62673419864e91e9edb0338ce510", 16); - - BigInteger sigR = ASN1Integer.getInstance(sig.getObjectAt(0)).getValue(); - if (!r.equals(sigR)) - { - fail("r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sigR.toString(16)); - } - - BigInteger sigS = ASN1Integer.getInstance(sig.getObjectAt(1)).getValue(); - if (!s.equals(sigS)) - { - fail("s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sigS.toString(16)); - } - - // Verify the signature - DSAPublicKeyParameters pubKey = new DSAPublicKeyParameters(y, dsaParams); - - dsa.init(false, pubKey); - - dsa.update(M, 0, M.length); - - if (!dsa.verifySignature(encSig)) - { - fail("signature fails"); - } - } - - private void dsa2Test1() - { - byte[] seed = Hex.decode("ED8BEE8D1CB89229D2903CBF0E51EE7377F48698"); - - DSAParametersGenerator pGen = new DSAParametersGenerator(); - - pGen.init(new DSAParameterGenerationParameters(1024, 160, 80, new DSATestSecureRandom(seed))); - - DSAParameters params = pGen.generateParameters(); - - DSAValidationParameters pv = params.getValidationParameters(); - - if (pv.getCounter() != 5) - { - fail("counter incorrect"); - } - - if (!Arrays.areEqual(seed, pv.getSeed())) - { - fail("seed incorrect"); - } - - if (!params.getQ().equals(new BigInteger("E950511EAB424B9A19A2AEB4E159B7844C589C4F", 16))) - { - fail("Q incorrect"); - } - - if (!params.getP().equals(new BigInteger( - "E0A67598CD1B763B" + - "C98C8ABB333E5DDA0CD3AA0E5E1FB5BA8A7B4EABC10BA338" + - "FAE06DD4B90FDA70D7CF0CB0C638BE3341BEC0AF8A7330A3" + - "307DED2299A0EE606DF035177A239C34A912C202AA5F83B9" + - "C4A7CF0235B5316BFC6EFB9A248411258B30B839AF172440" + - "F32563056CB67A861158DDD90E6A894C72A5BBEF9E286C6B", 16))) - { - fail("P incorrect"); - } - - if (!params.getG().equals(new BigInteger( - "D29D5121B0423C27" + - "69AB21843E5A3240FF19CACC792264E3BB6BE4F78EDD1B15" + - "C4DFF7F1D905431F0AB16790E1F773B5CE01C804E509066A" + - "9919F5195F4ABC58189FD9FF987389CB5BEDF21B4DAB4F8B" + - "76A055FFE2770988FE2EC2DE11AD92219F0B351869AC24DA" + - "3D7BA87011A701CE8EE7BFE49486ED4527B7186CA4610A75", 16))) - { - fail("G incorrect"); - } - - DSAKeyPairGenerator kpGen = new DSAKeyPairGenerator(); - - kpGen.init(new DSAKeyGenerationParameters(new TestRandomBigInteger("D0EC4E50BB290A42E9E355C73D8809345DE2E139", 16), params)); - - AsymmetricCipherKeyPair kp = kpGen.generateKeyPair(); - - DSAPublicKeyParameters pub = (DSAPublicKeyParameters)kp.getPublic(); - DSAPrivateKeyParameters priv = (DSAPrivateKeyParameters)kp.getPrivate(); - - if (!pub.getY().equals(new BigInteger( - "25282217F5730501" + - "DD8DBA3EDFCF349AAFFEC20921128D70FAC44110332201BB" + - "A3F10986140CBB97C726938060473C8EC97B4731DB004293" + - "B5E730363609DF9780F8D883D8C4D41DED6A2F1E1BBBDC97" + - "9E1B9D6D3C940301F4E978D65B19041FCF1E8B518F5C0576" + - "C770FE5A7A485D8329EE2914A2DE1B5DA4A6128CEAB70F79", 16))) - { - fail("Y value incorrect"); - } - - if (!priv.getX().equals( - new BigInteger("D0EC4E50BB290A42E9E355C73D8809345DE2E139", 16))) - { - fail("X value incorrect"); - } - - DSASigner signer = new DSASigner(); - - signer.init(true, new ParametersWithRandom(kp.getPrivate(), new FixedSecureRandom( - new FixedSecureRandom.Source[] { - new FixedSecureRandom.BigInteger("349C55648DCF992F3F33E8026CFAC87C1D2BA075"), - new FixedSecureRandom.Data(Hex.decode("01020304")) }))); - - byte[] msg = Hex.decode("A9993E364706816ABA3E25717850C26C9CD0D89D"); - - BigInteger[] sig = signer.generateSignature(msg); - - if (!sig[0].equals(new BigInteger("636155AC9A4633B4665D179F9E4117DF68601F34", 16))) - { - fail("R value incorrect"); - } - - if (!sig[1].equals(new BigInteger("6C540B02D9D4852F89DF8CFC99963204F4347704", 16))) - { - fail("S value incorrect"); - } - - signer.init(false, kp.getPublic()); - - if (!signer.verifySignature(msg, sig[0], sig[1])) - { - fail("signature not verified"); - } - - } - - private void dsa2Test2() - { - byte[] seed = Hex.decode("5AFCC1EFFC079A9CCA6ECA86D6E3CC3B18642D9BE1CC6207C84002A9"); - - DSAParametersGenerator pGen = new DSAParametersGenerator(new SHA224Digest()); - - pGen.init(new DSAParameterGenerationParameters(2048, 224, 80, new DSATestSecureRandom(seed))); - - DSAParameters params = pGen.generateParameters(); - - DSAValidationParameters pv = params.getValidationParameters(); - - if (pv.getCounter() != 21) - { - fail("counter incorrect"); - } - - if (!Arrays.areEqual(seed, pv.getSeed())) - { - fail("seed incorrect"); - } - - if (!params.getQ().equals(new BigInteger("90EAF4D1AF0708B1B612FF35E0A2997EB9E9D263C9CE659528945C0D", 16))) - { - fail("Q incorrect"); - } - - if (!params.getP().equals(new BigInteger( - "C196BA05AC29E1F9C3C72D56DFFC6154" + - "A033F1477AC88EC37F09BE6C5BB95F51C296DD20D1A28A06" + - "7CCC4D4316A4BD1DCA55ED1066D438C35AEBAABF57E7DAE4" + - "28782A95ECA1C143DB701FD48533A3C18F0FE23557EA7AE6" + - "19ECACC7E0B51652A8776D02A425567DED36EABD90CA33A1" + - "E8D988F0BBB92D02D1D20290113BB562CE1FC856EEB7CDD9" + - "2D33EEA6F410859B179E7E789A8F75F645FAE2E136D252BF" + - "FAFF89528945C1ABE705A38DBC2D364AADE99BE0D0AAD82E" + - "5320121496DC65B3930E38047294FF877831A16D5228418D" + - "E8AB275D7D75651CEFED65F78AFC3EA7FE4D79B35F62A040" + - "2A1117599ADAC7B269A59F353CF450E6982D3B1702D9CA83", 16))) - { - fail("P incorrect"); - } - - if (!params.getG().equals(new BigInteger( - "A59A749A11242C58C894E9E5A91804E8"+ - "FA0AC64B56288F8D47D51B1EDC4D65444FECA0111D78F35F"+ - "C9FDD4CB1F1B79A3BA9CBEE83A3F811012503C8117F98E50"+ - "48B089E387AF6949BF8784EBD9EF45876F2E6A5A495BE64B"+ - "6E770409494B7FEE1DBB1E4B2BC2A53D4F893D418B715959"+ - "2E4FFFDF6969E91D770DAEBD0B5CB14C00AD68EC7DC1E574"+ - "5EA55C706C4A1C5C88964E34D09DEB753AD418C1AD0F4FDF"+ - "D049A955E5D78491C0B7A2F1575A008CCD727AB376DB6E69"+ - "5515B05BD412F5B8C2F4C77EE10DA48ABD53F5DD498927EE"+ - "7B692BBBCDA2FB23A516C5B4533D73980B2A3B60E384ED20"+ - "0AE21B40D273651AD6060C13D97FD69AA13C5611A51B9085", 16))) - { - fail("G incorrect"); - } - - DSAKeyPairGenerator kpGen = new DSAKeyPairGenerator(); - - kpGen.init(new DSAKeyGenerationParameters(new TestRandomData(Hex.decode("00D0F09ED3E2568F6CADF9224117DA2AEC5A4300E009DE1366023E17")), params)); - - AsymmetricCipherKeyPair kp = kpGen.generateKeyPair(); - - DSAPublicKeyParameters pub = (DSAPublicKeyParameters)kp.getPublic(); - DSAPrivateKeyParameters priv = (DSAPrivateKeyParameters)kp.getPrivate(); - - if (!pub.getY().equals(new BigInteger( - "70035C9A3B225B258F16741F3941FBF0" + - "6F3D056CD7BD864604CBB5EE9DD85304EE8E8E4ABD5E9032" + - "11DDF25CE149075510ACE166970AFDC7DF552B7244F342FA" + - "02F7A621405B754909D757F97290E1FE5036E904CF593446" + - "0C046D95659821E1597ED9F2B1F0E20863A6BBD0CE74DACB" + - "A5D8C68A90B29C2157CDEDB82EC12B81EE3068F9BF5F7F34" + - "6ECA41ED174CCCD7D154FA4F42F80FFE1BF46AE9D8125DEB" + - "5B4BA08A72BDD86596DBEDDC9550FDD650C58F5AE5133509" + - "A702F79A31ECB490F7A3C5581631F7C5BE4FF7F9E9F27FA3" + - "90E47347AD1183509FED6FCF198BA9A71AB3335B4F38BE8D" + - "15496A00B6DC2263E20A5F6B662320A3A1EC033AA61E3B68", 16))) - { - fail("Y value incorrect"); - } - - if (!priv.getX().equals( - new BigInteger("00D0F09ED3E2568F6CADF9224117DA2AEC5A4300E009DE1366023E17", 16))) - { - fail("X value incorrect"); - } - - DSASigner signer = new DSASigner(); - - signer.init(true, new ParametersWithRandom(kp.getPrivate(), new FixedSecureRandom( - new FixedSecureRandom.Source[] { - new FixedSecureRandom.BigInteger(Hex.decode("735959CC4463B8B440E407EECA8A473BF6A6D1FE657546F67D401F05")), - new FixedSecureRandom.Data(Hex.decode("01020304")) - }))); - - byte[] msg = Hex.decode("23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7"); - - BigInteger[] sig = signer.generateSignature(msg); - - if (!sig[0].equals(new BigInteger("4400138D05F9639CAF54A583CAAF25D2B76D0C3EAD752CE17DBC85FE", 16))) - { - fail("R value incorrect"); - } - - if (!sig[1].equals(new BigInteger("874D4F12CB13B61732D398445698CFA9D92381D938AA57EE2C9327B3", 16))) - { - fail("S value incorrect"); - } - - signer.init(false, kp.getPublic()); - - if (!signer.verifySignature(msg, sig[0], sig[1])) - { - fail("signature not verified"); - } - } - - private void dsa2Test3() - { - byte[] seed = Hex.decode("4783081972865EA95D43318AB2EAF9C61A2FC7BBF1B772A09017BDF5A58F4FF0"); - - DSAParametersGenerator pGen = new DSAParametersGenerator(new SHA256Digest()); - - pGen.init(new DSAParameterGenerationParameters(2048, 256, 80, new DSATestSecureRandom(seed))); - - DSAParameters params = pGen.generateParameters(); - - DSAValidationParameters pv = params.getValidationParameters(); - - if (pv.getCounter() != 12) - { - fail("counter incorrect"); - } - - if (!Arrays.areEqual(seed, pv.getSeed())) - { - fail("seed incorrect"); - } - - if (!params.getQ().equals(new BigInteger("C24ED361870B61E0D367F008F99F8A1F75525889C89DB1B673C45AF5867CB467", 16))) - { - fail("Q incorrect"); - } - - if (!params.getP().equals(new BigInteger( - "F56C2A7D366E3EBDEAA1891FD2A0D099" + - "436438A673FED4D75F594959CFFEBCA7BE0FC72E4FE67D91" + - "D801CBA0693AC4ED9E411B41D19E2FD1699C4390AD27D94C" + - "69C0B143F1DC88932CFE2310C886412047BD9B1C7A67F8A2" + - "5909132627F51A0C866877E672E555342BDF9355347DBD43" + - "B47156B2C20BAD9D2B071BC2FDCF9757F75C168C5D9FC431" + - "31BE162A0756D1BDEC2CA0EB0E3B018A8B38D3EF2487782A" + - "EB9FBF99D8B30499C55E4F61E5C7DCEE2A2BB55BD7F75FCD" + - "F00E48F2E8356BDB59D86114028F67B8E07B127744778AFF" + - "1CF1399A4D679D92FDE7D941C5C85C5D7BFF91BA69F9489D" + - "531D1EBFA727CFDA651390F8021719FA9F7216CEB177BD75", 16))) - { - fail("P incorrect"); - } - - if (!params.getG().equals(new BigInteger( - "8DC6CC814CAE4A1C05A3E186A6FE27EA" + - "BA8CDB133FDCE14A963A92E809790CBA096EAA26140550C1" + - "29FA2B98C16E84236AA33BF919CD6F587E048C52666576DB" + - "6E925C6CBE9B9EC5C16020F9A44C9F1C8F7A8E611C1F6EC2" + - "513EA6AA0B8D0F72FED73CA37DF240DB57BBB27431D61869" + - "7B9E771B0B301D5DF05955425061A30DC6D33BB6D2A32BD0" + - "A75A0A71D2184F506372ABF84A56AEEEA8EB693BF29A6403" + - "45FA1298A16E85421B2208D00068A5A42915F82CF0B858C8" + - "FA39D43D704B6927E0B2F916304E86FB6A1B487F07D8139E" + - "428BB096C6D67A76EC0B8D4EF274B8A2CF556D279AD267CC" + - "EF5AF477AFED029F485B5597739F5D0240F67C2D948A6279", 16))) - { - fail("G incorrect"); - } - - DSAKeyPairGenerator kpGen = new DSAKeyPairGenerator(); - - kpGen.init(new DSAKeyGenerationParameters(new TestRandomData(Hex.decode("0CAF2EF547EC49C4F3A6FE6DF4223A174D01F2C115D49A6F73437C29A2A8458C")), params)); - - AsymmetricCipherKeyPair kp = kpGen.generateKeyPair(); - - DSAPublicKeyParameters pub = (DSAPublicKeyParameters)kp.getPublic(); - DSAPrivateKeyParameters priv = (DSAPrivateKeyParameters)kp.getPrivate(); - - if (!pub.getY().equals(new BigInteger( - "2828003D7C747199143C370FDD07A286" + - "1524514ACC57F63F80C38C2087C6B795B62DE1C224BF8D1D" + - "1424E60CE3F5AE3F76C754A2464AF292286D873A7A30B7EA" + - "CBBC75AAFDE7191D9157598CDB0B60E0C5AA3F6EBE425500" + - "C611957DBF5ED35490714A42811FDCDEB19AF2AB30BEADFF" + - "2907931CEE7F3B55532CFFAEB371F84F01347630EB227A41" + - "9B1F3F558BC8A509D64A765D8987D493B007C4412C297CAF" + - "41566E26FAEE475137EC781A0DC088A26C8804A98C23140E" + - "7C936281864B99571EE95C416AA38CEEBB41FDBFF1EB1D1D" + - "C97B63CE1355257627C8B0FD840DDB20ED35BE92F08C49AE" + - "A5613957D7E5C7A6D5A5834B4CB069E0831753ECF65BA02B", 16))) - { - fail("Y value incorrect"); - } - - if (!priv.getX().equals( - new BigInteger("0CAF2EF547EC49C4F3A6FE6DF4223A174D01F2C115D49A6F73437C29A2A8458C", 16))) - { - fail("X value incorrect"); - } - - DSASigner signer = new DSASigner(); - - signer.init(true, new ParametersWithRandom(kp.getPrivate(), new FixedSecureRandom( - new FixedSecureRandom.Source[] { - new FixedSecureRandom.BigInteger(Hex.decode("0CAF2EF547EC49C4F3A6FE6DF4223A174D01F2C115D49A6F73437C29A2A8458C")), - new FixedSecureRandom.Data(Hex.decode("01020304")) - }))); - - byte[] msg = Hex.decode("BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD"); - - BigInteger[] sig = signer.generateSignature(msg); - - if (!sig[0].equals(new BigInteger("315C875DCD4850E948B8AC42824E9483A32D5BA5ABE0681B9B9448D444F2BE3C", 16))) - { - fail("R value incorrect"); - } - - if (!sig[1].equals(new BigInteger("89718D12E54A8D9ED066E4A55F7ED5A2229CD23B9A3CEE78F83ED6AA61F6BCB9", 16))) - { - fail("S value incorrect"); - } - - signer.init(false, kp.getPublic()); - - if (!signer.verifySignature(msg, sig[0], sig[1])) - { - fail("signature not verified"); - } - } - - private void dsa2Test4() - { - byte[] seed = Hex.decode("193AFCA7C1E77B3C1ECC618C81322E47B8B8B997C9C83515C59CC446C2D9BD47"); - - DSAParametersGenerator pGen = new DSAParametersGenerator(new SHA256Digest()); - - pGen.init(new DSAParameterGenerationParameters(3072, 256, 80, new DSATestSecureRandom(seed))); - - DSAParameters params = pGen.generateParameters(); - - DSAValidationParameters pv = params.getValidationParameters(); - - if (pv.getCounter() != 20) - { - fail("counter incorrect"); - } - - if (!Arrays.areEqual(seed, pv.getSeed())) - { - fail("seed incorrect"); - } - - if (!params.getQ().equals(new BigInteger("CFA0478A54717B08CE64805B76E5B14249A77A4838469DF7F7DC987EFCCFB11D", 16))) - { - fail("Q incorrect"); - } - - if (!params.getP().equals(new BigInteger( - "90066455B5CFC38F9CAA4A48B4281F292C260FEEF01FD610" + - "37E56258A7795A1C7AD46076982CE6BB956936C6AB4DCFE0" + - "5E6784586940CA544B9B2140E1EB523F009D20A7E7880E4E" + - "5BFA690F1B9004A27811CD9904AF70420EEFD6EA11EF7DA1" + - "29F58835FF56B89FAA637BC9AC2EFAAB903402229F491D8D" + - "3485261CD068699B6BA58A1DDBBEF6DB51E8FE34E8A78E54" + - "2D7BA351C21EA8D8F1D29F5D5D15939487E27F4416B0CA63" + - "2C59EFD1B1EB66511A5A0FBF615B766C5862D0BD8A3FE7A0" + - "E0DA0FB2FE1FCB19E8F9996A8EA0FCCDE538175238FC8B0E" + - "E6F29AF7F642773EBE8CD5402415A01451A840476B2FCEB0" + - "E388D30D4B376C37FE401C2A2C2F941DAD179C540C1C8CE0" + - "30D460C4D983BE9AB0B20F69144C1AE13F9383EA1C08504F" + - "B0BF321503EFE43488310DD8DC77EC5B8349B8BFE97C2C56" + - "0EA878DE87C11E3D597F1FEA742D73EEC7F37BE43949EF1A" + - "0D15C3F3E3FC0A8335617055AC91328EC22B50FC15B941D3" + - "D1624CD88BC25F3E941FDDC6200689581BFEC416B4B2CB73", 16))) - { - fail("P incorrect"); - } - - if (!params.getG().equals(new BigInteger( - "5E5CBA992E0A680D885EB903AEA78E4A45A469103D448EDE" + - "3B7ACCC54D521E37F84A4BDD5B06B0970CC2D2BBB715F7B8" + - "2846F9A0C393914C792E6A923E2117AB805276A975AADB52" + - "61D91673EA9AAFFEECBFA6183DFCB5D3B7332AA19275AFA1" + - "F8EC0B60FB6F66CC23AE4870791D5982AAD1AA9485FD8F4A" + - "60126FEB2CF05DB8A7F0F09B3397F3937F2E90B9E5B9C9B6" + - "EFEF642BC48351C46FB171B9BFA9EF17A961CE96C7E7A7CC" + - "3D3D03DFAD1078BA21DA425198F07D2481622BCE45969D9C" + - "4D6063D72AB7A0F08B2F49A7CC6AF335E08C4720E31476B6" + - "7299E231F8BD90B39AC3AE3BE0C6B6CACEF8289A2E2873D5" + - "8E51E029CAFBD55E6841489AB66B5B4B9BA6E2F784660896" + - "AFF387D92844CCB8B69475496DE19DA2E58259B090489AC8" + - "E62363CDF82CFD8EF2A427ABCD65750B506F56DDE3B98856" + - "7A88126B914D7828E2B63A6D7ED0747EC59E0E0A23CE7D8A" + - "74C1D2C2A7AFB6A29799620F00E11C33787F7DED3B30E1A2" + - "2D09F1FBDA1ABBBFBF25CAE05A13F812E34563F99410E73B", 16))) - { - fail("G incorrect"); - } - - DSAKeyPairGenerator kpGen = new DSAKeyPairGenerator(); - - kpGen.init(new DSAKeyGenerationParameters(new TestRandomData(Hex.decode("3ABC1587297CE7B9EA1AD6651CF2BC4D7F92ED25CABC8553F567D1B40EBB8764")), params)); - - AsymmetricCipherKeyPair kp = kpGen.generateKeyPair(); - - DSAPublicKeyParameters pub = (DSAPublicKeyParameters)kp.getPublic(); - DSAPrivateKeyParameters priv = (DSAPrivateKeyParameters)kp.getPrivate(); - - if (!pub.getY().equals(new BigInteger( - "8B891C8692D3DE875879390F2698B26FBECCA6B075535DCE" + - "6B0C862577F9FA0DEF6074E7A7624121224A595896ABD4CD" + - "A56B2CEFB942E025D2A4282FFAA98A48CDB47E1A6FCB5CFB" + - "393EF35AF9DF913102BB303C2B5C36C3F8FC04ED7B8B69FE" + - "FE0CF3E1FC05CFA713B3435B2656E913BA8874AEA9F93600" + - "6AEB448BCD005D18EC3562A33D04CF25C8D3D69844343442" + - "FA3DB7DE618C5E2DA064573E61E6D5581BFB694A23AC87FD" + - "5B52D62E954E1376DB8DDB524FFC0D469DF978792EE44173" + - "8E5DB05A7DC43E94C11A2E7A4FBE383071FA36D2A7EC8A93" + - "88FE1C4F79888A99D3B6105697C2556B79BB4D7E781CEBB3" + - "D4866AD825A5E830846072289FDBC941FA679CA82F5F78B7" + - "461B2404DB883D215F4E0676CF5493950AC5591697BFEA8D" + - "1EE6EC016B89BA51CAFB5F9C84C989FA117375E94578F28B" + - "E0B34CE0545DA46266FD77F62D8F2CEE92AB77012AFEBC11" + - "008985A821CD2D978C7E6FE7499D1AAF8DE632C21BB48CA5" + - "CBF9F31098FD3FD3854C49A65D9201744AACE540354974F9", 16))) - { - fail("Y value incorrect"); - } - - if (!priv.getX().equals( - new BigInteger("3ABC1587297CE7B9EA1AD6651CF2BC4D7F92ED25CABC8553F567D1B40EBB8764", 16))) - { - fail("X value incorrect"); - } - - DSASigner signer = new DSASigner(); - - signer.init(true, new ParametersWithRandom(kp.getPrivate(), new FixedSecureRandom( - new FixedSecureRandom.Source[] - { new FixedSecureRandom.BigInteger("A6902C1E6E3943C5628061588A8B007BCCEA91DBF12915483F04B24AB0678BEE"), - new FixedSecureRandom.Data(Hex.decode("01020304")) }))); - - byte[] msg = Hex.decode("BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD"); - - BigInteger[] sig = signer.generateSignature(msg); - - if (!sig[0].equals(new BigInteger("5F184E645A38BE8FB4A6871B6503A9D12924C7ABE04B71410066C2ECA6E3BE3E", 16))) - { - fail("R value incorrect"); - } - - if (!sig[1].equals(new BigInteger("91EB0C7BA3D4B9B60B825C3D9F2CADA8A2C9D7723267B033CBCDCF8803DB9C18", 16))) - { - fail("S value incorrect"); - } - - signer.init(false, kp.getPublic()); - - if (!signer.verifySignature(msg, sig[0], sig[1])) - { - fail("signature not verified"); - } - } - - public static void main( - String[] args) - { - runTest(new DSATest()); - } - - private class DSATestSecureRandom - extends TestRandomData - { - private boolean first = true; - - public DSATestSecureRandom(byte[] value) - { - super(value); - } - - public void nextBytes(byte[] bytes) - { - if (first) - { - super.nextBytes(bytes); - first = false; - } - else - { - bytes[bytes.length - 1] = 2; - } - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DSTU4145Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DSTU4145Test.java deleted file mode 100644 index bb11e38b8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DSTU4145Test.java +++ /dev/null @@ -1,278 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.signers.DSTU4145Signer; -import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.math.ec.ECPoint; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestRandomData; - -public class DSTU4145Test - extends SimpleTest -{ - private static final BigInteger ZERO = BigInteger.valueOf(0); - private static final BigInteger ONE = BigInteger.valueOf(1); - - public static void main(String[] args) - { - runTest(new DSTU4145Test()); - } - - public String getName() - { - return "DSTU4145"; - } - - private void test163() - throws Exception - { - SecureRandom random = new TestRandomData(Hex.decode("01025e40bd97db012b7a1d79de8e12932d247f61c6")); - - byte[] hash = Hex.decode("09c9c44277910c9aaee486883a2eb95b7180166ddf73532eeb76edaef52247ff"); - for (int i = 0; i < hash.length / 2; i++) - { - byte tmp = hash[i]; - hash[i] = hash[hash.length - 1 - i]; - hash[hash.length - 1 - i] = tmp; - } - - BigInteger r = new BigInteger("274ea2c0caa014a0d80a424f59ade7a93068d08a7", 16); - BigInteger s = new BigInteger("2100d86957331832b8e8c230f5bd6a332b3615aca", 16); - - ECCurve.F2m curve = new ECCurve.F2m(163, 3, 6, 7, ONE, new BigInteger("5FF6108462A2DC8210AB403925E638A19C1455D21", 16)); - ECPoint P = curve.createPoint(new BigInteger("72d867f93a93ac27df9ff01affe74885c8c540420", 16), new BigInteger("0224a9c3947852b97c5599d5f4ab81122adc3fd9b", 16)); - BigInteger n = new BigInteger("400000000000000000002BEC12BE2262D39BCF14D", 16); - - BigInteger d = new BigInteger("183f60fdf7951ff47d67193f8d073790c1c9b5a3e", 16); - ECPoint Q = P.multiply(d).negate(); - - ECDomainParameters domain = new ECDomainParameters(curve, P, n); - CipherParameters privKey = new ParametersWithRandom(new ECPrivateKeyParameters(d, domain), random); - ECPublicKeyParameters pubKey = new ECPublicKeyParameters(Q, domain); - - DSTU4145Signer dstuSigner = new DSTU4145Signer(); - dstuSigner.init(true, privKey); - BigInteger[] rs = dstuSigner.generateSignature(hash); - - if (rs[0].compareTo(r) != 0) - { - fail("r component wrong"); - } - - if (rs[1].compareTo(s) != 0) - { - fail("s component wrong"); - } - - dstuSigner.init(false, pubKey); - if (!dstuSigner.verifySignature(hash, r, s)) - { - fail("verification fails"); - } - } - - private void test173() - throws Exception - { - SecureRandom random = new TestRandomData(Hex.decode("0000137449348C1249971759D99C252FFE1E14D8B31F")); - - byte[] hash = Hex.decode("0137187EA862117EF1484289470ECAC802C5A651FDA8"); - for (int i = 0; i < hash.length / 2; i++) - { - byte tmp = hash[i]; - hash[i] = hash[hash.length - 1 - i]; - hash[hash.length - 1 - i] = tmp; - } - - BigInteger r = new BigInteger("13ae89746386709cdbd237cc5ec20ca30004a82ead8", 16); - BigInteger s = new BigInteger("3597912cdd093b3e711ccb74a79d3c4ab4c7cccdc60", 16); - - ECCurve.F2m curve = new ECCurve.F2m(173, 1, 2, 10, ZERO, new BigInteger("108576C80499DB2FC16EDDF6853BBB278F6B6FB437D9", 16)); - ECPoint P = curve.createPoint(new BigInteger("BE6628EC3E67A91A4E470894FBA72B52C515F8AEE9", 16), new BigInteger("D9DEEDF655CF5412313C11CA566CDC71F4DA57DB45C", 16)); - BigInteger n = new BigInteger("800000000000000000000189B4E67606E3825BB2831", 16); - - BigInteger d = new BigInteger("955CD7E344303D1034E66933DC21C8044D42ADB8", 16); - ECPoint Q = P.multiply(d).negate(); - - ECDomainParameters domain = new ECDomainParameters(curve, P, n); - CipherParameters privKey = new ParametersWithRandom(new ECPrivateKeyParameters(d, domain), random); - ECPublicKeyParameters pubKey = new ECPublicKeyParameters(Q, domain); - - DSTU4145Signer dstuSigner = new DSTU4145Signer(); - dstuSigner.init(true, privKey); - BigInteger[] rs = dstuSigner.generateSignature(hash); - - if (rs[0].compareTo(r) != 0) - { - fail("r component wrong"); - } - - if (rs[1].compareTo(s) != 0) - { - fail("s component wrong"); - } - - dstuSigner.init(false, pubKey); - if (!dstuSigner.verifySignature(hash, r, s)) - { - fail("verification fails"); - } - } - - private void test283() - throws Exception - { - SecureRandom random = new TestRandomData(Hex.decode("00000000245383CB3AD41BF30F5F7E8FBA858509B2D5558C92D539A6D994BFA98BC6940E")); - - byte[] hash = Hex.decode("0137187EA862117EF1484289470ECAC802C5A651FDA8"); - for (int i = 0; i < hash.length / 2; i++) - { - byte tmp = hash[i]; - hash[i] = hash[hash.length - 1 - i]; - hash[hash.length - 1 - i] = tmp; - } - - BigInteger r = new BigInteger("12a5edcc38d92208ff23036d75b000c7e4bc0f9af2d40b35f15d6fd15e01234e67781a8", 16); - BigInteger s = new BigInteger("2de0775577f75b643cf5afc80d4fe10b21100690f17e2cab7bdc9b50ec87c5727aeb515", 16); - - ECCurve.F2m curve = new ECCurve.F2m(283, 5, 7, 12, ONE, new BigInteger("27B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5", 16)); - ECPoint P = curve.createPoint(new BigInteger("4D95820ACE761110824CE425C8089129487389B7F0E0A9D043DDC0BB0A4CC9EB25", 16), new BigInteger("954C9C4029B2C62DE35C2B9C2A164984BF1101951E3A68ED03DF234DDE5BB2013152F2", 16)); - BigInteger n = new BigInteger("3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307", 16); - - BigInteger d = new BigInteger("B844EEAF15213E4BAD4FB84796D68F2448DB8EB7B4621EC0D51929874892C43E", 16); - ECPoint Q = P.multiply(d).negate(); - - ECDomainParameters domain = new ECDomainParameters(curve, P, n); - CipherParameters privKey = new ParametersWithRandom(new ECPrivateKeyParameters(d, domain), random); - ECPublicKeyParameters pubKey = new ECPublicKeyParameters(Q, domain); - - DSTU4145Signer dstuSigner = new DSTU4145Signer(); - dstuSigner.init(true, privKey); - BigInteger[] rs = dstuSigner.generateSignature(hash); - - if (rs[0].compareTo(r) != 0) - { - fail("r component wrong"); - } - - if (rs[1].compareTo(s) != 0) - { - fail("s component wrong"); - } - - dstuSigner.init(false, pubKey); - if (!dstuSigner.verifySignature(hash, r, s)) - { - fail("verification fails"); - } - } - - private void test431() - throws Exception - { - SecureRandom random = new TestRandomData(Hex.decode("0000C4224DBBD800988DBAA39DE838294C345CDA5F5929D1174AA8D9340A5E79D10ACADE6B53CF873E7301A3871C2073AD75AB530457")); - - byte[] hash = Hex.decode("0137187EA862117EF1484289470ECAC802C5A651FDA8"); - for (int i = 0; i < hash.length / 2; i++) - { - byte tmp = hash[i]; - hash[i] = hash[hash.length - 1 - i]; - hash[hash.length - 1 - i] = tmp; - } - - BigInteger r = new BigInteger("1911fefb1f494bebcf8dffdf5276946ff9c9f662192ee18c718db47310a439c784fe07577b16e1edbe16179876e0792a634f1c9c3a2e", 16); - BigInteger s = new BigInteger("3852170ee801c2083c52f1ea77b987a5432acecd9c654f064e87bf179e0a397151edbca430082e43bd38a67b55424b5bbc7f2713f620", 16); - - ECCurve.F2m curve = new ECCurve.F2m(431, 1, 3, 5, ONE, new BigInteger("3CE10490F6A708FC26DFE8C3D27C4F94E690134D5BFF988D8D28AAEAEDE975936C66BAC536B18AE2DC312CA493117DAA469C640CAF3", 16)); - ECPoint P = curve.createPoint(new BigInteger("9548BCDF314CEEEAF099C780FFEFBF93F9FE5B5F55547603C9C8FC1A2774170882B3BE35E892C6D4296B8DEA282EC30FB344272791", 16), new BigInteger("4C6CBD7C62A8EEEFDE17A8B5E196E49A22CE6DE128ABD9FBD81FA4411AD5A38E2A810BEDE09A7C6226BCDCB4A4A5DA37B4725E00AA74", 16)); - BigInteger n = new BigInteger("3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBA3175458009A8C0A724F02F81AA8A1FCBAF80D90C7A95110504CF", 16); - - BigInteger d = new BigInteger("D0F97354E314191FD773E2404F478C8AEE0FF5109F39E6F37D1FEEC8B2ED1691D84C9882CC729E716A71CC013F66CAC60E29E22C", 16); - ECPoint Q = P.multiply(d).negate(); - - ECDomainParameters domain = new ECDomainParameters(curve, P, n); - CipherParameters privKey = new ParametersWithRandom(new ECPrivateKeyParameters(d, domain), random); - ECPublicKeyParameters pubKey = new ECPublicKeyParameters(Q, domain); - - DSTU4145Signer dstuSigner = new DSTU4145Signer(); - dstuSigner.init(true, privKey); - BigInteger[] rs = dstuSigner.generateSignature(hash); - - if (rs[0].compareTo(r) != 0) - { - fail("r component wrong"); - } - - if (rs[1].compareTo(s) != 0) - { - fail("s component wrong"); - } - - dstuSigner.init(false, pubKey); - if (!dstuSigner.verifySignature(hash, r, s)) - { - fail("verification fails"); - } - } - - private void testTruncation() - { - SecureRandom random = new TestRandomData(Hex.decode("0000C4224DBBD800988DBAA39DE838294C345CDA5F5929D1174AA8D9340A5E79D10ACADE6B53CF873E7301A3871C2073AD75AB530457")); - - // use extra long "hash" with set bits... - byte[] hash = Hex.decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - - ECCurve.F2m curve = new ECCurve.F2m(173, 1, 2, 10, ZERO, new BigInteger("108576C80499DB2FC16EDDF6853BBB278F6B6FB437D9", 16)); - ECPoint P = curve.createPoint(new BigInteger("BE6628EC3E67A91A4E470894FBA72B52C515F8AEE9", 16), new BigInteger("D9DEEDF655CF5412313C11CA566CDC71F4DA57DB45C", 16)); - BigInteger n = new BigInteger("800000000000000000000189B4E67606E3825BB2831", 16); - - BigInteger d = new BigInteger("955CD7E344303D1034E66933DC21C8044D42ADB8", 16); - ECPoint Q = P.multiply(d).negate(); - - ECDomainParameters domain = new ECDomainParameters(curve, P, n); - CipherParameters privKey = new ParametersWithRandom(new ECPrivateKeyParameters(d, domain), random); - ECPublicKeyParameters pubKey = new ECPublicKeyParameters(Q, domain); - - DSTU4145Signer dstuSigner = new DSTU4145Signer(); - dstuSigner.init(true, privKey); - BigInteger[] rs = dstuSigner.generateSignature(hash); - - BigInteger r = new BigInteger("6bb5c0cb82e5067485458ebfe81025f03b687c63a27", 16); - BigInteger s = new BigInteger("34d6b1868969b86ecf934167c8fe352c63d1074bd", 16); - - if (rs[0].compareTo(r) != 0) - { - fail("r component wrong"); - } - - if (rs[1].compareTo(s) != 0) - { - fail("s component wrong"); - } - - dstuSigner.init(false, pubKey); - if (!dstuSigner.verifySignature(hash, rs[0], rs[1])) - { - fail("verification fails"); - } - } - - public void performTest() - throws Exception - { - test163(); - test173(); - test283(); - test431(); - testTruncation(); - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DSTU7564Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DSTU7564Test.java deleted file mode 100644 index 405ea8472..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DSTU7564Test.java +++ /dev/null @@ -1,679 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.digests.DSTU7564Digest; -import com.fr.third.org.bouncycastle.crypto.macs.DSTU7564Mac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - -public class DSTU7564Test - extends DigestTest -{ - - private static String[] messages = - { - "", - "a", - "abc", - "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" - }; - - private static String[] digests = - { - "cd5101d1ccdf0d1d1f4ada56e888cd724ca1a0838a3521e7131d4fb78d0f5eb6", - "c51a1d639596fb613d86557314a150c40f8fff3de48bc93a3b03c161f4105ee4", - "0bd1b36109f1318411a0517315aa46b8839df06622a278676f5487996c9cfc04", - "02621dbb53f2c7001be64d7308ecb80d21ba7797c92e98d1efc240d41e4c414b" - }; - - protected Digest cloneDigest(Digest digest) - { - return new DSTU7564Digest((DSTU7564Digest)digest); - } - - public DSTU7564Test() - { - super(new DSTU7564Digest(256), messages, digests); - } - - public static void main(String[] args) - { - runTest(new DSTU7564Test()); - } - - public void performTest() - { - super.performTest(); - - hash256Tests(); - hash384Tests(); - hash512Tests(); - macTests(); - overflowTest(); - keySizeTest(); - } - - private void overflowTest() - { - int macBitSize = 256; - byte[] input = new byte[1024]; - for (int i = 0; i != input.length; i++) - { - input[i] = (byte)(i & 0xff); - } - byte[] key = Hex.decode("1F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100"); - - byte[] expectedMac = Hex.decode("165382df70adcb040b17c1aced117d26d598b239ab631271a05f6d0f875ae9ea"); - byte[] mac = new byte[macBitSize / 8]; - - DSTU7564Mac dstu7564mac = new DSTU7564Mac(macBitSize); - - dstu7564mac.init(new KeyParameter(key)); - dstu7564mac.update(input, 0, input.length); - dstu7564mac.doFinal(mac, 0); - - if (!Arrays.areEqual(expectedMac, mac)) - { - fail("Failed overflow test 1 - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - macBitSize = 256; - input = new byte[1023]; - for (int i = 0; i != input.length; i++) - { - input[i] = (byte)(i & 0xff); - } - key = Hex.decode("1F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100"); - - expectedMac = Hex.decode("ed45f163e694d990d2d835dca2f3f869a55a31396c8138161b190d5914d50686"); - mac = new byte[macBitSize / 8]; - - dstu7564mac = new DSTU7564Mac(macBitSize); - - dstu7564mac.init(new KeyParameter(key)); - dstu7564mac.update(input, 0, input.length); - dstu7564mac.doFinal(mac, 0); - - if (!Arrays.areEqual(expectedMac, mac)) - { - fail("Failed overflow test 2 - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - DSTU7564Digest digest = new DSTU7564Digest(macBitSize); - byte[] expectedDigest = Hex.decode("6bfc5ec8c1f5963fbed89da115d86e9330634eca341dd42fd94a7007e4af7942"); - byte[] digestBuf = new byte[macBitSize / 8]; - - digest.update(input, 0, input.length); - digest.doFinal(digestBuf, 0); - - if (!Arrays.areEqual(expectedDigest, digestBuf)) - { - fail("Failed overflow test 3 - expected " - + Hex.toHexString(expectedDigest) - + " got " + Hex.toHexString(digestBuf)); - } - - expectedDigest = Hex.decode("6f8f0a3f8261af77581ab01cb89d4cb5ed87ca1d9954f11d5586e94b45c82fb8"); - - input = new byte[51]; - for (int i = 0; i != input.length; i++) - { - input[i] = (byte)(i & 0xff); - } - - digest.update(input, 0, input.length); - digest.doFinal(digestBuf, 0); - - if (!Arrays.areEqual(expectedDigest, digestBuf)) - { - fail("Failed overflow test 4 - expected " - + Hex.toHexString(expectedDigest) - + " got " + Hex.toHexString(digestBuf)); - } - - input = new byte[52]; - for (int i = 0; i != input.length; i++) - { - input[i] = (byte)(i & 0xff); - } - - expectedDigest = Hex.decode("8b6fe2ba77e684b2a1ac82232f4efc49f681cd18c82a0cfff530186a2fc642d2"); - - digest.update(input, 0, input.length); - digest.doFinal(digestBuf, 0); - - if (!Arrays.areEqual(expectedDigest, digestBuf)) - { - fail("Failed overflow test 5 - expected " - + Hex.toHexString(expectedDigest) - + " got " + Hex.toHexString(digestBuf)); - } - - - input = new byte[53]; - for (int i = 0; i != input.length; i++) - { - input[i] = (byte)(i & 0xff); - } - - expectedDigest = Hex.decode("837f2b0cbe39a4defdfcb44272288d4091cab850161c70695d7831fc5f00e171"); - - digest.update(input, 0, input.length); - digest.doFinal(digestBuf, 0); - - if (!Arrays.areEqual(expectedDigest, digestBuf)) - { - fail("Failed overflow test 6 - expected " - + Hex.toHexString(expectedDigest) - + " got " + Hex.toHexString(digestBuf)); - } - - input = new byte[54]; - for (int i = 0; i != input.length; i++) - { - input[i] = (byte)(i & 0xff); - } - - expectedDigest = Hex.decode("21d423d5b8c7f18a0da42cdd95b36b66344125e2adc6edeab5899926442113bc"); - - digest.update(input, 0, input.length); - digest.doFinal(digestBuf, 0); - - if (!Arrays.areEqual(expectedDigest, digestBuf)) - { - fail("Failed overflow test 7 - expected " - + Hex.toHexString(expectedDigest) - + " got " + Hex.toHexString(digestBuf)); - } - - input = new byte[55]; - for (int i = 0; i != input.length; i++) - { - input[i] = (byte)(i & 0xff); - } - - expectedDigest = Hex.decode("0e7bf74464b81b3ae7d904170776d29f4b02a7227da578dd562d01027af7fd0e"); - - digest.update(input, 0, input.length); - digest.doFinal(digestBuf, 0); - - if (!Arrays.areEqual(expectedDigest, digestBuf)) - { - fail("Failed overflow test 8 - expected " - + Hex.toHexString(expectedDigest) - + " got " + Hex.toHexString(digestBuf)); - } - - input = new byte[56]; - for (int i = 0; i != input.length; i++) - { - input[i] = (byte)(i & 0xff); - } - - expectedDigest = Hex.decode("badea1f49cbcec94acec52b4c695acdddd786cca5a6763929f341a58c5134b3b"); - - digest.update(input, 0, input.length); - digest.doFinal(digestBuf, 0); - - if (!Arrays.areEqual(expectedDigest, digestBuf)) - { - fail("Failed overflow test 9 - expected " - + Hex.toHexString(expectedDigest) - + " got " + Hex.toHexString(digestBuf)); - } - - input = new byte[57]; - for (int i = 0; i != input.length; i++) - { - input[i] = (byte)(i & 0xff); - } - - expectedDigest = Hex.decode("a13b5f6f53ee043292ed65b66c1d49759be4d2fe0c2f6148f2416487965f7bde"); - - digest.update(input, 0, input.length); - digest.doFinal(digestBuf, 0); - - if (!Arrays.areEqual(expectedDigest, digestBuf)) - { - fail("Failed overflow test 10 - expected " - + Hex.toHexString(expectedDigest) - + " got " + Hex.toHexString(digestBuf)); - } - - input = new byte[63]; - for (int i = 0; i != input.length; i++) - { - input[i] = (byte)(i & 0xff); - } - - expectedDigest = Hex.decode("03a44a02c9ffafb43addb290bbcf3b8168f624e8cbd332dc6a9dc7df9d39cbc2"); - - digest.update(input, 0, input.length); - digest.doFinal(digestBuf, 0); - - if (!Arrays.areEqual(expectedDigest, digestBuf)) - { - fail("Failed overflow test 11 - expected " - + Hex.toHexString(expectedDigest) - + " got " + Hex.toHexString(digestBuf)); - } - - input = new byte[64]; - for (int i = 0; i != input.length; i++) - { - input[i] = (byte)(i & 0xff); - } - - expectedDigest = Hex.decode("08f4ee6f1be6903b324c4e27990cb24ef69dd58dbe84813ee0a52f6631239875"); - - digest.update(input, 0, input.length); - digest.doFinal(digestBuf, 0); - - if (!Arrays.areEqual(expectedDigest, digestBuf)) - { - fail("Failed overflow test 12 - expected " - + Hex.toHexString(expectedDigest) - + " got " + Hex.toHexString(digestBuf)); - } - - input = new byte[65]; - for (int i = 0; i != input.length; i++) - { - input[i] = (byte)(i & 0xff); - } - - expectedDigest = Hex.decode("a81c2fb92351f370050b7c36cd51736d5603a50ec1106cbd5fe1c9be2e5c77a6"); - - digest.update(input, 0, input.length); - digest.doFinal(digestBuf, 0); - - if (!Arrays.areEqual(expectedDigest, digestBuf)) - { - fail("Failed overflow test 13 - expected " - + Hex.toHexString(expectedDigest) - + " got " + Hex.toHexString(digestBuf)); - } - } - - private void macTests() - { - - //test1 - int macBitSize = 256; - byte[] input = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E"); - byte[] key = Hex.decode("1F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100"); - - byte[] expectedMac = Hex.decode("B60594D56FA79BA210314C72C2495087CCD0A99FC04ACFE2A39EF669925D98EE"); - byte[] mac = new byte[macBitSize / 8]; - - DSTU7564Mac dstu7564mac = new DSTU7564Mac(macBitSize); - - dstu7564mac.init(new KeyParameter(key)); - dstu7564mac.update(input, 0, input.length); - dstu7564mac.doFinal(mac, 0); - - if (!Arrays.areEqual(expectedMac, mac)) - { - fail("Failed mac test 1 - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - //test1a - input = Hex.decode("0001020304050607"); - key = Hex.decode("08F4EE6F1BE6903B324C4E27990CB24EF69DD58DBE84813EE0A52F6631239875"); - - expectedMac = Hex.decode("383A0B11989ABF61B2CF3EB489351EB7C9AEF70CF5A9D6DBD90F340FF151BA2D"); - mac = new byte[macBitSize / 8]; - - dstu7564mac = new DSTU7564Mac(macBitSize); - - dstu7564mac.init(new KeyParameter(key)); - dstu7564mac.update(input, 0, input.length); - dstu7564mac.doFinal(mac, 0); - - if (!Arrays.areEqual(expectedMac, mac)) - { - fail("Failed mac test 1a - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - //test 2 - macBitSize = 384; - input = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E"); - key = Hex.decode("2F2E2D2C2B2A292827262524232221201F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100"); - - expectedMac = Hex.decode("BEBFD8D730336F043ABACB41829E79A4D320AEDDD8D14024D5B805DA70C396FA295C281A38B30AE728A304B3F5AE490E"); - mac = new byte[macBitSize / 8]; - - dstu7564mac = new DSTU7564Mac(macBitSize); - - dstu7564mac.init(new KeyParameter(key)); - dstu7564mac.update(input, 0, input.length); - dstu7564mac.doFinal(mac, 0); - - if (!Arrays.areEqual(expectedMac, mac)) - { - fail("Failed mac test 2 - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - //test 3 - macBitSize = 512; - input = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E"); - key = Hex.decode("3F3E3D3C3B3A393837363534333231302F2E2D2C2B2A292827262524232221201F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100"); - - expectedMac = Hex.decode("F270043C06A5C37E65D9D791C5FBFB966E5EE709F8F54019C9A55B76CA40B70100579F269CEC24E347A9D864614CF3ABBF6610742E4DB3BD2ABC000387C49D24"); - mac = new byte[macBitSize / 8]; - - dstu7564mac = new DSTU7564Mac(macBitSize); - - dstu7564mac.init(new KeyParameter(key)); - dstu7564mac.update(input, 0, input.length); - dstu7564mac.doFinal(mac, 0); - - if (!Arrays.areEqual(expectedMac, mac)) - { - fail("Failed mac test 3 - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - // check doFinal() has reset - dstu7564mac.update(input, 0, input.length); - dstu7564mac.doFinal(mac, 0); - - if (!Arrays.areEqual(expectedMac, mac)) - { - fail("Failed mac test reset - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - // check that init reset correctly - dstu7564mac.init(new KeyParameter(key)); - dstu7564mac.init(new KeyParameter(key)); - dstu7564mac.update(input, 0, input.length); - dstu7564mac.doFinal(mac, 0); - - if (!Arrays.areEqual(expectedMac, mac)) - { - fail("Failed mac test double init - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - // check simple reset - dstu7564mac = new DSTU7564Mac(macBitSize); - dstu7564mac.reset(); - } - - private void hash512Tests() - { - - int hashBitSize = 512; - - //test 1 - byte[] input = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - byte[] expectedHash = Hex.decode("3813E2109118CDFB5A6D5E72F7208DCCC80A2DFB3AFDFB02F46992B5EDBE536B3560DD1D7E29C6F53978AF58B444E37BA685C0DD910533BA5D78EFFFC13DE62A"); - byte[] hash = new byte[hashBitSize / 8]; - - - DSTU7564Digest dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-512 test 1 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - - //test 2 - input = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F"); - expectedHash = Hex.decode("76ED1AC28B1D0143013FFA87213B4090B356441263C13E03FA060A8CADA32B979635657F256B15D5FCA4A174DE029F0B1B4387C878FCC1C00E8705D783FD7FFE"); - hash = new byte[hashBitSize / 8]; - - - dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-512 test 2 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - - //test 3 - input = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF"); - expectedHash = Hex.decode("0DD03D7350C409CB3C29C25893A0724F6B133FA8B9EB90A64D1A8FA93B56556611EB187D715A956B107E3BFC76482298133A9CE8CBC0BD5E1436A5B197284F7E"); - hash = new byte[hashBitSize / 8]; - - - dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-512 test 3 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - - //test 4 - input = Hex.decode("FF"); - expectedHash = Hex.decode("871B18CF754B72740307A97B449ABEB32B64444CC0D5A4D65830AE5456837A72D8458F12C8F06C98C616ABE11897F86263B5CB77C420FB375374BEC52B6D0292"); - hash = new byte[hashBitSize / 8]; - - - dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-512 test 4 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - - //test 5 - input = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"); - expectedHash = Hex.decode("B189BFE987F682F5F167F0D7FA565330E126B6E592B1C55D44299064EF95B1A57F3C2D0ECF17869D1D199EBBD02E8857FB8ADD67A8C31F56CD82C016CF743121"); - hash = new byte[hashBitSize / 8]; - - - dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-512 test 5 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - - - //test 6 - input = Hex.decode(""); - expectedHash = Hex.decode("656B2F4CD71462388B64A37043EA55DBE445D452AECD46C3298343314EF04019BCFA3F04265A9857F91BE91FCE197096187CEDA78C9C1C021C294A0689198538"); - hash = new byte[hashBitSize / 8]; - - - dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-512 test 6 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - } - - private void hash384Tests() - { - - int hashBitSize = 384; - - //test 1 - byte[] input = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E"); - byte[] expectedHash = Hex.decode("D9021692D84E5175735654846BA751E6D0ED0FAC36DFBC0841287DCB0B5584C75016C3DECC2A6E47C50B2F3811E351B8"); - byte[] hash = new byte[hashBitSize / 8]; - - - DSTU7564Digest dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-384 test 1 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - } - - private void keySizeTest() - { - doKeySizeTest(new DSTU7564Mac(512)); - doKeySizeTest(new DSTU7564Mac(256)); - } - - private void doKeySizeTest(Mac dstuMac) - { - /* Define message */ - final byte[] myMessage = "1234567890123456".getBytes(); - - /* Determine underlying engine size */ - final int myEngineSize = dstuMac.getMacSize() == 32 ? 64 : 128; - - /* Define key (can be any multiple of engineSize) */ - final byte[] myKey = new byte[myEngineSize]; - - /* Initialise Mac (will fail with ArrayIndexOutOfBoundsException) */ - dstuMac.init(new KeyParameter(myKey)); - final int myOutSize = dstuMac.getMacSize(); - final byte[] myOut = new byte[myOutSize]; - dstuMac.update(myMessage, 0, myMessage.length); - dstuMac.doFinal(myOut, 0); - } - - private void hash256Tests() - { - - int hashBitSize = 256; - - //test 1 - byte[] input = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - byte[] expectedHash = Hex.decode("08F4EE6F1BE6903B324C4E27990CB24EF69DD58DBE84813EE0A52F6631239875"); - byte[] hash = new byte[hashBitSize / 8]; - - - DSTU7564Digest dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-256 test 1 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - - //test 2 - input = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F"); - expectedHash = Hex.decode("0A9474E645A7D25E255E9E89FFF42EC7EB31349007059284F0B182E452BDA882"); - hash = new byte[hashBitSize / 8]; - - - dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-256 test 2 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - - //test 3 - input = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF"); - expectedHash = Hex.decode("D305A32B963D149DC765F68594505D4077024F836C1BF03806E1624CE176C08F"); - hash = new byte[hashBitSize / 8]; - - dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-256 test 3 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - - //test 4 - input = Hex.decode("FF"); - expectedHash = Hex.decode("EA7677CA4526555680441C117982EA14059EA6D0D7124D6ECDB3DEEC49E890F4"); - hash = new byte[hashBitSize / 8]; - - dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-256 test 4 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - - //test 5 - input = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E"); - expectedHash = Hex.decode("1075C8B0CB910F116BDA5FA1F19C29CF8ECC75CAFF7208BA2994B68FC56E8D16"); - hash = new byte[hashBitSize / 8]; - - dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-256 test 5 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - - //test 6 - input = Hex.decode(""); - expectedHash = Hex.decode("CD5101D1CCDF0D1D1F4ADA56E888CD724CA1A0838A3521E7131D4FB78D0F5EB6"); - hash = new byte[hashBitSize / 8]; - - dstu7564 = new DSTU7564Digest(hashBitSize); - dstu7564.update(input, 0, input.length); - dstu7564.doFinal(hash, 0); - - if (!Arrays.areEqual(expectedHash, hash)) - { - fail("Failed hash-256 test 6 - expected " - + Hex.toHexString(expectedHash) - + " got " + Hex.toHexString(hash)); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DSTU7624Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DSTU7624Test.java deleted file mode 100644 index 439929912..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DSTU7624Test.java +++ /dev/null @@ -1,1467 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.engines.DSTU7624Engine; -import com.fr.third.org.bouncycastle.crypto.engines.DSTU7624WrapEngine; -import com.fr.third.org.bouncycastle.crypto.macs.DSTU7624Mac; -import com.fr.third.org.bouncycastle.crypto.macs.KGMac; -import com.fr.third.org.bouncycastle.crypto.modes.AEADBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.KCCMBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.KCTRBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.KGCMBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.KXTSBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.OFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.AEADParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class DSTU7624Test - extends CipherTest -{ - private static final SecureRandom RANDOM = new SecureRandom(); - - private static byte[] randomBytes(int min, int max) - { - int count = min + RNGUtils.nextInt(RANDOM,max - min); - byte[] result = new byte[count]; - RANDOM.nextBytes(result); - return result; - } - - static SimpleTest[] tests = - { - //ECB mode - new BlockCipherVectorTest(0, new DSTU7624Engine(128), new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F")), "101112131415161718191A1B1C1D1E1F", "81BF1C7D779BAC20E1C9EA39B4D2AD06"), - new BlockCipherVectorTest(1, new DSTU7624Engine(128), new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F")), "202122232425262728292A2B2C2D2E2F", "58EC3E091000158A1148F7166F334F14"), - new BlockCipherVectorTest(2, new DSTU7624Engine(256), new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F")), "202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F", "F66E3D570EC92135AEDAE323DCBD2A8CA03963EC206A0D5A88385C24617FD92C"), - new BlockCipherVectorTest(3, new DSTU7624Engine(256), new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F")), "404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F", "606990E9E6B7B67A4BD6D893D72268B78E02C83C3CD7E102FD2E74A8FDFE5DD9"), - new BlockCipherVectorTest(4, new DSTU7624Engine(512), new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F")), "404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F", "4A26E31B811C356AA61DD6CA0596231A67BA8354AA47F3A13E1DEEC320EB56B895D0F417175BAB662FD6F134BB15C86CCB906A26856EFEB7C5BC6472940DD9D9"), - - //CBC mode - new BlockCipherVectorTest(5, new CBCBlockCipher(new DSTU7624Engine(128)), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F")), Hex.decode("101112131415161718191A1B1C1D1E1F")), "202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F", "A73625D7BE994E85469A9FAABCEDAAB6DBC5F65DD77BB35E06BD7D1D8EAFC8624D6CB31CE189C82B8979F2936DE9BF14"), - new BlockCipherVectorTest(6, new CBCBlockCipher(new DSTU7624Engine(128)), new ParametersWithIV(new KeyParameter(Hex.decode("0F0E0D0C0B0A09080706050403020100")), Hex.decode("1F1E1D1C1B1A19181716151413121110")), "88F2F048BA696170E3818915E0DBC0AFA6F141FEBC2F817138DA4AAB2DBF9CE490A488C9C82AC83FB0A6C0EEB64CFD22", "4F4E4D4C4B4A494847464544434241403F3E3D3C3B3A393837363534333231302F2E2D2C2B2A29282726252423222120"), - new BlockCipherVectorTest(7, new CBCBlockCipher(new DSTU7624Engine(128)), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F")), Hex.decode("202122232425262728292A2B2C2D2E2F")), "303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D8000", "13EA15843AD14C50BC03ECEF1F43E398E4217752D3EB046AC393DACC5CA1D6FA0EB9FCEB229362B4F1565527EE3D8433"), - new BlockCipherVectorTest(8, new CBCBlockCipher(new DSTU7624Engine(128)), new ParametersWithIV(new KeyParameter(Hex.decode("1F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100")), Hex.decode("2F2E2D2C2B2A29282726252423222120")), "BC8F026FC603ECE05C24FDE87542730999B381870882AC0535D4368C4BABD81B884E96E853EE7E055262D9D204FBE212", "5F5E5D5C5B5A595857565554535251504F4E4D4C4B4A494847464544434241403F3E3D3C3B3A39383736353433323130"), - new BlockCipherVectorTest(9, new CBCBlockCipher(new DSTU7624Engine(256)), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F")), Hex.decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F")), "404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F", "9CDFDAA75929E7C2A5CFC1BF16B42C5AE3886D0258E8C577DC01DAF62D185FB999B9867736B87110F5F1BC7481912C593F48FF79E2AFDFAB9F704A277EC3E557B1B0A9F223DAE6ED5AF591C4F2D6FB22E48334F5E9B96B1A2EA5200F30A406CE"), - new BlockCipherVectorTest(10, new CBCBlockCipher(new DSTU7624Engine(256)), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F")), Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F")), "606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF", "B8A2474578C2FEBF3F94703587BD5FDC3F4A4D2F43575B6144A1E1031FB3D1452B7FD52F5E3411461DAC506869FF8D2FAEF4FEE60379AE00B33AA3EAF911645AF8091CD8A45D141D1FB150E5A01C1F26FF3DBD26AC4225EC7577B2CE57A5B0FF"), - new BlockCipherVectorTest(11, new CBCBlockCipher(new DSTU7624Engine(256)), new ParametersWithIV(new KeyParameter(Hex.decode("3F3E3D3C3B3A393837363534333231302F2E2D2C2B2A292827262524232221201F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100")), Hex.decode("5F5E5D5C5B5A595857565554535251504F4E4D4C4B4A49484746454443424140")), "C69A59E10D00F087319B62288A57417C074EAD07C732A87055F0A5AD2BB288105705C45E091A9A6726E9672DC7D8C76FC45C782BCFEF7C39D94DEB84B17035BC8651255A0D34373451B6E1A2C827DB97566C9FF5506C5579F982A0EFC5BA7C28", "BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0AFAEADACABAAA9A8A7A6A5A4A3A2A1A09F9E9D9C9B9A999897969594939291908F8E8D8C8B8A898887868584838281807F7E7D7C7B7A797877767574737271706F6E6D6C6B6A69686766656463626160"), - new BlockCipherVectorTest(12, new CBCBlockCipher(new DSTU7624Engine(512)), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F")), Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F")), "808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF", "D4739B829EF901B24C1162AE4FDEF897EDA41FAC7F5770CDC90E1D1CDF124E8D7831E06B4498A4B6F6EC815DF2461DC99BB0449B0F09FCAA2C84090534BCC9329626FD74EF8F0A0BCB5765184629C3CBF53B0FB134F6D0421174B1C4E884D1CD1069A7AD19752DCEBF655842E79B7858BDE01390A760D85E88925BFE38B0FA57"), - new BlockCipherVectorTest(13, new CBCBlockCipher(new DSTU7624Engine(512)), new ParametersWithIV(new KeyParameter(Hex.decode("3F3E3D3C3B3A393837363534333231302F2E2D2C2B2A292827262524232221201F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100")), Hex.decode("7F7E7D7C7B7A797877767574737271706F6E6D6C6B6A696867666564636261605F5E5D5C5B5A595857565554535251504F4E4D4C4B4A49484746454443424140")), "5D5B3E3DE5BAA70E0A0684D458856CE759C6018D0B3F087FC1DAC101D380236DD934F2880B02D56A575BCA35A0CE4B0D9BA1F4A39C16CA7D80D59956630F09E54EC91E32B6830FE08323ED393F8028D150BF03CAD0629A5AFEEFF6E44257980618DB2F32B7B2B65B96E8451F1090829D2FFFC615CC1581E9221438DCEAD1FD12", "FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0EFEEEDECEBEAE9E8E7E6E5E4E3E2E1E0DFDEDDDCDBDAD9D8D7D6D5D4D3D2D1D0CFCECDCCCBCAC9C8C7C6C5C4C3C2C1C0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0AFAEADACABAAA9A8A7A6A5A4A3A2A1A09F9E9D9C9B9A999897969594939291908F8E8D8C8B8A89888786858483828180"), - - //CFB mode - new BlockCipherVectorTest(14, new CFBBlockCipher(new DSTU7624Engine(128), 128), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F")), Hex.decode("101112131415161718191A1B1C1D1E1F")), "202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F", "A19E3E5E53BE8A07C9E0C01298FF83291F8EE6212110BE3FA5C72C88A082520B265570FE28680719D9B4465E169BC37A"), - - //OFB mode - new BlockCipherVectorTest(15, new OFBBlockCipher(new DSTU7624Engine(128), 128), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F")), Hex.decode("101112131415161718191A1B1C1D1E1F")), "202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F", "A19E3E5E53BE8A07C9E0C01298FF832953205C661BD85A51F3A94113BC785CAB634B36E89A8FDD16A12E4467F5CC5A26"), - new BlockCipherVectorTest(16, new OFBBlockCipher(new DSTU7624Engine(128), 128), new ParametersWithIV(new KeyParameter(Hex.decode("0F0E0D0C0B0A09080706050403020100")), Hex.decode("1F1E1D1C1B1A19181716151413121110")), "649A1EAAE160AF20F5B3EF2F58D66C1178B82E00D26F30689C8EC22E8E86E9CBB0BD4FFEE39EB13C2311276A906DD636", "4F4E4D4C4B4A494847464544434241403F3E3D3C3B3A393837363534333231302F2E2D2C2B2A29282726252423222120"), - new BlockCipherVectorTest(17, new OFBBlockCipher(new DSTU7624Engine(128), 128), new ParametersWithIV(new KeyParameter(Hex.decode("1F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100")), Hex.decode("2F2E2D2C2B2A29282726252423222120")), "1A66CFBFEC00C6D52E39923E858DD64B214AB787798D3D5059A6B498AD66B34EAC48C4074BEC0D98C6", "5F5E5D5C5B5A595857565554535251504F4E4D4C4B4A494847464544434241403F3E3D3C3B3A393837"), - new BlockCipherVectorTest(18, new OFBBlockCipher(new DSTU7624Engine(256), 256), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F")), Hex.decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F")), "404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F90", "B62F7F144A8C6772E693A96890F064C3F06831BF743F5B0DD061067F3D22877331AA6A99D939F05B7550E9402BD1615CC7B2D4A167E83EC0D8A894F92C72E176F3880B61C311D69CE1210C59184E818E19"), - new BlockCipherVectorTest(19, new OFBBlockCipher(new DSTU7624Engine(256), 256), new ParametersWithIV(new KeyParameter(Hex.decode("1F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100")), Hex.decode("3F3E3D3C3B3A393837363534333231302F2E2D2C2B2A29282726252423222120")), "7758A939DD6BD00CAF9153E5A5D5A66129105CA1EA54A97C06FA4A40960A068F55E34F9339A14436216948F92FA2FB5286D3AB1E81543FC0018A0C4E8C493475F4D35DCFB0A7A5377F6669B857CDC978E4", "9F9E9D9C9B9A999897969594939291908F8E8D8C8B8A898887868584838281807F7E7D7C7B7A797877767574737271706F6E6D6C6B6A696867666564636261605F5E5D5C5B5A595857565554535251504F"), - new BlockCipherVectorTest(20, new OFBBlockCipher(new DSTU7624Engine(256), 256), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F")), Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F")), "606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0", "0008F28A82D2D01D23BFB2F8BB4F06D8FE73BA4F48A2977585570ED3818323A668883C9DCFF610CC7E3EA5C025FBBC5CA6520F8F11CA35CEB9B07031E6DBFABE39001E9A3CC0A24BBC565939592B4DEDBD"), - new BlockCipherVectorTest(21, new OFBBlockCipher(new DSTU7624Engine(256), 256), new ParametersWithIV(new KeyParameter(Hex.decode("3F3E3D3C3B3A393837363534333231302F2E2D2C2B2A292827262524232221201F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100")), Hex.decode("5F5E5D5C5B5A595857565554535251504F4E4D4C4B4A49484746454443424140")), "98E122708FDABB1B1A5765C396DC79D7573221EC486ADDABD1770B147A6DD00B5FBC4F1EC68C59775B7AAA4D43C4CCE4F396D982DF64D30B03EF6C3B997BA0ED940BBC590BD30D64B5AE207147D71086B5", "BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0AFAEADACABAAA9A8A7A6A5A4A3A2A1A09F9E9D9C9B9A999897969594939291908F8E8D8C8B8A898887868584838281807F7E7D7C7B7A797877767574737271706F"), - new BlockCipherVectorTest(22, new OFBBlockCipher(new DSTU7624Engine(512), 512), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F")), Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F")), "808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0", "CAA761980599B3ED2E945C41891BAD95F72B11C73ED26536A6847458BC76C827357156B4B3FE0DC1877F5B9F17B866C37B21D89531DB48007D05DEC928B06766C014BB9080385EDF0677E48A0A39B5E7489E28E82FFFD1F84694F17296CB701656"), - new BlockCipherVectorTest(23, new OFBBlockCipher(new DSTU7624Engine(512), 512), new ParametersWithIV(new KeyParameter(Hex.decode("3F3E3D3C3B3A393837363534333231302F2E2D2C2B2A292827262524232221201F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100")), Hex.decode("7F7E7D7C7B7A797877767574737271706F6E6D6C6B6A696867666564636261605F5E5D5C5B5A595857565554535251504F4E4D4C4B4A49484746454443424140")), "06C061A4A66DFC0910034B3CFBDC4206D8908241C56BF41C4103CFD6DF322210B87F57EAE9F9AD815E606A7D1E8E6BD7CB1EBFBDBCB085C2D06BF3CC1586CB2EE1D81D38437F425131321647E42F5DE309D33F25B89DE37124683E4B44824FC56D", "EFEEEDECEBEAE9E8E7E6E5E4E3E2E1E0DFDEDDDCDBDAD9D8D7D6D5D4D3D2D1D0CFCECDCCCBCAC9C8C7C6C5C4C3C2C1C0BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0AFAEADACABAAA9A8A7A6A5A4A3A2A1A09F9E9D9C9B9A999897969594939291908F"), - - //CTR mode - new BlockCipherVectorTest(24, new KCTRBlockCipher(new DSTU7624Engine(128)), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F")), Hex.decode("101112131415161718191A1B1C1D1E1F")), "202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748", "A90A6B9780ABDFDFF64D14F5439E88F266DC50EDD341528DD5E698E2F000CE21F872DAF9FE1811844A"), - new BlockCipherVectorTest(25, new KCTRBlockCipher(new DSTU7624Engine(128)), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F")), Hex.decode("101112131415161718191A1B1C1D1E1F")), "303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F", "B91A7B8790BBCFCFE65D04E5538E98E216AC209DA33122FDA596E8928070BE51"), - new StreamCipherVectorTest(26, new KCTRBlockCipher(new DSTU7624Engine(128)), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F")), Hex.decode("101112131415161718191A1B1C1D1E1F")), "202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748", "A90A6B9780ABDFDFF64D14F5439E88F266DC50EDD341528DD5E698E2F000CE21F872DAF9FE1811844A"), - new StreamCipherVectorTest(27, new KCTRBlockCipher(new DSTU7624Engine(128)), new ParametersWithIV(new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F")), Hex.decode("101112131415161718191A1B1C1D1E1F")), "303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F", "B91A7B8790BBCFCFE65D04E5538E98E216AC209DA33122FDA596E8928070BE51") - }; - - - public DSTU7624Test() - { - super(tests, new DSTU7624Engine(128), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "DSTU7624"; - } - - public void performTest() - throws Exception - { - super.performTest(); - - MacTests(); - KeyWrapTests(); - CCMModeTests(); - XTSModeTests(); - GCMModeTests(); - } - - public static void main( - String[] args) - { - runTest(new DSTU7624Test()); - } - - - private void MacTests() - { - - //test 1 - byte[] key = Hex.decode("000102030405060708090A0B0C0D0E0F"); - - byte[] authtext = Hex.decode("202122232425262728292A2B2C2D2E2F" + - "303132333435363738393A3B3C3D3E3F" + - "404142434445464748494A4B4C4D4E4F"); - - byte[] expectedMac = Hex.decode("123B4EAB8E63ECF3E645A99C1115E241"); - - byte[] mac = new byte[expectedMac.length]; - - DSTU7624Mac dstu7624Mac = new DSTU7624Mac(128, 128); - dstu7624Mac.init(new KeyParameter(key)); - dstu7624Mac.update(authtext, 0, authtext.length); - dstu7624Mac.doFinal(mac, 0); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed MAC test 1 - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - - //test 2 - key = Hex.decode("000102030405060708090A0B0C0D0E0F" + - "101112131415161718191A1B1C1D1E1F" + - "202122232425262728292A2B2C2D2E2F" + - "303132333435363738393A3B3C3D3E3F"); - - authtext = Hex.decode("404142434445464748494A4B4C4D4E4F" + - "505152535455565758595A5B5C5D5E5F" + - "606162636465666768696A6B6C6D6E6F" + - "707172737475767778797A7B7C7D7E7F" + - "808182838485868788898A8B8C8D8E8F" + - "909192939495969798999A9B9C9D9E9F" + - "A0A1A2A3A4A5A6A7A8A9AAABACADAEAF" + - "B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"); - - expectedMac = Hex.decode("7279FA6BC8EF7525B2B35260D00A1743"); - - dstu7624Mac = new DSTU7624Mac(512, 128); - dstu7624Mac.init(new KeyParameter(key)); - dstu7624Mac.update(authtext, 0, authtext.length); - dstu7624Mac.doFinal(mac, 0); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed MAC test 2 - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - // check that reset correctly on doFinal() - dstu7624Mac.update(authtext, 0, authtext.length); - dstu7624Mac.doFinal(mac, 0); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed MAC test reset - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - // check that init reset correctly - dstu7624Mac.init(new KeyParameter(key)); - dstu7624Mac.init(new KeyParameter(key)); - dstu7624Mac.update(authtext, 0, authtext.length); - dstu7624Mac.doFinal(mac, 0); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed MAC test double init - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - // check simple reset - dstu7624Mac = new DSTU7624Mac(512, 128); - dstu7624Mac.reset(); - } - - private void KeyWrapTests() - throws Exception - { - //test 1 - /* - * Initial implementation had bugs handling offset and length correctly, so for - * this first test case we embed the input inside a larger buffer. - */ - byte[] textA = randomBytes(1, 64); - byte[] textB = randomBytes(1, 64); - byte[] textToWrap = Arrays.concatenate(new byte[][]{ textA, Hex.decode("101112131415161718191A1B1C1D1E1F"), textB }); - - byte[] key = Hex.decode("000102030405060708090A0B0C0D0E0F"); - byte[] expectedWrappedText = Hex.decode("1DC91DC6E52575F6DBED25ADDA95A1B6AD3E15056E489738972C199FB9EE2913"); - byte[] output = new byte[expectedWrappedText.length]; - - DSTU7624WrapEngine wrapper = new DSTU7624WrapEngine(128); - wrapper.init(true, new KeyParameter(key)); - output = wrapper.wrap(textToWrap, textA.length, textToWrap.length - textA.length - textB.length); - - if (!Arrays.areEqual(output, expectedWrappedText)) - { - fail("Failed KW (wrapping) test 1 - expected " - + Hex.toHexString(expectedWrappedText) - + " got " + Hex.toHexString(output)); - } - - output = Arrays.concatenate(new byte[][]{ textB, output, textA }); - - wrapper.init(false, new KeyParameter(key)); - output = wrapper.unwrap(output, textB.length, output.length - textB.length - textA.length); - - byte[] expected = Arrays.copyOfRange(textToWrap, textA.length, textToWrap.length - textB.length); - if (!Arrays.areEqual(output, expected)) - { - fail("Failed KW (unwrapping) test 1 - expected " - + Hex.toHexString(expected) - + " got " + Hex.toHexString(output)); - } - - //test 2 - key = Hex.decode("000102030405060708090A0B0C0D0E0F"); - textToWrap = Hex.decode("101112131415161718191A1B1C1D1E1F20219000000000000000800000000000"); - expectedWrappedText = Hex.decode("0EA983D6CE48484D51462C32CC61672210FCC44196ABE635BAF878FDB83E1A63114128585D49DB355C5819FD38039169"); - - output = new byte[expectedWrappedText.length]; - - wrapper.init(true, new KeyParameter(key)); - output = wrapper.wrap(textToWrap, 0, textToWrap.length); - - - if (!Arrays.areEqual(output, expectedWrappedText)) - { - fail("Failed KW (wrapping) test 2 - expected " - + Hex.toHexString(expectedWrappedText) - + " got " + Hex.toHexString(output)); - } - - - wrapper.init(false, new KeyParameter(key)); - - output = wrapper.unwrap(expectedWrappedText, 0, expectedWrappedText.length); - if (!Arrays.areEqual(output, textToWrap)) - { - fail("Failed KW (unwrapping) test 2 - expected " - + Hex.toHexString(textToWrap) - + " got " + Hex.toHexString(output)); - } - - //test 3 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); - textToWrap = Hex.decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F"); - expectedWrappedText = Hex.decode("2D09A7C18E6A5A0816331EC27CEA596903F77EC8D63F3BDB73299DE7FD9F4558E05992B0B24B39E02EA496368E0841CC1E3FA44556A3048C5A6E9E335717D17D"); - - output = new byte[expectedWrappedText.length]; - - wrapper = new DSTU7624WrapEngine(128); - wrapper.init(true, new KeyParameter(key)); - output = wrapper.wrap(textToWrap, 0, textToWrap.length); - - - if (!Arrays.areEqual(output, expectedWrappedText)) - { - fail("Failed KW (wrapping) test 3 - expected " - + Hex.toHexString(expectedWrappedText) - + " got " + Hex.toHexString(output)); - } - - wrapper.init(false, new KeyParameter(key)); - - output = wrapper.unwrap(expectedWrappedText, 0, expectedWrappedText.length); - - if (!Arrays.areEqual(output, textToWrap)) - { - fail("Failed KW (unwrapping) test 3 - expected " - + Hex.toHexString(textToWrap) - + " got " + Hex.toHexString(output)); - } - - //test 4 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); - textToWrap = Hex.decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464E8040000000000020"); - expectedWrappedText = Hex.decode("37E3EECB91150C6FA04CFD19D6FC57B7168C9FA5C5ED18601C68EE4AFD7301F8C8C51D7A0A5CD34F6FAB0D8AF11845CC1E4B16E0489FDA1D76BA4EFCFD161F76"); - - output = new byte[expectedWrappedText.length]; - - wrapper = new DSTU7624WrapEngine(128); - wrapper.init(true, new KeyParameter(key)); - output = wrapper.wrap(textToWrap, 0, textToWrap.length); - - - if (!Arrays.areEqual(output, expectedWrappedText)) - { - fail("Failed KW (wrapping) test 4 - expected " - + Hex.toHexString(expectedWrappedText) - + " got " + Hex.toHexString(output)); - } - - wrapper.init(false, new KeyParameter(key)); - - output = wrapper.unwrap(expectedWrappedText, 0, expectedWrappedText.length); - - if (!Arrays.areEqual(output, textToWrap)) - { - fail("Failed KW (unwrapping) test 4 - expected " - + Hex.toHexString(textToWrap) - + " got " + Hex.toHexString(output)); - } - - //test 5 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); - textToWrap = Hex.decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F"); - expectedWrappedText = Hex.decode("BE59D3C3C31B2685A8FA57CD000727F16AF303F0D87BC2D7ABD80DC2796BBC4CDBC4E0408943AF4DAF7DE9084DC81BFEF15FDCDD0DF399983DF69BF730D7AE2A199CA4F878E4723B7171DD4D1E8DF59C0F25FA0C20946BA64F9037D724BB1D50B6C2BD9788B2AF83EF6163087CD2D4488BC19F3A858D813E3A8947A529B6D65D"); - - output = new byte[expectedWrappedText.length]; - - wrapper = new DSTU7624WrapEngine(256); - wrapper.init(true, new KeyParameter(key)); - output = wrapper.wrap(textToWrap, 0, textToWrap.length); - - - if (!Arrays.areEqual(output, expectedWrappedText)) - { - fail("Failed KW (wrapping) test 5 - expected " - + Hex.toHexString(expectedWrappedText) - + " got " + Hex.toHexString(output)); - } - - wrapper.init(false, new KeyParameter(key)); - - output = wrapper.unwrap(expectedWrappedText, 0, expectedWrappedText.length); - - if (!Arrays.areEqual(output, textToWrap)) - { - fail("Failed KW (unwrapping) test 5 - expected " - + Hex.toHexString(textToWrap) - + " got " + Hex.toHexString(output)); - } - } - - private void CCMModeTests() - throws Exception - { - //test 1 - byte[] key = Hex.decode("000102030405060708090a0b0c0d0e0f"); - byte[] iv = Hex.decode("101112131415161718191a1b1c1d1e1f"); - byte[] input = Hex.decode("303132333435363738393a3b3c3d3e3f"); - byte[] authText = Hex.decode("202122232425262728292a2b2c2d2e2f"); - - byte[] expectedMac = Hex.decode("26a936173a4dc9160d6e3fda3a974060"); - byte[] expectedEncrypted = Hex.decode("b91a7b8790bbcfcfe65d04e5538e98e2704454c9dd39adace0b19d03f6aab07e"); - - byte[] mac; - byte[] encrypted = new byte[expectedEncrypted.length]; - - byte[] decrypted = new byte[encrypted.length]; - byte[] expectedDecrypted = new byte[input.length + expectedMac.length]; - System.arraycopy(input, 0, expectedDecrypted, 0, input.length); - System.arraycopy(expectedMac, 0, expectedDecrypted, input.length, expectedMac.length); - int len; - - - AEADParameters param = new AEADParameters(new KeyParameter(key), 128, iv); - - KCCMBlockCipher dstu7624ccm = new KCCMBlockCipher(new DSTU7624Engine(128)); - - dstu7624ccm.init(true, param); - - dstu7624ccm.processAADBytes(authText, 0, authText.length); - - len = dstu7624ccm.processBytes(input, 0, input.length, encrypted, 0); - - - dstu7624ccm.doFinal(encrypted, len); - - mac = dstu7624ccm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed CCM mac test 1 - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - if (!Arrays.areEqual(encrypted, expectedEncrypted)) - { - fail("Failed CCM encrypt test 1 - expected " - + Hex.toHexString(expectedEncrypted) - + " got " + Hex.toHexString(encrypted)); - } - - dstu7624ccm.init(false, param); - - dstu7624ccm.processAADBytes(authText, 0, authText.length); - - len = dstu7624ccm.processBytes(expectedEncrypted, 0, expectedEncrypted.length, decrypted, 0); - - dstu7624ccm.doFinal(decrypted, len); - - if (!Arrays.areEqual(decrypted, expectedDecrypted)) - { - fail("Failed CCM decrypt/verify mac test 1 - expected " - + Hex.toHexString(expectedDecrypted) - + " got " + Hex.toHexString(decrypted)); - } - - //test 2 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); - iv = Hex.decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - input = Hex.decode("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F"); - authText = Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F"); - - expectedMac = Hex.decode("9AB831B4B0BF0FDBC36E4B4FD58F0F00"); - expectedEncrypted = Hex.decode("7EC15C54BB553CB1437BE0EFDD2E810F6058497EBCE4408A08A73FADF3F459D56B0103702D13AB73ACD2EB33A8B5E9CFFF5EB21865A6B499C10C810C4BAEBE809C48AD90A9E12A68380EF1C1B7C83EE1"); - - mac = new byte[expectedMac.length]; - encrypted = new byte[expectedEncrypted.length]; - - decrypted = new byte[encrypted.length]; - expectedDecrypted = new byte[input.length + expectedMac.length]; - System.arraycopy(input, 0, expectedDecrypted, 0, input.length); - System.arraycopy(expectedMac, 0, expectedDecrypted, input.length, expectedMac.length); - - - param = new AEADParameters(new KeyParameter(key), 128, iv); - - dstu7624ccm = new KCCMBlockCipher(new DSTU7624Engine(256)); - - dstu7624ccm.init(true, param); - - dstu7624ccm.processAADBytes(authText, 0, authText.length); - - len = dstu7624ccm.processBytes(input, 0, input.length, encrypted, 0); - - dstu7624ccm.doFinal(encrypted, len); - - mac = dstu7624ccm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed CCM mac test 2 - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - if (!Arrays.areEqual(encrypted, expectedEncrypted)) - { - fail("Failed CCM encrypt test 2 - expected " - + Hex.toHexString(expectedEncrypted) - + " got " + Hex.toHexString(encrypted)); - } - - dstu7624ccm.init(false, param); - - dstu7624ccm.processAADBytes(authText, 0, authText.length); - - len = dstu7624ccm.processBytes(expectedEncrypted, 0, expectedEncrypted.length, decrypted, 0); - - dstu7624ccm.doFinal(decrypted, len); - - if (!Arrays.areEqual(decrypted, expectedDecrypted)) - { - fail("Failed CCM decrypt/verify mac test 2 - expected " - + Hex.toHexString(expectedDecrypted) - + " got " + Hex.toHexString(decrypted)); - } - - //test 3 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - iv = Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F"); - input = Hex.decode("808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"); - authText = Hex.decode("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F"); - - expectedMac = Hex.decode("924FA0326824355595C98028E84D86279CEA9135FAB35F22054AE3203E68AE46"); - expectedEncrypted = Hex.decode("3EBDB4584B5169A26FBEBA0295B4223F58D5D8A031F2950A1D7764FAB97BA058E9E2DAB90FF0C519AA88435155A71B7B53BB100F5D20AFFAC0552F5F2813DEE8DD3653491737B9615A5CCD83DB32F1E479BF227C050325BBBFF60BCA9558D7FE"); - - mac = new byte[expectedMac.length]; - encrypted = new byte[expectedEncrypted.length]; - - decrypted = new byte[encrypted.length]; - expectedDecrypted = new byte[input.length + expectedMac.length]; - System.arraycopy(input, 0, expectedDecrypted, 0, input.length); - System.arraycopy(expectedMac, 0, expectedDecrypted, input.length, expectedMac.length); - - - param = new AEADParameters(new KeyParameter(key), 256, iv); - - dstu7624ccm = new KCCMBlockCipher(new DSTU7624Engine(256), 6); - - dstu7624ccm.init(true, param); - - dstu7624ccm.processAADBytes(authText, 0, authText.length); - - len = dstu7624ccm.processBytes(input, 0, input.length, encrypted, 0); - - dstu7624ccm.doFinal(encrypted, len); - - mac = dstu7624ccm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed CCM mac test 3 - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - if (!Arrays.areEqual(encrypted, expectedEncrypted)) - { - fail("Failed CCM encrypt test 3 - expected " - + Hex.toHexString(expectedEncrypted) - + " got " + Hex.toHexString(encrypted)); - } - - dstu7624ccm.init(false, param); - - dstu7624ccm.processAADBytes(authText, 0, authText.length); - - len = dstu7624ccm.processBytes(expectedEncrypted, 0, expectedEncrypted.length, decrypted, 0); - - dstu7624ccm.doFinal(decrypted, len); - - if (!Arrays.areEqual(decrypted, expectedDecrypted)) - { - fail("Failed CCM decrypt/verify mac test 3 - expected " - + Hex.toHexString(expectedDecrypted) - + " got " + Hex.toHexString(decrypted)); - } - - //test 4 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - iv = Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F"); - input = Hex.decode("C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF"); - authText = Hex.decode("808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"); - - expectedMac = Hex.decode("D4155EC3D888C8D32FE184AC260FD60F567705E1DF362A6F1F9C287156AA96D91BC4C56F9709E72F3D79CF0A9AC8BDC2BA836BE50E823AB50FB1B39080390923"); - expectedEncrypted = Hex.decode("220642D7277D104788CF97B10210984F506435512F7BF153C5CDABFECC10AFB4A2E2FC51F616AF80FFDD0607FAD4F542B8EF0667717CE3EAAA8FBC303CE76C99BD8F80CE149143C04FC2490272A31B029DDADA82F055FE4ABEF452A7D438B21E59C1D8B3DD4606BAD66A6F36300EF3CE0E5F3BB59F11416E80B7FC5A8E8B057A"); - - mac = new byte[expectedMac.length]; - encrypted = new byte[expectedEncrypted.length]; - - decrypted = new byte[encrypted.length]; - expectedDecrypted = new byte[input.length + expectedMac.length]; - System.arraycopy(input, 0, expectedDecrypted, 0, input.length); - System.arraycopy(expectedMac, 0, expectedDecrypted, input.length, expectedMac.length); - - - param = new AEADParameters(new KeyParameter(key), 512, iv); - - dstu7624ccm = new KCCMBlockCipher(new DSTU7624Engine(512), 8); - - dstu7624ccm.init(true, param); - - dstu7624ccm.processAADBytes(authText, 0, authText.length); - - len = dstu7624ccm.processBytes(input, 0, input.length, encrypted, 0); - - dstu7624ccm.doFinal(encrypted, len); - - mac = dstu7624ccm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed CCM mac test 4 - expected " - + Hex.toHexString(expectedMac) - + " got " + Hex.toHexString(mac)); - } - - if (!Arrays.areEqual(encrypted, expectedEncrypted)) - { - fail("Failed CCM encrypt test 4 - expected " - + Hex.toHexString(expectedEncrypted) - + " got " + Hex.toHexString(encrypted)); - } - - dstu7624ccm.init(false, param); - - dstu7624ccm.processAADBytes(authText, 0, authText.length); - - len = dstu7624ccm.processBytes(expectedEncrypted, 0, expectedEncrypted.length, decrypted, 0); - - dstu7624ccm.doFinal(decrypted, len); - - if (!Arrays.areEqual(decrypted, expectedDecrypted)) - { - fail("Failed CCM decrypt/verify mac test 4 - expected " - + Hex.toHexString(expectedDecrypted) - + " got " + Hex.toHexString(decrypted)); - } - - doFinalTest(new KCCMBlockCipher(new DSTU7624Engine(512), 8), key, iv, authText, input, expectedEncrypted); - } - - private void XTSModeTests() - throws Exception - { - - //test 1 - byte[] key = Hex.decode("000102030405060708090A0B0C0D0E0F"); - byte[] iv = Hex.decode("101112131415161718191A1B1C1D1E1F"); - byte[] plainText = Hex.decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - - byte[] output = new byte[plainText.length]; - byte[] expectedCipherText = Hex.decode("B3E431B3FBAF31108C302669EE7116D1CF518B6D329D30618DF5628E426BDEF1"); - - byte[] decrypted = new byte[plainText.length]; - - - int len; - - KXTSBlockCipher dstu7624xts = new KXTSBlockCipher(new DSTU7624Engine(128)); - ParametersWithIV param = new ParametersWithIV(new KeyParameter(key), iv); - - dstu7624xts.init(true, param); - len = dstu7624xts.processBytes(plainText, 0, plainText.length, output, 0); - - dstu7624xts.doFinal(output, len); - - if (!Arrays.areEqual(output, expectedCipherText)) - { - fail("Failed XTS encrypt test 1 - expected " - + Hex.toHexString(expectedCipherText) - + " got " + Hex.toHexString(output)); - } - - - dstu7624xts.init(false, param); - len = dstu7624xts.processBytes(expectedCipherText, 0, expectedCipherText.length, decrypted, 0); - dstu7624xts.doFinal(decrypted, len); - - if (!Arrays.areEqual(decrypted, plainText)) - { - fail("Failed XTS decrypt test 1 - expected " - + Hex.toHexString(plainText) - + " got " + Hex.toHexString(decrypted)); - } - - //test 2 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); - iv = Hex.decode("202122232425262728292A2B2C2D2E2F"); - plainText = Hex.decode("303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F"); - - output = new byte[plainText.length]; - expectedCipherText = Hex.decode("830AC78A6F629CB4C7D5D156FD84955BD0998CA1E0BC1FF135676BF2A2598FA1"); - - decrypted = new byte[plainText.length]; - - - dstu7624xts = new KXTSBlockCipher(new DSTU7624Engine(128)); - param = new ParametersWithIV(new KeyParameter(key), iv); - - dstu7624xts.init(true, param); - len = dstu7624xts.processBytes(plainText, 0, plainText.length, output, 0); - dstu7624xts.doFinal(output, len); - - if (!Arrays.areEqual(output, expectedCipherText)) - { - fail("Failed XTS encrypt test 2 - expected " - + Hex.toHexString(expectedCipherText) - + " got " + Hex.toHexString(output)); - } - - - dstu7624xts.init(false, param); - len = dstu7624xts.processBytes(expectedCipherText, 0, expectedCipherText.length, decrypted, 0); - dstu7624xts.doFinal(decrypted, len); - - if (!Arrays.areEqual(decrypted, plainText)) - { - fail("Failed XTS decrypt test 2 - expected " - + Hex.toHexString(plainText) - + " got " + Hex.toHexString(decrypted)); - } - - - //test 3 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); - iv = Hex.decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - plainText = Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F"); - - output = new byte[plainText.length]; - expectedCipherText = Hex.decode("E0E51EAEA6A3134600758EA7F87E88025D8B82897C8DB099B843054C3A51883756913571530BA8FA23003E337627E698674B807E847EC6B2292627736562F9F62B2DE9E6AAC5DF74C09A0C5CF80280174AEC9BDD4E73F7D63EDBC29A6922637A"); - - decrypted = new byte[plainText.length]; - - dstu7624xts = new KXTSBlockCipher(new DSTU7624Engine(256)); - param = new ParametersWithIV(new KeyParameter(key), iv); - - dstu7624xts.init(true, param); - len = dstu7624xts.processBytes(plainText, 0, plainText.length, output, 0); - dstu7624xts.doFinal(output, len); - - if (!Arrays.areEqual(output, expectedCipherText)) - { - fail("Failed XTS encrypt test 3 - expected " - + Hex.toHexString(expectedCipherText) - + " got " + Hex.toHexString(output)); - } - - dstu7624xts.init(false, param); - len = dstu7624xts.processBytes(expectedCipherText, 0, expectedCipherText.length, decrypted, 0); - dstu7624xts.doFinal(decrypted, len); - - if (!Arrays.areEqual(decrypted, plainText)) - { - fail("Failed XTS decrypt test 3 - expected " - + Hex.toHexString(plainText) - + " got " + Hex.toHexString(decrypted)); - } - - //test 4 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - iv = Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F"); - plainText = Hex.decode("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"); - - output = new byte[plainText.length]; - expectedCipherText = Hex.decode("30663E4686574B343A1898E46973CD37DB9D775D356512EB59E723397F2A333CE2C0E96538781FF48EA1D93BDF88FFF8BB7BC4FB80A609881220C7FE21881C7374F65B232A8F94CD0E3DDC7614830C23CFCE98ADC5113496F9E106E8C8BFF3AB"); - - decrypted = new byte[plainText.length]; - - dstu7624xts = new KXTSBlockCipher(new DSTU7624Engine(256)); - param = new ParametersWithIV(new KeyParameter(key), iv); - - dstu7624xts.init(true, param); - len = dstu7624xts.processBytes(plainText, 0, plainText.length, output, 0); - dstu7624xts.doFinal(output, len); - - if (!Arrays.areEqual(output, expectedCipherText)) - { - fail("Failed XTS encrypt test 4 - expected " - + Hex.toHexString(expectedCipherText) - + " got " + Hex.toHexString(output)); - } - - - dstu7624xts.init(false, param); - len = dstu7624xts.processBytes(expectedCipherText, 0, expectedCipherText.length, decrypted, 0); - dstu7624xts.doFinal(decrypted, len); - - if (!Arrays.areEqual(decrypted, plainText)) - { - fail("Failed XTS decrypt test 4 - expected " - + Hex.toHexString(plainText) - + " got " + Hex.toHexString(decrypted)); - } - - //test 5 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - iv = Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F"); - plainText = Hex.decode("808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF"); - - output = new byte[plainText.length]; - expectedCipherText = Hex.decode("5C6250BD2E40AAE27E1E57512CD38E6A51D0C2B04F0D6A50E0CB43358B8C4E8BA361331436C6FFD38D77BBBBF5FEC56A234108A6CC8CB298360943E849E5BD64D26ECA2FA8AEAD070656C3777BA412BCAF3D2F08C26CF86CA8F0921043A15D709AE1112611E22D4396E582CCB661E0F778B6F38561BC338AFD5D1036ED8B322D"); - - decrypted = new byte[plainText.length]; - - dstu7624xts = new KXTSBlockCipher(new DSTU7624Engine(512)); - param = new ParametersWithIV(new KeyParameter(key), iv); - - dstu7624xts.init(true, param); - len = dstu7624xts.processBytes(plainText, 0, plainText.length, output, 0); - dstu7624xts.doFinal(output, len); - - if (!Arrays.areEqual(output, expectedCipherText)) - { - fail("Failed XTS encrypt test 5 - expected " - + Hex.toHexString(expectedCipherText) - + " got " + Hex.toHexString(output)); - } - - - dstu7624xts.init(false, param); - len = dstu7624xts.processBytes(expectedCipherText, 0, expectedCipherText.length, decrypted, 0); - dstu7624xts.doFinal(decrypted, len); - - if (!Arrays.areEqual(decrypted, plainText)) - { - fail("Failed XTS decrypt test 5 - expected " - + Hex.toHexString(plainText) - + " got " + Hex.toHexString(decrypted)); - } - } - - private void GCMModeTests() - throws Exception - { - //test 1 - byte[] key = Hex.decode("000102030405060708090A0B0C0D0E0F"); - - byte[] iv = Hex.decode("101112131415161718191A1B1C1D1E1F"); - - byte[] authText = Hex.decode("202122232425262728292A2B2C2D2E2F"); - - byte[] plainText = Hex.decode("303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F"); - - byte[] expectedEncrypted = Hex.decode("B91A7B8790BBCFCFE65D04E5538E98E216AC209DA33122FDA596E8928070BE51"); - - byte[] expectedMac = Hex.decode("C8310571CD60F9584B45C1B4ECE179AF"); - - byte[] expectedOutput = new byte[expectedEncrypted.length + expectedMac.length]; - System.arraycopy(expectedEncrypted, 0, expectedOutput, 0, expectedEncrypted.length); - System.arraycopy(expectedMac, 0, expectedOutput, expectedEncrypted.length, expectedMac.length); - - byte[] mac = new byte[expectedMac.length]; - - byte[] encrypted = new byte[expectedEncrypted.length + mac.length]; - - byte[] decrypted = new byte[plainText.length + mac.length]; - - System.arraycopy(expectedMac, 0, decrypted, plainText.length, mac.length); - - int len; - - AEADParameters parameters = new AEADParameters(new KeyParameter(key), 128, iv); - - KGCMBlockCipher dstu7624gcm = new KGCMBlockCipher(new DSTU7624Engine(128)); - - dstu7624gcm.init(true, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - - len = dstu7624gcm.processBytes(plainText, 0, plainText.length, encrypted, 0); - dstu7624gcm.doFinal(encrypted, len); - - mac = dstu7624gcm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 1 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - if (!Arrays.areEqual(encrypted, expectedOutput)) - { - fail("Failed GCM/GMAC test 1 - expected encrypted: " - + Hex.toHexString(expectedOutput) - + " got encrypted: " + Hex.toHexString(encrypted)); - } - - - dstu7624gcm.init(false, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - - len = dstu7624gcm.processBytes(expectedOutput, 0, expectedOutput.length, decrypted, 0); - dstu7624gcm.doFinal(decrypted, len); - - - mac = dstu7624gcm.getMac(); - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 1 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - //remove mac at the end of decrypted data - byte[] tempDecrypted = new byte[plainText.length]; - System.arraycopy(decrypted, 0, tempDecrypted, 0, plainText.length); - decrypted = tempDecrypted; - - - if (!Arrays.areEqual(decrypted, plainText)) - { - fail("Failed GCM/GMAC test 1 - expected decrypted: " - + Hex.toHexString(plainText) - + " got decrypted: " + Hex.toHexString(decrypted)); - } - - //test 2 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); - - iv = Hex.decode("202122232425262728292A2B2C2D2E2F"); - - authText = Hex.decode("303132333435363738393A3B3C3D3E3F"); - - plainText = Hex.decode("505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F"); - - expectedEncrypted = Hex.decode("FF83F27C6D4EA26101B1986235831406A297940D6C0E695596D612623E0E7CDC"); - - expectedMac = Hex.decode("3C474281AFEAE4FD6D61E995258747AB"); - - expectedOutput = new byte[expectedEncrypted.length + expectedMac.length]; - System.arraycopy(expectedEncrypted, 0, expectedOutput, 0, expectedEncrypted.length); - System.arraycopy(expectedMac, 0, expectedOutput, expectedEncrypted.length, expectedMac.length); - - - mac = new byte[expectedMac.length]; - - encrypted = new byte[expectedEncrypted.length + mac.length]; - - decrypted = new byte[plainText.length + mac.length]; - - System.arraycopy(expectedMac, 0, decrypted, plainText.length, mac.length); - - parameters = new AEADParameters(new KeyParameter(key), 128, iv); - - dstu7624gcm = new KGCMBlockCipher(new DSTU7624Engine(128)); - - dstu7624gcm.init(true, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - len = dstu7624gcm.processBytes(plainText, 0, plainText.length, encrypted, 0); - - dstu7624gcm.doFinal(encrypted, len); - - mac = dstu7624gcm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 2 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - if (!Arrays.areEqual(encrypted, expectedOutput)) - { - fail("Failed GCM/GMAC test 2 - expected encrypted: " - + Hex.toHexString(expectedOutput) - + " got encrypted: " + Hex.toHexString(encrypted)); - } - - - dstu7624gcm.init(false, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - len = dstu7624gcm.processBytes(expectedOutput, 0, expectedOutput.length, decrypted, 0); - - dstu7624gcm.doFinal(decrypted, len); - - mac = dstu7624gcm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 2 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - //remove mac at the end of decrypted data - tempDecrypted = new byte[plainText.length]; - System.arraycopy(decrypted, 0, tempDecrypted, 0, plainText.length); - decrypted = tempDecrypted; - - if (!Arrays.areEqual(decrypted, plainText)) - { - fail("Failed GCM/GMAC test 2 - expected decrypted: " - + Hex.toHexString(plainText) - + " got decrypted: " + Hex.toHexString(decrypted)); - } - - //test 3 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); - - iv = Hex.decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - - authText = Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F"); - - plainText = Hex.decode("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F"); - - expectedEncrypted = Hex.decode("7EC15C54BB553CB1437BE0EFDD2E810F6058497EBCE4408A08A73FADF3F459D56B0103702D13AB73ACD2EB33A8B5E9CFFF5EB21865A6B499C10C810C4BAEBE80"); - - expectedMac = Hex.decode("1D61B0A3018F6B849CBA20AF1DDDA245"); - - expectedOutput = new byte[expectedEncrypted.length + expectedMac.length]; - System.arraycopy(expectedEncrypted, 0, expectedOutput, 0, expectedEncrypted.length); - System.arraycopy(expectedMac, 0, expectedOutput, expectedEncrypted.length, expectedMac.length); - - - mac = new byte[expectedMac.length]; - - encrypted = new byte[expectedEncrypted.length + mac.length]; - - decrypted = new byte[plainText.length + mac.length]; - - System.arraycopy(expectedMac, 0, decrypted, plainText.length, mac.length); - - - parameters = new AEADParameters(new KeyParameter(key), 128, iv); - - dstu7624gcm = new KGCMBlockCipher(new DSTU7624Engine(256)); - - dstu7624gcm.init(true, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - len = dstu7624gcm.processBytes(plainText, 0, plainText.length, encrypted, 0); - - dstu7624gcm.doFinal(encrypted, len); - - mac = dstu7624gcm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 3 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - if (!Arrays.areEqual(encrypted, expectedOutput)) - { - fail("Failed GCM/GMAC test 3 - expected encrypted: " - + Hex.toHexString(expectedOutput) - + " got encrypted: " + Hex.toHexString(encrypted)); - } - - dstu7624gcm.init(false, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - len = dstu7624gcm.processBytes(expectedOutput, 0, expectedOutput.length, decrypted, 0); - - dstu7624gcm.doFinal(decrypted, len); - - mac = dstu7624gcm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 3 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - //remove mac at the end of decrypted data - tempDecrypted = new byte[plainText.length]; - System.arraycopy(decrypted, 0, tempDecrypted, 0, plainText.length); - decrypted = tempDecrypted; - - if (!Arrays.areEqual(decrypted, plainText)) - { - fail("Failed GCM/GMAC test 3 - expected decrypted: " - + Hex.toHexString(plainText) - + " got decrypted: " + Hex.toHexString(decrypted)); - } - - //test 4 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); - - iv = Hex.decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - - authText = Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F"); - - plainText = Hex.decode("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F"); - - expectedEncrypted = Hex.decode("7EC15C54BB553CB1437BE0EFDD2E810F6058497EBCE4408A08A73FADF3F459D56B0103702D13AB73ACD2EB33A8B5E9CFFF5EB21865A6B499C10C810C4BAEBE80"); - - expectedMac = Hex.decode("1D61B0A3018F6B849CBA20AF1DDDA245B1B296258AC0352A52D3F372E72224CE"); - - expectedOutput = new byte[expectedEncrypted.length + expectedMac.length]; - System.arraycopy(expectedEncrypted, 0, expectedOutput, 0, expectedEncrypted.length); - System.arraycopy(expectedMac, 0, expectedOutput, expectedEncrypted.length, expectedMac.length); - - - mac = new byte[expectedMac.length]; - - encrypted = new byte[expectedEncrypted.length + mac.length]; - - decrypted = new byte[plainText.length + mac.length]; - - System.arraycopy(expectedMac, 0, decrypted, plainText.length, mac.length); - - parameters = new AEADParameters(new KeyParameter(key), 256, iv); - - dstu7624gcm = new KGCMBlockCipher(new DSTU7624Engine(256)); - - dstu7624gcm.init(true, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - len = dstu7624gcm.processBytes(plainText, 0, plainText.length, encrypted, 0); - - dstu7624gcm.doFinal(encrypted, len); - - mac = dstu7624gcm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 4 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - if (!Arrays.areEqual(encrypted, expectedOutput)) - { - fail("Failed GCM/GMAC test 4 - expected encrypted: " - + Hex.toHexString(expectedOutput) - + " got encrypted: " + Hex.toHexString(encrypted)); - } - - - dstu7624gcm.init(false, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - len = dstu7624gcm.processBytes(expectedOutput, 0, expectedOutput.length, decrypted, 0); - - dstu7624gcm.doFinal(decrypted, len); - - mac = dstu7624gcm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 4 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - //remove mac at the end of decrypted data - tempDecrypted = new byte[plainText.length]; - System.arraycopy(decrypted, 0, tempDecrypted, 0, plainText.length); - decrypted = tempDecrypted; - - if (!Arrays.areEqual(decrypted, plainText)) - { - fail("Failed GCM/GMAC test 4 - expected decrypted: " - + Hex.toHexString(plainText) - + " got decrypted: " + Hex.toHexString(decrypted)); - } - - //test 5 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - - iv = Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F"); - - authText = Hex.decode("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F"); - - plainText = Hex.decode("808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"); - - expectedEncrypted = Hex.decode("3EBDB4584B5169A26FBEBA0295B4223F58D5D8A031F2950A1D7764FAB97BA058E9E2DAB90FF0C519AA88435155A71B7B53BB100F5D20AFFAC0552F5F2813DEE8"); - - expectedMac = Hex.decode("8555FD3D9B02C2325ACA3CC9309D6B4B9AFC697D13BBBFF067198D5D86CB9820"); - - expectedOutput = new byte[expectedEncrypted.length + expectedMac.length]; - System.arraycopy(expectedEncrypted, 0, expectedOutput, 0, expectedEncrypted.length); - System.arraycopy(expectedMac, 0, expectedOutput, expectedEncrypted.length, expectedMac.length); - - - mac = new byte[expectedMac.length]; - - encrypted = new byte[expectedEncrypted.length + mac.length]; - - decrypted = new byte[plainText.length + mac.length]; - - System.arraycopy(expectedMac, 0, decrypted, plainText.length, mac.length); - - - parameters = new AEADParameters(new KeyParameter(key), 256, iv); - - dstu7624gcm = new KGCMBlockCipher(new DSTU7624Engine(256)); - dstu7624gcm.init(true, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - len = dstu7624gcm.processBytes(plainText, 0, plainText.length, encrypted, 0); - - dstu7624gcm.doFinal(encrypted, len); - - mac = dstu7624gcm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 5 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - if (!Arrays.areEqual(encrypted, expectedOutput)) - { - fail("Failed GCM/GMAC test 5 - expected encrypted: " - + Hex.toHexString(expectedOutput) - + " got encrypted: " + Hex.toHexString(encrypted)); - } - - - dstu7624gcm.init(false, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - len = dstu7624gcm.processBytes(expectedOutput, 0, expectedOutput.length, decrypted, 0); - - dstu7624gcm.doFinal(decrypted, len); - - mac = dstu7624gcm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 5 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - //remove mac at the end of decrypted data - tempDecrypted = new byte[plainText.length]; - System.arraycopy(decrypted, 0, tempDecrypted, 0, plainText.length); - decrypted = tempDecrypted; - - if (!Arrays.areEqual(decrypted, plainText)) - { - fail("Failed GCM/GMAC test 5 - expected decrypted: " - + Hex.toHexString(plainText) - + " got decrypted: " + Hex.toHexString(decrypted)); - } - - //test 6 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - - iv = Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F"); - - authText = Hex.decode("808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"); - - plainText = Hex.decode("C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF"); - - expectedEncrypted = Hex.decode("220642D7277D104788CF97B10210984F506435512F7BF153C5CDABFECC10AFB4A2E2FC51F616AF80FFDD0607FAD4F542B8EF0667717CE3EAAA8FBC303CE76C99"); - - expectedMac = Hex.decode("78A77E5948F5DC05F551486FDBB44898C9AB1BD439D7519841AE31007C09E1B312E5EA5929F952F6A3EEF5CBEAEF262B8EC1884DFCF4BAAF7B5C9291A22489E1"); - - expectedOutput = new byte[expectedEncrypted.length + expectedMac.length]; - System.arraycopy(expectedEncrypted, 0, expectedOutput, 0, expectedEncrypted.length); - System.arraycopy(expectedMac, 0, expectedOutput, expectedEncrypted.length, expectedMac.length); - - - mac = new byte[expectedMac.length]; - - encrypted = new byte[expectedEncrypted.length + mac.length]; - - decrypted = new byte[plainText.length + mac.length]; - - System.arraycopy(expectedMac, 0, decrypted, plainText.length, mac.length); - - parameters = new AEADParameters(new KeyParameter(key), 512, iv); - - dstu7624gcm = new KGCMBlockCipher(new DSTU7624Engine(512)); - - dstu7624gcm.init(true, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - len = dstu7624gcm.processBytes(plainText, 0, plainText.length, encrypted, 0); - - dstu7624gcm.doFinal(encrypted, len); - - mac = dstu7624gcm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 6 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - if (!Arrays.areEqual(encrypted, expectedOutput)) - { - fail("Failed GCM/GMAC test 6 - expected encrypted: " - + Hex.toHexString(expectedOutput) - + " got encrypted: " + Hex.toHexString(encrypted)); - } - - dstu7624gcm.init(false, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - len = dstu7624gcm.processBytes(expectedOutput, 0, expectedOutput.length, decrypted, 0); - - dstu7624gcm.doFinal(decrypted, len); - - mac = dstu7624gcm.getMac(); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 6 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - //remove mac at the end of decrypted data - tempDecrypted = new byte[plainText.length]; - System.arraycopy(decrypted, 0, tempDecrypted, 0, plainText.length); - decrypted = tempDecrypted; - - if (!Arrays.areEqual(decrypted, plainText)) - { - fail("Failed GCM/GMAC test 6 - expected decrypted: " - + Hex.toHexString(plainText) - + " got decrypted: " + Hex.toHexString(decrypted)); - } - - /* Testing mac producing without encryption */ - //test 7 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); - - authText = Hex.decode("303132333435363738393A3B3C3D3E3F"); - - expectedMac = Hex.decode("5AE309EE80B583C6523397ADCB5704C4"); - - mac = new byte[expectedMac.length]; - - parameters = new AEADParameters(new KeyParameter(key), 128, new byte[16]); - - dstu7624gcm = new KGCMBlockCipher(new DSTU7624Engine(128)); - - dstu7624gcm.init(true, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - dstu7624gcm.doFinal(mac, 0); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 7 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - //test 8 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); - - authText = Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F"); - - expectedMac = Hex.decode("FF48B56F2C26CC484B8F5952D7B3E1FE"); - - mac = new byte[expectedMac.length]; - - parameters = new AEADParameters(new KeyParameter(key), 128, new byte[16]); - - dstu7624gcm = new KGCMBlockCipher(new DSTU7624Engine(256)); - - dstu7624gcm.init(true, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - dstu7624gcm.doFinal(mac, 0); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 8 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - //test 9 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); - - authText = Hex.decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F"); - - expectedMac = Hex.decode("FF48B56F2C26CC484B8F5952D7B3E1FE69577701C50BE96517B33921E44634CD"); - - mac = new byte[expectedMac.length]; - - parameters = new AEADParameters(new KeyParameter(key), 256, new byte[32]); - - dstu7624gcm = new KGCMBlockCipher(new DSTU7624Engine(256)); - - dstu7624gcm.init(true, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - dstu7624gcm.doFinal(mac, 0); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 9 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - //test 10 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - - authText = Hex.decode("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F"); - - expectedMac = Hex.decode("96F61FA0FDE92883C5041D748F9AE91F3A0A50415BFA1466855340A5714DC01F"); - - mac = new byte[expectedMac.length]; - - parameters = new AEADParameters(new KeyParameter(key), 256, new byte[32]); - - dstu7624gcm = new KGCMBlockCipher(new DSTU7624Engine(256)); - - dstu7624gcm.init(true, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - dstu7624gcm.doFinal(mac, 0); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 10 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - //test 11 - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - - authText = Hex.decode("808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"); - - expectedMac = Hex.decode("897C32E05E776FD988C5171FE70BB72949172E514E3308A871BA5BD898FB6EBD6E3897D2D55697D90D6428216C08052E3A5E7D4626F4DBBF1546CE21637357A3"); - - mac = new byte[expectedMac.length]; - - parameters = new AEADParameters(new KeyParameter(key), 512, new byte[32]); - - dstu7624gcm = new KGCMBlockCipher(new DSTU7624Engine(512)); - - dstu7624gcm.init(true, parameters); - dstu7624gcm.processAADBytes(authText, 0, authText.length); - dstu7624gcm.doFinal(mac, 0); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 11 - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - - doFinalTest(new KGCMBlockCipher(new DSTU7624Engine(512)), key, new byte[32], authText, null, expectedMac); - - //test 11 - as KGMac - key = Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); - - authText = Hex.decode("808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"); - - expectedMac = Hex.decode("897C32E05E776FD988C5171FE70BB72949172E514E3308A871BA5BD898FB6EBD6E3897D2D55697D90D6428216C08052E3A5E7D4626F4DBBF1546CE21637357A3"); - - mac = new byte[expectedMac.length]; - - KGMac dstuGmac = new KGMac(new KGCMBlockCipher(new DSTU7624Engine(512))); - - dstuGmac.init(new ParametersWithIV(new KeyParameter(key), new byte[32])); - - dstuGmac.update(authText, 0, authText.length); - - dstuGmac.doFinal(mac, 0); - - if (!Arrays.areEqual(mac, expectedMac)) - { - fail("Failed GCM/GMAC test 11 (mac) - expected mac: " - + Hex.toHexString(expectedMac) - + " got mac: " + Hex.toHexString(mac)); - } - } - - private void doFinalTest(AEADBlockCipher cipher, byte[] key, byte[] iv, byte[] authText, byte[] input, byte[] expected) - throws Exception - { - byte[] output = new byte[expected.length]; - - AEADParameters parameters = new AEADParameters(new KeyParameter(key), cipher.getUnderlyingCipher().getBlockSize() * 8, iv); - - cipher.init(true, parameters); - cipher.processAADBytes(authText, 0, authText.length); - - int off = 0; - if (input != null) - { - off = cipher.processBytes(input, 0, input.length, output, 0); - } - - cipher.doFinal(output, off); - - if (!Arrays.areEqual(output, expected)) - { - System.err.println(Hex.toHexString(output)); - System.err.println(Hex.toHexString(expected)); - fail("Failed doFinal test - init: " + cipher.getAlgorithmName()); - } - - cipher.processAADBytes(authText, 0, authText.length); - - off = 0; - if (input != null) - { - off = cipher.processBytes(input, 0, input.length, output, 0); - } - - cipher.doFinal(output, off); - - if (!Arrays.areEqual(output, expected)) - { - fail("Failed doFinal test - after: " + cipher.getAlgorithmName()); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DeterministicDSATest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DeterministicDSATest.java deleted file mode 100644 index 4d26e114c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DeterministicDSATest.java +++ /dev/null @@ -1,524 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.asn1.nist.NISTNamedCurves; -import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.DSA; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA224Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA384Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA3Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512Digest; -import com.fr.third.org.bouncycastle.crypto.params.DSAParameters; -import com.fr.third.org.bouncycastle.crypto.params.DSAPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.signers.DSASigner; -import com.fr.third.org.bouncycastle.crypto.signers.ECDSASigner; -import com.fr.third.org.bouncycastle.crypto.signers.HMacDSAKCalculator; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Tests are taken from RFC 6979 - "Deterministic Usage of the Digital Signature Algorithm (DSA) and Elliptic Curve Digital Signature Algorithm (ECDSA)" - */ -public class DeterministicDSATest - extends SimpleTest -{ - - public static final byte[] SAMPLE = Hex.decode("73616d706c65"); // "sample" - public static final byte[] TEST = Hex.decode("74657374"); // "test" - - // test vectors from appendix in RFC 6979 - private void testHMacDeterministic() - { - DSAParameters dsaParameters = new DSAParameters( - new BigInteger("86F5CA03DCFEB225063FF830A0C769B9DD9D6153AD91D7CE27F787C43278B447" + - "E6533B86B18BED6E8A48B784A14C252C5BE0DBF60B86D6385BD2F12FB763ED88" + - "73ABFD3F5BA2E0A8C0A59082EAC056935E529DAF7C610467899C77ADEDFC846C" + - "881870B7B19B2B58F9BE0521A17002E3BDD6B86685EE90B3D9A1B02B782B1779", 16), - new BigInteger("996F967F6C8E388D9E28D01E205FBA957A5698B1", 16), - new BigInteger("07B0F92546150B62514BB771E2A0C0CE387F03BDA6C56B505209FF25FD3C133D" + - "89BBCD97E904E09114D9A7DEFDEADFC9078EA544D2E401AEECC40BB9FBBF78FD" + - "87995A10A1C27CB7789B594BA7EFB5C4326A9FE59A070E136DB77175464ADCA4" + - "17BE5DCE2F40D10A46A3A3943F26AB7FD9C0398FF8C76EE0A56826A8A88F1DBD", 16)); - - DSAPrivateKeyParameters privKey = new DSAPrivateKeyParameters(new BigInteger("411602CB19A6CCC34494D79D98EF1E7ED5AF25F7", 16), dsaParameters); - - doTestHMACDetDSASample(new SHA1Digest(), privKey, new BigInteger("2E1A0C2562B2912CAAF89186FB0F42001585DA55", 16), new BigInteger("29EFB6B0AFF2D7A68EB70CA313022253B9A88DF5", 16)); - doTestHMACDetDSASample(new SHA224Digest(), privKey, new BigInteger("4BC3B686AEA70145856814A6F1BB53346F02101E", 16), new BigInteger("410697B92295D994D21EDD2F4ADA85566F6F94C1", 16)); - doTestHMACDetDSASample(new SHA256Digest(), privKey, new BigInteger("81F2F5850BE5BC123C43F71A3033E9384611C545", 16), new BigInteger("4CDD914B65EB6C66A8AAAD27299BEE6B035F5E89", 16)); - doTestHMACDetDSASample(new SHA384Digest(), privKey, new BigInteger("07F2108557EE0E3921BC1774F1CA9B410B4CE65A", 16), new BigInteger("54DF70456C86FAC10FAB47C1949AB83F2C6F7595", 16)); - doTestHMACDetDSASample(new SHA512Digest(), privKey, new BigInteger("16C3491F9B8C3FBBDD5E7A7B667057F0D8EE8E1B", 16), new BigInteger("02C36A127A7B89EDBB72E4FFBC71DABC7D4FC69C", 16)); - - doTestHMACDetDSATest(new SHA1Digest(), privKey, new BigInteger("42AB2052FD43E123F0607F115052A67DCD9C5C77", 16), new BigInteger("183916B0230D45B9931491D4C6B0BD2FB4AAF088", 16)); - doTestHMACDetDSATest(new SHA224Digest(), privKey, new BigInteger("6868E9964E36C1689F6037F91F28D5F2C30610F2", 16), new BigInteger("49CEC3ACDC83018C5BD2674ECAAD35B8CD22940F", 16)); - doTestHMACDetDSATest(new SHA256Digest(), privKey, new BigInteger("22518C127299B0F6FDC9872B282B9E70D0790812", 16), new BigInteger("6837EC18F150D55DE95B5E29BE7AF5D01E4FE160", 16)); - doTestHMACDetDSATest(new SHA384Digest(), privKey, new BigInteger("854CF929B58D73C3CBFDC421E8D5430CD6DB5E66", 16), new BigInteger("91D0E0F53E22F898D158380676A871A157CDA622", 16)); - doTestHMACDetDSATest(new SHA512Digest(), privKey, new BigInteger("8EA47E475BA8AC6F2D821DA3BD212D11A3DEB9A0", 16), new BigInteger("7C670C7AD72B6C050C109E1790008097125433E8", 16)); - - doTestHMACDetDSATest(new SHA3Digest(224), privKey, new BigInteger("58748b6ca41d25e41f7bfa51fed204a10a1bd1d3", 16), new BigInteger("86de2fdad0bc848dd20ddd9dc6253fc6d7553268", 16)); - doTestHMACDetDSATest(new SHA3Digest(256), privKey, new BigInteger("98c7a7906ada494285b3ab15cf9188a425f26bd4", 16), new BigInteger("21c5ed876037470d3959fa12f918674a4bf190e9", 16)); - doTestHMACDetDSATest(new SHA3Digest(384), privKey, new BigInteger("445ec584ec15c14abc67c99886a30a286cc83b33", 16), new BigInteger("21f564d5bb4b175e89a1a6fb2f27cd34c861142d", 16)); - doTestHMACDetDSATest(new SHA3Digest(512), privKey, new BigInteger("16918083f4c3ff4fc9b327e9e120a30ec39faaf6", 16), new BigInteger("1e9183a1dc7c20dbb596920cd94da3844a087203", 16)); - - dsaParameters = new DSAParameters( - new BigInteger("9DB6FB5951B66BB6FE1E140F1D2CE5502374161FD6538DF1648218642F0B5C48" + - "C8F7A41AADFA187324B87674FA1822B00F1ECF8136943D7C55757264E5A1A44F" + - "FE012E9936E00C1D3E9310B01C7D179805D3058B2A9F4BB6F9716BFE6117C6B5" + - "B3CC4D9BE341104AD4A80AD6C94E005F4B993E14F091EB51743BF33050C38DE2" + - "35567E1B34C3D6A5C0CEAA1A0F368213C3D19843D0B4B09DCB9FC72D39C8DE41" + - "F1BF14D4BB4563CA28371621CAD3324B6A2D392145BEBFAC748805236F5CA2FE" + - "92B871CD8F9C36D3292B5509CA8CAA77A2ADFC7BFD77DDA6F71125A7456FEA15" + - "3E433256A2261C6A06ED3693797E7995FAD5AABBCFBE3EDA2741E375404AE25B", 16), - new BigInteger("F2C3119374CE76C9356990B465374A17F23F9ED35089BD969F61C6DDE9998C1F", 16), - new BigInteger("5C7FF6B06F8F143FE8288433493E4769C4D988ACE5BE25A0E24809670716C613" + - "D7B0CEE6932F8FAA7C44D2CB24523DA53FBE4F6EC3595892D1AA58C4328A06C4" + - "6A15662E7EAA703A1DECF8BBB2D05DBE2EB956C142A338661D10461C0D135472" + - "085057F3494309FFA73C611F78B32ADBB5740C361C9F35BE90997DB2014E2EF5" + - "AA61782F52ABEB8BD6432C4DD097BC5423B285DAFB60DC364E8161F4A2A35ACA" + - "3A10B1C4D203CC76A470A33AFDCBDD92959859ABD8B56E1725252D78EAC66E71" + - "BA9AE3F1DD2487199874393CD4D832186800654760E1E34C09E4D155179F9EC0" + - "DC4473F996BDCE6EED1CABED8B6F116F7AD9CF505DF0F998E34AB27514B0FFE7", 16)); - - privKey = new DSAPrivateKeyParameters(new BigInteger("69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC", 16), dsaParameters); - - doTestHMACDetDSASample(new SHA1Digest(), privKey, new BigInteger("3A1B2DBD7489D6ED7E608FD036C83AF396E290DBD602408E8677DAABD6E7445A", 16), new BigInteger("D26FCBA19FA3E3058FFC02CA1596CDBB6E0D20CB37B06054F7E36DED0CDBBCCF", 16)); - doTestHMACDetDSASample(new SHA224Digest(), privKey, new BigInteger("DC9F4DEADA8D8FF588E98FED0AB690FFCE858DC8C79376450EB6B76C24537E2C", 16), new BigInteger("A65A9C3BC7BABE286B195D5DA68616DA8D47FA0097F36DD19F517327DC848CEC", 16)); - doTestHMACDetDSASample(new SHA256Digest(), privKey, new BigInteger("EACE8BDBBE353C432A795D9EC556C6D021F7A03F42C36E9BC87E4AC7932CC809", 16), new BigInteger("7081E175455F9247B812B74583E9E94F9EA79BD640DC962533B0680793A38D53", 16)); - doTestHMACDetDSASample(new SHA384Digest(), privKey, new BigInteger("B2DA945E91858834FD9BF616EBAC151EDBC4B45D27D0DD4A7F6A22739F45C00B", 16), new BigInteger("19048B63D9FD6BCA1D9BAE3664E1BCB97F7276C306130969F63F38FA8319021B", 16)); - doTestHMACDetDSASample(new SHA512Digest(), privKey, new BigInteger("2016ED092DC5FB669B8EFB3D1F31A91EECB199879BE0CF78F02BA062CB4C942E", 16), new BigInteger("D0C76F84B5F091E141572A639A4FB8C230807EEA7D55C8A154A224400AFF2351", 16)); - - doTestHMACDetDSATest(new SHA1Digest(), privKey, new BigInteger("C18270A93CFC6063F57A4DFA86024F700D980E4CF4E2CB65A504397273D98EA0", 16), new BigInteger("414F22E5F31A8B6D33295C7539C1C1BA3A6160D7D68D50AC0D3A5BEAC2884FAA", 16)); - doTestHMACDetDSATest(new SHA224Digest(), privKey, new BigInteger("272ABA31572F6CC55E30BF616B7A265312018DD325BE031BE0CC82AA17870EA3", 16), new BigInteger("E9CC286A52CCE201586722D36D1E917EB96A4EBDB47932F9576AC645B3A60806", 16)); - doTestHMACDetDSATest(new SHA256Digest(), privKey, new BigInteger("8190012A1969F9957D56FCCAAD223186F423398D58EF5B3CEFD5A4146A4476F0", 16), new BigInteger("7452A53F7075D417B4B013B278D1BB8BBD21863F5E7B1CEE679CF2188E1AB19E", 16)); - doTestHMACDetDSATest(new SHA384Digest(), privKey, new BigInteger("239E66DDBE8F8C230A3D071D601B6FFBDFB5901F94D444C6AF56F732BEB954BE", 16), new BigInteger("6BD737513D5E72FE85D1C750E0F73921FE299B945AAD1C802F15C26A43D34961", 16)); - doTestHMACDetDSATest(new SHA512Digest(), privKey, new BigInteger("89EC4BB1400ECCFF8E7D9AA515CD1DE7803F2DAFF09693EE7FD1353E90A68307", 16), new BigInteger("C9F0BDABCC0D880BB137A994CC7F3980CE91CC10FAF529FC46565B15CEA854E1", 16)); - } - - private void doTestHMACDetDSASample(Digest digest, DSAPrivateKeyParameters privKey, BigInteger r, BigInteger s) - { - doTestHMACDetECDSA(new DSASigner(new HMacDSAKCalculator(digest)), digest, SAMPLE, privKey, r, s); - } - - private void doTestHMACDetDSATest(Digest digest, DSAPrivateKeyParameters privKey, BigInteger r, BigInteger s) - { - doTestHMACDetECDSA(new DSASigner(new HMacDSAKCalculator(digest)), digest, TEST, privKey, r, s); - } - - // test vectors from appendix in RFC 6979 - private void testECHMacDeterministic() - { - X9ECParameters x9ECParameters = NISTNamedCurves.getByName("P-192"); - ECDomainParameters ecDomainParameters = new ECDomainParameters(x9ECParameters.getCurve(), x9ECParameters.getG(), x9ECParameters.getN()); - - ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(new BigInteger("6FAB034934E4C0FC9AE67F5B5659A9D7D1FEFD187EE09FD4", 16), ecDomainParameters); - - doTestHMACDetECDSASample(new SHA1Digest(), privKey, new BigInteger("98C6BD12B23EAF5E2A2045132086BE3EB8EBD62ABF6698FF", 16), new BigInteger("57A22B07DEA9530F8DE9471B1DC6624472E8E2844BC25B64", 16)); - doTestHMACDetECDSASample(new SHA224Digest(), privKey, new BigInteger("A1F00DAD97AEEC91C95585F36200C65F3C01812AA60378F5", 16), new BigInteger("E07EC1304C7C6C9DEBBE980B9692668F81D4DE7922A0F97A", 16)); - doTestHMACDetECDSASample(new SHA256Digest(), privKey, new BigInteger("4B0B8CE98A92866A2820E20AA6B75B56382E0F9BFD5ECB55", 16), new BigInteger("CCDB006926EA9565CBADC840829D8C384E06DE1F1E381B85", 16)); - doTestHMACDetECDSASample(new SHA384Digest(), privKey, new BigInteger("DA63BF0B9ABCF948FBB1E9167F136145F7A20426DCC287D5", 16), new BigInteger("C3AA2C960972BD7A2003A57E1C4C77F0578F8AE95E31EC5E", 16)); - doTestHMACDetECDSASample(new SHA512Digest(), privKey, new BigInteger("4D60C5AB1996BD848343B31C00850205E2EA6922DAC2E4B8", 16), new BigInteger("3F6E837448F027A1BF4B34E796E32A811CBB4050908D8F67", 16)); - - doTestHMACDetECDSATest(new SHA1Digest(), privKey, new BigInteger("0F2141A0EBBC44D2E1AF90A50EBCFCE5E197B3B7D4DE036D", 16), new BigInteger("EB18BC9E1F3D7387500CB99CF5F7C157070A8961E38700B7", 16)); - doTestHMACDetECDSATest(new SHA224Digest(), privKey, new BigInteger("6945A1C1D1B2206B8145548F633BB61CEF04891BAF26ED34", 16), new BigInteger("B7FB7FDFC339C0B9BD61A9F5A8EAF9BE58FC5CBA2CB15293", 16)); - doTestHMACDetECDSATest(new SHA256Digest(), privKey, new BigInteger("3A718BD8B4926C3B52EE6BBE67EF79B18CB6EB62B1AD97AE", 16), new BigInteger("5662E6848A4A19B1F1AE2F72ACD4B8BBE50F1EAC65D9124F", 16)); - doTestHMACDetECDSATest(new SHA384Digest(), privKey, new BigInteger("B234B60B4DB75A733E19280A7A6034BD6B1EE88AF5332367", 16), new BigInteger("7994090B2D59BB782BE57E74A44C9A1C700413F8ABEFE77A", 16)); - doTestHMACDetECDSATest(new SHA512Digest(), privKey, new BigInteger("FE4F4AE86A58B6507946715934FE2D8FF9D95B6B098FE739", 16), new BigInteger("74CF5605C98FBA0E1EF34D4B5A1577A7DCF59457CAE52290", 16)); - - doTestHMACDetECDSATest(new SHA3Digest(224), privKey, new BigInteger("abfcb817d04cc223f0d9c02c6db9230a91f955bf4556e0c6", 16), new BigInteger("ec2c29065a50d8ea39533d49472ccf538a5388cb31900e8f", 16)); - doTestHMACDetECDSATest(new SHA3Digest(256), privKey, new BigInteger("a2c2d5362d3cea77191edb239bf22a14dcc59d6500a744fc", 16), new BigInteger("6c63f3012353082026be7e2c6f37e6d7811066ddc9b9ee47", 16)); - doTestHMACDetECDSATest(new SHA3Digest(384), privKey, new BigInteger("2ff2c37d48cd6691c8adb9d2b1c1af203a1a6b8769c588dd", 16), new BigInteger("79c8171097f845c608dafd218ba096a51e0e4882faf2c08d", 16)); - doTestHMACDetECDSATest(new SHA3Digest(512), privKey, new BigInteger("384619b82461f4cc852dfa1e87cd87105e8eb3cfd0fb6461", 16), new BigInteger("d0aac03f72e90942821e3af1f77fd8a6ae82d1ed31b8ed06", 16)); - - x9ECParameters = NISTNamedCurves.getByName("P-224"); - ecDomainParameters = new ECDomainParameters(x9ECParameters.getCurve(), x9ECParameters.getG(), x9ECParameters.getN()); - - privKey = new ECPrivateKeyParameters(new BigInteger("F220266E1105BFE3083E03EC7A3A654651F45E37167E88600BF257C1", 16), ecDomainParameters); - - doTestHMACDetECDSASample(new SHA1Digest(), privKey, new BigInteger("22226F9D40A96E19C4A301CE5B74B115303C0F3A4FD30FC257FB57AC", 16), new BigInteger("66D1CDD83E3AF75605DD6E2FEFF196D30AA7ED7A2EDF7AF475403D69", 16)); - doTestHMACDetECDSASample(new SHA224Digest(), privKey, new BigInteger("1CDFE6662DDE1E4A1EC4CDEDF6A1F5A2FB7FBD9145C12113E6ABFD3E", 16), new BigInteger("A6694FD7718A21053F225D3F46197CA699D45006C06F871808F43EBC", 16)); - doTestHMACDetECDSASample(new SHA256Digest(), privKey, new BigInteger("61AA3DA010E8E8406C656BC477A7A7189895E7E840CDFE8FF42307BA", 16), new BigInteger("BC814050DAB5D23770879494F9E0A680DC1AF7161991BDE692B10101", 16)); - doTestHMACDetECDSASample(new SHA384Digest(), privKey, new BigInteger("0B115E5E36F0F9EC81F1325A5952878D745E19D7BB3EABFABA77E953", 16), new BigInteger("830F34CCDFE826CCFDC81EB4129772E20E122348A2BBD889A1B1AF1D", 16)); - doTestHMACDetECDSASample(new SHA512Digest(), privKey, new BigInteger("074BD1D979D5F32BF958DDC61E4FB4872ADCAFEB2256497CDAC30397", 16), new BigInteger("A4CECA196C3D5A1FF31027B33185DC8EE43F288B21AB342E5D8EB084", 16)); - - doTestHMACDetECDSATest(new SHA1Digest(), privKey, new BigInteger("DEAA646EC2AF2EA8AD53ED66B2E2DDAA49A12EFD8356561451F3E21C", 16), new BigInteger("95987796F6CF2062AB8135271DE56AE55366C045F6D9593F53787BD2", 16)); - doTestHMACDetECDSATest(new SHA224Digest(), privKey, new BigInteger("C441CE8E261DED634E4CF84910E4C5D1D22C5CF3B732BB204DBEF019", 16), new BigInteger("902F42847A63BDC5F6046ADA114953120F99442D76510150F372A3F4", 16)); - doTestHMACDetECDSATest(new SHA256Digest(), privKey, new BigInteger("AD04DDE87B84747A243A631EA47A1BA6D1FAA059149AD2440DE6FBA6", 16), new BigInteger("178D49B1AE90E3D8B629BE3DB5683915F4E8C99FDF6E666CF37ADCFD", 16)); - doTestHMACDetECDSATest(new SHA384Digest(), privKey, new BigInteger("389B92682E399B26518A95506B52C03BC9379A9DADF3391A21FB0EA4", 16), new BigInteger("414A718ED3249FF6DBC5B50C27F71F01F070944DA22AB1F78F559AAB", 16)); - doTestHMACDetECDSATest(new SHA512Digest(), privKey, new BigInteger("049F050477C5ADD858CAC56208394B5A55BAEBBE887FDF765047C17C", 16), new BigInteger("077EB13E7005929CEFA3CD0403C7CDCC077ADF4E44F3C41B2F60ECFF", 16)); - - x9ECParameters = NISTNamedCurves.getByName("P-256"); - ecDomainParameters = new ECDomainParameters(x9ECParameters.getCurve(), x9ECParameters.getG(), x9ECParameters.getN()); - - privKey = new ECPrivateKeyParameters(new BigInteger("C9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721", 16), ecDomainParameters); - - doTestHMACDetECDSASample(new SHA1Digest(), privKey, new BigInteger("61340C88C3AAEBEB4F6D667F672CA9759A6CCAA9FA8811313039EE4A35471D32", 16), new BigInteger("6D7F147DAC089441BB2E2FE8F7A3FA264B9C475098FDCF6E00D7C996E1B8B7EB", 16)); - doTestHMACDetECDSASample(new SHA224Digest(), privKey, new BigInteger("53B2FFF5D1752B2C689DF257C04C40A587FABABB3F6FC2702F1343AF7CA9AA3F", 16), new BigInteger("B9AFB64FDC03DC1A131C7D2386D11E349F070AA432A4ACC918BEA988BF75C74C", 16)); - doTestHMACDetECDSASample(new SHA256Digest(), privKey, new BigInteger("EFD48B2AACB6A8FD1140DD9CD45E81D69D2C877B56AAF991C34D0EA84EAF3716", 16), new BigInteger("F7CB1C942D657C41D436C7A1B6E29F65F3E900DBB9AFF4064DC4AB2F843ACDA8", 16)); - doTestHMACDetECDSASample(new SHA384Digest(), privKey, new BigInteger("0EAFEA039B20E9B42309FB1D89E213057CBF973DC0CFC8F129EDDDC800EF7719", 16), new BigInteger("4861F0491E6998B9455193E34E7B0D284DDD7149A74B95B9261F13ABDE940954", 16)); - doTestHMACDetECDSASample(new SHA512Digest(), privKey, new BigInteger("8496A60B5E9B47C825488827E0495B0E3FA109EC4568FD3F8D1097678EB97F00", 16), new BigInteger("2362AB1ADBE2B8ADF9CB9EDAB740EA6049C028114F2460F96554F61FAE3302FE", 16)); - - doTestHMACDetECDSATest(new SHA1Digest(), privKey, new BigInteger("0CBCC86FD6ABD1D99E703E1EC50069EE5C0B4BA4B9AC60E409E8EC5910D81A89", 16), new BigInteger("01B9D7B73DFAA60D5651EC4591A0136F87653E0FD780C3B1BC872FFDEAE479B1", 16)); - doTestHMACDetECDSATest(new SHA224Digest(), privKey, new BigInteger("C37EDB6F0AE79D47C3C27E962FA269BB4F441770357E114EE511F662EC34A692", 16), new BigInteger("C820053A05791E521FCAAD6042D40AEA1D6B1A540138558F47D0719800E18F2D", 16)); - doTestHMACDetECDSATest(new SHA256Digest(), privKey, new BigInteger("F1ABB023518351CD71D881567B1EA663ED3EFCF6C5132B354F28D3B0B7D38367", 16), new BigInteger("019F4113742A2B14BD25926B49C649155F267E60D3814B4C0CC84250E46F0083", 16)); - doTestHMACDetECDSATest(new SHA384Digest(), privKey, new BigInteger("83910E8B48BB0C74244EBDF7F07A1C5413D61472BD941EF3920E623FBCCEBEB6", 16), new BigInteger("8DDBEC54CF8CD5874883841D712142A56A8D0F218F5003CB0296B6B509619F2C", 16)); - doTestHMACDetECDSATest(new SHA512Digest(), privKey, new BigInteger("461D93F31B6540894788FD206C07CFA0CC35F46FA3C91816FFF1040AD1581A04", 16), new BigInteger("39AF9F15DE0DB8D97E72719C74820D304CE5226E32DEDAE67519E840D1194E55", 16)); - - x9ECParameters = NISTNamedCurves.getByName("P-384"); - ecDomainParameters = new ECDomainParameters(x9ECParameters.getCurve(), x9ECParameters.getG(), x9ECParameters.getN()); - - privKey = new ECPrivateKeyParameters(new BigInteger("6B9D3DAD2E1B8C1C05B19875B6659F4DE23C3B667BF297BA9AA47740787137D8" + - "96D5724E4C70A825F872C9EA60D2EDF5", 16), ecDomainParameters); - - doTestHMACDetECDSASample(new SHA1Digest(), privKey, new BigInteger("EC748D839243D6FBEF4FC5C4859A7DFFD7F3ABDDF72014540C16D73309834FA3" + - "7B9BA002899F6FDA3A4A9386790D4EB2", 16), - new BigInteger("A3BCFA947BEEF4732BF247AC17F71676CB31A847B9FF0CBC9C9ED4C1A5B3FACF" + - "26F49CA031D4857570CCB5CA4424A443", 16)); - doTestHMACDetECDSASample(new SHA224Digest(), privKey, new BigInteger("42356E76B55A6D9B4631C865445DBE54E056D3B3431766D0509244793C3F9366" + - "450F76EE3DE43F5A125333A6BE060122", 16), - new BigInteger("9DA0C81787064021E78DF658F2FBB0B042BF304665DB721F077A4298B095E483" + - "4C082C03D83028EFBF93A3C23940CA8D", 16)); - doTestHMACDetECDSASample(new SHA256Digest(), privKey, new BigInteger("21B13D1E013C7FA1392D03C5F99AF8B30C570C6F98D4EA8E354B63A21D3DAA33" + - "BDE1E888E63355D92FA2B3C36D8FB2CD", 16), - new BigInteger("F3AA443FB107745BF4BD77CB3891674632068A10CA67E3D45DB2266FA7D1FEEB" + - "EFDC63ECCD1AC42EC0CB8668A4FA0AB0", 16)); - doTestHMACDetECDSASample(new SHA384Digest(), privKey, new BigInteger("94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C" + - "81A648152E44ACF96E36DD1E80FABE46", 16), - new BigInteger("99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94F" + - "A329C145786E679E7B82C71A38628AC8", 16)); - doTestHMACDetECDSASample(new SHA512Digest(), privKey, new BigInteger("ED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799C" + - "FE30F35CC900056D7C99CD7882433709", 16), - new BigInteger("512C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112" + - "DC7CC3EF3446DEFCEB01A45C2667FDD5", 16)); - - doTestHMACDetECDSATest(new SHA1Digest(), privKey, new BigInteger("4BC35D3A50EF4E30576F58CD96CE6BF638025EE624004A1F7789A8B8E43D0678" + - "ACD9D29876DAF46638645F7F404B11C7", 16), - new BigInteger("D5A6326C494ED3FF614703878961C0FDE7B2C278F9A65FD8C4B7186201A29916" + - "95BA1C84541327E966FA7B50F7382282", 16)); - doTestHMACDetECDSATest(new SHA224Digest(), privKey, new BigInteger("E8C9D0B6EA72A0E7837FEA1D14A1A9557F29FAA45D3E7EE888FC5BF954B5E624" + - "64A9A817C47FF78B8C11066B24080E72", 16), - new BigInteger("07041D4A7A0379AC7232FF72E6F77B6DDB8F09B16CCE0EC3286B2BD43FA8C614" + - "1C53EA5ABEF0D8231077A04540A96B66", 16)); - doTestHMACDetECDSATest(new SHA256Digest(), privKey, new BigInteger("6D6DEFAC9AB64DABAFE36C6BF510352A4CC27001263638E5B16D9BB51D451559" + - "F918EEDAF2293BE5B475CC8F0188636B", 16), - new BigInteger("2D46F3BECBCC523D5F1A1256BF0C9B024D879BA9E838144C8BA6BAEB4B53B47D" + - "51AB373F9845C0514EEFB14024787265", 16)); - doTestHMACDetECDSATest(new SHA384Digest(), privKey, new BigInteger("8203B63D3C853E8D77227FB377BCF7B7B772E97892A80F36AB775D509D7A5FEB" + - "0542A7F0812998DA8F1DD3CA3CF023DB", 16), - new BigInteger("DDD0760448D42D8A43AF45AF836FCE4DE8BE06B485E9B61B827C2F13173923E0" + - "6A739F040649A667BF3B828246BAA5A5", 16)); - doTestHMACDetECDSATest(new SHA512Digest(), privKey, new BigInteger("A0D5D090C9980FAF3C2CE57B7AE951D31977DD11C775D314AF55F76C676447D0" + - "6FB6495CD21B4B6E340FC236584FB277", 16), - new BigInteger("976984E59B4C77B0E8E4460DCA3D9F20E07B9BB1F63BEEFAF576F6B2E8B22463" + - "4A2092CD3792E0159AD9CEE37659C736", 16)); - - x9ECParameters = NISTNamedCurves.getByName("P-521"); - ecDomainParameters = new ECDomainParameters(x9ECParameters.getCurve(), x9ECParameters.getG(), x9ECParameters.getN()); - - privKey = new ECPrivateKeyParameters(new BigInteger("0FAD06DAA62BA3B25D2FB40133DA757205DE67F5BB0018FEE8C86E1B68C7E75C" + - "AA896EB32F1F47C70855836A6D16FCC1466F6D8FBEC67DB89EC0C08B0E996B83" + - "538", 16), ecDomainParameters); - - doTestHMACDetECDSASample(new SHA1Digest(), privKey, new BigInteger("0343B6EC45728975EA5CBA6659BBB6062A5FF89EEA58BE3C80B619F322C87910" + - "FE092F7D45BB0F8EEE01ED3F20BABEC079D202AE677B243AB40B5431D497C55D" + - "75D", 16), - new BigInteger("0E7B0E675A9B24413D448B8CC119D2BF7B2D2DF032741C096634D6D65D0DBE3D" + - "5694625FB9E8104D3B842C1B0E2D0B98BEA19341E8676AEF66AE4EBA3D5475D5" + - "D16", 16)); - doTestHMACDetECDSASample(new SHA224Digest(), privKey, new BigInteger("1776331CFCDF927D666E032E00CF776187BC9FDD8E69D0DABB4109FFE1B5E2A3" + - "0715F4CC923A4A5E94D2503E9ACFED92857B7F31D7152E0F8C00C15FF3D87E2E" + - "D2E", 16), - new BigInteger("050CB5265417FE2320BBB5A122B8E1A32BD699089851128E360E620A30C7E17B" + - "A41A666AF126CE100E5799B153B60528D5300D08489CA9178FB610A2006C254B" + - "41F", 16)); - doTestHMACDetECDSASample(new SHA256Digest(), privKey, new BigInteger("1511BB4D675114FE266FC4372B87682BAECC01D3CC62CF2303C92B3526012659" + - "D16876E25C7C1E57648F23B73564D67F61C6F14D527D54972810421E7D87589E" + - "1A7", 16), - new BigInteger("04A171143A83163D6DF460AAF61522695F207A58B95C0644D87E52AA1A347916" + - "E4F7A72930B1BC06DBE22CE3F58264AFD23704CBB63B29B931F7DE6C9D949A7E" + - "CFC", 16)); - doTestHMACDetECDSASample(new SHA384Digest(), privKey, new BigInteger("1EA842A0E17D2DE4F92C15315C63DDF72685C18195C2BB95E572B9C5136CA4B4" + - "B576AD712A52BE9730627D16054BA40CC0B8D3FF035B12AE75168397F5D50C67" + - "451", 16), - new BigInteger("1F21A3CEE066E1961025FB048BD5FE2B7924D0CD797BABE0A83B66F1E35EEAF5" + - "FDE143FA85DC394A7DEE766523393784484BDF3E00114A1C857CDE1AA203DB65" + - "D61", 16)); - doTestHMACDetECDSASample(new SHA512Digest(), privKey, new BigInteger("0C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F1" + - "74E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E37" + - "7FA", 16), - new BigInteger("0617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF2" + - "82623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A" + - "67A", 16)); - - doTestHMACDetECDSATest(new SHA1Digest(), privKey, new BigInteger("13BAD9F29ABE20DE37EBEB823C252CA0F63361284015A3BF430A46AAA80B87B0" + - "693F0694BD88AFE4E661FC33B094CD3B7963BED5A727ED8BD6A3A202ABE009D0" + - "367", 16), - new BigInteger("1E9BB81FF7944CA409AD138DBBEE228E1AFCC0C890FC78EC8604639CB0DBDC90" + - "F717A99EAD9D272855D00162EE9527567DD6A92CBD629805C0445282BBC91679" + - "7FF", 16)); - doTestHMACDetECDSATest(new SHA224Digest(), privKey, new BigInteger("1C7ED902E123E6815546065A2C4AF977B22AA8EADDB68B2C1110E7EA44D42086" + - "BFE4A34B67DDC0E17E96536E358219B23A706C6A6E16BA77B65E1C595D43CAE1" + - "7FB", 16), - new BigInteger("177336676304FCB343CE028B38E7B4FBA76C1C1B277DA18CAD2A8478B2A9A9F5" + - "BEC0F3BA04F35DB3E4263569EC6AADE8C92746E4C82F8299AE1B8F1739F8FD51" + - "9A4", 16)); - doTestHMACDetECDSATest(new SHA256Digest(), privKey, new BigInteger("00E871C4A14F993C6C7369501900C4BC1E9C7B0B4BA44E04868B30B41D807104" + - "2EB28C4C250411D0CE08CD197E4188EA4876F279F90B3D8D74A3C76E6F1E4656" + - "AA8", 16), - new BigInteger("0CD52DBAA33B063C3A6CD8058A1FB0A46A4754B034FCC644766CA14DA8CA5CA9" + - "FDE00E88C1AD60CCBA759025299079D7A427EC3CC5B619BFBC828E7769BCD694" + - "E86", 16)); - doTestHMACDetECDSATest(new SHA384Digest(), privKey, new BigInteger("14BEE21A18B6D8B3C93FAB08D43E739707953244FDBE924FA926D76669E7AC8C" + - "89DF62ED8975C2D8397A65A49DCC09F6B0AC62272741924D479354D74FF60755" + - "78C", 16), - new BigInteger("133330865C067A0EAF72362A65E2D7BC4E461E8C8995C3B6226A21BD1AA78F0E" + - "D94FE536A0DCA35534F0CD1510C41525D163FE9D74D134881E35141ED5E8E95B" + - "979", 16)); - doTestHMACDetECDSATest(new SHA512Digest(), privKey, new BigInteger("13E99020ABF5CEE7525D16B69B229652AB6BDF2AFFCAEF38773B4B7D08725F10" + - "CDB93482FDCC54EDCEE91ECA4166B2A7C6265EF0CE2BD7051B7CEF945BABD47E" + - "E6D", 16), - new BigInteger("1FBD0013C674AA79CB39849527916CE301C66EA7CE8B80682786AD60F98F7E78" + - "A19CA69EFF5C57400E3B3A0AD66CE0978214D13BAF4E9AC60752F7B155E2DE4D" + - "CE3", 16)); - - x9ECParameters = NISTNamedCurves.getByName("B-163"); - ecDomainParameters = new ECDomainParameters(x9ECParameters.getCurve(), x9ECParameters.getG(), x9ECParameters.getN()); - - privKey = new ECPrivateKeyParameters(new BigInteger("35318FC447D48D7E6BC93B48617DDDEDF26AA658F", 16), ecDomainParameters); - - doTestHMACDetECDSASample(new SHA1Digest(), privKey, new BigInteger("153FEBD179A69B6122DEBF5BC61EB947B24C93526", 16), new BigInteger("37AC9C670F8CF18045049BAE7DD35553545C19E49", 16)); - doTestHMACDetECDSASample(new SHA224Digest(), privKey, new BigInteger("0A379E69C44F9C16EA3215EA39EB1A9B5D58CC955", 16), new BigInteger("04BAFF5308DA2A7FE2C1742769265AD3ED1D24E74", 16)); - doTestHMACDetECDSASample(new SHA256Digest(), privKey, new BigInteger("134E00F78FC1CB9501675D91C401DE20DDF228CDC", 16), new BigInteger("373273AEC6C36CB7BAFBB1903A5F5EA6A1D50B624", 16)); - doTestHMACDetECDSASample(new SHA384Digest(), privKey, new BigInteger("29430B935AF8E77519B0CA4F6903B0B82E6A21A66", 16), new BigInteger("1EA1415306E9353FA5AA54BC7C2581DFBB888440D", 16)); - doTestHMACDetECDSASample(new SHA512Digest(), privKey, new BigInteger("0B2F177A99F9DF2D51CCAF55F015F326E4B65E7A0", 16), new BigInteger("0DF1FB4487E9B120C5E970EFE48F55E406306C3A1", 16)); - - doTestHMACDetECDSATest(new SHA1Digest(), privKey, new BigInteger("256D4079C6C7169B8BC92529D701776A269D56308", 16), new BigInteger("341D3FFEC9F1EB6A6ACBE88E3C86A1C8FDEB8B8E1", 16)); - doTestHMACDetECDSATest(new SHA224Digest(), privKey, new BigInteger("28ECC6F1272CE80EA59DCF32F7AC2D861BA803393", 16), new BigInteger("0AD4AE2C06E60183C1567D2B82F19421FE3053CE2", 16)); - doTestHMACDetECDSATest(new SHA256Digest(), privKey, new BigInteger("227DF377B3FA50F90C1CB3CDCBBDBA552C1D35104", 16), new BigInteger("1F7BEAD92583FE920D353F368C1960D0E88B46A56", 16)); - doTestHMACDetECDSATest(new SHA384Digest(), privKey, new BigInteger("11811DAFEEA441845B6118A0DFEE8A0061231337D", 16), new BigInteger("36258301865EE48C5C6F91D63F62695002AB55B57", 16)); - doTestHMACDetECDSATest(new SHA512Digest(), privKey, new BigInteger("3B6BB95CA823BE2ED8E3972FF516EB8972D765571", 16), new BigInteger("13DC6F420628969DF900C3FCC48220B38BE24A541", 16)); - - x9ECParameters = NISTNamedCurves.getByName("B-233"); - ecDomainParameters = new ECDomainParameters(x9ECParameters.getCurve(), x9ECParameters.getG(), x9ECParameters.getN()); - - privKey = new ECPrivateKeyParameters(new BigInteger("07ADC13DD5BF34D1DDEEB50B2CE23B5F5E6D18067306D60C5F6FF11E5D3", 16), ecDomainParameters); - - doTestHMACDetECDSASample(new SHA1Digest(), privKey, new BigInteger("015CC6FD78BB06E0878E71465515EA5A21A2C18E6FC77B4B158DBEB3944", 16), new BigInteger("0822A4A6C2EB2DF213A5E90BF40377956365EE8C4B4A5A4E2EB9270CB6A", 16)); - doTestHMACDetECDSASample(new SHA224Digest(), privKey, new BigInteger("05D9920B53471148E10502AB49AB7A3F11084820A074FD89883CF51BC1A", 16), new BigInteger("04D3938900C0A9AAA7080D1DFEB56CFB0FADABE4214536C7ED5117ED13A", 16)); - doTestHMACDetECDSASample(new SHA256Digest(), privKey, new BigInteger("0A797F3B8AEFCE7456202DF1E46CCC291EA5A49DA3D4BDDA9A4B62D5E0D", 16), new BigInteger("01F6F81DA55C22DA4152134C661588F4BD6F82FDBAF0C5877096B070DC2", 16)); - doTestHMACDetECDSASample(new SHA384Digest(), privKey, new BigInteger("015E85A8D46225DD7E314A1C4289731FC14DECE949349FE535D11043B85", 16), new BigInteger("03F189D37F50493EFD5111A129443A662AB3C6B289129AD8C0CAC85119C", 16)); - doTestHMACDetECDSASample(new SHA512Digest(), privKey, new BigInteger("03B62A4BF783919098B1E42F496E65F7621F01D1D466C46940F0F132A95", 16), new BigInteger("0F4BE031C6E5239E7DAA014CBBF1ED19425E49DAEB426EC9DF4C28A2E30", 16)); - - doTestHMACDetECDSATest(new SHA1Digest(), privKey, new BigInteger("02F1FEDC57BE203E4C8C6B8C1CEB35E13C1FCD956AB41E3BD4C8A6EFB1F", 16), new BigInteger("05738EC8A8EDEA8E435EE7266AD3EDE1EEFC2CEBE2BE1D614008D5D2951", 16)); - doTestHMACDetECDSATest(new SHA224Digest(), privKey, new BigInteger("0CCE175124D3586BA7486F7146894C65C2A4A5A1904658E5C7F9DF5FA5D", 16), new BigInteger("08804B456D847ACE5CA86D97BF79FD6335E5B17F6C0D964B5D0036C867E", 16)); - doTestHMACDetECDSATest(new SHA256Digest(), privKey, new BigInteger("035C3D6DFEEA1CFB29B93BE3FDB91A7B130951770C2690C16833A159677", 16), new BigInteger("0600F7301D12AB376B56D4459774159ADB51F97E282FF384406AFD53A02", 16)); - doTestHMACDetECDSATest(new SHA384Digest(), privKey, new BigInteger("061602FC8068BFD5FB86027B97455D200EC603057446CCE4D76DB8EF42C", 16), new BigInteger("03396DD0D59C067BB999B422D9883736CF9311DFD6951F91033BD03CA8D", 16)); - doTestHMACDetECDSATest(new SHA512Digest(), privKey, new BigInteger("07E12CB60FDD614958E8E34B3C12DDFF35D85A9C5800E31EA2CC2EF63B1", 16), new BigInteger("0E8970FD99D836F3CC1C807A2C58760DE6EDAA23705A82B9CB1CE93FECC", 16)); - - x9ECParameters = NISTNamedCurves.getByName("B-283"); - ecDomainParameters = new ECDomainParameters(x9ECParameters.getCurve(), x9ECParameters.getG(), x9ECParameters.getN()); - - privKey = new ECPrivateKeyParameters(new BigInteger("14510D4BC44F2D26F4553942C98073C1BD35545CEABB5CC138853C5158D2729EA408836", 16), ecDomainParameters); - - doTestHMACDetECDSASample(new SHA1Digest(), privKey, new BigInteger("201E18D48C6DB3D5D097C4DCE1E25587E1501FC3CF47BDB5B4289D79E273D6A9" + - "ACB8285", 16), new BigInteger("151AE05712B024CE617358260774C8CA8B0E7A7E72EF8229BF2ACE7609560CB3" + - "0322C4F", 16)); - doTestHMACDetECDSASample(new SHA224Digest(), privKey, new BigInteger("143E878DDFD4DF40D97B8CD638B3C4706501C2201CF7108F2FB91478C11D6947" + - "3246925", 16), new BigInteger("0CBF1B9717FEEA3AABB09D9654110144267098E0E1E8D0289A6211BE0EEDFDD8" + - "6A3DB79", 16)); - doTestHMACDetECDSASample(new SHA256Digest(), privKey, new BigInteger("29FD82497FB3E5CEF65579272138DE59E2B666B8689466572B3B69A172CEE83B" + - "E145659", 16), new BigInteger("05A89D9166B40795AF0FE5958201B9C0523E500013CA12B4840EA2BC53F25F9B" + - "3CE87C0", 16)); - doTestHMACDetECDSASample(new SHA384Digest(), privKey, new BigInteger("2F00689C1BFCD2A8C7A41E0DE55AE182E6463A152828EF89FE3525139B660329" + - "4E69353", 16), new BigInteger("1744514FE0A37447250C8A329EAAADA81572226CABA16F39270EE5DD03F27B1F" + - "665EB5D", 16)); - doTestHMACDetECDSASample(new SHA512Digest(), privKey, new BigInteger("0DA43A9ADFAA6AD767998A054C6A8F1CF77A562924628D73C62761847AD8286E" + - "0D91B47", 16), new BigInteger("1D118733AE2C88357827CAFC6F68ABC25C80C640532925E95CFE66D40F8792F3" + - "AC44C42", 16)); - - doTestHMACDetECDSATest(new SHA1Digest(), privKey, new BigInteger("05A408133919F2CDCDBE5E4C14FBC706C1F71BADAFEF41F5DE4EC27272FC1CA9" + - "366FBB2", 16), new BigInteger("012966272872C097FEA7BCE64FAB1A81982A773E26F6E4EF7C99969846E67CA9" + - "CBE1692", 16)); - doTestHMACDetECDSATest(new SHA224Digest(), privKey, new BigInteger("08F3824E40C16FF1DDA8DC992776D26F4A5981AB5092956C4FDBB4F1AE0A711E" + - "EAA10E5", 16), new BigInteger("0A64B91EFADB213E11483FB61C73E3EF63D3B44EEFC56EA401B99DCC60CC28E9" + - "9F0F1FA", 16)); - doTestHMACDetECDSATest(new SHA256Digest(), privKey, new BigInteger("3597B406F5329D11A79E887847E5EC60861CCBB19EC61F252DB7BD549C699951" + - "C182796", 16), new BigInteger("0A6A100B997BC622D91701D9F5C6F6D3815517E577622DA69D3A0E8917C1CBE6" + - "3ACD345", 16)); - doTestHMACDetECDSATest(new SHA384Digest(), privKey, new BigInteger("1BB490926E5A1FDC7C5AA86D0835F9B994EDA315CA408002AF54A298728D422E" + - "BF59E4C", 16), new BigInteger("36C682CFC9E2C89A782BFD3A191609D1F0C1910D5FD6981442070393159D65FB" + - "CC0A8BA", 16)); - doTestHMACDetECDSATest(new SHA512Digest(), privKey, new BigInteger("19944AA68F9778C2E3D6E240947613E6DA60EFCE9B9B2C063FF5466D72745B5A" + - "0B25BA2", 16), new BigInteger("03F1567B3C5B02DF15C874F0EE22850824693D5ADC4663BAA19E384E550B1DD4" + - "1F31EE6", 16)); - - x9ECParameters = NISTNamedCurves.getByName("B-409"); - ecDomainParameters = new ECDomainParameters(x9ECParameters.getCurve(), x9ECParameters.getG(), x9ECParameters.getN()); - - privKey = new ECPrivateKeyParameters(new BigInteger("0494994CC325B08E7B4CE038BD9436F90B5E59A2C13C3140CD3AE07C04A01FC489F572CE0569A6DB7B8060393DE76330C624177", 16), ecDomainParameters); - - doTestHMACDetECDSASample(new SHA1Digest(), privKey, new BigInteger("0D8783188E1A540E2022D389E1D35B32F56F8C2BB5636B8ABF7718806B27A713" + - "EBAE37F63ECD4B61445CEF5801B62594EF3E982", 16), new BigInteger("03A6B4A80E204DB0DE12E7415C13C9EC091C52935658316B4A0C591216A38791" + - "54BEB1712560E346E7EF26517707435B55C3141", 16)); - doTestHMACDetECDSASample(new SHA224Digest(), privKey, new BigInteger("0EE4F39ACC2E03CE96C3D9FCBAFA5C22C89053662F8D4117752A9B10F09ADFDA" + - "59DB061E247FE5321D6B170EE758ACE1BE4D157", 16), new BigInteger("00A2B83265B456A430A8BF27DCC8A9488B3F126C10F0D6D64BF7B8A218FAAF20" + - "E51A295A3AE78F205E5A4A6AE224C3639F1BB34", 16)); - doTestHMACDetECDSASample(new SHA256Digest(), privKey, new BigInteger("02D8B1B31E33E74D7EB46C30FDE5AD2CA04EC8FE08FBA0E73BA5E568953AC5EA" + - "307C072942238DFC07F4A4D7C7C6A9F86436D17", 16), new BigInteger("079F7D471E6CB73234AF7F7C381D2CE15DE35BAF8BB68393B73235B3A26EC2DF" + - "4842CE433FB492D6E074E604D4870024D42189A", 16)); - doTestHMACDetECDSASample(new SHA384Digest(), privKey, new BigInteger("07BC638B7E7CE6FEE5E9C64A0F966D722D01BB4BC3F3A35F30D4CDDA92DFC5F7" + - "F0B4BBFE8065D9AD452FD77A1914BE3A2440C18", 16), new BigInteger("06D904429850521B28A32CBF55C7C0FDF35DC4E0BDA2552C7BF68A171E970E67" + - "88ACC0B9521EACB4796E057C70DD9B95FED5BFB", 16)); - doTestHMACDetECDSASample(new SHA512Digest(), privKey, new BigInteger("05D178DECAFD2D02A3DA0D8BA1C4C1D95EE083C760DF782193A9F7B4A8BE6FC5" + - "C21FD60613BCA65C063A61226E050A680B3ABD4", 16), new BigInteger("013B7581E98F6A63FBBCB3E49BCDA60F816DB230B888506D105DC229600497C3" + - "B46588C784BE3AA9343BEF82F7C9C80AEB63C3B", 16)); - - doTestHMACDetECDSATest(new SHA1Digest(), privKey, new BigInteger("049F54E7C10D2732B4638473053782C6919218BBEFCEC8B51640FC193E832291" + - "F05FA12371E9B448417B3290193F08EE9319195", 16), new BigInteger("0499E267DEC84E02F6F108B10E82172C414F15B1B7364BE8BFD66ADC0C5DE23F" + - "EE3DF0D811134C25AFE0E05A6672F98889F28F1", 16)); - doTestHMACDetECDSATest(new SHA224Digest(), privKey, new BigInteger("0B1527FFAA7DD7C7E46B628587A5BEC0539A2D04D3CF27C54841C2544E1BBDB4" + - "2FDBDAAF8671A4CA86DFD619B1E3732D7BB56F2", 16), new BigInteger("0442C68C044868DF4832C807F1EDDEBF7F5052A64B826FD03451440794063F52" + - "B022DF304F47403D4069234CA9EB4C964B37C02", 16)); - doTestHMACDetECDSATest(new SHA256Digest(), privKey, new BigInteger("0BB27755B991D6D31757BCBF68CB01225A38E1CFA20F775E861055DD108ED7EA" + - "455E4B96B2F6F7CD6C6EC2B3C70C3EDDEB9743B", 16), new BigInteger("0C5BE90980E7F444B5F7A12C9E9AC7A04CA81412822DD5AD1BE7C45D5032555E" + - "A070864245CF69266871FEB8CD1B7EDC30EF6D5", 16)); - doTestHMACDetECDSATest(new SHA384Digest(), privKey, new BigInteger("04EFEB7098772187907C87B33E0FBBA4584226C50C11E98CA7AAC6986F8D3BE0" + - "44E5B52D201A410B852536527724CA5F8CE6549", 16), new BigInteger("09574102FEB3EF87E6D66B94119F5A6062950FF4F902EA1E6BD9E2037F33FF99" + - "1E31F5956C23AFE48FCDC557FD6F088C7C9B2B3", 16)); - doTestHMACDetECDSATest(new SHA512Digest(), privKey, new BigInteger("07E0249C68536AE2AEC2EC30090340DA49E6DC9E9EEC8F85E5AABFB234B6DA7D" + - "2E9524028CF821F21C6019770474CC40B01FAF6", 16), new BigInteger("08125B5A03FB44AE81EA46D446130C2A415ECCA265910CA69D55F2453E16CD7B" + - "2DFA4E28C50FA8137F9C0C6CEE4CD37ABCCF6D8", 16)); - - x9ECParameters = NISTNamedCurves.getByName("B-571"); - ecDomainParameters = new ECDomainParameters(x9ECParameters.getCurve(), x9ECParameters.getG(), x9ECParameters.getN()); - - privKey = new ECPrivateKeyParameters(new BigInteger("028A04857F24C1C082DF0D909C0E72F453F2E2340CCB071F0E389BCA2575DA19" + - "124198C57174929AD26E348CF63F78D28021EF5A9BF2D5CBEAF6B7CCB6C4DA82" + - "4DD5C82CFB24E11", 16), ecDomainParameters); - - doTestHMACDetECDSASample(new SHA1Digest(), privKey, new BigInteger("147D3EB0EDA9F2152DFD014363D6A9CE816D7A1467D326A625FC4AB0C786E1B7" + - "4DDF7CD4D0E99541391B266C704BB6B6E8DCCD27B460802E0867143727AA4155" + - "55454321EFE5CB6", 16), - new BigInteger("17319571CAF533D90D2E78A64060B9C53169AB7FC908947B3EDADC54C79CCF0A" + - "7920B4C64A4EAB6282AFE9A459677CDA37FD6DD50BEF18709590FE18B923BDF7" + - "4A66B189A850819", 16)); - - doTestHMACDetECDSASample(new SHA224Digest(), privKey, new BigInteger("10F4B63E79B2E54E4F4F6A2DBC786D8F4A143ECA7B2AD97810F6472AC6AE2085" + - "3222854553BE1D44A7974599DB7061AE8560DF57F2675BE5F9DD94ABAF3D47F1" + - "582B318E459748B", 16), - new BigInteger("3BBEA07C6B269C2B7FE9AE4DDB118338D0C2F0022920A7F9DCFCB7489594C03B" + - "536A9900C4EA6A10410007222D3DAE1A96F291C4C9275D75D98EB290DC0EEF17" + - "6037B2C7A7A39A3", 16)); - - doTestHMACDetECDSASample(new SHA256Digest(), privKey, new BigInteger("213EF9F3B0CFC4BF996B8AF3A7E1F6CACD2B87C8C63820000800AC787F17EC99" + - "C04BCEDF29A8413CFF83142BB88A50EF8D9A086AF4EB03E97C567500C21D8657" + - "14D832E03C6D054", 16), - new BigInteger("3D32322559B094E20D8935E250B6EC139AC4AAB77920812C119AF419FB62B332" + - "C8D226C6C9362AE3C1E4AABE19359B8428EA74EC8FBE83C8618C2BCCB6B43FBA" + - "A0F2CCB7D303945", 16)); - - doTestHMACDetECDSASample(new SHA384Digest(), privKey, new BigInteger("375D8F49C656A0BBD21D3F54CDA287D853C4BB1849983CD891EF6CD6BB56A62B" + - "687807C16685C2C9BCA2663C33696ACCE344C45F3910B1DF806204FF731ECB28" + - "9C100EF4D1805EC", 16), - new BigInteger("1CDEC6F46DFEEE44BCE71D41C60550DC67CF98D6C91363625AC2553E4368D2DF" + - "B734A8E8C72E118A76ACDB0E58697940A0F3DF49E72894BD799450FC9E550CC0" + - "4B9FF9B0380021C", 16)); - doTestHMACDetECDSASample(new SHA512Digest(), privKey, new BigInteger("1C26F40D940A7EAA0EB1E62991028057D91FEDA0366B606F6C434C361F04E545" + - "A6A51A435E26416F6838FFA260C617E798E946B57215284182BE55F29A355E60" + - "24FE32A47289CF0", 16), - new BigInteger("3691DE4369D921FE94EDDA67CB71FBBEC9A436787478063EB1CC778B3DCDC1C4" + - "162662752D28DEEDF6F32A269C82D1DB80C87CE4D3B662E03AC347806E3F19D1" + - "8D6D4DE7358DF7E", 16)); - - doTestHMACDetECDSATest(new SHA1Digest(), privKey, new BigInteger("133F5414F2A9BC41466D339B79376038A64D045E5B0F792A98E5A7AA87E0AD01" + - "6419E5F8D176007D5C9C10B5FD9E2E0AB8331B195797C0358BA05ECBF24ACE59" + - "C5F368A6C0997CC", 16), - new BigInteger("3D16743AE9F00F0B1A500F738719C5582550FEB64689DA241665C4CE4F328BA0" + - "E34A7EF527ED13BFA5889FD2D1D214C11EB17D6BC338E05A56F41CAFF1AF7B8D" + - "574DB62EF0D0F21", 16)); - - doTestHMACDetECDSATest(new SHA224Digest(), privKey, new BigInteger("3048E76506C5C43D92B2E33F62B33E3111CEEB87F6C7DF7C7C01E3CDA28FA5E8" + - "BE04B5B23AA03C0C70FEF8F723CBCEBFF0B7A52A3F5C8B84B741B4F6157E69A5" + - "FB0524B48F31828", 16), - new BigInteger("2C99078CCFE5C82102B8D006E3703E020C46C87C75163A2CD839C885550BA5CB" + - "501AC282D29A1C26D26773B60FBE05AAB62BFA0BA32127563D42F7669C97784C" + - "8897C22CFB4B8FA", 16)); - - doTestHMACDetECDSATest(new SHA256Digest(), privKey, new BigInteger("184BC808506E11A65D628B457FDA60952803C604CC7181B59BD25AEE1411A66D" + - "12A777F3A0DC99E1190C58D0037807A95E5080FA1B2E5CCAA37B50D401CFFC34" + - "17C005AEE963469", 16), - new BigInteger("27280D45F81B19334DBDB07B7E63FE8F39AC7E9AE14DE1D2A6884D2101850289" + - "D70EE400F26ACA5E7D73F534A14568478E59D00594981ABE6A1BA18554C13EB5" + - "E03921E4DC98333", 16)); - - doTestHMACDetECDSATest(new SHA384Digest(), privKey, new BigInteger("319EE57912E7B0FAA1FBB145B0505849A89C6DB1EC06EA20A6A7EDE072A6268A" + - "F6FD9C809C7E422A5F33C6C3326EAD7402467DF3272A1B2726C1C20975950F0F" + - "50D8324578F13EC", 16), - new BigInteger("2CF3EA27EADD0612DD2F96F46E89AB894B01A10DF985C5FC099CFFE0EA083EB4" + - "4BE682B08BFE405DAD5F37D0A2C59015BA41027E24B99F8F75A70B6B7385BF39" + - "BBEA02513EB880C", 16)); - doTestHMACDetECDSATest(new SHA512Digest(), privKey, new BigInteger("2AA1888EAB05F7B00B6A784C4F7081D2C833D50794D9FEAF6E22B8BE728A2A90" + - "BFCABDC803162020AA629718295A1489EE7ED0ECB8AAA197B9BDFC49D18DDD78" + - "FC85A48F9715544", 16), - new BigInteger("0AA5371FE5CA671D6ED9665849C37F394FED85D51FEF72DA2B5F28EDFB2C6479" + - "CA63320C19596F5E1101988E2C619E302DD05112F47E8823040CE540CD3E90DC" + - "F41DBC461744EE9", 16)); - - } - - private void doTestHMACDetECDSASample(Digest digest, ECPrivateKeyParameters privKey, BigInteger r, BigInteger s) - { - doTestHMACDetECDSA(new ECDSASigner(new HMacDSAKCalculator(digest)), digest, SAMPLE, privKey, r, s); - } - - private void doTestHMACDetECDSATest(Digest digest, ECPrivateKeyParameters privKey, BigInteger r, BigInteger s) - { - doTestHMACDetECDSA(new ECDSASigner(new HMacDSAKCalculator(digest)), digest, TEST, privKey, r, s); - } - - private void doTestHMACDetECDSA(DSA detSigner, Digest digest, byte[] data, CipherParameters privKey, BigInteger r, BigInteger s) - { - byte[] m = new byte[digest.getDigestSize()]; - - digest.update(data, 0, data.length); - - digest.doFinal(m, 0); - - detSigner.init(true, privKey); - - BigInteger[] rs = detSigner.generateSignature(m); - - if (!r.equals(rs[0])) - { - fail("r value wrong, got " + rs[0].toString(16)); - } - if (!s.equals(rs[1])) - { - fail("s value wrong, got " + rs[1].toString(16)); - } - } - - public String getName() - { - return "DeterministicDSA"; - } - - public void performTest() - { - testHMacDeterministic(); - testECHMacDeterministic(); - } - - - public static void main( - String[] args) - { - runTest(new DeterministicDSATest()); - } -} - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DigestRandomNumberTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DigestRandomNumberTest.java deleted file mode 100644 index 62d7b5f6f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DigestRandomNumberTest.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.crypto.prng.DigestRandomGenerator; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.Digest; - -public class DigestRandomNumberTest - extends SimpleTest -{ - private static final byte[] ZERO_SEED = { 0, 0, 0, 0, 0, 0, 0, 0 }; - - private static final byte[] TEST_SEED = Hex.decode("81dcfafc885914057876"); - - private static final byte[] expected0SHA1 = Hex.decode("95bca677b3d4ff793213c00892d2356ec729ee02"); - private static final byte[] noCycle0SHA1 = Hex.decode("d57ccd0eb12c3938d59226412bc1268037b6b846"); - private static final byte[] expected0SHA256 = Hex.decode("587e2dfd597d086e47ddcd343eac983a5c913bef8c6a1a560a5c1bc3a74b0991"); - private static final byte[] noCycle0SHA256 = Hex.decode("e5776c4483486ba7be081f4e1b9dafbab25c8fae290fd5474c1ceda2c16f9509"); - private static final byte[] expected100SHA1 = Hex.decode("b9d924092546e0876cafd4937d7364ebf9efa4be"); - private static final byte[] expected100SHA256 = Hex.decode("fbc4aa54b948b99de104c44563a552899d718bb75d1941cc62a2444b0506abaf"); - private static final byte[] expectedTestSHA1 = Hex.decode("e9ecef9f5306daf1ac51a89a211a64cb24415649"); - private static final byte[] expectedTestSHA256 = Hex.decode("bdab3ca831b472a2fa09bd1bade541ef16c96640a91fcec553679a136061de98"); - - private static final byte[] sha1Xors = Hex.decode("7edcc1216934f3891b03ffa65821611a3e2b1f79"); - private static final byte[] sha256Xors = Hex.decode("5ec48189cc0aa71e79c707bc3c33ffd47bbba368a83d6cfebf3cd3969d7f3eed"); - - public String getName() - { - return "DigestRandomNumber"; - } - - private void doExpectedTest(Digest digest, int seed, byte[] expected) - { - doExpectedTest(digest, seed, expected, null); - } - - private void doExpectedTest(Digest digest, int seed, byte[] expected, byte[] noCycle) - { - DigestRandomGenerator rGen = new DigestRandomGenerator(digest); - byte[] output = new byte[digest.getDigestSize()]; - - rGen.addSeedMaterial(seed); - - for (int i = 0; i != 1024; i++) - { - rGen.nextBytes(output); - } - - if (noCycle != null) - { - if (Arrays.areEqual(noCycle, output)) - { - fail("seed not being cycled!"); - } - } - - if (!Arrays.areEqual(expected, output)) - { - fail("expected output doesn't match"); - } - } - - private void doExpectedTest(Digest digest, byte[] seed, byte[] expected) - { - DigestRandomGenerator rGen = new DigestRandomGenerator(digest); - byte[] output = new byte[digest.getDigestSize()]; - - rGen.addSeedMaterial(seed); - - for (int i = 0; i != 1024; i++) - { - rGen.nextBytes(output); - } - - if (!Arrays.areEqual(expected, output)) - { - fail("expected output doesn't match"); - } - } - - private void doCountTest(Digest digest, byte[] seed, byte[] expectedXors) - { - DigestRandomGenerator rGen = new DigestRandomGenerator(digest); - byte[] output = new byte[digest.getDigestSize()]; - int[] averages = new int[digest.getDigestSize()]; - byte[] ands = new byte[digest.getDigestSize()]; - byte[] xors = new byte[digest.getDigestSize()]; - byte[] ors = new byte[digest.getDigestSize()]; - - rGen.addSeedMaterial(seed); - - for (int i = 0; i != 1000000; i++) - { - rGen.nextBytes(output); - for (int j = 0; j != output.length; j++) - { - averages[j] += output[j] & 0xff; - ands[j] &= output[j]; - xors[j] ^= output[j]; - ors[j] |= output[j]; - } - } - - for (int i = 0; i != output.length; i++) - { - if ((averages[i] / 1000000) != 127) - { - fail("average test failed for " + digest.getAlgorithmName()); - } - if (ands[i] != 0) - { - fail("and test failed for " + digest.getAlgorithmName()); - } - if ((ors[i] & 0xff) != 0xff) - { - fail("or test failed for " + digest.getAlgorithmName()); - } - if (xors[i] != expectedXors[i]) - { - fail("xor test failed for " + digest.getAlgorithmName()); - } - } - } - - public void performTest() - throws Exception - { - doExpectedTest(new SHA1Digest(), 0, expected0SHA1, noCycle0SHA1); - doExpectedTest(new SHA256Digest(), 0, expected0SHA256, noCycle0SHA256); - - doExpectedTest(new SHA1Digest(), 100, expected100SHA1); - doExpectedTest(new SHA256Digest(), 100, expected100SHA256); - - doExpectedTest(new SHA1Digest(), ZERO_SEED, expected0SHA1); - doExpectedTest(new SHA256Digest(), ZERO_SEED, expected0SHA256); - - doExpectedTest(new SHA1Digest(), TEST_SEED, expectedTestSHA1); - doExpectedTest(new SHA256Digest(), TEST_SEED, expectedTestSHA256); - - doCountTest(new SHA1Digest(), TEST_SEED, sha1Xors); - doCountTest(new SHA256Digest(), TEST_SEED, sha256Xors); - } - - public static void main( - String[] args) - { - runTest(new DigestRandomNumberTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DigestTest.java deleted file mode 100644 index 70c2e1ea9..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/DigestTest.java +++ /dev/null @@ -1,246 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.EncodableDigest; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Memoable; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public abstract class DigestTest - extends SimpleTest -{ - private Digest digest; - private String[] input; - private String[] results; - - DigestTest( - Digest digest, - String[] input, - String[] results) - { - this.digest = digest; - this.input = input; - this.results = results; - } - - public String getName() - { - return digest.getAlgorithmName(); - } - - public void performTest() - { - byte[] resBuf = new byte[digest.getDigestSize()]; - - for (int i = 0; i < input.length - 1; i++) - { - byte[] m = toByteArray(input[i]); - - vectorTest(digest, i, resBuf, m, Hex.decode(results[i])); - } - - offsetTest(digest, 0, toByteArray(input[0]), Hex.decode(results[0])); - - byte[] lastV = toByteArray(input[input.length - 1]); - byte[] lastDigest = Hex.decode(results[input.length - 1]); - - vectorTest(digest, input.length - 1, resBuf, lastV, Hex.decode(results[input.length - 1])); - - testClone(resBuf, lastV, lastDigest); - testMemo(resBuf, lastV, lastDigest); - if (digest instanceof EncodableDigest) - { - testEncodedState(resBuf, lastV, lastDigest); - } - } - - private void testEncodedState(byte[] resBuf, byte[] input, byte[] expected) - { - // test state encoding; - digest.update(input, 0, input.length / 2); - - // copy the Digest - Digest copy1 = cloneDigest(((EncodableDigest)digest).getEncodedState()); - Digest copy2 = cloneDigest(((EncodableDigest)copy1).getEncodedState()); - - digest.update(input, input.length / 2, input.length - input.length / 2); - - digest.doFinal(resBuf, 0); - - if (!areEqual(expected, resBuf)) - { - fail("failing state vector test", expected, new String(Hex.encode(resBuf))); - } - - copy1.update(input, input.length / 2, input.length - input.length / 2); - copy1.doFinal(resBuf, 0); - - if (!areEqual(expected, resBuf)) - { - fail("failing state copy1 vector test", expected, new String(Hex.encode(resBuf))); - } - - copy2.update(input, input.length / 2, input.length - input.length / 2); - copy2.doFinal(resBuf, 0); - - if (!areEqual(expected, resBuf)) - { - fail("failing state copy2 vector test", expected, new String(Hex.encode(resBuf))); - } - } - - private void testMemo(byte[] resBuf, byte[] input, byte[] expected) - { - Memoable m = (Memoable)digest; - - digest.update(input, 0, input.length/2); - - // copy the Digest - Memoable copy1 = m.copy(); - Memoable copy2 = copy1.copy(); - - digest.update(input, input.length/2, input.length - input.length/2); - digest.doFinal(resBuf, 0); - - if (!areEqual(expected, resBuf)) - { - fail("failing memo vector test", results[results.length - 1], new String(Hex.encode(resBuf))); - } - - m.reset(copy1); - - digest.update(input, input.length/2, input.length - input.length/2); - digest.doFinal(resBuf, 0); - - if (!areEqual(expected, resBuf)) - { - fail("failing memo reset vector test", results[results.length - 1], new String(Hex.encode(resBuf))); - } - - Digest md = (Digest)copy2; - - md.update(input, input.length/2, input.length - input.length/2); - md.doFinal(resBuf, 0); - - if (!areEqual(expected, resBuf)) - { - fail("failing memo copy vector test", results[results.length - 1], new String(Hex.encode(resBuf))); - } - } - - private void testClone(byte[] resBuf, byte[] input, byte[] expected) - { - digest.update(input, 0, input.length / 2); - - // clone the Digest - Digest d = cloneDigest(digest); - - digest.update(input, input.length/2, input.length - input.length/2); - digest.doFinal(resBuf, 0); - - if (!areEqual(expected, resBuf)) - { - fail("failing clone vector test", results[results.length - 1], new String(Hex.encode(resBuf))); - } - - d.update(input, input.length/2, input.length - input.length/2); - d.doFinal(resBuf, 0); - - if (!areEqual(expected, resBuf)) - { - fail("failing second clone vector test", results[results.length - 1], new String(Hex.encode(resBuf))); - } - } - - protected byte[] toByteArray(String input) - { - byte[] bytes = new byte[input.length()]; - - for (int i = 0; i != bytes.length; i++) - { - bytes[i] = (byte)input.charAt(i); - } - - return bytes; - } - - private void vectorTest( - Digest digest, - int count, - byte[] resBuf, - byte[] input, - byte[] expected) - { - digest.update(input, 0, input.length); - digest.doFinal(resBuf, 0); - - if (!areEqual(resBuf, expected)) - { - fail("Vector " + count + " failed got " + new String(Hex.encode(resBuf))); - } - } - - private void offsetTest( - Digest digest, - int count, - byte[] input, - byte[] expected) - { - byte[] resBuf = new byte[expected.length + 11]; - - digest.update(input, 0, input.length); - digest.doFinal(resBuf, 11); - - if (!areEqual(Arrays.copyOfRange(resBuf, 11, resBuf.length), expected)) - { - fail("Offset " + count + " failed got " + new String(Hex.encode(resBuf))); - } - } - - protected abstract Digest cloneDigest(Digest digest); - - protected Digest cloneDigest(byte[] encodedState) - { - throw new IllegalStateException("Unsupported"); - } - - // - // optional tests - // - protected void millionATest( - String expected) - { - byte[] resBuf = new byte[digest.getDigestSize()]; - - for (int i = 0; i < 1000000; i++) - { - digest.update((byte)'a'); - } - - digest.doFinal(resBuf, 0); - - if (!areEqual(resBuf, Hex.decode(expected))) - { - fail("Million a's failed", expected, new String(Hex.encode(resBuf))); - } - } - - protected void sixtyFourKTest( - String expected) - { - byte[] resBuf = new byte[digest.getDigestSize()]; - - for (int i = 0; i < 65536; i++) - { - digest.update((byte)(i & 0xff)); - } - - digest.doFinal(resBuf, 0); - - if (!areEqual(resBuf, Hex.decode(expected))) - { - fail("64k test failed", expected, new String(Hex.encode(resBuf))); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/EAXTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/EAXTest.java deleted file mode 100644 index cb5e746d1..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/EAXTest.java +++ /dev/null @@ -1,354 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.modes.AEADBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.EAXBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.AEADParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class EAXTest - extends SimpleTest -{ - private byte[] K1 = Hex.decode("233952DEE4D5ED5F9B9C6D6FF80FF478"); - private byte[] N1 = Hex.decode("62EC67F9C3A4A407FCB2A8C49031A8B3"); - private byte[] A1 = Hex.decode("6BFB914FD07EAE6B"); - private byte[] P1 = Hex.decode(""); - private byte[] C1 = Hex.decode("E037830E8389F27B025A2D6527E79D01"); - private byte[] T1 = Hex.decode("E037830E8389F27B025A2D6527E79D01"); - - private byte[] K2 = Hex.decode("91945D3F4DCBEE0BF45EF52255F095A4"); - private byte[] N2 = Hex.decode("BECAF043B0A23D843194BA972C66DEBD"); - private byte[] A2 = Hex.decode("FA3BFD4806EB53FA"); - private byte[] P2 = Hex.decode("F7FB"); - private byte[] C2 = Hex.decode("19DD5C4C9331049D0BDAB0277408F67967E5"); - private byte[] T2 = Hex.decode("5C4C9331049D0BDAB0277408F67967E5"); - - private byte[] K3 = Hex.decode("01F74AD64077F2E704C0F60ADA3DD523"); - private byte[] N3 = Hex.decode("70C3DB4F0D26368400A10ED05D2BFF5E"); - private byte[] A3 = Hex.decode("234A3463C1264AC6"); - private byte[] P3 = Hex.decode("1A47CB4933"); - private byte[] C3 = Hex.decode("D851D5BAE03A59F238A23E39199DC9266626C40F80"); - private byte[] T3 = Hex.decode("3A59F238A23E39199DC9266626C40F80"); - - private byte[] K4 = Hex.decode("D07CF6CBB7F313BDDE66B727AFD3C5E8"); - private byte[] N4 = Hex.decode("8408DFFF3C1A2B1292DC199E46B7D617"); - private byte[] A4 = Hex.decode("33CCE2EABFF5A79D"); - private byte[] P4 = Hex.decode("481C9E39B1"); - private byte[] C4 = Hex.decode("632A9D131AD4C168A4225D8E1FF755939974A7BEDE"); - private byte[] T4 = Hex.decode("D4C168A4225D8E1FF755939974A7BEDE"); - - private byte[] K5 = Hex.decode("35B6D0580005BBC12B0587124557D2C2"); - private byte[] N5 = Hex.decode("FDB6B06676EEDC5C61D74276E1F8E816"); - private byte[] A5 = Hex.decode("AEB96EAEBE2970E9"); - private byte[] P5 = Hex.decode("40D0C07DA5E4"); - private byte[] C5 = Hex.decode("071DFE16C675CB0677E536F73AFE6A14B74EE49844DD"); - private byte[] T5 = Hex.decode("CB0677E536F73AFE6A14B74EE49844DD"); - - private byte[] K6 = Hex.decode("BD8E6E11475E60B268784C38C62FEB22"); - private byte[] N6 = Hex.decode("6EAC5C93072D8E8513F750935E46DA1B"); - private byte[] A6 = Hex.decode("D4482D1CA78DCE0F"); - private byte[] P6 = Hex.decode("4DE3B35C3FC039245BD1FB7D"); - private byte[] C6 = Hex.decode("835BB4F15D743E350E728414ABB8644FD6CCB86947C5E10590210A4F"); - private byte[] T6 = Hex.decode("ABB8644FD6CCB86947C5E10590210A4F"); - - private byte[] K7 = Hex.decode("7C77D6E813BED5AC98BAA417477A2E7D"); - private byte[] N7 = Hex.decode("1A8C98DCD73D38393B2BF1569DEEFC19"); - private byte[] A7 = Hex.decode("65D2017990D62528"); - private byte[] P7 = Hex.decode("8B0A79306C9CE7ED99DAE4F87F8DD61636"); - private byte[] C7 = Hex.decode("02083E3979DA014812F59F11D52630DA30137327D10649B0AA6E1C181DB617D7F2"); - private byte[] T7 = Hex.decode("137327D10649B0AA6E1C181DB617D7F2"); - - private byte[] K8 = Hex.decode("5FFF20CAFAB119CA2FC73549E20F5B0D"); - private byte[] N8 = Hex.decode("DDE59B97D722156D4D9AFF2BC7559826"); - private byte[] A8 = Hex.decode("54B9F04E6A09189A"); - private byte[] P8 = Hex.decode("1BDA122BCE8A8DBAF1877D962B8592DD2D56"); - private byte[] C8 = Hex.decode("2EC47B2C4954A489AFC7BA4897EDCDAE8CC33B60450599BD02C96382902AEF7F832A"); - private byte[] T8 = Hex.decode("3B60450599BD02C96382902AEF7F832A"); - - private byte[] K9 = Hex.decode("A4A4782BCFFD3EC5E7EF6D8C34A56123"); - private byte[] N9 = Hex.decode("B781FCF2F75FA5A8DE97A9CA48E522EC"); - private byte[] A9 = Hex.decode("899A175897561D7E"); - private byte[] P9 = Hex.decode("6CF36720872B8513F6EAB1A8A44438D5EF11"); - private byte[] C9 = Hex.decode("0DE18FD0FDD91E7AF19F1D8EE8733938B1E8E7F6D2231618102FDB7FE55FF1991700"); - private byte[] T9 = Hex.decode("E7F6D2231618102FDB7FE55FF1991700"); - - private byte[] K10 = Hex.decode("8395FCF1E95BEBD697BD010BC766AAC3"); - private byte[] N10 = Hex.decode("22E7ADD93CFC6393C57EC0B3C17D6B44"); - private byte[] A10 = Hex.decode("126735FCC320D25A"); - private byte[] P10 = Hex.decode("CA40D7446E545FFAED3BD12A740A659FFBBB3CEAB7"); - private byte[] C10 = Hex.decode("CB8920F87A6C75CFF39627B56E3ED197C552D295A7CFC46AFC253B4652B1AF3795B124AB6E"); - private byte[] T10 = Hex.decode("CFC46AFC253B4652B1AF3795B124AB6E"); - - private byte[] K11 = Hex.decode("8395FCF1E95BEBD697BD010BC766AAC3"); - private byte[] N11 = Hex.decode("22E7ADD93CFC6393C57EC0B3C17D6B44"); - private byte[] A11 = Hex.decode("126735FCC320D25A"); - private byte[] P11 = Hex.decode("CA40D7446E545FFAED3BD12A740A659FFBBB3CEAB7"); - private byte[] C11 = Hex.decode("CB8920F87A6C75CFF39627B56E3ED197C552D295A7CFC46AFC"); - private byte[] T11 = Hex.decode("CFC46AFC"); - - private static final int NONCE_LEN = 8; - private static final int MAC_LEN = 8; - private static final int AUTHEN_LEN = 20; - - public String getName() - { - return "EAX"; - } - - public void performTest() - throws Exception - { - checkVectors(1, K1, 128, N1, A1, P1, T1, C1); - checkVectors(2, K2, 128, N2, A2, P2, T2, C2); - checkVectors(3, K3, 128, N3, A3, P3, T3, C3); - checkVectors(4, K4, 128, N4, A4, P4, T4, C4); - checkVectors(5, K5, 128, N5, A5, P5, T5, C5); - checkVectors(6, K6, 128, N6, A6, P6, T6, C6); - checkVectors(7, K7, 128, N7, A7, P7, T7, C7); - checkVectors(8, K8, 128, N8, A8, P8, T8, C8); - checkVectors(9, K9, 128, N9, A9, P9, T9, C9); - checkVectors(10, K10, 128, N10, A10, P10, T10, C10); - checkVectors(11, K11, 32, N11, A11, P11, T11, C11); - - EAXBlockCipher eax = new EAXBlockCipher(new AESEngine()); - ivParamTest(1, eax, K1, N1); - - // - // exception tests - // - - try - { - eax.init(false, new AEADParameters(new KeyParameter(K1), 32, N2, A2)); - - byte[] enc = new byte[C2.length]; - int len = eax.processBytes(C2, 0, C2.length, enc, 0); - - len += eax.doFinal(enc, len); - - fail("invalid cipher text not picked up"); - } - catch (InvalidCipherTextException e) - { - // expected - } - - try - { - eax.init(false, new KeyParameter(K1)); - - fail("illegal argument not picked up"); - } - catch (IllegalArgumentException e) - { - // expected - } - - randomTests(); - AEADTestUtil.testReset(this, new EAXBlockCipher(new AESEngine()), new EAXBlockCipher(new AESEngine()), new AEADParameters(new KeyParameter(K1), 32, N2)); - AEADTestUtil.testTampering(this, eax, new AEADParameters(new KeyParameter(K1), 32, N2)); - AEADTestUtil.testOutputSizes(this, new EAXBlockCipher(new AESEngine()), new AEADParameters( - new KeyParameter(K1), 32, N2)); - AEADTestUtil.testBufferSizeChecks(this, new EAXBlockCipher(new AESEngine()), new AEADParameters( - new KeyParameter(K1), 32, N2)); - } - - private void checkVectors( - int count, - byte[] k, - int macSize, - byte[] n, - byte[] a, - byte[] p, - byte[] t, - byte[] c) - throws InvalidCipherTextException - { - byte[] fa = new byte[a.length / 2]; - byte[] la = new byte[a.length - (a.length / 2)]; - System.arraycopy(a, 0, fa, 0, fa.length); - System.arraycopy(a, fa.length, la, 0, la.length); - - checkVectors(count, "all initial associated data", k, macSize, n, a, null, p, t, c); - checkVectors(count, "subsequent associated data", k, macSize, n, null, a, p, t, c); - checkVectors(count, "split associated data", k, macSize, n, fa, la, p, t, c); - } - - private void checkVectors( - int count, - String additionalDataType, - byte[] k, - int macSize, - byte[] n, - byte[] a, - byte[] sa, - byte[] p, - byte[] t, - byte[] c) - throws InvalidCipherTextException - { - EAXBlockCipher encEax = new EAXBlockCipher(new AESEngine()); - EAXBlockCipher decEax = new EAXBlockCipher(new AESEngine()); - - AEADParameters parameters = new AEADParameters(new KeyParameter(k), macSize, n, a); - encEax.init(true, parameters); - decEax.init(false, parameters); - - runCheckVectors(count, encEax, decEax, additionalDataType, sa, p, t, c); - runCheckVectors(count, encEax, decEax, additionalDataType, sa, p, t, c); - - // key reuse test - parameters = new AEADParameters(null, macSize, n, a); - encEax.init(true, parameters); - decEax.init(false, parameters); - - runCheckVectors(count, encEax, decEax, additionalDataType, sa, p, t, c); - runCheckVectors(count, encEax, decEax, additionalDataType, sa, p, t, c); - } - - private void runCheckVectors( - int count, - EAXBlockCipher encEax, - EAXBlockCipher decEax, - String additionalDataType, - byte[] sa, - byte[] p, - byte[] t, - byte[] c) - throws InvalidCipherTextException - { - byte[] enc = new byte[c.length]; - - if (sa != null) - { - encEax.processAADBytes(sa, 0, sa.length); - } - - int len = encEax.processBytes(p, 0, p.length, enc, 0); - - len += encEax.doFinal(enc, len); - - if (!areEqual(c, enc)) - { - fail("encrypted stream fails to match in test " + count + " with " + additionalDataType); - } - - byte[] tmp = new byte[enc.length]; - - if (sa != null) - { - decEax.processAADBytes(sa, 0, sa.length); - } - - len = decEax.processBytes(enc, 0, enc.length, tmp, 0); - - len += decEax.doFinal(tmp, len); - - byte[] dec = new byte[len]; - - System.arraycopy(tmp, 0, dec, 0, len); - - if (!areEqual(p, dec)) - { - fail("decrypted stream fails to match in test " + count + " with " + additionalDataType); - } - - if (!areEqual(t, decEax.getMac())) - { - fail("MAC fails to match in test " + count + " with " + additionalDataType); - } - } - - private void ivParamTest( - int count, - AEADBlockCipher eax, - byte[] k, - byte[] n) - throws InvalidCipherTextException - { - byte[] p = Strings.toByteArray("hello world!!"); - - eax.init(true, new ParametersWithIV(new KeyParameter(k), n)); - - byte[] enc = new byte[p.length + 8]; - - int len = eax.processBytes(p, 0, p.length, enc, 0); - - len += eax.doFinal(enc, len); - - eax.init(false, new ParametersWithIV(new KeyParameter(k), n)); - - byte[] tmp = new byte[enc.length]; - - len = eax.processBytes(enc, 0, enc.length, tmp, 0); - - len += eax.doFinal(tmp, len); - - byte[] dec = new byte[len]; - - System.arraycopy(tmp, 0, dec, 0, len); - - if (!areEqual(p, dec)) - { - fail("decrypted stream fails to match in test " + count); - } - } - - private void randomTests() - throws InvalidCipherTextException - { - SecureRandom srng = new SecureRandom(); - for (int i = 0; i < 10; ++i) - { - randomTest(srng); - } - } - - private void randomTest( - SecureRandom srng) - throws InvalidCipherTextException - { - int DAT_LEN = srng.nextInt() >>> 22; // Note: JDK1.0 compatibility - byte[] nonce = new byte[NONCE_LEN]; - byte[] authen = new byte[AUTHEN_LEN]; - byte[] datIn = new byte[DAT_LEN]; - byte[] key = new byte[16]; - srng.nextBytes(nonce); - srng.nextBytes(authen); - srng.nextBytes(datIn); - srng.nextBytes(key); - - AESEngine engine = new AESEngine(); - KeyParameter sessKey = new KeyParameter(key); - EAXBlockCipher eaxCipher = new EAXBlockCipher(engine); - - AEADParameters params = new AEADParameters(sessKey, MAC_LEN * 8, nonce, authen); - eaxCipher.init(true, params); - - byte[] intrDat = new byte[eaxCipher.getOutputSize(datIn.length)]; - int outOff = eaxCipher.processBytes(datIn, 0, DAT_LEN, intrDat, 0); - outOff += eaxCipher.doFinal(intrDat, outOff); - - eaxCipher.init(false, params); - byte[] datOut = new byte[eaxCipher.getOutputSize(outOff)]; - int resultLen = eaxCipher.processBytes(intrDat, 0, outOff, datOut, 0); - eaxCipher.doFinal(datOut, resultLen); - - if (!areEqual(datIn, datOut)) - { - fail("EAX roundtrip failed to match"); - } - } - - public static void main(String[] args) - { - runTest(new EAXTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECDHKEKGeneratorTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECDHKEKGeneratorTest.java deleted file mode 100644 index bd8f6e79e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECDHKEKGeneratorTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.nist.NISTObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.crypto.DerivationFunction; -import com.fr.third.org.bouncycastle.crypto.DerivationParameters; -import com.fr.third.org.bouncycastle.crypto.agreement.kdf.DHKDFParameters; -import com.fr.third.org.bouncycastle.crypto.agreement.kdf.ECDHKEKGenerator; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * ECDHKEK Generator tests. - */ -public class ECDHKEKGeneratorTest - extends SimpleTest -{ - private byte[] seed1 = Hex.decode("db4a8daba1f98791d54e940175dd1a5f3a0826a1066aa9b668d4dc1e1e0790158dcad1533c03b44214d1b61fefa8b579"); - private ASN1ObjectIdentifier alg1 = NISTObjectIdentifiers.id_aes256_wrap; - private byte[] result1 = Hex.decode("8ecc6d85caf25eaba823a7d620d4ab0d33e4c645f2"); - - private byte[] seed2 = Hex.decode("75d7487b5d3d2bfb3c69ce0365fe64e3bfab5d0d63731628a9f47eb8fddfa28c65decaf228a0b38f0c51c6a3356d7c56"); - private ASN1ObjectIdentifier alg2 = NISTObjectIdentifiers.id_aes128_wrap; - private byte[] result2 = Hex.decode("042be1faca3a4a8fc859241bfb87ba35"); - - private byte[] seed3 = Hex.decode("fdeb6d809f997e8ac174d638734dc36d37aaf7e876e39967cd82b1cada3de772449788461ee7f856bad9305627f8e48b"); - private ASN1ObjectIdentifier alg3 = PKCSObjectIdentifiers.id_alg_CMS3DESwrap; - private byte[] result3 = Hex.decode("bcd701fc92109b1b9d6f3b6497ad5ca9627fa8a597010305"); - - public ECDHKEKGeneratorTest() - { - } - - public void performTest() - { - checkMask(1, new ECDHKEKGenerator(new SHA1Digest()), new DHKDFParameters(alg1, 256, seed1), result1); - checkMask(2, new ECDHKEKGenerator(new SHA1Digest()), new DHKDFParameters(alg2, 128, seed2), result2); - checkMask(3, new ECDHKEKGenerator(new SHA1Digest()), new DHKDFParameters(alg3, 192, seed3), result3); - } - - private void checkMask( - int count, - DerivationFunction kdf, - DerivationParameters params, - byte[] result) - { - byte[] data = new byte[result.length]; - - kdf.init(params); - - kdf.generateBytes(data, 0, data.length); - - if (!areEqual(result, data)) - { - fail("ECDHKEKGenerator failed generator test " + count); - } - } - - public String getName() - { - return "ECDHKEKGenerator"; - } - - public static void main( - String[] args) - { - runTest(new ECDHKEKGeneratorTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECGOST3410Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECGOST3410Test.java deleted file mode 100644 index 64781d79c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECGOST3410Test.java +++ /dev/null @@ -1,327 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.digests.GOST3411Digest; -import com.fr.third.org.bouncycastle.crypto.generators.ECKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.signers.ECGOST3410Signer; -import com.fr.third.org.bouncycastle.math.ec.ECConstants; -import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestRandomData; - -/** - * ECGOST3410 tests are taken from GOST R 34.10-2001. - */ -public class ECGOST3410Test - extends SimpleTest - { - byte[] hashmessage = Hex.decode("3042453136414534424341374533364339313734453431443642453241453435"); - - /** - * ECGOST3410 over the field Fp
- */ - BigInteger r = new BigInteger("29700980915817952874371204983938256990422752107994319651632687982059210933395"); - BigInteger s = new BigInteger("574973400270084654178925310019147038455227042649098563933718999175515839552"); - - byte[] kData = new BigInteger("53854137677348463731403841147996619241504003434302020712960838528893196233395").toByteArray(); - - SecureRandom k = new TestRandomData(kData); - - private void ecGOST3410_TEST() - { - BigInteger mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564821041"); //p - BigInteger mod_q = new BigInteger("57896044618658097711785492504343953927082934583725450622380973592137631069619"); - - ECCurve.Fp curve = new ECCurve.Fp( - mod_p, // p - new BigInteger("7"), // a - new BigInteger("43308876546767276905765904595650931995942111794451039583252968842033849580414"), // b - mod_q, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.createPoint( - new BigInteger("2"), // x - new BigInteger("4018974056539037503335449422937059775635739389905545080690979365213431566280")), // y - mod_q); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("55441196065363246126355624130324183196576709222340016572108097750006097525544"), // d - params); - - ParametersWithRandom param = new ParametersWithRandom(priKey, k); - - ECGOST3410Signer ecgost3410 = new ECGOST3410Signer(); - - ecgost3410.init(true, param); - - byte[] mVal = new BigInteger("20798893674476452017134061561508270130637142515379653289952617252661468872421").toByteArray(); - byte[] message = new byte[mVal.length]; - - for (int i = 0; i != mVal.length; i++) - { - message[i] = mVal[mVal.length - 1 - i]; - } - - BigInteger[] sig = ecgost3410.generateSignature(message); - - if (!r.equals(sig[0])) - { - fail("r component wrong.", r, sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong.", s, sig[1]); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.createPoint( - new BigInteger("57520216126176808443631405023338071176630104906313632182896741342206604859403"), // x - new BigInteger("17614944419213781543809391949654080031942662045363639260709847859438286763994")), // y - params); - - ecgost3410.init(false, pubKey); - if (!ecgost3410.verifySignature(message, sig[0], sig[1])) - { - fail("verification fails"); - } - } - - /** - * Test Sign & Verify with test parameters - * see: http://www.ietf.org/internet-drafts/draft-popov-cryptopro-cpalgs-01.txt - * gostR3410-2001-TestParamSet P.46 - */ - private void ecGOST3410_TestParam() - { - SecureRandom random = new SecureRandom(); - - BigInteger mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564821041"); //p - BigInteger mod_q = new BigInteger("57896044618658097711785492504343953927082934583725450622380973592137631069619"); - - ECCurve.Fp curve = new ECCurve.Fp( - mod_p, // p - new BigInteger("7"), // a - new BigInteger("43308876546767276905765904595650931995942111794451039583252968842033849580414"), // b - mod_q, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.createPoint( - new BigInteger("2"), // x - new BigInteger("4018974056539037503335449422937059775635739389905545080690979365213431566280")), // y - mod_q); - - ECKeyPairGenerator pGen = new ECKeyPairGenerator(); - ECKeyGenerationParameters genParam = new ECKeyGenerationParameters( - params, - random); - - pGen.init(genParam); - - AsymmetricCipherKeyPair pair = pGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - ECGOST3410Signer ecgost3410 = new ECGOST3410Signer(); - - ecgost3410.init(true, param); - - //get hash message using the digest GOST3411. - byte[] message = "Message for sign".getBytes(); - GOST3411Digest gost3411 = new GOST3411Digest(); - gost3411.update(message, 0, message.length); - byte[] hashmessage = new byte[gost3411.getDigestSize()]; - gost3411.doFinal(hashmessage, 0); - - BigInteger[] sig = ecgost3410.generateSignature(hashmessage); - - ecgost3410.init(false, pair.getPublic()); - - if (!ecgost3410.verifySignature(hashmessage, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - /** - * Test Sign & Verify with A parameters - * see: http://www.ietf.org/internet-drafts/draft-popov-cryptopro-cpalgs-01.txt - * gostR3410-2001-CryptoPro-A-ParamSet P.47 - */ - public void ecGOST3410_AParam() - { - SecureRandom random = new SecureRandom(); - - BigInteger mod_p = new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639319"); //p - BigInteger mod_q = new BigInteger("115792089237316195423570985008687907853073762908499243225378155805079068850323"); - - ECCurve.Fp curve = new ECCurve.Fp( - mod_p, // p - new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639316"), // a - new BigInteger("166"), // b - mod_q, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.createPoint( - new BigInteger("1"), // x - new BigInteger("64033881142927202683649881450433473985931760268884941288852745803908878638612")), // y - mod_q); - - ECKeyPairGenerator pGen = new ECKeyPairGenerator(); - ECKeyGenerationParameters genParam = new ECKeyGenerationParameters( - params, - random); - - pGen.init(genParam); - - AsymmetricCipherKeyPair pair = pGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - ECGOST3410Signer ecgost3410 = new ECGOST3410Signer(); - - ecgost3410.init(true, param); - - BigInteger[] sig = ecgost3410.generateSignature(hashmessage); - - ecgost3410.init(false, pair.getPublic()); - - if (!ecgost3410.verifySignature(hashmessage, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - /** - * Test Sign & Verify with B parameters - * see: http://www.ietf.org/internet-drafts/draft-popov-cryptopro-cpalgs-01.txt - * gostR3410-2001-CryptoPro-B-ParamSet P.47-48 - */ - private void ecGOST3410_BParam() - { - SecureRandom random = new SecureRandom(); - - BigInteger mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564823193"); //p - BigInteger mod_q = new BigInteger("57896044618658097711785492504343953927102133160255826820068844496087732066703"); - - ECCurve.Fp curve = new ECCurve.Fp( - mod_p, // p - new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564823190"), // a - new BigInteger("28091019353058090096996979000309560759124368558014865957655842872397301267595"), // b - mod_q, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.createPoint( - new BigInteger("1"), // x - new BigInteger("28792665814854611296992347458380284135028636778229113005756334730996303888124")), // y - mod_q); - - ECKeyPairGenerator pGen = new ECKeyPairGenerator(); - ECKeyGenerationParameters genParam = new ECKeyGenerationParameters( - params, - random); - - pGen.init(genParam); - - AsymmetricCipherKeyPair pair = pGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - ECGOST3410Signer ecgost3410 = new ECGOST3410Signer(); - - ecgost3410.init(true, param); - - BigInteger[] sig = ecgost3410.generateSignature(hashmessage); - - ecgost3410.init(false, pair.getPublic()); - - if (!ecgost3410.verifySignature(hashmessage, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - /** - * Test Sign & Verify with C parameters - * see: http://www.ietf.org/internet-drafts/draft-popov-cryptopro-cpalgs-01.txt - * gostR3410-2001-CryptoPro-C-ParamSet P.48 - */ - private void ecGOST3410_CParam() - { - SecureRandom random = new SecureRandom(); - - BigInteger mod_p = new BigInteger("70390085352083305199547718019018437841079516630045180471284346843705633502619"); //p - BigInteger mod_q = new BigInteger("70390085352083305199547718019018437840920882647164081035322601458352298396601"); - - ECCurve.Fp curve = new ECCurve.Fp( - mod_p, // p - new BigInteger("70390085352083305199547718019018437841079516630045180471284346843705633502616"), // a - new BigInteger("32858"), // b - mod_q, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.createPoint( - new BigInteger("0"), // x - new BigInteger("29818893917731240733471273240314769927240550812383695689146495261604565990247")), // y - mod_q); - - ECKeyPairGenerator pGen = new ECKeyPairGenerator(); - ECKeyGenerationParameters genParam = new ECKeyGenerationParameters( - params, - random); - - pGen.init(genParam); - - AsymmetricCipherKeyPair pair = pGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - ECGOST3410Signer ecgost3410 = new ECGOST3410Signer(); - - ecgost3410.init(true, param); - - BigInteger[] sig = ecgost3410.generateSignature(hashmessage); - - ecgost3410.init(false, pair.getPublic()); - - if (!ecgost3410.verifySignature(hashmessage, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - public String getName() - { - return "ECGOST3410"; - } - - public void performTest() - { - ecGOST3410_TEST(); - ecGOST3410_TestParam(); - ecGOST3410_AParam(); - ecGOST3410_BParam(); - ecGOST3410_CParam(); - } - - public static void main( - String[] args) - { - runTest(new ECGOST3410Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECIESKeyEncapsulationTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECIESKeyEncapsulationTest.java deleted file mode 100644 index b70d66f95..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECIESKeyEncapsulationTest.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.asn1.sec.SECNamedCurves; -import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.generators.ECKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.KDF2BytesGenerator; -import com.fr.third.org.bouncycastle.crypto.kems.ECIESKeyEncapsulation; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Tests for the ECIES Key Encapsulation Mechanism - */ -public class ECIESKeyEncapsulationTest - extends SimpleTest -{ - public String getName() - { - return "ECIESKeyEncapsulation"; - } - - public void performTest() - throws Exception - { - - // Set EC domain parameters and generate key pair - X9ECParameters spec = SECNamedCurves.getByName("secp224r1"); - ECDomainParameters ecDomain = new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN()); - ECKeyPairGenerator ecGen = new ECKeyPairGenerator(); - - ecGen.init(new ECKeyGenerationParameters(ecDomain, new SecureRandom())); - - AsymmetricCipherKeyPair keys = ecGen.generateKeyPair(); - - // Set ECIES-KEM parameters - ECIESKeyEncapsulation kem; - KDF2BytesGenerator kdf = new KDF2BytesGenerator(new SHA1Digest()); - SecureRandom rnd = new SecureRandom(); - byte[] out = new byte[57]; - KeyParameter key1, key2; - - // Test basic ECIES-KEM - kem = new ECIESKeyEncapsulation(kdf, rnd); - - kem.init(keys.getPublic()); - key1 = (KeyParameter)kem.encrypt(out, 128); - - kem.init(keys.getPrivate()); - key2 = (KeyParameter)kem.decrypt(out, 128); - - if (!areEqual(key1.getKey(), key2.getKey())) - { - fail("failed basic test"); - } - - // Test ECIES-KEM using new cofactor mode - kem = new ECIESKeyEncapsulation(kdf, rnd, true, false, false); - - kem.init(keys.getPublic()); - key1 = (KeyParameter)kem.encrypt(out, 128); - - kem.init(keys.getPrivate()); - key2 = (KeyParameter)kem.decrypt(out, 128); - - if (!areEqual(key1.getKey(), key2.getKey())) - { - fail("failed cofactor test"); - } - - // Test ECIES-KEM using old cofactor mode - kem = new ECIESKeyEncapsulation(kdf, rnd, false, true, false); - - kem.init(keys.getPublic()); - key1 = (KeyParameter)kem.encrypt(out, 128); - - kem.init(keys.getPrivate()); - key2 = (KeyParameter)kem.decrypt(out, 128); - - if (!areEqual(key1.getKey(), key2.getKey())) - { - fail("failed old cofactor test"); - } - - // Test ECIES-KEM using single hash mode - kem = new ECIESKeyEncapsulation(kdf, rnd, false, false, true); - - kem.init(keys.getPublic()); - key1 = (KeyParameter)kem.encrypt(out, 128); - - kem.init(keys.getPrivate()); - key2 = (KeyParameter)kem.decrypt(out, 128); - - if (!areEqual(key1.getKey(), key2.getKey())) - { - fail("failed single hash test"); - } - - // Test ECIES-KEM using new cofactor mode and single hash mode - kem = new ECIESKeyEncapsulation(kdf, rnd, true, false, true); - - kem.init(keys.getPublic()); - key1 = (KeyParameter)kem.encrypt(out, 128); - - kem.init(keys.getPrivate()); - key2 = (KeyParameter)kem.decrypt(out, 128); - - if (!areEqual(key1.getKey(), key2.getKey())) - { - fail("failed cofactor and single hash test"); - } - - // Test ECIES-KEM using old cofactor mode and single hash mode - kem = new ECIESKeyEncapsulation(kdf, rnd, false, true, true); - - kem.init(keys.getPublic()); - key1 = (KeyParameter)kem.encrypt(out, 128); - - kem.init(keys.getPrivate()); - key2 = (KeyParameter)kem.decrypt(out, 128); - - if (!areEqual(key1.getKey(), key2.getKey())) - { - fail("failed old cofactor and single hash test"); - } - } - - public static void main( - String[] args) - { - runTest(new ECIESKeyEncapsulationTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECIESTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECIESTest.java deleted file mode 100644 index 3d8b66e9c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECIESTest.java +++ /dev/null @@ -1,545 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.x9.ECNamedCurveTable; -import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.BufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.KeyEncoder; -import com.fr.third.org.bouncycastle.crypto.KeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.agreement.ECDHBasicAgreement; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512Digest; -import com.fr.third.org.bouncycastle.crypto.engines.IESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.TwofishEngine; -import com.fr.third.org.bouncycastle.crypto.generators.ECKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.EphemeralKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.KDF2BytesGenerator; -import com.fr.third.org.bouncycastle.crypto.kems.ECIESKeyEncapsulation; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECNamedDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.IESParameters; -import com.fr.third.org.bouncycastle.crypto.params.IESWithCipherParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.crypto.parsers.ECIESPublicKeyParser; -import com.fr.third.org.bouncycastle.math.ec.ECConstants; -import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * test for ECIES - Elliptic Curve Integrated Encryption Scheme - */ -public class ECIESTest - extends SimpleTest -{ - private static byte[] TWOFISH_IV = Hex.decode("000102030405060708090a0b0c0d0e0f"); - - ECIESTest() - { - } - - public String getName() - { - return "ECIES"; - } - - private void doStaticTest(byte[] iv) - throws Exception - { - BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q - new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a - new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("651056770906015076056810763456358567190100156695615665659"), // d - params); - - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("0262b12d60690cdcf330babab6e69763b471f994dd702d16a5")), // Q - params); - - AsymmetricCipherKeyPair p1 = new AsymmetricCipherKeyPair(pubKey, priKey); - AsymmetricCipherKeyPair p2 = new AsymmetricCipherKeyPair(pubKey, priKey); - - // - // stream test - // - IESEngine i1 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest())); - IESEngine i2 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest())); - byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; - byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 }; - CipherParameters p = new IESParameters(d, e, 64); - - i1.init(true, p1.getPrivate(), p2.getPublic(), p); - i2.init(false, p2.getPrivate(), p1.getPublic(), p); - - byte[] message = Hex.decode("1234567890abcdef"); - - byte[] out1 = i1.processBlock(message, 0, message.length); - - if (!areEqual(out1, Hex.decode("468d89877e8238802403ec4cb6b329faeccfa6f3a730f2cdb3c0a8e8"))) - { - fail("stream cipher test failed on enc"); - } - - byte[] out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("stream cipher test failed"); - } - - // - // twofish with CBC - // - BufferedBlockCipher c1 = new PaddedBufferedBlockCipher( - new CBCBlockCipher(new TwofishEngine())); - BufferedBlockCipher c2 = new PaddedBufferedBlockCipher( - new CBCBlockCipher(new TwofishEngine())); - i1 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest()), - c1); - i2 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest()), - c2); - d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; - e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 }; - p = new IESWithCipherParameters(d, e, 64, 128); - - if (iv != null) - { - p = new ParametersWithIV(p, iv); - } - - i1.init(true, p1.getPrivate(), p2.getPublic(), p); - i2.init(false, p2.getPrivate(), p1.getPublic(), p); - - message = Hex.decode("1234567890abcdef"); - - out1 = i1.processBlock(message, 0, message.length); - - if (!areEqual(out1, (iv == null) ? - Hex.decode("b8a06ea5c2b9df28b58a0a90a734cde8c9c02903e5c220021fe4417410d1e53a32a71696") - : Hex.decode("f246b0e26a2711992cac9c590d08e45c5e730b7c0f4218bb064e27b7dd7c8a3bd8bf01c3"))) - { - fail("twofish cipher test failed on enc"); - } - - out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("twofish cipher test failed"); - } - } - - private void doShortTest(byte[] iv) - throws Exception - { - BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q - new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a - new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("651056770906015076056810763456358567190100156695615665659"), // d - params); - - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("0262b12d60690cdcf330babab6e69763b471f994dd702d16a5")), // Q - params); - - AsymmetricCipherKeyPair p1 = new AsymmetricCipherKeyPair(pubKey, priKey); - AsymmetricCipherKeyPair p2 = new AsymmetricCipherKeyPair(pubKey, priKey); - - // - // stream test - V 0 - // - IESEngine i1 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest())); - IESEngine i2 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest())); - byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; - byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 }; - CipherParameters p = new IESParameters(d, e, 64); - - i1.init(true, p1.getPrivate(), p2.getPublic(), p); - i2.init(false, p2.getPrivate(), p1.getPublic(), p); - - byte[] message = new byte[0]; - - byte[] out1 = i1.processBlock(message, 0, message.length); - - byte[] out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("stream cipher test failed"); - } - - try - { - i2.processBlock(out1, 0, out1.length - 1); - fail("no exception"); - } - catch (InvalidCipherTextException ex) - { - if (!"Length of input must be greater than the MAC and V combined".equals(ex.getMessage())) - { - fail("wrong exception"); - } - } - - // with ephemeral key pair - - // Generate the ephemeral key pair - ECKeyPairGenerator gen = new ECKeyPairGenerator(); - gen.init(new ECKeyGenerationParameters(params, new SecureRandom())); - - EphemeralKeyPairGenerator ephKeyGen = new EphemeralKeyPairGenerator(gen, new KeyEncoder() - { - public byte[] getEncoded(AsymmetricKeyParameter keyParameter) - { - return ((ECPublicKeyParameters)keyParameter).getQ().getEncoded(false); - } - }); - - i1.init(p2.getPublic(), p, ephKeyGen); - i2.init(p2.getPrivate(), p, new ECIESPublicKeyParser(params)); - - out1 = i1.processBlock(message, 0, message.length); - - out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("V cipher test failed"); - } - - try - { - i2.processBlock(out1, 0, out1.length - 1); - fail("no exception"); - } - catch (InvalidCipherTextException ex) - { - if (!"Length of input must be greater than the MAC and V combined".equals(ex.getMessage())) - { - fail("wrong exception"); - } - } - } - - private void doEphemeralTest(byte[] iv, final boolean usePointCompression) - throws Exception - { - BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q - new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a - new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("651056770906015076056810763456358567190100156695615665659"), // d - params); - - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("0262b12d60690cdcf330babab6e69763b471f994dd702d16a5")), // Q - params); - - AsymmetricCipherKeyPair p1 = new AsymmetricCipherKeyPair(pubKey, priKey); - AsymmetricCipherKeyPair p2 = new AsymmetricCipherKeyPair(pubKey, priKey); - - // Generate the ephemeral key pair - ECKeyPairGenerator gen = new ECKeyPairGenerator(); - gen.init(new ECKeyGenerationParameters(params, new SecureRandom())); - - EphemeralKeyPairGenerator ephKeyGen = new EphemeralKeyPairGenerator(gen, new KeyEncoder() - { - public byte[] getEncoded(AsymmetricKeyParameter keyParameter) - { - return ((ECPublicKeyParameters)keyParameter).getQ().getEncoded(usePointCompression); - } - }); - - // - // stream test - // - IESEngine i1 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest())); - IESEngine i2 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest())); - - byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; - byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 }; - CipherParameters p = new IESParameters(d, e, 64); - - i1.init(p2.getPublic(), p, ephKeyGen); - i2.init(p2.getPrivate(), p, new ECIESPublicKeyParser(params)); - - byte[] message = Hex.decode("1234567890abcdef"); - - byte[] out1 = i1.processBlock(message, 0, message.length); - - byte[] out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("stream cipher test failed"); - } - - // - // twofish with CBC - // - BufferedBlockCipher c1 = new PaddedBufferedBlockCipher( - new CBCBlockCipher(new TwofishEngine())); - BufferedBlockCipher c2 = new PaddedBufferedBlockCipher( - new CBCBlockCipher(new TwofishEngine())); - i1 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest()), - c1); - i2 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest()), - c2); - d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; - e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 }; - p = new IESWithCipherParameters(d, e, 64, 128); - - if (iv != null) - { - p = new ParametersWithIV(p, iv); - } - - i1.init(p2.getPublic(), p, ephKeyGen); - i2.init(p2.getPrivate(), p, new ECIESPublicKeyParser(params)); - - message = Hex.decode("1234567890abcdef"); - - out1 = i1.processBlock(message, 0, message.length); - - out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("twofish cipher test failed"); - } - } - - private void doTest(AsymmetricCipherKeyPair p1, AsymmetricCipherKeyPair p2) - throws Exception - { - // - // stream test - // - IESEngine i1 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest())); - IESEngine i2 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest())); - byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; - byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 }; - IESParameters p = new IESParameters(d, e, 64); - - i1.init(true, p1.getPrivate(), p2.getPublic(), p); - i2.init(false, p2.getPrivate(), p1.getPublic(), p); - - byte[] message = Hex.decode("1234567890abcdef"); - - byte[] out1 = i1.processBlock(message, 0, message.length); - - byte[] out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("stream cipher test failed"); - } - - // - // twofish with CBC - // - BufferedBlockCipher c1 = new PaddedBufferedBlockCipher( - new CBCBlockCipher(new TwofishEngine())); - BufferedBlockCipher c2 = new PaddedBufferedBlockCipher( - new CBCBlockCipher(new TwofishEngine())); - i1 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest()), - c1); - i2 = new IESEngine( - new ECDHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest()), - c2); - d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; - e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 }; - p = new IESWithCipherParameters(d, e, 64, 128); - - i1.init(true, p1.getPrivate(), p2.getPublic(), p); - i2.init(false, p2.getPrivate(), p1.getPublic(), p); - - message = Hex.decode("1234567890abcdef"); - - out1 = i1.processBlock(message, 0, message.length); - - out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("twofish cipher test failed"); - } - } - - public void performTest() - throws Exception - { - doStaticTest(null); - doStaticTest(TWOFISH_IV); - doShortTest(null); - - BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q - new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a - new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); - - ECKeyPairGenerator eGen = new ECKeyPairGenerator(); - KeyGenerationParameters gParam = new ECKeyGenerationParameters(params, new SecureRandom()); - - eGen.init(gParam); - - AsymmetricCipherKeyPair p1 = eGen.generateKeyPair(); - AsymmetricCipherKeyPair p2 = eGen.generateKeyPair(); - - doTest(p1, p2); - - doEphemeralTest(null, false); - doEphemeralTest(null, true); - doEphemeralTest(TWOFISH_IV, false); - doEphemeralTest(TWOFISH_IV, true); - - doCofactorTest(true, false); - doCofactorTest(false, false); - doCofactorTest(false, true); - doCofactorTest(true, true); - } - - private void doCofactorTest(boolean newCofactorMode, boolean oldCofactorMode) - { - - /* Create the generator */ - ECKeyPairGenerator myGenerator = new ECKeyPairGenerator(); - SecureRandom myRandom = new SecureRandom(); - String myCurve = "sect571k1"; /* Any curve will do */ - - /* Lookup the parameters */ - X9ECParameters x9 = ECNamedCurveTable.getByName(myCurve); - - /* Initialise the generator */ - ASN1ObjectIdentifier myOid = ECNamedCurveTable.getOID(myCurve); - ECNamedDomainParameters myDomain = new ECNamedDomainParameters(myOid, x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed()); - ECKeyGenerationParameters myParams = new ECKeyGenerationParameters(myDomain, myRandom); - myGenerator.init(myParams); - - /* Create the key Pair */ - AsymmetricCipherKeyPair myPair = myGenerator.generateKeyPair(); - - /* Determine message length */ - int myFieldSize = x9.getCurve().getFieldSize(); - myFieldSize = (myFieldSize + 8 - 1) / 8; - int myLen = 2 * myFieldSize + 1; - byte[] myMessage = new byte[myLen]; - int myKeyLen = 256 / 8; - - /* Create agreement */ - ECIESKeyEncapsulation myAgreement = new ECIESKeyEncapsulation(new KDF2BytesGenerator(new SHA512Digest()), myRandom, newCofactorMode, oldCofactorMode, false); - myAgreement.init(myPair.getPublic()); - KeyParameter mySender = (KeyParameter) myAgreement.encrypt(myMessage, myKeyLen); - byte[] mySenderKey = mySender.getKey(); - - /* Accept agreement */ - myAgreement.init(myPair.getPrivate()); - KeyParameter myReceiver = (KeyParameter) myAgreement.decrypt(myMessage, myKeyLen); - byte[] myReceiverKey = myReceiver.getKey(); - - /* Check that keys match */ - isTrue("new " + newCofactorMode + " old " + oldCofactorMode, Arrays.areEqual(mySenderKey, myReceiverKey)); - } - - public static void main( - String[] args) - { - runTest(new ECIESTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECNRTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECNRTest.java deleted file mode 100644 index a98e59785..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECNRTest.java +++ /dev/null @@ -1,168 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.x9.ECNamedCurveTable; -import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.TigerDigest; -import com.fr.third.org.bouncycastle.crypto.generators.ECKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECNamedDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.signers.ECNRSigner; -import com.fr.third.org.bouncycastle.math.ec.ECConstants; -import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.BigIntegers; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestRandomBigInteger; - -/** - * ECNR tests. - */ -public class ECNRTest - extends SimpleTest -{ - /** - * a basic regression test with 239 bit prime - */ - BigInteger r = new BigInteger("308636143175167811492623515537541734843573549327605293463169625072911693"); - BigInteger s = new BigInteger("852401710738814635664888632022555967400445256405412579597015412971797143"); - - byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("700000017569056646655505781757157107570501575775705779575555657156756655")); - - SecureRandom k = new TestRandomBigInteger(kData); - - private void ecNR239bitPrime() - { - BigInteger n = new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - n); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("876300101507107567501066130761671078357010671067781776716671676178726717"), // d - params); - - ECNRSigner ecnr = new ECNRSigner(); - ParametersWithRandom param = new ParametersWithRandom(priKey, k); - - ecnr.init(true, param); - - byte[] message = new BigInteger("968236873715988614170569073515315707566766479517").toByteArray(); - BigInteger[] sig = ecnr.generateSignature(message); - - if (!r.equals(sig[0])) - { - fail("r component wrong.", r, sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong.", s, sig[1]); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70")), // Q - params); - - ecnr.init(false, pubKey); - if (!ecnr.verifySignature(message, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - private void rangeTest() - { - /* Create the generator */ - ECKeyPairGenerator myGenerator = new ECKeyPairGenerator(); - SecureRandom myRandom = new SecureRandom(); - String myCurve = "brainpoolP192t1"; - - /* Lookup the parameters */ - final X9ECParameters x9 = ECNamedCurveTable.getByName(myCurve); - - /* Initialise the generator */ - final ASN1ObjectIdentifier myOid = ECNamedCurveTable.getOID(myCurve); - ECNamedDomainParameters myDomain = new ECNamedDomainParameters(myOid, x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed()); - ECKeyGenerationParameters myParams = new ECKeyGenerationParameters(myDomain, myRandom); - myGenerator.init(myParams); - - /* Create the key Pair */ - AsymmetricCipherKeyPair myPair = myGenerator.generateKeyPair(); - - /* Create the digest and the output buffer */ - Digest myDigest = new TigerDigest(); - byte[] myArtifact = new byte[myDigest.getDigestSize()]; - final byte[] myMessage = "Hello there. How is life treating you?".getBytes(); - myDigest.update(myMessage, 0, myMessage.length); - myDigest.doFinal(myArtifact, 0); - - /* Create signer */ - ECNRSigner signer = new ECNRSigner(); - signer.init(true, myPair.getPrivate()); - - try - { - signer.generateSignature(myArtifact); - fail("out of range input not caught"); - } - catch (DataLengthException e) - { - isTrue(e.getMessage().equals("input too large for ECNR key")); - } - - // - // check upper bound - BigInteger order = ((ECPublicKeyParameters)myPair.getPublic()).getParameters().getN(); - - signer.init(true, myPair.getPrivate()); - byte[] msg = BigIntegers.asUnsignedByteArray(order.subtract(BigIntegers.ONE)); - BigInteger[] sig = signer.generateSignature(msg); - - signer.init(false, myPair.getPublic()); - if (!signer.verifySignature(msg, sig[0], sig[1])) - { - fail("ECNR failed 2"); - } - - isTrue(Arrays.areEqual(msg, signer.getRecoveredMessage(sig[0], sig[1]))); - } - - public String getName() - { - return "ECNR"; - } - - public void performTest() - { - ecNR239bitPrime(); - rangeTest(); - } - - public static void main( - String[] args) - { - runTest(new ECNRTest()); - } -} - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECTest.java deleted file mode 100644 index 81123f3e3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ECTest.java +++ /dev/null @@ -1,1137 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.nist.NISTNamedCurves; -import com.fr.third.org.bouncycastle.asn1.sec.SECNamedCurves; -import com.fr.third.org.bouncycastle.asn1.x9.ECNamedCurveTable; -import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.BasicAgreement; -import com.fr.third.org.bouncycastle.crypto.agreement.ECDHBasicAgreement; -import com.fr.third.org.bouncycastle.crypto.agreement.ECDHCBasicAgreement; -import com.fr.third.org.bouncycastle.crypto.agreement.ECDHCUnifiedAgreement; -import com.fr.third.org.bouncycastle.crypto.agreement.ECMQVBasicAgreement; -import com.fr.third.org.bouncycastle.crypto.digests.SHA3Digest; -import com.fr.third.org.bouncycastle.crypto.ec.CustomNamedCurves; -import com.fr.third.org.bouncycastle.crypto.generators.ECKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ECDHUPrivateParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECDHUPublicParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.MQVPrivateParameters; -import com.fr.third.org.bouncycastle.crypto.params.MQVPublicParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.signers.DSADigestSigner; -import com.fr.third.org.bouncycastle.crypto.signers.ECDSASigner; -import com.fr.third.org.bouncycastle.math.ec.ECConstants; -import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.math.ec.ECPoint; -import com.fr.third.org.bouncycastle.util.BigIntegers; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestRandomBigInteger; - -/** - * ECDSA tests are taken from X9.62. - */ -public class ECTest - extends SimpleTest -{ - /** - * X9.62 - 1998,
- * J.3.1, Page 152, ECDSA over the field Fp
- * an example with 192 bit prime - */ - private void testECDSA192bitPrime() - { - BigInteger r = new BigInteger("3342403536405981729393488334694600415596881826869351677613"); - BigInteger s = new BigInteger("5735822328888155254683894997897571951568553642892029982342"); - - byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("6140507067065001063065065565667405560006161556565665656654")); - - SecureRandom k = new TestRandomBigInteger(kData); - - BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q - new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a - new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("651056770906015076056810763456358567190100156695615665659"), // d - params); - - ParametersWithRandom param = new ParametersWithRandom(priKey, k); - - ECDSASigner ecdsa = new ECDSASigner(); - - ecdsa.init(true, param); - - byte[] message = new BigInteger("968236873715988614170569073515315707566766479517").toByteArray(); - BigInteger[] sig = ecdsa.generateSignature(message); - - if (!r.equals(sig[0])) - { - fail("r component wrong." + Strings.lineSeparator() - + " expecting: " + r + Strings.lineSeparator() - + " got : " + sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong." + Strings.lineSeparator() - + " expecting: " + s + Strings.lineSeparator() - + " got : " + sig[1]); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("0262b12d60690cdcf330babab6e69763b471f994dd702d16a5")), // Q - params); - - ecdsa.init(false, pubKey); - if (!ecdsa.verifySignature(message, sig[0], sig[1])) - { - fail("verification fails"); - } - } - - private void decodeTest() - { - X9ECParameters x9 = ECNamedCurveTable.getByName("prime192v1"); - ECPoint p = x9.getG(); - - if (!p.getAffineXCoord().toBigInteger().equals(new BigInteger("188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012", 16))) - { - fail("x uncompressed incorrectly"); - } - - if (!p.getAffineYCoord().toBigInteger().equals(new BigInteger("7192b95ffc8da78631011ed6b24cdd573f977a11e794811", 16))) - { - fail("y uncompressed incorrectly"); - } - - byte[] encoding = p.getEncoded(true); - - if (!areEqual(encoding, Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012"))) - { - fail("point compressed incorrectly"); - } - } - - /** - * X9.62 - 1998,
- * J.3.2, Page 155, ECDSA over the field Fp
- * an example with 239 bit prime - */ - private void testECDSA239bitPrime() - { - BigInteger r = new BigInteger("308636143175167811492622547300668018854959378758531778147462058306432176"); - BigInteger s = new BigInteger("323813553209797357708078776831250505931891051755007842781978505179448783"); - - byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("700000017569056646655505781757157107570501575775705779575555657156756655")); - - SecureRandom k = new TestRandomBigInteger(kData); - - BigInteger n = new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - n); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("876300101507107567501066130761671078357010671067781776716671676178726717"), // d - params); - - ECDSASigner ecdsa = new ECDSASigner(); - ParametersWithRandom param = new ParametersWithRandom(priKey, k); - - ecdsa.init(true, param); - - byte[] message = new BigInteger("968236873715988614170569073515315707566766479517").toByteArray(); - BigInteger[] sig = ecdsa.generateSignature(message); - - if (!r.equals(sig[0])) - { - fail("r component wrong." + Strings.lineSeparator() - + " expecting: " + r + Strings.lineSeparator() - + " got : " + sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong." + Strings.lineSeparator() - + " expecting: " + s + Strings.lineSeparator() - + " got : " + sig[1]); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70")), // Q - params); - - ecdsa.init(false, pubKey); - if (!ecdsa.verifySignature(message, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - - /** - * X9.62 - 1998,
- * J.2.1, Page 100, ECDSA over the field F2m
- * an example with 191 bit binary field - */ - private void testECDSA191bitBinary() - { - BigInteger r = new BigInteger("87194383164871543355722284926904419997237591535066528048"); - BigInteger s = new BigInteger("308992691965804947361541664549085895292153777025772063598"); - - byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("1542725565216523985789236956265265265235675811949404040041")); - - SecureRandom k = new TestRandomBigInteger(kData); - - BigInteger n = new BigInteger("1569275433846670190958947355803350458831205595451630533029"); - BigInteger h = BigInteger.valueOf(2); - - ECCurve.F2m curve = new ECCurve.F2m( - 191, // m - 9, //k - new BigInteger("2866537B676752636A68F56554E12640276B649EF7526267", 16), // a - new BigInteger("2E45EF571F00786F67B0081B9495A3D95462F5DE0AA185EC", 16), // b - n, h); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("0436B3DAF8A23206F9C4F299D7B21A9C369137F2C84AE1AA0D765BE73433B3F95E332932E70EA245CA2418EA0EF98018FB")), // G - n, h); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("1275552191113212300012030439187146164646146646466749494799"), // d - params); - - ECDSASigner ecdsa = new ECDSASigner(); - ParametersWithRandom param = new ParametersWithRandom(priKey, k); - - ecdsa.init(true, param); - - byte[] message = new BigInteger("968236873715988614170569073515315707566766479517").toByteArray(); - BigInteger[] sig = ecdsa.generateSignature(message); - - if (!r.equals(sig[0])) - { - fail("r component wrong." + Strings.lineSeparator() - + " expecting: " + r + Strings.lineSeparator() - + " got : " + sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong." + Strings.lineSeparator() - + " expecting: " + s + Strings.lineSeparator() - + " got : " + sig[1]); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("045DE37E756BD55D72E3768CB396FFEB962614DEA4CE28A2E755C0E0E02F5FB132CAF416EF85B229BBB8E1352003125BA1")), // Q - params); - - ecdsa.init(false, pubKey); - if (!ecdsa.verifySignature(message, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - - /** - * X9.62 - 1998,
- * J.2.1, Page 100, ECDSA over the field F2m
- * an example with 191 bit binary field - */ - private void testECDSA239bitBinary() - { - BigInteger r = new BigInteger("21596333210419611985018340039034612628818151486841789642455876922391552"); - BigInteger s = new BigInteger("197030374000731686738334997654997227052849804072198819102649413465737174"); - - byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("171278725565216523967285789236956265265265235675811949404040041670216363")); - - SecureRandom k = new TestRandomBigInteger(kData); - - BigInteger n = new BigInteger("220855883097298041197912187592864814557886993776713230936715041207411783"); - BigInteger h = BigInteger.valueOf(4); - - ECCurve.F2m curve = new ECCurve.F2m( - 239, // m - 36, //k - new BigInteger("32010857077C5431123A46B808906756F543423E8D27877578125778AC76", 16), // a - new BigInteger("790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16", 16), // b - n, h); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305")), // G - n, h); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("145642755521911534651321230007534120304391871461646461466464667494947990"), // d - params); - - ECDSASigner ecdsa = new ECDSASigner(); - ParametersWithRandom param = new ParametersWithRandom(priKey, k); - - ecdsa.init(true, param); - - byte[] message = new BigInteger("968236873715988614170569073515315707566766479517").toByteArray(); - BigInteger[] sig = ecdsa.generateSignature(message); - - if (!r.equals(sig[0])) - { - fail("r component wrong." + Strings.lineSeparator() - + " expecting: " + r + Strings.lineSeparator() - + " got : " + sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong." + Strings.lineSeparator() - + " expecting: " + s + Strings.lineSeparator() - + " got : " + sig[1]); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5")), // Q - params); - - ecdsa.init(false, pubKey); - if (!ecdsa.verifySignature(message, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - // L 4.1 X9.62 2005 - private void testECDSAP224sha224() - { - X9ECParameters p = NISTNamedCurves.getByName("P-224"); - ECDomainParameters params = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()); - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("6081831502424510080126737029209236539191290354021104541805484120491"), // d - params); - SecureRandom k = new TestRandomBigInteger(BigIntegers.asUnsignedByteArray(new BigInteger("15456715103636396133226117016818339719732885723579037388121116732601"))); - - byte[] M = Hex.decode("8797A3C693CC292441039A4E6BAB7387F3B4F2A63D00ED384B378C79"); - - ECDSASigner dsa = new ECDSASigner(); - - dsa.init(true, new ParametersWithRandom(priKey, k)); - - BigInteger[] sig = dsa.generateSignature(M); - - BigInteger r = new BigInteger("26477406756127720855365980332052585411804331993436302005017227573742"); - BigInteger s = new BigInteger("17694958233103667059888193972742186995283044672015112738919822429978"); - - if (!r.equals(sig[0])) - { - fail("r component wrong." + Strings.lineSeparator() - + " expecting: " + r + Strings.lineSeparator() - + " got : " + sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong." + Strings.lineSeparator() - + " expecting: " + s + Strings.lineSeparator() - + " got : " + sig[1]); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - params.getCurve().decodePoint(Hex.decode("03FD44EC11F9D43D9D23B1E1D1C9ED6519B40ECF0C79F48CF476CC43F1")), // Q - params); - - dsa.init(false, pubKey); - if (!dsa.verifySignature(M, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - private void testECDSASecP224k1sha256() - { - X9ECParameters p = SECNamedCurves.getByName("secp224k1"); - ECDomainParameters params = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()); - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("BE6F6E91FE96840A6518B56F3FE21689903A64FA729057AB872A9F51", 16), // d - params); - SecureRandom k = new TestRandomBigInteger(Hex.decode("00c39beac93db21c3266084429eb9b846b787c094f23a4de66447efbb3")); - - byte[] M = Hex.decode("E5D5A7ADF73C5476FAEE93A2C76CE94DC0557DB04CDC189504779117920B896D"); - - ECDSASigner dsa = new ECDSASigner(); - - dsa.init(true, new ParametersWithRandom(priKey, k)); - - BigInteger[] sig = dsa.generateSignature(M); - - BigInteger r = new BigInteger("8163E5941BED41DA441B33E653C632A55A110893133351E20CE7CB75", 16); - BigInteger s = new BigInteger("D12C3FC289DDD5F6890DCE26B65792C8C50E68BF551D617D47DF15A8", 16); - - if (!r.equals(sig[0])) - { - fail("r component wrong." + Strings.lineSeparator() - + " expecting: " + r + Strings.lineSeparator() - + " got : " + sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong." + Strings.lineSeparator() - + " expecting: " + s + Strings.lineSeparator() - + " got : " + sig[1]); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - params.getCurve().decodePoint(Hex.decode("04C5C9B38D3603FCCD6994CBB9594E152B658721E483669BB42728520F484B537647EC816E58A8284D3B89DFEDB173AFDC214ECA95A836FA7C")), // Q - params); - - dsa.init(false, pubKey); - if (!dsa.verifySignature(M, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - // L4.2 X9.62 2005 - private void testECDSAP256sha256() - { - X9ECParameters p = NISTNamedCurves.getByName("P-256"); - ECDomainParameters params = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()); - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("20186677036482506117540275567393538695075300175221296989956723148347484984008"), // d - params); - SecureRandom k = new TestRandomBigInteger(BigIntegers.asUnsignedByteArray(new BigInteger("72546832179840998877302529996971396893172522460793442785601695562409154906335"))); - - byte[] M = Hex.decode("1BD4ED430B0F384B4E8D458EFF1A8A553286D7AC21CB2F6806172EF5F94A06AD"); - - ECDSASigner dsa = new ECDSASigner(); - - dsa.init(true, new ParametersWithRandom(priKey, k)); - - BigInteger[] sig = dsa.generateSignature(M); - - BigInteger r = new BigInteger("97354732615802252173078420023658453040116611318111190383344590814578738210384"); - BigInteger s = new BigInteger("98506158880355671805367324764306888225238061309262649376965428126566081727535"); - - if (!r.equals(sig[0])) - { - fail("r component wrong." + Strings.lineSeparator() - + " expecting: " + r + Strings.lineSeparator() - + " got : " + sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong." + Strings.lineSeparator() - + " expecting: " + s + Strings.lineSeparator() - + " got : " + sig[1]); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - params.getCurve().decodePoint(Hex.decode("03596375E6CE57E0F20294FC46BDFCFD19A39F8161B58695B3EC5B3D16427C274D")), // Q - params); - - dsa.init(false, pubKey); - if (!dsa.verifySignature(M, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - private void testECDSAP256sha3(int size, BigInteger s) - { - X9ECParameters p = NISTNamedCurves.getByName("P-256"); - ECDomainParameters params = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()); - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("20186677036482506117540275567393538695075300175221296989956723148347484984008"), // d - params); - SecureRandom k = new TestRandomBigInteger(BigIntegers.asUnsignedByteArray(new BigInteger("72546832179840998877302529996971396893172522460793442785601695562409154906335"))); - - byte[] M = Hex.decode("1BD4ED430B0F384B4E8D458EFF1A8A553286D7AC21CB2F6806172EF5F94A06AD"); - - DSADigestSigner dsa = new DSADigestSigner(new ECDSASigner(), new SHA3Digest(size)); - - dsa.init(true, new ParametersWithRandom(priKey, k)); - - dsa.update(M, 0, M.length); - - byte[] encSig = dsa.generateSignature(); - - ASN1Sequence sig = ASN1Sequence.getInstance(encSig); - - BigInteger r = new BigInteger("97354732615802252173078420023658453040116611318111190383344590814578738210384"); - - BigInteger sigR = ASN1Integer.getInstance(sig.getObjectAt(0)).getValue(); - if (!r.equals(sigR)) - { - fail("r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sigR.toString(16)); - } - - BigInteger sigS = ASN1Integer.getInstance(sig.getObjectAt(1)).getValue(); - if (!s.equals(sigS)) - { - fail("s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sigS.toString(16)); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - params.getCurve().decodePoint(Hex.decode("03596375E6CE57E0F20294FC46BDFCFD19A39F8161B58695B3EC5B3D16427C274D")), // Q - params); - - dsa.init(false, pubKey); - - dsa.update(M, 0, M.length); - - if (!dsa.verifySignature(encSig)) - { - fail("signature fails"); - } - } - - private void testECDSAP224OneByteOver() - { - X9ECParameters p = NISTNamedCurves.getByName("P-224"); - ECDomainParameters params = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()); - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("6081831502424510080126737029209236539191290354021104541805484120491"), // d - params); - SecureRandom k = new TestRandomBigInteger(BigIntegers.asUnsignedByteArray(new BigInteger("15456715103636396133226117016818339719732885723579037388121116732601"))); - - byte[] M = Hex.decode("8797A3C693CC292441039A4E6BAB7387F3B4F2A63D00ED384B378C79FF"); - - ECDSASigner dsa = new ECDSASigner(); - - dsa.init(true, new ParametersWithRandom(priKey, k)); - - BigInteger[] sig = dsa.generateSignature(M); - - BigInteger r = new BigInteger("26477406756127720855365980332052585411804331993436302005017227573742"); - BigInteger s = new BigInteger("17694958233103667059888193972742186995283044672015112738919822429978"); - - if (!r.equals(sig[0])) - { - fail("r component wrong." + Strings.lineSeparator() - + " expecting: " + r + Strings.lineSeparator() - + " got : " + sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong." + Strings.lineSeparator() - + " expecting: " + s + Strings.lineSeparator() - + " got : " + sig[1]); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - params.getCurve().decodePoint(Hex.decode("03FD44EC11F9D43D9D23B1E1D1C9ED6519B40ECF0C79F48CF476CC43F1")), // Q - params); - - dsa.init(false, pubKey); - if (!dsa.verifySignature(M, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - // L4.3 X9.62 2005 - private void testECDSAP521sha512() - { - X9ECParameters p = NISTNamedCurves.getByName("P-521"); - ECDomainParameters params = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()); - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("617573726813476282316253885608633222275541026607493641741273231656161177732180358888434629562647985511298272498852936680947729040673640492310550142822667389"), // d - params); - SecureRandom k = new TestRandomBigInteger(BigIntegers.asUnsignedByteArray(new BigInteger("6806532878215503520845109818432174847616958675335397773700324097584974639728725689481598054743894544060040710846048585856076812050552869216017728862957612913"))); - - byte[] M = Hex.decode("6893B64BD3A9615C39C3E62DDD269C2BAAF1D85915526083183CE14C2E883B48B193607C1ED871852C9DF9C3147B574DC1526C55DE1FE263A676346A20028A66"); - - ECDSASigner dsa = new ECDSASigner(); - - dsa.init(true, new ParametersWithRandom(priKey, k)); - - BigInteger[] sig = dsa.generateSignature(M); - - BigInteger r = new BigInteger("1368926195812127407956140744722257403535864168182534321188553460365652865686040549247096155740756318290773648848859639978618869784291633651685766829574104630"); - BigInteger s = new BigInteger("1624754720348883715608122151214003032398685415003935734485445999065609979304811509538477657407457976246218976767156629169821116579317401249024208611945405790"); - - if (!r.equals(sig[0])) - { - fail("r component wrong." + Strings.lineSeparator() - + " expecting: " + r + Strings.lineSeparator() - + " got : " + sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong." + Strings.lineSeparator() - + " expecting: " + s + Strings.lineSeparator() - + " got : " + sig[1]); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - params.getCurve().decodePoint(Hex.decode("020145E221AB9F71C5FE740D8D2B94939A09E2816E2167A7D058125A06A80C014F553E8D6764B048FB6F2B687CEC72F39738F223D4CE6AFCBFF2E34774AA5D3C342CB3")), // Q - params); - - dsa.init(false, pubKey); - if (!dsa.verifySignature(M, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - /** - * General test for long digest. - */ - private void testECDSA239bitBinaryAndLargeDigest() - { - BigInteger r = new BigInteger("21596333210419611985018340039034612628818151486841789642455876922391552"); - BigInteger s = new BigInteger("144940322424411242416373536877786566515839911620497068645600824084578597"); - - byte[] kData = BigIntegers.asUnsignedByteArray(new BigInteger("171278725565216523967285789236956265265265235675811949404040041670216363")); - - SecureRandom k = new TestRandomBigInteger(kData); - - BigInteger n = new BigInteger("220855883097298041197912187592864814557886993776713230936715041207411783"); - BigInteger h = BigInteger.valueOf(4); - - ECCurve.F2m curve = new ECCurve.F2m( - 239, // m - 36, //k - new BigInteger("32010857077C5431123A46B808906756F543423E8D27877578125778AC76", 16), // a - new BigInteger("790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16", 16), // b - n, h); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305")), // G - n, h); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("145642755521911534651321230007534120304391871461646461466464667494947990"), // d - params); - - ECDSASigner ecdsa = new ECDSASigner(); - ParametersWithRandom param = new ParametersWithRandom(priKey, k); - - ecdsa.init(true, param); - - byte[] message = new BigInteger("968236873715988614170569073515315707566766479517968236873715988614170569073515315707566766479517968236873715988614170569073515315707566766479517").toByteArray(); - BigInteger[] sig = ecdsa.generateSignature(message); - - if (!r.equals(sig[0])) - { - fail("r component wrong." + Strings.lineSeparator() - + " expecting: " + r + Strings.lineSeparator() - + " got : " + sig[0]); - } - - if (!s.equals(sig[1])) - { - fail("s component wrong." + Strings.lineSeparator() - + " expecting: " + s + Strings.lineSeparator() - + " got : " + sig[1]); - } - - // Verify the signature - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5")), // Q - params); - - ecdsa.init(false, pubKey); - if (!ecdsa.verifySignature(message, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - /** - * key generation test - */ - private void testECDSAKeyGenTest() - { - SecureRandom random = new SecureRandom(); - - BigInteger n = new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - n); - - ECKeyPairGenerator pGen = new ECKeyPairGenerator(); - ECKeyGenerationParameters genParam = new ECKeyGenerationParameters( - params, - random); - - pGen.init(genParam); - - AsymmetricCipherKeyPair pair = pGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - ECDSASigner ecdsa = new ECDSASigner(); - - ecdsa.init(true, param); - - byte[] message = new BigInteger("968236873715988614170569073515315707566766479517").toByteArray(); - BigInteger[] sig = ecdsa.generateSignature(message); - - ecdsa.init(false, pair.getPublic()); - - if (!ecdsa.verifySignature(message, sig[0], sig[1])) - { - fail("signature fails"); - } - } - - /** - * Basic Key Agreement Test - */ - private void testECDHBasicAgreement() - { - SecureRandom random = new SecureRandom(); - - BigInteger n = new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - n); - - ECKeyPairGenerator pGen = new ECKeyPairGenerator(); - ECKeyGenerationParameters genParam = new ECKeyGenerationParameters( - params, - random); - - pGen.init(genParam); - - AsymmetricCipherKeyPair p1 = pGen.generateKeyPair(); - AsymmetricCipherKeyPair p2 = pGen.generateKeyPair(); - - // - // two way - // - BasicAgreement e1 = new ECDHBasicAgreement(); - BasicAgreement e2 = new ECDHBasicAgreement(); - - e1.init(p1.getPrivate()); - e2.init(p2.getPrivate()); - - BigInteger k1 = e1.calculateAgreement(p2.getPublic()); - BigInteger k2 = e2.calculateAgreement(p1.getPublic()); - - if (!k1.equals(k2)) - { - fail("calculated agreement test failed"); - } - - // - // two way - // - e1 = new ECDHCBasicAgreement(); - e2 = new ECDHCBasicAgreement(); - - e1.init(p1.getPrivate()); - e2.init(p2.getPrivate()); - - k1 = e1.calculateAgreement(p2.getPublic()); - k2 = e2.calculateAgreement(p1.getPublic()); - - if (!k1.equals(k2)) - { - fail("calculated agreement test failed"); - } - } - - private void testECDHBasicAgreementCofactor() - { - SecureRandom random = new SecureRandom(); - - X9ECParameters x9 = CustomNamedCurves.getByName("curve25519"); - ECDomainParameters ec = new ECDomainParameters(x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed()); - - ECKeyPairGenerator kpg = new ECKeyPairGenerator(); - kpg.init(new ECKeyGenerationParameters(ec, random)); - - AsymmetricCipherKeyPair p1 = kpg.generateKeyPair(); - AsymmetricCipherKeyPair p2 = kpg.generateKeyPair(); - - BasicAgreement e1 = new ECDHBasicAgreement(); - BasicAgreement e2 = new ECDHBasicAgreement(); - - e1.init(p1.getPrivate()); - e2.init(p2.getPrivate()); - - BigInteger k1 = e1.calculateAgreement(p2.getPublic()); - BigInteger k2 = e2.calculateAgreement(p1.getPublic()); - - if (!k1.equals(k2)) - { - fail("calculated agreement test failed"); - } - } - - private void testECMQVTestVector1() - { - // Test Vector from GEC-2 - - X9ECParameters x9 = SECNamedCurves.getByName("secp160r1"); - ECDomainParameters p = new ECDomainParameters( - x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed()); - - AsymmetricCipherKeyPair U1 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("0251B4496FECC406ED0E75A24A3C03206251419DC0")), p), - new ECPrivateKeyParameters( - new BigInteger("AA374FFC3CE144E6B073307972CB6D57B2A4E982", 16), p)); - - AsymmetricCipherKeyPair U2 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("03D99CE4D8BF52FA20BD21A962C6556B0F71F4CA1F")), p), - new ECPrivateKeyParameters( - new BigInteger("149EC7EA3A220A887619B3F9E5B4CA51C7D1779C", 16), p)); - - AsymmetricCipherKeyPair V1 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("0349B41E0E9C0369C2328739D90F63D56707C6E5BC")), p), - new ECPrivateKeyParameters( - new BigInteger("45FB58A92A17AD4B15101C66E74F277E2B460866", 16), p)); - - AsymmetricCipherKeyPair V2 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("02706E5D6E1F640C6E9C804E75DBC14521B1E5F3B5")), p), - new ECPrivateKeyParameters( - new BigInteger("18C13FCED9EADF884F7C595C8CB565DEFD0CB41E", 16), p)); - - BigInteger x = calculateAgreement(U1, U2, V1, V2); - - if (x == null - || !x.equals(new BigInteger("5A6955CEFDB4E43255FB7FCF718611E4DF8E05AC", 16))) - { - fail("MQV Test Vector #1 agreement failed"); - } - } - - private void testECMQVTestVector2() - { - // Test Vector from GEC-2 - - X9ECParameters x9 = SECNamedCurves.getByName("sect163k1"); - ECDomainParameters p = new ECDomainParameters( - x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed()); - - AsymmetricCipherKeyPair U1 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("03037D529FA37E42195F10111127FFB2BB38644806BC")), p), - new ECPrivateKeyParameters( - new BigInteger("03A41434AA99C2EF40C8495B2ED9739CB2155A1E0D", 16), p)); - - AsymmetricCipherKeyPair U2 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("02015198E74BC2F1E5C9A62B80248DF0D62B9ADF8429")), p), - new ECPrivateKeyParameters( - new BigInteger("032FC4C61A8211E6A7C4B8B0C03CF35F7CF20DBD52", 16), p)); - - AsymmetricCipherKeyPair V1 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("03072783FAAB9549002B4F13140B88132D1C75B3886C")), p), - new ECPrivateKeyParameters( - new BigInteger("57E8A78E842BF4ACD5C315AA0569DB1703541D96", 16), p)); - - AsymmetricCipherKeyPair V2 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("03067E3AEA3510D69E8EDD19CB2A703DDC6CF5E56E32")), p), - new ECPrivateKeyParameters( - new BigInteger("02BD198B83A667A8D908EA1E6F90FD5C6D695DE94F", 16), p)); - - BigInteger x = calculateAgreement(U1, U2, V1, V2); - - if (x == null - || !x.equals(new BigInteger("038359FFD30C0D5FC1E6154F483B73D43E5CF2B503", 16))) - { - fail("MQV Test Vector #2 agreement failed"); - } - } - - private void testECMQVRandom() - { - SecureRandom random = new SecureRandom(); - - BigInteger n = new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16), // b - n, ECConstants.ONE); - - ECDomainParameters parameters = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - n); - - ECKeyPairGenerator pGen = new ECKeyPairGenerator(); - - pGen.init(new ECKeyGenerationParameters(parameters, random)); - - - // Pre-established key pairs - AsymmetricCipherKeyPair U1 = pGen.generateKeyPair(); - AsymmetricCipherKeyPair V1 = pGen.generateKeyPair(); - - // Ephemeral key pairs - AsymmetricCipherKeyPair U2 = pGen.generateKeyPair(); - AsymmetricCipherKeyPair V2 = pGen.generateKeyPair(); - - BigInteger x = calculateAgreement(U1, U2, V1, V2); - - if (x == null) - { - fail("MQV Test Vector (random) agreement failed"); - } - } - - private static BigInteger calculateAgreement( - AsymmetricCipherKeyPair U1, - AsymmetricCipherKeyPair U2, - AsymmetricCipherKeyPair V1, - AsymmetricCipherKeyPair V2) - { - ECMQVBasicAgreement u = new ECMQVBasicAgreement(); - u.init(new MQVPrivateParameters( - (ECPrivateKeyParameters)U1.getPrivate(), - (ECPrivateKeyParameters)U2.getPrivate(), - (ECPublicKeyParameters)U2.getPublic())); - BigInteger ux = u.calculateAgreement(new MQVPublicParameters( - (ECPublicKeyParameters)V1.getPublic(), - (ECPublicKeyParameters)V2.getPublic())); - - ECMQVBasicAgreement v = new ECMQVBasicAgreement(); - v.init(new MQVPrivateParameters( - (ECPrivateKeyParameters)V1.getPrivate(), - (ECPrivateKeyParameters)V2.getPrivate(), - (ECPublicKeyParameters)V2.getPublic())); - BigInteger vx = v.calculateAgreement(new MQVPublicParameters( - (ECPublicKeyParameters)U1.getPublic(), - (ECPublicKeyParameters)U2.getPublic())); - - if (ux.equals(vx)) - { - return ux; - } - - return null; - } - - private void testECUnifiedTestVector1() - { - // Test Vector from NIST sample data - - X9ECParameters x9 = NISTNamedCurves.getByName("P-224"); - ECDomainParameters p = new ECDomainParameters( - x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed()); - - AsymmetricCipherKeyPair U1 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("040784e946ef1fae0cfe127042a310a018ba639d3f6b41f265904f0a7b21b7953efe638b45e6c0c0d34a883a510ce836d143d831daa9ce8a12")), p), - new ECPrivateKeyParameters( - new BigInteger("86d1735ca357890aeec8eccb4859275151356ecee9f1b2effb76b092", 16), p)); - - AsymmetricCipherKeyPair U2 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("04b33713dc0d56215be26ee6c5e60ad36d12e02e78529ae3ff07873c6b39598bda41c1cf86ee3981f40e102333c15fef214bda034291c1aca6")), p), - new ECPrivateKeyParameters( - new BigInteger("764010b3137ef8d34a3552955ada572a4fa1bb1f5289f27c1bf18344", 16), p)); - - AsymmetricCipherKeyPair V1 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("0484c22d9575d09e280613c8758467f84869c6eede4f6c1b644517d6a72c4fc5c68fa12b4c259032fc5949c630259948fca38fb3342d9cb0a8")), p), - new ECPrivateKeyParameters( - new BigInteger("e37964e391f5058fb43435352a9913438a1ec10831f755273285230a", 16), p)); - - AsymmetricCipherKeyPair V2 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("044b917e9ce693b277c8095e535ea81c2dea089446a8c55438eda750fb6170c85b86390481fff2dff94b7dff3e42d35ff623921cb558967b48")), p), - new ECPrivateKeyParameters( - new BigInteger("ab40d67f59ba7265d8ad33ade8f704d13a7ba2298b69172a7cd02515", 16), p)); - - byte[] x = calculateUnifiedAgreement(U1, U2, V1, V2); - - if (x == null - || !areEqual(Hex.decode("80315a208b1cd6119264e5c03242b7db96379986fdc4c2f06bf88d0655cda75d4dc7e94a8df9f03239d5da9a18d364cebc6c63f01b6f4378"), x)) - { - fail("EC combined Test Vector #1 agreement failed"); - } - } - - private void testECUnifiedTestVector2() - { - // Test Vector from NIST sample data - - X9ECParameters x9 = NISTNamedCurves.getByName("P-256"); - ECDomainParameters p = new ECDomainParameters( - x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed()); - - AsymmetricCipherKeyPair U1 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("047581b35964a983414ebdd56f4ebb1ddcad10881b200666a51ae41306e1ecf1db368468a5e8a65ca10ccea526472c8982db68316c468800e171c11f4ee694fce4")), p), - new ECPrivateKeyParameters( - new BigInteger("2eb7ef76d4936123b6f13035045aedf45c1c7731f35d529d25941926b5bb38bb", 16), p)); - - AsymmetricCipherKeyPair U2 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("045b1e4cdeb0728333c0a51631b1a75269e4878d10732f4cb94d600483db4bd9ee625c374592c3db7e9f8b4f2c91a0098a158bc37b922e4243bd9cbdefe67d6ab0")), p), - new ECPrivateKeyParameters( - new BigInteger("78acde388a022261767e6b3dd6dd016c53b70a084260ec87d395aec761c082de", 16), p)); - - AsymmetricCipherKeyPair V1 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("04e4916d616803ff1bd9569f35b7d06f792f19c1fb4e6fa916d686c027a17d8dffd570193d8e101624ac2ea0bcb762d5613f05452670f09af66ef70861fb528868")), p), - new ECPrivateKeyParameters( - new BigInteger("9c85898640a1b1de8ce7f557492dc1460530b9e17afaaf742eb953bb644e9c5a", 16), p)); - - AsymmetricCipherKeyPair V2 = new AsymmetricCipherKeyPair( - new ECPublicKeyParameters( - p.getCurve().decodePoint(Hex.decode("04d1cd23c29d0fc865c316d44a1fd5adb6605ee47c9ddfec3a9b0a5e532d52704e74ff5d149aeb50856fefb38d5907b6dbb580fe6dc166bcfcbee4eb376d77e95c")), p), - new ECPrivateKeyParameters( - new BigInteger("d6e11d5d3b85b201b8f4c12dadfad3000e267961a806a0658a2b859d44389599", 16), p)); - - byte[] x = calculateUnifiedAgreement(U1, U2, V1, V2); - - if (x == null - || !areEqual(Hex.decode("02886e53998b06d92f04e4579cbfa5f35c96334d3890298264e7f956da70966af07bf1b3abbaa8d76fbaf435508bdabbbbbdae1a191d91480ed88374c3552233"), x)) - { - fail("EC combined Test Vector #2 agreement failed"); - } - } - - private byte[] calculateUnifiedAgreement( - AsymmetricCipherKeyPair U1, - AsymmetricCipherKeyPair U2, - AsymmetricCipherKeyPair V1, - AsymmetricCipherKeyPair V2) - { - ECDHCUnifiedAgreement u = new ECDHCUnifiedAgreement(); - u.init(new ECDHUPrivateParameters( - (ECPrivateKeyParameters)U1.getPrivate(), - (ECPrivateKeyParameters)U2.getPrivate(), - (ECPublicKeyParameters)U2.getPublic())); - byte[] ux = u.calculateAgreement(new ECDHUPublicParameters( - (ECPublicKeyParameters)V1.getPublic(), - (ECPublicKeyParameters)V2.getPublic())); - - ECDHCUnifiedAgreement v = new ECDHCUnifiedAgreement(); - v.init(new ECDHUPrivateParameters( - (ECPrivateKeyParameters)V1.getPrivate(), - (ECPrivateKeyParameters)V2.getPrivate(), - (ECPublicKeyParameters)V2.getPublic())); - byte[] vx = v.calculateAgreement(new ECDHUPublicParameters( - (ECPublicKeyParameters)U1.getPublic(), - (ECPublicKeyParameters)U2.getPublic())); - - if (areEqual(ux, vx)) - { - return ux; - } - - return null; - } - - public String getName() - { - return "EC"; - } - - public void performTest() - { - decodeTest(); - testECDSA192bitPrime(); - testECDSA239bitPrime(); - testECDSA191bitBinary(); - testECDSA239bitBinary(); - testECDSAKeyGenTest(); - testECDHBasicAgreement(); - testECDHBasicAgreementCofactor(); - - testECDSAP224sha224(); - testECDSAP224OneByteOver(); - testECDSAP256sha256(); - testECDSAP521sha512(); - testECDSASecP224k1sha256(); - testECDSA239bitBinaryAndLargeDigest(); - - testECDSAP256sha3(224, new BigInteger("84d7d8e68e405064109cd9fc3e3026d74d278aada14ce6b7a9dd0380c154dc94", 16)); - testECDSAP256sha3(256, new BigInteger("99a43bdab4af989aaf2899079375642f2bae2dce05bcd8b72ec8c4a8d9a143f", 16)); - testECDSAP256sha3(384, new BigInteger("aa27726509c37aaf601de6f7e01e11c19add99530c9848381c23365dc505b11a", 16)); - testECDSAP256sha3(512, new BigInteger("f8306b57a1f5068bf12e53aabaae39e2658db39bc56747eaefb479995130ad16", 16)); - - testECMQVTestVector1(); - testECMQVTestVector2(); - testECMQVRandom(); - - testECUnifiedTestVector1(); - testECUnifiedTestVector2(); - } - - - public static void main( - String[] args) - { - runTest(new ECTest()); - } -} - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Ed25519Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Ed25519Test.java deleted file mode 100644 index 5d056f56d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Ed25519Test.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.Signer; -import com.fr.third.org.bouncycastle.crypto.generators.Ed25519KeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.Ed25519KeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.Ed25519PublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.signers.Ed25519Signer; -import com.fr.third.org.bouncycastle.crypto.signers.Ed25519ctxSigner; -import com.fr.third.org.bouncycastle.crypto.signers.Ed25519phSigner; -import com.fr.third.org.bouncycastle.math.ec.rfc8032.Ed25519; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class Ed25519Test - extends SimpleTest -{ - private static final SecureRandom RANDOM = new SecureRandom(); - - public String getName() - { - return "Ed25519"; - } - - public static void main(String[] args) - { - runTest(new Ed25519Test()); - } - - public void performTest() throws Exception - { - for (int i = 0; i < 10; ++i) - { - testConsistency(Ed25519.Algorithm.Ed25519, null); - - byte[] context = randomContext(RANDOM.nextInt() & 255); - testConsistency(Ed25519.Algorithm.Ed25519ctx, context); - testConsistency(Ed25519.Algorithm.Ed25519ph, context); - } - - basicSigTest(); - } - - private void basicSigTest() - throws Exception - { - Ed25519PrivateKeyParameters privateKey = new Ed25519PrivateKeyParameters( - Hex.decode("9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"), 0); - Ed25519PublicKeyParameters publicKey = new Ed25519PublicKeyParameters( - Hex.decode("d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a"), 0); - - byte[] sig = Hex.decode("e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b"); - - Signer signer = new Ed25519Signer(); - - signer.init(true, privateKey); - - areEqual(sig, signer.generateSignature()); - - signer.init(false, publicKey); - - isTrue(signer.verifySignature(sig)); - } - - private Signer createSigner(int algorithm, byte[] context) - { - switch (algorithm) - { - case Ed25519.Algorithm.Ed25519: - return new Ed25519Signer(); - case Ed25519.Algorithm.Ed25519ctx: - return new Ed25519ctxSigner(context); - case Ed25519.Algorithm.Ed25519ph: - return new Ed25519phSigner(context); - default: - throw new IllegalArgumentException("algorithm"); - } - } - - private byte[] randomContext(int length) - { - byte[] context = new byte[length]; - RANDOM.nextBytes(context); - return context; - } - - private void testConsistency(int algorithm, byte[] context) throws Exception - { - Ed25519KeyPairGenerator kpg = new Ed25519KeyPairGenerator(); - kpg.init(new Ed25519KeyGenerationParameters(RANDOM)); - - AsymmetricCipherKeyPair kp = kpg.generateKeyPair(); - Ed25519PrivateKeyParameters privateKey = (Ed25519PrivateKeyParameters)kp.getPrivate(); - Ed25519PublicKeyParameters publicKey = (Ed25519PublicKeyParameters)kp.getPublic(); - - byte[] msg = new byte[RANDOM.nextInt() & 255]; - RANDOM.nextBytes(msg); - - Signer signer = createSigner(algorithm, context); - signer.init(true, privateKey); - signer.update(msg, 0, msg.length); - byte[] signature = signer.generateSignature(); - - Signer verifier = createSigner(algorithm, context); - - { - verifier.init(false, publicKey); - verifier.update(msg, 0, msg.length); - boolean shouldVerify = verifier.verifySignature(signature); - - if (!shouldVerify) - { - fail("Ed25519(" + algorithm + ") signature failed to verify"); - } - } - - { - byte[] wrongLengthSignature = Arrays.append(signature, (byte)0x00); - - verifier.init(false, publicKey); - verifier.update(msg, 0, msg.length); - boolean shouldNotVerify = verifier.verifySignature(wrongLengthSignature); - - if (shouldNotVerify) - { - fail("Ed25519(" + algorithm + ") wrong length signature incorrectly verified"); - } - } - - { - byte[] badSignature = Arrays.clone(signature); - badSignature[(RANDOM.nextInt() >>> 1) % badSignature.length] ^= 1 << (RANDOM.nextInt() & 7); - - verifier.init(false, publicKey); - verifier.update(msg, 0, msg.length); - boolean shouldNotVerify = verifier.verifySignature(badSignature); - - if (shouldNotVerify) - { - fail("Ed25519(" + algorithm + ") bad signature incorrectly verified"); - } - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Ed448Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Ed448Test.java deleted file mode 100644 index dfa8e3322..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Ed448Test.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.Signer; -import com.fr.third.org.bouncycastle.crypto.generators.Ed448KeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.Ed448KeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.Ed448PrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.Ed448PublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.signers.Ed448Signer; -import com.fr.third.org.bouncycastle.crypto.signers.Ed448phSigner; -import com.fr.third.org.bouncycastle.math.ec.rfc8032.Ed448; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class Ed448Test - extends SimpleTest -{ - private static final SecureRandom RANDOM = new SecureRandom(); - - public String getName() - { - return "Ed448"; - } - - public static void main(String[] args) - { - runTest(new Ed448Test()); - } - - public void performTest() throws Exception - { - basicSigTest(); - - for (int i = 0; i < 10; ++i) - { - byte[] context = randomContext(RANDOM.nextInt() & 255); - testConsistency(Ed448.Algorithm.Ed448, context); - testConsistency(Ed448.Algorithm.Ed448ph, context); - } - } - - private void basicSigTest() - throws Exception - { - Ed448PrivateKeyParameters privateKey = new Ed448PrivateKeyParameters( - Hex.decode( - "6c82a562cb808d10d632be89c8513ebf" + - "6c929f34ddfa8c9f63c9960ef6e348a3" + - "528c8a3fcc2f044e39a3fc5b94492f8f" + - "032e7549a20098f95b"), 0); - Ed448PublicKeyParameters publicKey = new Ed448PublicKeyParameters( - Hex.decode("5fd7449b59b461fd2ce787ec616ad46a" + - "1da1342485a70e1f8a0ea75d80e96778" + - "edf124769b46c7061bd6783df1e50f6c" + - "d1fa1abeafe8256180"), 0); - - byte[] sig = Hex.decode("533a37f6bbe457251f023c0d88f976ae" + - "2dfb504a843e34d2074fd823d41a591f" + - "2b233f034f628281f2fd7a22ddd47d78" + - "28c59bd0a21bfd3980ff0d2028d4b18a" + - "9df63e006c5d1c2d345b925d8dc00b41" + - "04852db99ac5c7cdda8530a113a0f4db" + - "b61149f05a7363268c71d95808ff2e65" + - "2600"); - - Signer signer = new Ed448Signer(new byte[0]); - - signer.init(true, privateKey); - - areEqual(sig, signer.generateSignature()); - - signer.init(false, publicKey); - - isTrue(signer.verifySignature(sig)); - } - - private Signer createSigner(int algorithm, byte[] context) - { - switch (algorithm) - { - case Ed448.Algorithm.Ed448: - return new Ed448Signer(context); - case Ed448.Algorithm.Ed448ph: - return new Ed448phSigner(context); - default: - throw new IllegalArgumentException("algorithm"); - } - } - - private byte[] randomContext(int length) - { - byte[] context = new byte[length]; - RANDOM.nextBytes(context); - return context; - } - - private void testConsistency(int algorithm, byte[] context) throws Exception - { - Ed448KeyPairGenerator kpg = new Ed448KeyPairGenerator(); - kpg.init(new Ed448KeyGenerationParameters(RANDOM)); - - AsymmetricCipherKeyPair kp = kpg.generateKeyPair(); - Ed448PrivateKeyParameters privateKey = (Ed448PrivateKeyParameters)kp.getPrivate(); - Ed448PublicKeyParameters publicKey = (Ed448PublicKeyParameters)kp.getPublic(); - - byte[] msg = new byte[RANDOM.nextInt() & 255]; - RANDOM.nextBytes(msg); - - Signer signer = createSigner(algorithm, context); - signer.init(true, privateKey); - signer.update(msg, 0, msg.length); - byte[] signature = signer.generateSignature(); - - Signer verifier = createSigner(algorithm, context); - - { - verifier.init(false, publicKey); - verifier.update(msg, 0, msg.length); - boolean shouldVerify = verifier.verifySignature(signature); - - if (!shouldVerify) - { - fail("Ed448(" + algorithm + ") signature failed to verify"); - } - } - - { - byte[] wrongLengthSignature = Arrays.append(signature, (byte)0x00); - - verifier.init(false, publicKey); - verifier.update(msg, 0, msg.length); - boolean shouldNotVerify = verifier.verifySignature(wrongLengthSignature); - - if (shouldNotVerify) - { - fail("Ed448(" + algorithm + ") wrong length signature incorrectly verified"); - } - } - - { - byte[] badSignature = Arrays.clone(signature); - badSignature[(RANDOM.nextInt() >>> 1) % badSignature.length] ^= 1 << (RANDOM.nextInt() & 7); - - verifier.init(false, publicKey); - verifier.update(msg, 0, msg.length); - boolean shouldNotVerify = verifier.verifySignature(badSignature); - - if (shouldNotVerify) - { - fail("Ed448(" + algorithm + ") bad signature incorrectly verified"); - } - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ElGamalTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ElGamalTest.java deleted file mode 100644 index 226bac5cc..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ElGamalTest.java +++ /dev/null @@ -1,285 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.engines.ElGamalEngine; -import com.fr.third.org.bouncycastle.crypto.generators.ElGamalKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.ElGamalParametersGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ElGamalParameters; -import com.fr.third.org.bouncycastle.crypto.params.ElGamalPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ElGamalPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.BigIntegers; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class ElGamalTest - extends SimpleTest -{ - private BigInteger g512 = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16); - private BigInteger p512 = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16); - - private BigInteger g768 = new BigInteger("7c240073c1316c621df461b71ebb0cdcc90a6e5527e5e126633d131f87461c4dc4afc60c2cb0f053b6758871489a69613e2a8b4c8acde23954c08c81cbd36132cfd64d69e4ed9f8e51ed6e516297206672d5c0a69135df0a5dcf010d289a9ca1", 16); - private BigInteger p768 = new BigInteger("8c9dd223debed1b80103b8b309715be009d48860ed5ae9b9d5d8159508efd802e3ad4501a7f7e1cfec78844489148cd72da24b21eddd01aa624291c48393e277cfc529e37075eccef957f3616f962d15b44aeab4039d01b817fde9eaa12fd73f", 16); - - private BigInteger g1024 = new BigInteger("1db17639cdf96bc4eabba19454f0b7e5bd4e14862889a725c96eb61048dcd676ceb303d586e30f060dbafd8a571a39c4d823982117da5cc4e0f89c77388b7a08896362429b94a18a327604eb7ff227bffbc83459ade299e57b5f77b50fb045250934938efa145511166e3197373e1b5b1e52de713eb49792bedde722c6717abf", 16); - private BigInteger p1024 = new BigInteger("a00e283b3c624e5b2b4d9fbc2653b5185d99499b00fd1bf244c6f0bb817b4d1c451b2958d62a0f8a38caef059fb5ecd25d75ed9af403f5b5bdab97a642902f824e3c13789fed95fa106ddfe0ff4a707c85e2eb77d49e68f2808bcea18ce128b178cd287c6bc00efa9a1ad2a673fe0dceace53166f75b81d6709d5f8af7c66bb7", 16); - - private BigInteger yPgpBogusPSamp = new BigInteger("de4688497cc05b45fe8559bc9918c45afcad69b74123a7236eba409fd9de8ea34c7869839ee9df35e3d97576145d089841aa65b5b4e061fae52c37e430354269a02496b8ed8456f2d0d7c9b0db985fbcb21ae9f78507ed6e3a29db595b201b1a4f931c7d791eede65ccf918e8a61cf146859151c78c41ad48853694623467d78", 16); - private BigInteger xPgpBogusPSamp = new BigInteger("cbaf780f2cfe4f987bbc5fcb0738bbd7912060ccfdf37cbfeea65c0fd857e74a8df6cc359375f28cf5725d081813c614410a78cbe4b06d677beea9ff0fa10b1dbc47a6ed8c5b8466d6a95d6574029dbdf72596392e1b6b230faf9916dc8455821c10527a375a4d1c8a54947d1fe714d321aca25ad486b4b456506999fd2fd11a", 16); - private BigInteger gPgpBogusPSamp = new BigInteger("153ffe9522076d1cbd6e75f0816a0fc2ebd8b0e0091406587387a1763022088a03b411eed07ff50efb82b21f1608c352d10f63ba7e7e981a2f3387cec8af2915953d00493857663ae8919f517fe90f1d2abe7af4305a344b10d1a25d75f65902cd7fd775853d3ac43d7c5253ad666e1e63ee98cdcb10af81273d4ff053ff07d51", 16); - private BigInteger pPgpBogusPSamp = new BigInteger("15061b26cdab4e865098a01c86f13b03220104c5443e950658b36b85245aa0c616a0c0d8d99c454bea087c172315e45b3bc9b925443948a2b6ba47608a6035b9a79a4ef34a78d7274a12ede8364f02d5030db864988643d7e92753df603bd69fbd2682ab0af64d1a866d1131a2cb13333cedb0a9e6eefddd9fff8154d34c2daab", 16); - private int lPgpBogusPSamp = 0; - - public String getName() - { - return "ElGamal"; - } - - private void testEnc( - int size, - int privateValueSize, - BigInteger g, - BigInteger p) - { - ElGamalParameters dhParams = new ElGamalParameters(p, g, privateValueSize); - ElGamalKeyGenerationParameters params = new ElGamalKeyGenerationParameters(new SecureRandom(), dhParams); - ElGamalKeyPairGenerator kpGen = new ElGamalKeyPairGenerator(); - - kpGen.init(params); - - // - // generate pair - // - AsymmetricCipherKeyPair pair = kpGen.generateKeyPair(); - - ElGamalPublicKeyParameters pu = (ElGamalPublicKeyParameters)pair.getPublic(); - ElGamalPrivateKeyParameters pv = (ElGamalPrivateKeyParameters)pair.getPrivate(); - - checkKeySize(privateValueSize, pv); - - ElGamalEngine e = new ElGamalEngine(); - - e.init(true, pu); - - if (e.getOutputBlockSize() != size / 4) - { - fail(size + " getOutputBlockSize() on encryption failed."); - } - - byte[] message = Hex.decode("5468697320697320612074657374"); - - byte[] pText = message; - byte[] cText = e.processBlock(pText, 0, pText.length); - - e.init(false, pv); - - if (e.getOutputBlockSize() != (size / 8) - 1) - { - fail(size + " getOutputBlockSize() on decryption failed."); - } - - pText = e.processBlock(cText, 0, cText.length); - - if (!Arrays.areEqual(message, pText)) - { - fail(size + " bit test failed"); - } - - e.init(true, pu); - - byte[] bytes = new byte[e.getInputBlockSize() + 2]; - - try - { - e.processBlock(bytes, 0, bytes.length); - - fail("out of range block not detected"); - } - catch (DataLengthException ex) - { - // expected - } - - try - { - bytes[0] = (byte)0xff; - - e.processBlock(bytes, 0, bytes.length - 1); - - fail("out of range block not detected"); - } - catch (DataLengthException ex) - { - // expected - } - - try - { - bytes[0] = (byte)0x7f; - - e.processBlock(bytes, 0, bytes.length - 1); - } - catch (DataLengthException ex) - { - fail("in range block failed"); - } - - try - { - bytes = BigIntegers.asUnsignedByteArray(p); - - e.processBlock(bytes, 0, bytes.length); - - fail("out of range block not detected"); - } - catch (DataLengthException ex) - { - // expected - } - - try - { - bytes = BigIntegers.asUnsignedByteArray(p.subtract(BigInteger.valueOf(1))); - - e.processBlock(bytes, 0, bytes.length); - } - catch (DataLengthException ex) - { - fail("boundary block rejected"); - } - } - - private void checkKeySize( - int privateValueSize, - ElGamalPrivateKeyParameters priv) - { - if (privateValueSize != 0) - { - if (priv.getX().bitLength() != privateValueSize) - { - fail("limited key check failed for key size " + privateValueSize); - } - } - } - - /** - * this test is can take quiet a while - * - * @param size size of key in bits. - */ - private void testGeneration( - int size) - { - ElGamalParametersGenerator pGen = new ElGamalParametersGenerator(); - - pGen.init(size, 10, new SecureRandom()); - - ElGamalParameters elParams = pGen.generateParameters(); - - if (elParams.getL() != 0) - { - fail("ElGamalParametersGenerator failed to set L to 0 in generated ElGamalParameters"); - } - - ElGamalKeyGenerationParameters params = new ElGamalKeyGenerationParameters(new SecureRandom(), elParams); - - ElGamalKeyPairGenerator kpGen = new ElGamalKeyPairGenerator(); - - kpGen.init(params); - - // - // generate first pair - // - AsymmetricCipherKeyPair pair = kpGen.generateKeyPair(); - - ElGamalPublicKeyParameters pu = (ElGamalPublicKeyParameters)pair.getPublic(); - ElGamalPrivateKeyParameters pv = (ElGamalPrivateKeyParameters)pair.getPrivate(); - - ElGamalEngine e = new ElGamalEngine(); - - e.init(true, new ParametersWithRandom(pu, new SecureRandom())); - - byte[] message = Hex.decode("5468697320697320612074657374"); - - byte[] pText = message; - byte[] cText = e.processBlock(pText, 0, pText.length); - - e.init(false, pv); - - pText = e.processBlock(cText, 0, cText.length); - - if (!Arrays.areEqual(message, pText)) - { - fail("generation test failed"); - } - } - - private void testInitCheck() - { - try - { - new ElGamalEngine().processBlock(new byte[]{ 1 }, 0, 1); - fail("failed initialisation check"); - } - catch (IllegalStateException e) - { - // expected - } - } - - private void testInvalidP() - { - ElGamalParameters dhParams = new ElGamalParameters(pPgpBogusPSamp, gPgpBogusPSamp, lPgpBogusPSamp); - ElGamalPublicKeyParameters pu = new ElGamalPublicKeyParameters(yPgpBogusPSamp, dhParams); - ElGamalPrivateKeyParameters pv = new ElGamalPrivateKeyParameters(xPgpBogusPSamp, dhParams); - - ElGamalEngine e = new ElGamalEngine(); - - e.init(true, pu); - - byte[] message = Hex.decode("5468697320697320612074657374"); - - byte[] pText = message; - byte[] cText = e.processBlock(pText, 0, pText.length); - - e.init(false, pv); - - pText = e.processBlock(cText, 0, cText.length); - - if (Arrays.areEqual(message, pText)) - { - fail("invalid test failed"); - } - } - - public void performTest() - { - testInvalidP(); - - testEnc(512, 0, g512, p512); - testEnc(768, 0, g768, p768); - testEnc(1024, 0, g1024, p1024); - - testEnc(512, 64, g512, p512); - testEnc(768, 128, g768, p768); - - // - // generation test. - // - testGeneration(258); - - testInitCheck(); - } - - public static void main( - String[] args) - { - runTest(new ElGamalTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/EqualsHashCodeTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/EqualsHashCodeTest.java deleted file mode 100644 index fb49f5446..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/EqualsHashCodeTest.java +++ /dev/null @@ -1,261 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.generators.DHKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.ElGamalKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.DHKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHValidationParameters; -import com.fr.third.org.bouncycastle.crypto.params.DSAParameters; -import com.fr.third.org.bouncycastle.crypto.params.DSAValidationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ElGamalKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ElGamalParameters; -import com.fr.third.org.bouncycastle.crypto.params.ElGamalPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ElGamalPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.GOST3410Parameters; -import com.fr.third.org.bouncycastle.crypto.params.GOST3410ValidationParameters; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -import java.math.BigInteger; -import java.security.SecureRandom; - -class DHTestKeyParameters - extends DHKeyParameters -{ - protected DHTestKeyParameters(boolean isPrivate, DHParameters params) - { - super(isPrivate, params); - } -} - -class ElGamalTestKeyParameters - extends ElGamalKeyParameters -{ - protected ElGamalTestKeyParameters(boolean isPrivate, ElGamalParameters params) - { - super(isPrivate, params); - } -} - -public class EqualsHashCodeTest - extends SimpleTest -{ - private static Object OTHER = new Object(); - - public String getName() - { - return "EqualsHashCode"; - } - - private void doTest(Object a, Object equalsA, Object notEqualsA) - { - if (a.equals(null)) - { - fail("a equaled null"); - } - - if (!a.equals(equalsA) || !equalsA.equals(a)) - { - fail("equality failed"); - } - - if (a.equals(OTHER)) - { - fail("other inequality failed"); - } - - if (a.equals(notEqualsA) || notEqualsA.equals(a)) - { - fail("inequality failed"); - } - - if (a.hashCode() != equalsA.hashCode()) - { - fail("hashCode equality failed"); - } - } - - private void dhTest() - { - BigInteger g512 = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16); - BigInteger p512 = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16); - - DHParameters dhParams = new DHParameters(p512, g512); - DHKeyGenerationParameters params = new DHKeyGenerationParameters(new SecureRandom(), dhParams); DHKeyPairGenerator kpGen = new DHKeyPairGenerator(); - - kpGen.init(params); - - AsymmetricCipherKeyPair pair = kpGen.generateKeyPair(); - DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.getPublic(); - DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.getPrivate(); - - DHPublicKeyParameters pu2 = new DHPublicKeyParameters(pu1.getY(), pu1.getParameters()); - DHPrivateKeyParameters pv2 = new DHPrivateKeyParameters(pv1.getX(), pv1.getParameters()); - DHPublicKeyParameters pu3 = new DHPublicKeyParameters(pv1.getX(), pu1.getParameters()); - DHPrivateKeyParameters pv3 = new DHPrivateKeyParameters(pu1.getY(), pu1.getParameters()); - - doTest(pu1, pu2, pu3); - doTest(pv1, pv2, pv3); - - DHParameters pr1 = pu1.getParameters(); - DHParameters pr2 = new DHParameters(pr1.getP(), pr1.getG(), pr1.getQ(), pr1.getM(), pr1.getL(), pr1.getJ(), pr1.getValidationParameters()); - DHParameters pr3 = new DHParameters(pr1.getG(), pr1.getP(), pr1.getQ(), pr1.getM(), pr1.getL(), pr1.getJ(), pr1.getValidationParameters()); - - doTest(pr1, pr2, pr3); - - pr3 = new DHParameters(pr1.getG(), pr1.getP(), null, pr1.getM(), pr1.getL(), pr1.getJ(), pr1.getValidationParameters()); - - doTest(pr1, pr2, pr3); - - pu2 = new DHPublicKeyParameters(pu1.getY(), pr2); - pv2 = new DHPrivateKeyParameters(pv1.getX(), pr2); - - doTest(pu1, pu2, pu3); - doTest(pv1, pv2, pv3); - - DHValidationParameters vp1 = new DHValidationParameters(new byte[20], 1024); - DHValidationParameters vp2 = new DHValidationParameters(new byte[20], 1024); - DHValidationParameters vp3 = new DHValidationParameters(new byte[24], 1024); - - doTest(vp1, vp1, vp3); - doTest(vp1, vp2, vp3); - - byte[] bytes = new byte[20]; - bytes[0] = 1; - - vp3 = new DHValidationParameters(bytes, 1024); - - doTest(vp1, vp2, vp3); - - vp3 = new DHValidationParameters(new byte[20], 2048); - - doTest(vp1, vp2, vp3); - - DHTestKeyParameters k1 = new DHTestKeyParameters(false, null); - DHTestKeyParameters k2 = new DHTestKeyParameters(false, null); - DHTestKeyParameters k3 = new DHTestKeyParameters(false, pu1.getParameters()); - - doTest(k1, k2, k3); - } - - private void elGamalTest() - { - BigInteger g512 = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16); - BigInteger p512 = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16); - - ElGamalParameters dhParams = new ElGamalParameters(p512, g512); - ElGamalKeyGenerationParameters params = new ElGamalKeyGenerationParameters(new SecureRandom(), dhParams); ElGamalKeyPairGenerator kpGen = new ElGamalKeyPairGenerator(); - - kpGen.init(params); - - AsymmetricCipherKeyPair pair = kpGen.generateKeyPair(); - ElGamalPublicKeyParameters pu1 = (ElGamalPublicKeyParameters)pair.getPublic(); - ElGamalPrivateKeyParameters pv1 = (ElGamalPrivateKeyParameters)pair.getPrivate(); - - ElGamalPublicKeyParameters pu2 = new ElGamalPublicKeyParameters(pu1.getY(), pu1.getParameters()); - ElGamalPrivateKeyParameters pv2 = new ElGamalPrivateKeyParameters(pv1.getX(), pv1.getParameters()); - ElGamalPublicKeyParameters pu3 = new ElGamalPublicKeyParameters(pv1.getX(), pu1.getParameters()); - ElGamalPrivateKeyParameters pv3 = new ElGamalPrivateKeyParameters(pu1.getY(), pu1.getParameters()); - - doTest(pu1, pu2, pu3); - doTest(pv1, pv2, pv3); - - ElGamalParameters pr1 = pu1.getParameters(); - ElGamalParameters pr2 = new ElGamalParameters(pr1.getP(), pr1.getG()); - ElGamalParameters pr3 = new ElGamalParameters(pr1.getG(), pr1.getP()); - - doTest(pr1, pr2, pr3); - - pu2 = new ElGamalPublicKeyParameters(pu1.getY(), pr2); - pv2 = new ElGamalPrivateKeyParameters(pv1.getX(), pr2); - - doTest(pu1, pu2, pu3); - doTest(pv1, pv2, pv3); - - ElGamalTestKeyParameters k1 = new ElGamalTestKeyParameters(false, null); - ElGamalTestKeyParameters k2 = new ElGamalTestKeyParameters(false, null); - ElGamalTestKeyParameters k3 = new ElGamalTestKeyParameters(false, pu1.getParameters()); - - doTest(k1, k2, k3); - } - - private void dsaTest() - { - BigInteger a = BigInteger.valueOf(1), b = BigInteger.valueOf(2), c = BigInteger.valueOf(3); - - DSAParameters dsaP1 = new DSAParameters(a, b, c); - DSAParameters dsaP2 = new DSAParameters(a, b, c); - DSAParameters dsaP3 = new DSAParameters(b, c, a); - - doTest(dsaP1, dsaP2, dsaP3); - - DSAValidationParameters vp1 = new DSAValidationParameters(new byte[20], 1024); - DSAValidationParameters vp2 = new DSAValidationParameters(new byte[20], 1024); - DSAValidationParameters vp3 = new DSAValidationParameters(new byte[24], 1024); - - doTest(vp1, vp1, vp3); - doTest(vp1, vp2, vp3); - - byte[] bytes = new byte[20]; - bytes[0] = 1; - - vp3 = new DSAValidationParameters(bytes, 1024); - - doTest(vp1, vp2, vp3); - - vp3 = new DSAValidationParameters(new byte[20], 2048); - - doTest(vp1, vp2, vp3); - } - - private void gost3410Test() - { - BigInteger a = BigInteger.valueOf(1), b = BigInteger.valueOf(2), c = BigInteger.valueOf(3); - - GOST3410Parameters g1 = new GOST3410Parameters(a, b, c); - GOST3410Parameters g2 = new GOST3410Parameters(a, b, c); - GOST3410Parameters g3 = new GOST3410Parameters(a, c, c); - - doTest(g1, g2, g3); - - GOST3410ValidationParameters v1 = new GOST3410ValidationParameters(100, 1); - GOST3410ValidationParameters v2 = new GOST3410ValidationParameters(100, 1); - GOST3410ValidationParameters v3 = new GOST3410ValidationParameters(101, 1); - - doTest(v1, v2, v3); - - v3 = new GOST3410ValidationParameters(100, 2); - - doTest(v1, v2, v3); - - v1 = new GOST3410ValidationParameters(100L, 1L); - v2 = new GOST3410ValidationParameters(100L, 1L); - v3 = new GOST3410ValidationParameters(101L, 1L); - - doTest(v1, v2, v3); - - v3 = new GOST3410ValidationParameters(100L, 2L); - - doTest(v1, v2, v3); - - } - - public void performTest() - throws Exception - { - dhTest(); - elGamalTest(); - gost3410Test(); - dsaTest(); - } - - public static void main( - String[] args) - { - runTest(new EqualsHashCodeTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/EthereumIESTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/EthereumIESTest.java deleted file mode 100644 index 67e482691..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/EthereumIESTest.java +++ /dev/null @@ -1,510 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.BufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.KeyEncoder; -import com.fr.third.org.bouncycastle.crypto.KeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.agreement.ECDHBasicAgreement; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.engines.EthereumIESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.TwofishEngine; -import com.fr.third.org.bouncycastle.crypto.generators.ECKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.EphemeralKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.IESParameters; -import com.fr.third.org.bouncycastle.crypto.params.IESWithCipherParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.crypto.parsers.ECIESPublicKeyParser; -import com.fr.third.org.bouncycastle.math.ec.ECConstants; -import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * test for Ethereum flavor of ECIES - Elliptic Curve Integrated Encryption Scheme - *- * Note the IV is always required when passing parameters, as the IV is added to the MAC. - */ -public class EthereumIESTest - extends SimpleTest -{ - private static byte[] TWOFISH_IV = Hex.decode("000102030405060708090a0b0c0d0e0f"); - - EthereumIESTest() - { - } - - public String getName() - { - return "EthereumIES"; - } - - private void doStaticTest(byte[] iv) - throws Exception - { - BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q - new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a - new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("651056770906015076056810763456358567190100156695615665659"), // d - params); - - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("0262b12d60690cdcf330babab6e69763b471f994dd702d16a5")), // Q - params); - - AsymmetricCipherKeyPair p1 = new AsymmetricCipherKeyPair(pubKey, priKey); - AsymmetricCipherKeyPair p2 = new AsymmetricCipherKeyPair(pubKey, priKey); - - byte[] commonMac = Hex.decode("0262b12d60690cdcf330baba03188da80eb03090f67cbf2043a18800f4ff0a0262b12d60690cdcf330bab6e69763b471f994dd2d16a5fd82ff1012b6e69763b4"); - - // - // stream test - // - EthereumIESEngine i1 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac); - EthereumIESEngine i2 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac); - byte[] d = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; - byte[] e = new byte[]{8, 7, 6, 5, 4, 3, 2, 1}; - CipherParameters p = new ParametersWithIV(new IESParameters(d, e, 64), new byte[32]); - - i1.init(true, p1.getPrivate(), p2.getPublic(), p); - i2.init(false, p2.getPrivate(), p1.getPublic(), p); - - byte[] message = Hex.decode("1234567890abcdef"); - - byte[] out1 = i1.processBlock(message, 0, message.length); - - if (!areEqual(out1, Hex.decode("fb493cdaaa2938daaa2fbbf0886f3b9575c810db240eb9f4adb9089b"))) - { - fail("stream cipher test failed on enc"); - } - - byte[] out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("stream cipher test failed"); - } - - // - // twofish with CBC - // - BufferedBlockCipher c1 = new PaddedBufferedBlockCipher( - new CBCBlockCipher(new TwofishEngine())); - BufferedBlockCipher c2 = new PaddedBufferedBlockCipher( - new CBCBlockCipher(new TwofishEngine())); - i1 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac, - c1); - i2 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac, - c2); - d = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; - e = new byte[]{8, 7, 6, 5, 4, 3, 2, 1}; - p = new IESWithCipherParameters(d, e, 64, 128); - - if (iv != null) - { - p = new ParametersWithIV(p, iv); - } - - i1.init(true, p1.getPrivate(), p2.getPublic(), p); - i2.init(false, p2.getPrivate(), p1.getPublic(), p); - - message = Hex.decode("1234567890abcdef"); - - out1 = i1.processBlock(message, 0, message.length); - - if (!areEqual(out1, (iv == null) ? - Hex.decode("b8a06ea5c2b9df28b58a0a90a734cde8c9c02903e5c220021fe4417410d1e53a32a71696") - : Hex.decode("34bb9676b087d0b3a016e70a93c4afcb507882a53c5ca7a770913e654ff1422c4b236cbf"))) - { - fail("twofish cipher test failed on enc"); - } - - out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("twofish cipher test failed"); - } - } - - private void doShortTest(byte[] iv) - throws Exception - { - BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q - new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a - new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("651056770906015076056810763456358567190100156695615665659"), // d - params); - - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("0262b12d60690cdcf330babab6e69763b471f994dd702d16a5")), // Q - params); - - AsymmetricCipherKeyPair p1 = new AsymmetricCipherKeyPair(pubKey, priKey); - AsymmetricCipherKeyPair p2 = new AsymmetricCipherKeyPair(pubKey, priKey); - - byte[] commonMac = Hex.decode("0262b12d60690cdcf330baba03188da80eb03090f67cbf2043a18800f4ff0a0262b12d60690cdcf330bab6e69763b471f994dd2d16a5fd82ff1012b6e69763b4"); - - // - // stream test - V 0 - // - EthereumIESEngine i1 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac); - EthereumIESEngine i2 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac); - byte[] d = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; - byte[] e = new byte[]{8, 7, 6, 5, 4, 3, 2, 1}; - CipherParameters p = new ParametersWithIV(new IESParameters(d, e, 64), new byte[32]); - - i1.init(true, p1.getPrivate(), p2.getPublic(), p); - i2.init(false, p2.getPrivate(), p1.getPublic(), p); - - byte[] message = new byte[0]; - - byte[] out1 = i1.processBlock(message, 0, message.length); - - byte[] out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("stream cipher test failed"); - } - - try - { - i2.processBlock(out1, 0, out1.length - 1); - fail("no exception"); - } - catch (InvalidCipherTextException ex) - { - if (!"length of input must be greater than the MAC and V combined".equals(ex.getMessage())) - { - fail("wrong exception"); - } - } - - // with ephemeral key pair - - // Generate the ephemeral key pair - ECKeyPairGenerator gen = new ECKeyPairGenerator(); - gen.init(new ECKeyGenerationParameters(params, new SecureRandom())); - - EphemeralKeyPairGenerator ephKeyGen = new EphemeralKeyPairGenerator(gen, new KeyEncoder() - { - public byte[] getEncoded(AsymmetricKeyParameter keyParameter) - { - return ((ECPublicKeyParameters)keyParameter).getQ().getEncoded(false); - } - }); - - i1.init(p2.getPublic(), p, ephKeyGen); - i2.init(p2.getPrivate(), p, new ECIESPublicKeyParser(params)); - - out1 = i1.processBlock(message, 0, message.length); - - out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("V cipher test failed"); - } - - try - { - i2.processBlock(out1, 0, out1.length - 1); - fail("no exception"); - } - catch (InvalidCipherTextException ex) - { - if (!"length of input must be greater than the MAC and V combined".equals(ex.getMessage())) - { - fail("wrong exception"); - } - } - } - - private void doEphemeralTest(byte[] iv, final boolean usePointCompression) - throws Exception - { - BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q - new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a - new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); - - ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( - new BigInteger("651056770906015076056810763456358567190100156695615665659"), // d - params); - - ECPublicKeyParameters pubKey = new ECPublicKeyParameters( - curve.decodePoint(Hex.decode("0262b12d60690cdcf330babab6e69763b471f994dd702d16a5")), // Q - params); - - AsymmetricCipherKeyPair p1 = new AsymmetricCipherKeyPair(pubKey, priKey); - AsymmetricCipherKeyPair p2 = new AsymmetricCipherKeyPair(pubKey, priKey); - - // Generate the ephemeral key pair - ECKeyPairGenerator gen = new ECKeyPairGenerator(); - gen.init(new ECKeyGenerationParameters(params, new SecureRandom())); - - EphemeralKeyPairGenerator ephKeyGen = new EphemeralKeyPairGenerator(gen, new KeyEncoder() - { - public byte[] getEncoded(AsymmetricKeyParameter keyParameter) - { - return ((ECPublicKeyParameters)keyParameter).getQ().getEncoded(usePointCompression); - } - }); - - byte[] commonMac = Hex.decode("0262b12d60690cdcf330baba03188da80eb03090f67cbf2043a18800f4ff0a0262b12d60690cdcf330bab6e69763b471f994dd2d16a5fd82ff1012b6e69763b4"); - - // - // stream test - // - EthereumIESEngine i1 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac); - EthereumIESEngine i2 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac); - - byte[] d = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; - byte[] e = new byte[]{8, 7, 6, 5, 4, 3, 2, 1}; - CipherParameters p = new ParametersWithIV(new IESParameters(d, e, 64), new byte[32]); - - i1.init(p2.getPublic(), p, ephKeyGen); - i2.init(p2.getPrivate(), p, new ECIESPublicKeyParser(params)); - - byte[] message = Hex.decode("1234567890abcdef"); - - byte[] out1 = i1.processBlock(message, 0, message.length); - - byte[] out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("stream cipher test failed"); - } - - // - // twofish with CBC - // - BufferedBlockCipher c1 = new PaddedBufferedBlockCipher( - new CBCBlockCipher(new TwofishEngine())); - BufferedBlockCipher c2 = new PaddedBufferedBlockCipher( - new CBCBlockCipher(new TwofishEngine())); - i1 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac, - c1); - i2 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac, - c2); - d = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; - e = new byte[]{8, 7, 6, 5, 4, 3, 2, 1}; - p = new IESWithCipherParameters(d, e, 64, 128); - - if (iv != null) - { - p = new ParametersWithIV(p, iv); - } - - i1.init(p2.getPublic(), p, ephKeyGen); - i2.init(p2.getPrivate(), p, new ECIESPublicKeyParser(params)); - - message = Hex.decode("1234567890abcdef"); - - out1 = i1.processBlock(message, 0, message.length); - - out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("twofish cipher test failed"); - } - } - - private void doTest(AsymmetricCipherKeyPair p1, AsymmetricCipherKeyPair p2) - throws Exception - { - byte[] commonMac = Hex.decode("0262b12d60690cdcf330baba03188da80eb03090f67cbf2043a18800f4ff0a0262b12d60690cdcf330bab6e69763b471f994dd2d16a5fd82ff1012b6e69763b4"); - - // - // stream test - // - EthereumIESEngine i1 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac); - EthereumIESEngine i2 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac); - byte[] d = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; - byte[] e = new byte[]{8, 7, 6, 5, 4, 3, 2, 1}; - ParametersWithIV p = new ParametersWithIV(new IESParameters(d, e, 64), new byte[32]); - - i1.init(true, p1.getPrivate(), p2.getPublic(), p); - i2.init(false, p2.getPrivate(), p1.getPublic(), p); - - byte[] message = Hex.decode("1234567890abcdef"); - - byte[] out1 = i1.processBlock(message, 0, message.length); - - byte[] out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("stream cipher test failed"); - } - - // - // twofish with CBC - // - BufferedBlockCipher c1 = new PaddedBufferedBlockCipher( - new CBCBlockCipher(new TwofishEngine())); - BufferedBlockCipher c2 = new PaddedBufferedBlockCipher( - new CBCBlockCipher(new TwofishEngine())); - i1 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac, - c1); - i2 = new EthereumIESEngine( - new ECDHBasicAgreement(), - new EthereumIESEngine.HandshakeKDFFunction(1, new SHA1Digest()), - new HMac(new SHA1Digest()), - commonMac, - c2); - d = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; - e = new byte[]{8, 7, 6, 5, 4, 3, 2, 1}; - p = new ParametersWithIV(new IESWithCipherParameters(d, e, 64, 128), new byte[16]); - - i1.init(true, p1.getPrivate(), p2.getPublic(), p); - i2.init(false, p2.getPrivate(), p1.getPublic(), p); - - message = Hex.decode("1234567890abcdef"); - - out1 = i1.processBlock(message, 0, message.length); - - out2 = i2.processBlock(out1, 0, out1.length); - - if (!areEqual(out2, message)) - { - fail("twofish cipher test failed"); - } - } - - public void performTest() - throws Exception - { - doStaticTest(TWOFISH_IV); - doShortTest(null); - - BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081"); - - ECCurve.Fp curve = new ECCurve.Fp( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q - new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a - new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16), // b - n, ECConstants.ONE); - - ECDomainParameters params = new ECDomainParameters( - curve, - curve.decodePoint(Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); - - ECKeyPairGenerator eGen = new ECKeyPairGenerator(); - KeyGenerationParameters gParam = new ECKeyGenerationParameters(params, new SecureRandom()); - - eGen.init(gParam); - - AsymmetricCipherKeyPair p1 = eGen.generateKeyPair(); - AsymmetricCipherKeyPair p2 = eGen.generateKeyPair(); - - doTest(p1, p2); - - doEphemeralTest(TWOFISH_IV, false); - doEphemeralTest(TWOFISH_IV, true); - } - - public static void main( - String[] args) - { - runTest(new EthereumIESTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GCMTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GCMTest.java deleted file mode 100644 index 5b7cf82e9..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GCMTest.java +++ /dev/null @@ -1,725 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.modes.GCMBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.gcm.BasicGCMMultiplier; -import com.fr.third.org.bouncycastle.crypto.modes.gcm.GCMMultiplier; -import com.fr.third.org.bouncycastle.crypto.modes.gcm.Tables4kGCMMultiplier; -import com.fr.third.org.bouncycastle.crypto.modes.gcm.Tables64kGCMMultiplier; -import com.fr.third.org.bouncycastle.crypto.modes.gcm.Tables8kGCMMultiplier; -import com.fr.third.org.bouncycastle.crypto.params.AEADParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.Times; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test vectors from "The Galois/Counter Mode of Operation (GCM)", McGrew/Viega, Appendix B - */ -public class GCMTest - extends SimpleTest -{ - private static final String[][] TEST_VECTORS = new String[][] { - { - "Test Case 1", - "00000000000000000000000000000000", - "", - "", - "000000000000000000000000", - "", - "58e2fccefa7e3061367f1d57a4e7455a", - }, - { - "Test Case 2", - "00000000000000000000000000000000", - "00000000000000000000000000000000", - "", - "000000000000000000000000", - "0388dace60b6a392f328c2b971b2fe78", - "ab6e47d42cec13bdf53a67b21257bddf", - }, - { - "Test Case 3", - "feffe9928665731c6d6a8f9467308308", - "d9313225f88406e5a55909c5aff5269a" - + "86a7a9531534f7da2e4c303d8a318a72" - + "1c3c0c95956809532fcf0e2449a6b525" - + "b16aedf5aa0de657ba637b391aafd255", - "", - "cafebabefacedbaddecaf888", - "42831ec2217774244b7221b784d0d49c" - + "e3aa212f2c02a4e035c17e2329aca12e" - + "21d514b25466931c7d8f6a5aac84aa05" - + "1ba30b396a0aac973d58e091473f5985", - "4d5c2af327cd64a62cf35abd2ba6fab4", - }, - { - "Test Case 4", - "feffe9928665731c6d6a8f9467308308", - "d9313225f88406e5a55909c5aff5269a" - + "86a7a9531534f7da2e4c303d8a318a72" - + "1c3c0c95956809532fcf0e2449a6b525" - + "b16aedf5aa0de657ba637b39", - "feedfacedeadbeeffeedfacedeadbeef" - + "abaddad2", - "cafebabefacedbaddecaf888", - "42831ec2217774244b7221b784d0d49c" - + "e3aa212f2c02a4e035c17e2329aca12e" - + "21d514b25466931c7d8f6a5aac84aa05" - + "1ba30b396a0aac973d58e091", - "5bc94fbc3221a5db94fae95ae7121a47", - }, - { - "Test Case 5", - "feffe9928665731c6d6a8f9467308308", - "d9313225f88406e5a55909c5aff5269a" - + "86a7a9531534f7da2e4c303d8a318a72" - + "1c3c0c95956809532fcf0e2449a6b525" - + "b16aedf5aa0de657ba637b39", - "feedfacedeadbeeffeedfacedeadbeef" - + "abaddad2", - "cafebabefacedbad", - "61353b4c2806934a777ff51fa22a4755" - + "699b2a714fcdc6f83766e5f97b6c7423" - + "73806900e49f24b22b097544d4896b42" - + "4989b5e1ebac0f07c23f4598", - "3612d2e79e3b0785561be14aaca2fccb", - }, - { - "Test Case 6", - "feffe9928665731c6d6a8f9467308308", - "d9313225f88406e5a55909c5aff5269a" - + "86a7a9531534f7da2e4c303d8a318a72" - + "1c3c0c95956809532fcf0e2449a6b525" - + "b16aedf5aa0de657ba637b39", - "feedfacedeadbeeffeedfacedeadbeef" - + "abaddad2", - "9313225df88406e555909c5aff5269aa" - + "6a7a9538534f7da1e4c303d2a318a728" - + "c3c0c95156809539fcf0e2429a6b5254" - + "16aedbf5a0de6a57a637b39b", - "8ce24998625615b603a033aca13fb894" - + "be9112a5c3a211a8ba262a3cca7e2ca7" - + "01e4a9a4fba43c90ccdcb281d48c7c6f" - + "d62875d2aca417034c34aee5", - "619cc5aefffe0bfa462af43c1699d050", - }, - { - "Test Case 7", - "00000000000000000000000000000000" - + "0000000000000000", - "", - "", - "000000000000000000000000", - "", - "cd33b28ac773f74ba00ed1f312572435", - }, - { - "Test Case 8", - "00000000000000000000000000000000" - + "0000000000000000", - "00000000000000000000000000000000", - "", - "000000000000000000000000", - "98e7247c07f0fe411c267e4384b0f600", - "2ff58d80033927ab8ef4d4587514f0fb", - }, - { - "Test Case 9", - "feffe9928665731c6d6a8f9467308308" - + "feffe9928665731c", - "d9313225f88406e5a55909c5aff5269a" - + "86a7a9531534f7da2e4c303d8a318a72" - + "1c3c0c95956809532fcf0e2449a6b525" - + "b16aedf5aa0de657ba637b391aafd255", - "", - "cafebabefacedbaddecaf888", - "3980ca0b3c00e841eb06fac4872a2757" - + "859e1ceaa6efd984628593b40ca1e19c" - + "7d773d00c144c525ac619d18c84a3f47" - + "18e2448b2fe324d9ccda2710acade256", - "9924a7c8587336bfb118024db8674a14", - }, - { - "Test Case 10", - "feffe9928665731c6d6a8f9467308308" - + "feffe9928665731c", - "d9313225f88406e5a55909c5aff5269a" - + "86a7a9531534f7da2e4c303d8a318a72" - + "1c3c0c95956809532fcf0e2449a6b525" - + "b16aedf5aa0de657ba637b39", - "feedfacedeadbeeffeedfacedeadbeef" - + "abaddad2", - "cafebabefacedbaddecaf888", - "3980ca0b3c00e841eb06fac4872a2757" - + "859e1ceaa6efd984628593b40ca1e19c" - + "7d773d00c144c525ac619d18c84a3f47" - + "18e2448b2fe324d9ccda2710", - "2519498e80f1478f37ba55bd6d27618c", - }, - { - "Test Case 11", - "feffe9928665731c6d6a8f9467308308" - + "feffe9928665731c", - "d9313225f88406e5a55909c5aff5269a" - + "86a7a9531534f7da2e4c303d8a318a72" - + "1c3c0c95956809532fcf0e2449a6b525" - + "b16aedf5aa0de657ba637b39", - "feedfacedeadbeeffeedfacedeadbeef" - + "abaddad2", - "cafebabefacedbad", - "0f10f599ae14a154ed24b36e25324db8" - + "c566632ef2bbb34f8347280fc4507057" - + "fddc29df9a471f75c66541d4d4dad1c9" - + "e93a19a58e8b473fa0f062f7", - "65dcc57fcf623a24094fcca40d3533f8", - }, - { - "Test Case 12", - "feffe9928665731c6d6a8f9467308308" - + "feffe9928665731c", - "d9313225f88406e5a55909c5aff5269a" - + "86a7a9531534f7da2e4c303d8a318a72" - + "1c3c0c95956809532fcf0e2449a6b525" - + "b16aedf5aa0de657ba637b39", - "feedfacedeadbeeffeedfacedeadbeef" - + "abaddad2", - "9313225df88406e555909c5aff5269aa" - + "6a7a9538534f7da1e4c303d2a318a728" - + "c3c0c95156809539fcf0e2429a6b5254" - + "16aedbf5a0de6a57a637b39b", - "d27e88681ce3243c4830165a8fdcf9ff" - + "1de9a1d8e6b447ef6ef7b79828666e45" - + "81e79012af34ddd9e2f037589b292db3" - + "e67c036745fa22e7e9b7373b", - "dcf566ff291c25bbb8568fc3d376a6d9", - }, - { - "Test Case 13", - "00000000000000000000000000000000" - + "00000000000000000000000000000000", - "", - "", - "000000000000000000000000", - "", - "530f8afbc74536b9a963b4f1c4cb738b", - }, - { - "Test Case 14", - "00000000000000000000000000000000" - + "00000000000000000000000000000000", - "00000000000000000000000000000000", - "", - "000000000000000000000000", - "cea7403d4d606b6e074ec5d3baf39d18", - "d0d1c8a799996bf0265b98b5d48ab919", - }, - { - "Test Case 15", - "feffe9928665731c6d6a8f9467308308" - + "feffe9928665731c6d6a8f9467308308", - "d9313225f88406e5a55909c5aff5269a" - + "86a7a9531534f7da2e4c303d8a318a72" - + "1c3c0c95956809532fcf0e2449a6b525" - + "b16aedf5aa0de657ba637b391aafd255", - "", - "cafebabefacedbaddecaf888", - "522dc1f099567d07f47f37a32a84427d" - + "643a8cdcbfe5c0c97598a2bd2555d1aa" - + "8cb08e48590dbb3da7b08b1056828838" - + "c5f61e6393ba7a0abcc9f662898015ad", - "b094dac5d93471bdec1a502270e3cc6c", - }, - { - "Test Case 16", - "feffe9928665731c6d6a8f9467308308" - + "feffe9928665731c6d6a8f9467308308", - "d9313225f88406e5a55909c5aff5269a" - + "86a7a9531534f7da2e4c303d8a318a72" - + "1c3c0c95956809532fcf0e2449a6b525" - + "b16aedf5aa0de657ba637b39", - "feedfacedeadbeeffeedfacedeadbeef" - + "abaddad2", - "cafebabefacedbaddecaf888", - "522dc1f099567d07f47f37a32a84427d" - + "643a8cdcbfe5c0c97598a2bd2555d1aa" - + "8cb08e48590dbb3da7b08b1056828838" - + "c5f61e6393ba7a0abcc9f662", - "76fc6ece0f4e1768cddf8853bb2d551b", - }, - { - "Test Case 17", - "feffe9928665731c6d6a8f9467308308" - + "feffe9928665731c6d6a8f9467308308", - "d9313225f88406e5a55909c5aff5269a" - + "86a7a9531534f7da2e4c303d8a318a72" - + "1c3c0c95956809532fcf0e2449a6b525" - + "b16aedf5aa0de657ba637b39", - "feedfacedeadbeeffeedfacedeadbeef" - + "abaddad2", - "cafebabefacedbad", - "c3762df1ca787d32ae47c13bf19844cb" - + "af1ae14d0b976afac52ff7d79bba9de0" - + "feb582d33934a4f0954cc2363bc73f78" - + "62ac430e64abe499f47c9b1f", - "3a337dbf46a792c45e454913fe2ea8f2", - }, - { - "Test Case 18", - "feffe9928665731c6d6a8f9467308308" - + "feffe9928665731c6d6a8f9467308308", - "d9313225f88406e5a55909c5aff5269a" - + "86a7a9531534f7da2e4c303d8a318a72" - + "1c3c0c95956809532fcf0e2449a6b525" - + "b16aedf5aa0de657ba637b39", - "feedfacedeadbeeffeedfacedeadbeef" - + "abaddad2", - "9313225df88406e555909c5aff5269aa" - + "6a7a9538534f7da1e4c303d2a318a728" - + "c3c0c95156809539fcf0e2429a6b5254" - + "16aedbf5a0de6a57a637b39b", - "5a8def2f0c9e53f1f75d7853659e2a20" - + "eeb2b22aafde6419a058ab4f6f746bf4" - + "0fc0c3b780f244452da3ebf1c5d82cde" - + "a2418997200ef82e44ae7e3f", - "a44a8266ee1c8eb0c8b5d4cf5ae9f19a", - }, - }; - - public String getName() - { - return "GCM"; - } - - public void performTest() throws Exception - { - for (int i = 0; i < TEST_VECTORS.length; ++i) - { - runTestCase(TEST_VECTORS[i]); - } - - randomTests(); - outputSizeTests(); - testExceptions(); - } - - protected BlockCipher createAESEngine() - { - return new AESEngine(); - } - - private void testExceptions() throws InvalidCipherTextException - { - GCMBlockCipher gcm = new GCMBlockCipher(createAESEngine()); - - try - { - gcm = new GCMBlockCipher(new DESEngine()); - - fail("incorrect block size not picked up"); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - gcm.init(false, new KeyParameter(new byte[16])); - - fail("illegal argument not picked up"); - } - catch (IllegalArgumentException e) - { - // expected - } - - AEADTestUtil.testTampering(this, gcm, new AEADParameters(new KeyParameter(new byte[16]), 128, new byte[16])); - - byte[] P = Strings.toByteArray("Hello world!"); - byte[] buf = new byte[100]; - - GCMBlockCipher c = new GCMBlockCipher(createAESEngine()); - AEADParameters aeadParameters = new AEADParameters(new KeyParameter(new byte[16]), 128, new byte[16]); - c.init(true, aeadParameters); - - c.processBytes(P, 0, P.length, buf, 0); - - c.doFinal(buf, 0); - - try - { - c.doFinal(buf, 0); - fail("no exception on reuse"); - } - catch (IllegalStateException e) - { - isTrue("wrong message", e.getMessage().equals("GCM cipher cannot be reused for encryption")); - } - - try - { - c.init(true, aeadParameters); - fail("no exception on reuse"); - } - catch (IllegalArgumentException e) - { - isTrue("wrong message", e.getMessage().equals("cannot reuse nonce for GCM encryption")); - } - } - - private void runTestCase(String[] testVector) - throws InvalidCipherTextException - { - for (int macLength = 12; macLength <= 16; ++macLength) - { - runTestCase(testVector, macLength); - } - } - - private void runTestCase(String[] testVector, int macLength) - throws InvalidCipherTextException - { - int pos = 0; - String testName = testVector[pos++]; - byte[] K = Hex.decode(testVector[pos++]); - byte[] P = Hex.decode(testVector[pos++]); - byte[] A = Hex.decode(testVector[pos++]); - byte[] IV = Hex.decode(testVector[pos++]); - byte[] C = Hex.decode(testVector[pos++]); - - // For short MAC, take leading bytes - byte[] t = Hex.decode(testVector[pos++]); - byte[] T = new byte[macLength]; - System.arraycopy(t, 0, T, 0, T.length); - - // Default multiplier - runTestCase(null, null, testName, K, IV, A, P, C, T); - - runTestCase(new BasicGCMMultiplier(), new BasicGCMMultiplier(), testName, K, IV, A, P, C, T); - runTestCase(new Tables4kGCMMultiplier(), new Tables4kGCMMultiplier(), testName, K, IV, A, P, C, T); - runTestCase(new Tables8kGCMMultiplier(), new Tables8kGCMMultiplier(), testName, K, IV, A, P, C, T); - runTestCase(new Tables64kGCMMultiplier(), new Tables64kGCMMultiplier(), testName, K, IV, A, P, C, T); - } - - private void runTestCase( - GCMMultiplier encM, - GCMMultiplier decM, - String testName, - byte[] K, - byte[] IV, - byte[] A, - byte[] P, - byte[] C, - byte[] T) - throws InvalidCipherTextException - { - byte[] fa = new byte[A.length / 2]; - byte[] la = new byte[A.length - (A.length / 2)]; - System.arraycopy(A, 0, fa, 0, fa.length); - System.arraycopy(A, fa.length, la, 0, la.length); - - runTestCase(encM, decM, testName + " all initial associated data", K, IV, A, null, P, C, T); - runTestCase(encM, decM, testName + " all subsequent associated data", K, IV, null, A, P, C, T); - runTestCase(encM, decM, testName + " split associated data", K, IV, fa, la, P, C, T); - } - - private void runTestCase( - GCMMultiplier encM, - GCMMultiplier decM, - String testName, - byte[] K, - byte[] IV, - byte[] A, - byte[] SA, - byte[] P, - byte[] C, - byte[] T) - throws InvalidCipherTextException - { - AEADParameters parameters = new AEADParameters(new KeyParameter(K), T.length * 8, IV, A); - GCMBlockCipher encCipher = initCipher(encM, true, parameters); - GCMBlockCipher decCipher = initCipher(decM, false, parameters); - checkTestCase(encCipher, decCipher, testName, SA, P, C, T); - encCipher = initCipher(encM, true, parameters); - checkTestCase(encCipher, decCipher, testName + " (reused)", SA, P, C, T); - - // Key reuse - AEADParameters keyReuseParams = AEADTestUtil.reuseKey(parameters); - - try - { - encCipher.init(true, keyReuseParams); - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isTrue("wrong message", "cannot reuse nonce for GCM encryption".equals(e.getMessage())); - } - } - - private GCMBlockCipher initCipher(GCMMultiplier m, boolean forEncryption, AEADParameters parameters) - { - GCMBlockCipher c = new GCMBlockCipher(createAESEngine(), m); - c.init(forEncryption, parameters); - return c; - } - - private void checkTestCase( - GCMBlockCipher encCipher, - GCMBlockCipher decCipher, - String testName, - byte[] SA, - byte[] P, - byte[] C, - byte[] T) - throws InvalidCipherTextException - { - byte[] enc = new byte[encCipher.getOutputSize(P.length)]; - if (SA != null) - { - encCipher.processAADBytes(SA, 0, SA.length); - } - int len = encCipher.processBytes(P, 0, P.length, enc, 0); - len += encCipher.doFinal(enc, len); - - if (enc.length != len) - { -// System.out.println("" + enc.length + "/" + len); - fail("encryption reported incorrect length: " + testName); - } - - byte[] mac = encCipher.getMac(); - - byte[] data = new byte[P.length]; - System.arraycopy(enc, 0, data, 0, data.length); - byte[] tail = new byte[enc.length - P.length]; - System.arraycopy(enc, P.length, tail, 0, tail.length); - - if (!areEqual(C, data)) - { - fail("incorrect encrypt in: " + testName); - } - - if (!areEqual(T, mac)) - { - fail("getMac() returned wrong mac in: " + testName); - } - - if (!areEqual(T, tail)) - { - fail("stream contained wrong mac in: " + testName); - } - - byte[] dec = new byte[decCipher.getOutputSize(enc.length)]; - if (SA != null) - { - decCipher.processAADBytes(SA, 0, SA.length); - } - len = decCipher.processBytes(enc, 0, enc.length, dec, 0); - len += decCipher.doFinal(dec, len); - mac = decCipher.getMac(); - - data = new byte[C.length]; - System.arraycopy(dec, 0, data, 0, data.length); - - if (!areEqual(P, data)) - { - fail("incorrect decrypt in: " + testName); - } - } - - private void randomTests() - throws InvalidCipherTextException - { - SecureRandom srng = new SecureRandom(); - srng.setSeed(Times.nanoTime()); - randomTests(srng, null); - randomTests(srng, new BasicGCMMultiplier()); - randomTests(srng, new Tables4kGCMMultiplier()); - randomTests(srng, new Tables8kGCMMultiplier()); - randomTests(srng, new Tables64kGCMMultiplier()); - } - - private void randomTests(SecureRandom srng, GCMMultiplier m) - throws InvalidCipherTextException - { - for (int i = 0; i < 10; ++i) - { - randomTest(srng, m); - } - } - - private void randomTest(SecureRandom srng, GCMMultiplier m) - throws InvalidCipherTextException - { - int kLength = 16 + 8 * (Math.abs(srng.nextInt()) % 3); - byte[] K = new byte[kLength]; - srng.nextBytes(K); - - int pLength = srng.nextInt() >>> 16; - byte[] P = new byte[pLength]; - srng.nextBytes(P); - - int aLength = srng.nextInt() >>> 24; - byte[] A = new byte[aLength]; - srng.nextBytes(A); - - int saLength = srng.nextInt() >>> 24; - byte[] SA = new byte[saLength]; - srng.nextBytes(SA); - - int ivLength = 1 + (srng.nextInt() >>> 24); - byte[] IV = new byte[ivLength]; - srng.nextBytes(IV); - - AEADParameters parameters = new AEADParameters(new KeyParameter(K), 16 * 8, IV, A); - GCMBlockCipher cipher = initCipher(m, true, parameters); - byte[] C = new byte[cipher.getOutputSize(P.length)]; - int predicted = cipher.getUpdateOutputSize(P.length); - - int split = nextInt(srng, SA.length + 1); - cipher.processAADBytes(SA, 0, split); - int len = cipher.processBytes(P, 0, P.length, C, 0); - cipher.processAADBytes(SA, split, SA.length - split); - - if (predicted != len) - { - fail("encryption reported incorrect update length in randomised test"); - } - - len += cipher.doFinal(C, len); - - if (C.length != len) - { - fail("encryption reported incorrect length in randomised test"); - } - - byte[] encT = cipher.getMac(); - byte[] tail = new byte[C.length - P.length]; - System.arraycopy(C, P.length, tail, 0, tail.length); - - if (!areEqual(encT, tail)) - { - fail("stream contained wrong mac in randomised test"); - } - - cipher.init(false, parameters); - byte[] decP = new byte[cipher.getOutputSize(C.length)]; - predicted = cipher.getUpdateOutputSize(C.length); - - split = nextInt(srng, SA.length + 1); - cipher.processAADBytes(SA, 0, split); - len = cipher.processBytes(C, 0, C.length, decP, 0); - cipher.processAADBytes(SA, split, SA.length - split); - - if (predicted != len) - { - fail("decryption reported incorrect update length in randomised test"); - } - - len += cipher.doFinal(decP, len); - - if (!areEqual(P, decP)) - { - fail("incorrect decrypt in randomised test"); - } - - byte[] decT = cipher.getMac(); - if (!areEqual(encT, decT)) - { - fail("decryption produced different mac from encryption"); - } - - // - // key reuse test - // - cipher.init(false, AEADTestUtil.reuseKey(parameters)); - decP = new byte[cipher.getOutputSize(C.length)]; - - split = nextInt(srng, SA.length + 1); - cipher.processAADBytes(SA, 0, split); - len = cipher.processBytes(C, 0, C.length, decP, 0); - cipher.processAADBytes(SA, split, SA.length - split); - - len += cipher.doFinal(decP, len); - - if (!areEqual(P, decP)) - { - fail("incorrect decrypt in randomised test"); - } - - decT = cipher.getMac(); - if (!areEqual(encT, decT)) - { - fail("decryption produced different mac from encryption"); - } - } - - private void outputSizeTests() - { - byte[] K = new byte[16]; - byte[] A = null; - byte[] IV = new byte[16]; - - AEADParameters parameters = new AEADParameters(new KeyParameter(K), 16 * 8, IV, A); - GCMBlockCipher cipher = initCipher(null, true, parameters); - - if (cipher.getUpdateOutputSize(0) != 0) - { - fail("incorrect getUpdateOutputSize for initial 0 bytes encryption"); - } - - if (cipher.getOutputSize(0) != 16) - { - fail("incorrect getOutputSize for initial 0 bytes encryption"); - } - - cipher.init(false, parameters); - - if (cipher.getUpdateOutputSize(0) != 0) - { - fail("incorrect getUpdateOutputSize for initial 0 bytes decryption"); - } - - // NOTE: 0 bytes would be truncated data, but we want it to fail in the doFinal, not here - if (cipher.getOutputSize(0) != 0) - { - fail("fragile getOutputSize for initial 0 bytes decryption"); - } - - if (cipher.getOutputSize(16) != 0) - { - fail("incorrect getOutputSize for initial MAC-size bytes decryption"); - } - } - - private static int nextInt(SecureRandom rand, int n) - { - if ((n & -n) == n) // i.e., n is a power of 2 - { - return (int)((n * (long)(rand.nextInt() >>> 1)) >> 31); - } - - int bits, value; - do - { - bits = rand.nextInt() >>> 1; - value = bits % n; - } - while (bits - value + (n - 1) < 0); - - return value; - } - - public static void main(String[] args) - { - runTest(new GCMTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GMacTest.java deleted file mode 100644 index 58f1ccd0e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GMacTest.java +++ /dev/null @@ -1,177 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.macs.GMac; -import com.fr.third.org.bouncycastle.crypto.modes.GCMBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test vectors for AES-GMAC, extracted from NIST CAVP GCM test - * vectors. - * - */ -public class GMacTest extends SimpleTest -{ - private static class TestCase - { - private byte[] key; - private byte[] iv; - private byte[] ad; - private byte[] tag; - private String name; - - private TestCase(final String name, final String key, final String iv, final String ad, final String tag) - { - this.name = name; - this.key = Hex.decode(key); - this.iv = Hex.decode(iv); - this.ad = Hex.decode(ad); - this.tag = Hex.decode(tag); - } - - public String getName() - { - return name; - } - - public byte[] getKey() - { - return key; - } - - public byte[] getIv() - { - return iv; - } - - public byte[] getAd() - { - return ad; - } - - public byte[] getTag() - { - return tag; - } - } - - private static TestCase[] TEST_VECTORS = new TestCase[] { - // Count = 0, from each of the PTlen = 0 test vector sequences - new TestCase("128/96/0/128", "11754cd72aec309bf52f7687212e8957", "3c819d9a9bed087615030b65", "", - "250327c674aaf477aef2675748cf6971"), - new TestCase("128/96/0/120", "272f16edb81a7abbea887357a58c1917", "794ec588176c703d3d2a7a07", "", - "b6e6f197168f5049aeda32dafbdaeb"), - new TestCase("128/96/0/112", "81b6844aab6a568c4556a2eb7eae752f", "ce600f59618315a6829bef4d", "", - "89b43e9dbc1b4f597dbbc7655bb5"), - new TestCase("128/96/0/104", "cde2f9a9b1a004165ef9dc981f18651b", "29512c29566c7322e1e33e8e", "", - "2e58ce7dabd107c82759c66a75"), - new TestCase("128/96/0/96", "b01e45cc3088aaba9fa43d81d481823f", "5a2c4a66468713456a4bd5e1", "", - "014280f944f53c681164b2ff"), - - new TestCase("128/96/128/128", "77be63708971c4e240d1cb79e8d77feb", "e0e00f19fed7ba0136a797f3", - "7a43ec1d9c0a5a78a0b16533a6213cab", "209fcc8d3675ed938e9c7166709dd946"), - new TestCase("128/96/128/96", "bea48ae4980d27f357611014d4486625", "32bddb5c3aa998a08556454c", - "8a50b0b8c7654bced884f7f3afda2ead", "8e0f6d8bf05ffebe6f500eb1"), - - new TestCase("128/96/384/128", "99e3e8793e686e571d8285c564f75e2b", "c2dd0ab868da6aa8ad9c0d23", - "b668e42d4e444ca8b23cfdd95a9fedd5178aa521144890b093733cf5cf22526c5917ee476541809ac6867a8c399309fc", - "3f4fba100eaf1f34b0baadaae9995d85"), - new TestCase("128/96/384/96", "c77acd1b0918e87053cb3e51651e7013", "39ff857a81745d10f718ac00", - "407992f82ea23b56875d9a3cb843ceb83fd27cb954f7c5534d58539fe96fb534502a1b38ea4fac134db0a42de4be1137", - "2a5dc173285375dc82835876"), - - new TestCase( - "128/1024/0/128", - "d0f1f4defa1e8c08b4b26d576392027c", - "42b4f01eb9f5a1ea5b1eb73b0fb0baed54f387ecaa0393c7d7dffc6af50146ecc021abf7eb9038d4303d91f8d741a11743166c0860208bcc02c6258fd9511a2fa626f96d60b72fcff773af4e88e7a923506e4916ecbd814651e9f445adef4ad6a6b6c7290cc13b956130eef5b837c939fcac0cbbcc9656cd75b13823ee5acdac", - "", "7ab49b57ddf5f62c427950111c5c4f0d"), - new TestCase( - "128/1024/384/96", - "3cce72d37933394a8cac8a82deada8f0", - "aa2f0d676d705d9733c434e481972d4888129cf7ea55c66511b9c0d25a92a174b1e28aa072f27d4de82302828955aadcb817c4907361869bd657b45ff4a6f323871987fcf9413b0702d46667380cd493ed24331a28b9ce5bbfa82d3a6e7679fcce81254ba64abcad14fd18b22c560a9d2c1cd1d3c42dac44c683edf92aced894", - "5686b458e9c176f4de8428d9ebd8e12f569d1c7595cf49a4b0654ab194409f86c0dd3fdb8eb18033bb4338c70f0b97d1", - "a3a9444b21f330c3df64c8b6"), }; - - public void performTest() - { - for (int i = 0; i < TEST_VECTORS.length; i++) - { - TestCase testCase = TEST_VECTORS[i]; - - Mac mac = new GMac(new GCMBlockCipher(new AESEngine()), testCase.getTag().length * 8); - CipherParameters key = new KeyParameter(testCase.getKey()); - mac.init(new ParametersWithIV(key, testCase.getIv())); - - testSingleByte(mac, testCase); - - mac = new GMac(new GCMBlockCipher(new AESEngine()), testCase.getTag().length * 8); - mac.init(new ParametersWithIV(key, testCase.getIv())); - testMultibyte(mac, testCase); - } - - // Invalid mac size - testInvalidMacSize(97); - testInvalidMacSize(136); - testInvalidMacSize(24); - } - - private void testInvalidMacSize(int size) - { - try - { - GMac mac = new GMac(new GCMBlockCipher(new AESEngine()), size); - mac.init(new ParametersWithIV(null, new byte[16])); - fail("Expected failure for illegal mac size " + size); - } - catch (IllegalArgumentException e) - { - if (!e.getMessage().startsWith("Invalid value for MAC size")) - { - fail("Illegal mac size failed with unexpected message"); - } - } - } - - private void testMultibyte(Mac mac, TestCase testCase) - { - mac.update(testCase.getAd(), 0, testCase.getAd().length); - checkMac(mac, testCase); - } - - private void testSingleByte(Mac mac, TestCase testCase) - { - final byte[] ad = testCase.getAd(); - for (int i = 0; i < ad.length; i++) - { - mac.update(ad[i]); - } - checkMac(mac, testCase); - } - - private void checkMac(Mac mac, TestCase testCase) - { - final byte[] generatedMac = new byte[mac.getMacSize()]; - mac.doFinal(generatedMac, 0); - if (!areEqual(testCase.getTag(), generatedMac)) - { - fail("Failed " + testCase.getName() + " - expected " + new String(Hex.encode(testCase.getTag())) + " got " - + new String(Hex.encode(generatedMac))); - } - } - - public String getName() - { - return "GMac"; - } - - public static void main(String[] args) - { - runTest(new GMacTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST28147MacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST28147MacTest.java deleted file mode 100644 index e32e07486..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST28147MacTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.engines.GOST28147Engine; -import com.fr.third.org.bouncycastle.crypto.macs.GOST28147Mac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithSBox; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * GOST 28147 MAC tester - */ -public class GOST28147MacTest - implements Test -{ - // - // these GOSTMac for testing. - // - static byte[] gkeyBytes1 = Hex.decode("6d145dc993f4019e104280df6fcd8cd8e01e101e4c113d7ec4f469ce6dcd9e49"); - static byte[] gkeyBytes2 = Hex.decode("6d145dc993f4019e104280df6fcd8cd8e01e101e4c113d7ec4f469ce6dcd9e49"); - - static byte[] input3 = Hex.decode("7768617420646f2079612077616e7420666f72206e6f7468696e673f"); - static byte[] input4 = Hex.decode("7768617420646f2079612077616e7420666f72206e6f7468696e673f"); - - static byte[] output7 = Hex.decode("93468a46"); - static byte[] output8 = Hex.decode("93468a46"); - - public GOST28147MacTest() - { - } - - public TestResult perform() - { - // test1 - Mac mac = new GOST28147Mac(); - KeyParameter key = new KeyParameter(gkeyBytes1); - - mac.init(key); - - mac.update(input3, 0, input3.length); - - byte[] out = new byte[4]; - - mac.doFinal(out, 0); - - if (!Arrays.areEqual(out, output7)) - { - return new SimpleTestResult(false, getName() + ": Failed test 1 - expected " + new String(Hex.encode(output7)) + " got " + new String(Hex.encode(out))); - } - - // test2 - key = new KeyParameter(gkeyBytes2); - - ParametersWithSBox gparam = new ParametersWithSBox(key, GOST28147Engine.getSBox("E-A")); - - mac.init(gparam); - - mac.update(input4, 0, input4.length); - - out = new byte[4]; - - mac.doFinal(out, 0); - - if (!Arrays.areEqual(out, output8)) - { - return new SimpleTestResult(false, getName() + ": Failed test 2 - expected " + new String(Hex.encode(output8)) + " got " + new String(Hex.encode(out))); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public String getName() - { - return "GOST28147Mac"; - } - - public static void main( - String[] args) - { - GOST28147MacTest test = new GOST28147MacTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST28147Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST28147Test.java deleted file mode 100644 index d887ba4a8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST28147Test.java +++ /dev/null @@ -1,371 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.CryptoException; -import com.fr.third.org.bouncycastle.crypto.digests.GOST3411Digest; -import com.fr.third.org.bouncycastle.crypto.engines.GOST28147Engine; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.GOFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithSBox; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class GOST28147Test - extends CipherTest -{ - static String input1 = "0000000000000000"; - static String output1 = "1b0bbc32cebcab42"; - static String input2 = "bc350e71aac5f5c2"; - static String output2 = "d35ab653493b49f5"; - static String input3 = "bc350e71aa11345709acde"; - static String output3 = "8824c124c4fd14301fb1e8"; - static String input4 = "000102030405060708090a0b0c0d0e0fff0102030405060708090a0b0c0d0e0f"; - static String output4 = "29b7083e0a6d955ca0ec5b04fdb4ea41949f1dd2efdf17baffc1780b031f3934"; - - static byte TestSBox[] = { - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF, - 0xF,0xE,0xD,0xC,0xB,0xA,0x9,0x8,0x7,0x6,0x5,0x4,0x3,0x2,0x1,0x0, - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF, - 0xF,0xE,0xD,0xC,0xB,0xA,0x9,0x8,0x7,0x6,0x5,0x4,0x3,0x2,0x1,0x0, - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF, - 0xF,0xE,0xD,0xC,0xB,0xA,0x9,0x8,0x7,0x6,0x5,0x4,0x3,0x2,0x1,0x0, - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF, - 0xF,0xE,0xD,0xC,0xB,0xA,0x9,0x8,0x7,0x6,0x5,0x4,0x3,0x2,0x1,0x0 - }; - - static byte[] TestSBox_1 = - { - 0xE, 0x3, 0xC, 0xD, 0x1, 0xF, 0xA, 0x9, 0xB, 0x6, 0x2, 0x7, 0x5, 0x0, 0x8, 0x4, - 0xD, 0x9, 0x0, 0x4, 0x7, 0x1, 0x3, 0xB, 0x6, 0xC, 0x2, 0xA, 0xF, 0xE, 0x5, 0x8, - 0x8, 0xB, 0xA, 0x7, 0x1, 0xD, 0x5, 0xC, 0x6, 0x3, 0x9, 0x0, 0xF, 0xE, 0x2, 0x4, - 0xD, 0x7, 0xC, 0x9, 0xF, 0x0, 0x5, 0x8, 0xA, 0x2, 0xB, 0x6, 0x4, 0x3, 0x1, 0xE, - 0xB, 0x4, 0x6, 0x5, 0x0, 0xF, 0x1, 0xC, 0x9, 0xE, 0xD, 0x8, 0x3, 0x7, 0xA, 0x2, - 0xD, 0xF, 0x9, 0x4, 0x2, 0xC, 0x5, 0xA, 0x6, 0x0, 0x3, 0x8, 0x7, 0xE, 0x1, 0xB, - 0xF, 0xE, 0x9, 0x5, 0xB, 0x2, 0x1, 0x8, 0x6, 0x0, 0xD, 0x3, 0x4, 0x7, 0xC, 0xA, - 0xA, 0x3, 0xE, 0x2, 0x0, 0x1, 0x4, 0x6, 0xB, 0x8, 0xC, 0x7, 0xD, 0x5, 0xF, 0x9 - }; - - static SimpleTest[] tests = - { new BlockCipherVectorTest(1, new GOST28147Engine(), - new KeyParameter(Hex.decode("546d203368656c326973652073736e62206167796967747473656865202c3d73")), - input1, output1), - new BlockCipherVectorTest(2, new CBCBlockCipher(new GOST28147Engine()), - new ParametersWithIV(new KeyParameter(Hex.decode("00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF")), - Hex.decode("1234567890abcdef")), input2, output2), - new BlockCipherVectorTest(3, new GOFBBlockCipher(new GOST28147Engine()), - new ParametersWithIV(new KeyParameter(Hex.decode("0011223344556677889900112233445566778899001122334455667788990011")), - Hex.decode("1234567890abcdef")), //IV - input3, output3), - new BlockCipherVectorTest(4, new CFBBlockCipher(new GOST28147Engine(), 64), - new ParametersWithIV(new KeyParameter(Hex.decode("aafd12f659cae63489b479e5076ddec2f06cb58faafd12f659cae63489b479e5")), - Hex.decode("aafd12f659cae634")), input4, output4), - - //tests with parameters, set S-box. - new BlockCipherVectorTest(5, new GOST28147Engine(), - new KeyParameter(Hex.decode("546d203368656c326973652073736e62206167796967747473656865202c3d73")),//key , default parameter S-box set to D-Test - input1, output1), - new BlockCipherVectorTest(6, new CFBBlockCipher(new GOST28147Engine(), 64), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("546d203368656c326973652073736e62206167796967747473656865202c3d73")), //key - GOST28147Engine.getSBox("D-Test")), //type S-box - Hex.decode("1234567890abcdef")), //IV - "0000000000000000", //input message - "b587f7a0814c911d"), //encrypt message - new BlockCipherVectorTest(7, new CFBBlockCipher(new GOST28147Engine(), 64), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("546d203368656c326973652073736e62206167796967747473656865202c3d73")), //key - GOST28147Engine.getSBox("E-Test")), //type S-box - Hex.decode("1234567890abcdef")), //IV - "0000000000000000", //input message - "e8287f53f991d52b"), //encrypt message - new BlockCipherVectorTest(8, new CFBBlockCipher(new GOST28147Engine(), 64), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("546d203368656c326973652073736e62206167796967747473656865202c3d73")), //key - GOST28147Engine.getSBox("E-A")), //type S-box - Hex.decode("1234567890abcdef")), //IV - "0000000000000000", //input message - "c41009dba22ebe35"), //encrypt message - new BlockCipherVectorTest(9, new CFBBlockCipher(new GOST28147Engine(), 8), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("546d203368656c326973652073736e62206167796967747473656865202c3d73")), //key - GOST28147Engine.getSBox("E-B")), //type S-box - Hex.decode("1234567890abcdef")), //IV - "0000000000000000", //input message - "80d8723fcd3aba28"), //encrypt message - new BlockCipherVectorTest(10, new CFBBlockCipher(new GOST28147Engine(), 8), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("546d203368656c326973652073736e62206167796967747473656865202c3d73")), //key - GOST28147Engine.getSBox("E-C")), //type S-box - Hex.decode("1234567890abcdef")), //IV - "0000000000000000", //input message - "739f6f95068499b5"), //encrypt message - new BlockCipherVectorTest(11, new CFBBlockCipher(new GOST28147Engine(), 8), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("546d203368656c326973652073736e62206167796967747473656865202c3d73")), //key - GOST28147Engine.getSBox("E-D")), //type S-box - Hex.decode("1234567890abcdef")), //IV - "0000000000000000", //input message - "4663f720f4340f57"), //encrypt message - new BlockCipherVectorTest(12, new CFBBlockCipher(new GOST28147Engine(), 8), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("546d203368656c326973652073736e62206167796967747473656865202c3d73")), //key - GOST28147Engine.getSBox("D-A")), //type S-box - Hex.decode("1234567890abcdef")), //IV - "0000000000000000", //input message - "5bb0a31d218ed564"), //encrypt message - new BlockCipherVectorTest(13, new CFBBlockCipher(new GOST28147Engine(), 8), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("546d203368656c326973652073736e62206167796967747473656865202c3d73")), //key - TestSBox), //set own S-box - Hex.decode("1234567890abcdef")), //IV - "0000000000000000", //input message - "c3af96ef788667c5"), //encrypt message - new BlockCipherVectorTest(14, new GOFBBlockCipher(new GOST28147Engine()), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("4ef72b778f0b0bebeef4f077551cb74a927b470ad7d7f2513454569a247e989d")), //key - GOST28147Engine.getSBox("E-A")), //type S-box - Hex.decode("1234567890abcdef")), //IV - "bc350e71aa11345709acde", //input message - "1bcc2282707c676fb656dc"), //encrypt message - new BlockCipherVectorTest(15, new GOFBBlockCipher(new GOST28147Engine()), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("0A43145BA8B9E9FF0AEA67D3F26AD87854CED8D9017B3D33ED81301F90FDF993")), //key - TestSBox_1), //type, IV, S-box - Hex.decode("8001069080010690")), - "094C912C5EFDD703D42118971694580B", //input message - "2707B58DF039D1A64460735FFE76D55F"), //encrypt message - new BlockCipherVectorTest(16, new GOFBBlockCipher(new GOST28147Engine()), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("0A43145BA8B9E9FF0AEA67D3F26AD87854CED8D9017B3D33ED81301F90FDF993")), //key - TestSBox_1), //type, S-box - Hex.decode("800107A0800107A0")), - "FE780800E0690083F20C010CF00C0329", //input message - "9AF623DFF948B413B53171E8D546188D"), //encrypt message - new BlockCipherVectorTest(17, new GOFBBlockCipher(new GOST28147Engine()), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("0A43145BA8B9E9FF0AEA67D3F26AD87854CED8D9017B3D33ED81301F90FDF993")), //key - TestSBox_1), //type, S-box - Hex.decode("8001114080011140")), - "D1088FD8C0A86EE8F1DCD1088FE8C058", //input message - "62A6B64D12253BCD8241A4BB0CFD3E7C"), //encrypt message - new BlockCipherVectorTest(18, new GOFBBlockCipher(new GOST28147Engine()), - new ParametersWithIV( - new ParametersWithSBox( - new KeyParameter(Hex.decode("0A43145BA8B9E9FF0AEA67D3F26AD87854CED8D9017B3D33ED81301F90FDF993")), //key - TestSBox_1), //type, IV, S-box - Hex.decode("80011A3080011A30")), - "D431FACD011C502C501B500A12921090", //input message - "07313C89D302FF73234B4A0506AB00F3"), //encrypt message - }; - - static private final int GOST28147_KEY_LENGTH = 32; - - private byte[] generateKey(byte[] startkey) - { - byte[] newKey = new byte[GOST28147_KEY_LENGTH]; - - GOST3411Digest digest = new GOST3411Digest(); - - digest.update(startkey, 0, startkey.length); - digest.doFinal(newKey, 0); - - return newKey; - } - - GOST28147Test() - { - super(tests, new GOST28147Engine(), new KeyParameter(new byte[32])); - } - - public void performTest() - throws Exception - { - super.performTest(); - - //advanced tests with GOST28147KeyGenerator: - //encrypt on hesh message; ECB mode: - byte[] in = Hex.decode("4e6f77206973207468652074696d6520666f7220616c6c20"); - byte[] output = Hex.decode("8ad3c8f56b27ff1fbd46409359bdc796bc350e71aac5f5c0"); - byte[] out = new byte[in.length]; - - byte[] key = generateKey(Hex.decode("0123456789abcdef")); //!!! heshing start_key - get 256 bits !!! -// System.out.println(new String(Hex.encode(key))); - CipherParameters param = new ParametersWithSBox(new KeyParameter(key), GOST28147Engine.getSBox("E-A")); - //CipherParameters param = new GOST28147Parameters(key,"D-Test"); - BufferedBlockCipher cipher = new BufferedBlockCipher(new GOST28147Engine()); - - cipher.init(true, param); - int len1 = cipher.processBytes(in, 0, in.length, out, 0); - try - { - cipher.doFinal(out, len1); - } - catch (CryptoException e) - { - fail("failed - exception " + e.toString(), e); - } - if (out.length != output.length) - { - fail("failed - " - + "expected " + new String(Hex.encode(output)) + " got " - + new String(Hex.encode(out))); - } - for (int i = 0; i != out.length; i++) - { - if (out[i] != output[i]) - { - fail("failed - " + "expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - } - - - //encrypt on hesh message; CFB mode: - in = Hex.decode("bc350e71aac5f5c2"); - output = Hex.decode("0ebbbafcf38f14a5"); - out = new byte[in.length]; - - key = generateKey(Hex.decode("0123456789abcdef")); //!!! heshing start_key - get 256 bits !!! - param = new ParametersWithIV(new ParametersWithSBox( - new KeyParameter(key), //key - GOST28147Engine.getSBox("E-A")), //type S-box - Hex.decode("1234567890abcdef")); //IV - - cipher = new BufferedBlockCipher(new CFBBlockCipher(new GOST28147Engine(), 64)); - - cipher.init(true, param); - len1 = cipher.processBytes(in, 0, in.length, out, 0); - try - { - cipher.doFinal(out, len1); - } - catch (CryptoException e) - { - fail("failed - exception " + e.toString(), e); - } - if (out.length != output.length) - { - fail("failed - " + "expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - for (int i = 0; i != out.length; i++) - { - if (out[i] != output[i]) - { - fail("failed - " + "expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - } - - - //encrypt on hesh message; CFB mode: - in = Hex.decode("000102030405060708090a0b0c0d0e0fff0102030405060708090a0b0c0d0e0f"); - output = Hex.decode("64988982819f0a1655e226e19ecad79d10cc73bac95c5d7da034786c12294225"); - out = new byte[in.length]; - - key = generateKey(Hex.decode("aafd12f659cae63489b479e5076ddec2f06cb58faafd12f659cae63489b479e5")); //!!! heshing start_key - get 256 bits !!! - param = new ParametersWithIV(new ParametersWithSBox( - new KeyParameter(key), //key - GOST28147Engine.getSBox("E-A")), //type S-box - Hex.decode("aafd12f659cae634")); //IV - - cipher = new BufferedBlockCipher(new CFBBlockCipher(new GOST28147Engine(), 64)); - - cipher.init(true, param); - len1 = cipher.processBytes(in, 0, in.length, out, 0); - - cipher.doFinal(out, len1); - - if (out.length != output.length) - { - fail("failed - " + "expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - - for (int i = 0; i != out.length; i++) - { - if (out[i] != output[i]) - { - fail("failed - " + "expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - } - - //encrypt on hesh message; OFB mode: - in = Hex.decode("bc350e71aa11345709acde"); - output = Hex.decode("1bcc2282707c676fb656dc"); - out = new byte[in.length]; - - key = generateKey(Hex.decode("0123456789abcdef")); //!!! heshing start_key - get 256 bits !!! - param = new ParametersWithIV(new ParametersWithSBox( - new KeyParameter(key), //key - GOST28147Engine.getSBox("E-A")), //type S-box - Hex.decode("1234567890abcdef")); //IV - - cipher = new BufferedBlockCipher(new GOFBBlockCipher(new GOST28147Engine())); - - cipher.init(true, param); - len1 = cipher.processBytes(in, 0, in.length, out, 0); - - cipher.doFinal(out, len1); - - if (out.length != output.length) - { - fail("failed - " + "expected " - + new String(Hex.encode(output)) + " got " - + new String(Hex.encode(out))); - } - for (int i = 0; i != out.length; i++) - { - if (out[i] != output[i]) - { - fail("failed - " + "expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - } - - // key reuse test - param = new ParametersWithIV(null, // key and sbox reused - Hex.decode("1234567890abcdef")); //IV - - cipher.init(true, param); - len1 = cipher.processBytes(in, 0, in.length, out, 0); - - cipher.doFinal(out, len1); - - if (out.length != output.length) - { - fail("failed - " + "expected " - + new String(Hex.encode(output)) + " got " - + new String(Hex.encode(out))); - } - for (int i = 0; i != out.length; i++) - { - if (out[i] != output[i]) - { - fail("failed - " + "expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - } - } - - public String getName() - { - return "GOST28147"; - } - - public static void main( - String[] args) - { - runTest(new GOST28147Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3410Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3410Test.java deleted file mode 100644 index 3b84e3be7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3410Test.java +++ /dev/null @@ -1,2428 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves; -import com.fr.third.org.bouncycastle.asn1.pkcs.PrivateKeyInfo; -import com.fr.third.org.bouncycastle.asn1.rosstandart.RosstandartObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.generators.ECKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.GOST3410KeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.GOST3410ParametersGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ECGOST3410Parameters; -import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECNamedDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.GOST3410KeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.GOST3410Parameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.signers.GOST3410Signer; -import com.fr.third.org.bouncycastle.crypto.util.PrivateKeyFactory; -import com.fr.third.org.bouncycastle.crypto.util.PrivateKeyInfoFactory; -import com.fr.third.org.bouncycastle.crypto.util.PublicKeyFactory; -import com.fr.third.org.bouncycastle.crypto.util.SubjectPublicKeyInfoFactory; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.FixedSecureRandom; -import com.fr.third.org.bouncycastle.util.test.NumberParsing; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestRandomData; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -public class GOST3410Test - implements Test -{ - byte[] hashmessage = Hex.decode("3042453136414534424341374533364339313734453431443642453241453435"); - - private byte[] zeroTwo(int length) - { - byte[] data = new byte[length]; - data[data.length - 1] = 0x02; - return data; - } - - - Test tests[] = - { - new GOST3410EncodingDecoding(), - new GOST3410_TEST1_512(), - new GOST3410_TEST2_512(), - new GOST3410_TEST1_1024(), - new GOST3410_TEST2_1024(), - new GOST3410_AParam(), - new GOST3410_BParam(), - new GOST3410_CParam(), - new GOST3410_DParam(), - new GOST3410_AExParam(), - new GOST3410_BExParam(), - new GOST3410_CExParam() - }; - - public static void main( - String[] args) - { - GOST3410Test test = new GOST3410Test(); - TestResult result = test.perform(); - - System.out.println(result); - } - - public TestResult perform() - { - for (int i = 0; i != tests.length; i++) - { - TestResult result = tests[i].perform(); - - if (!result.isSuccessful()) - { - return result; - } - } - - return new SimpleTestResult(true, "GOST3410: Okay"); - } - - private class GOST3410EncodingDecoding - implements Test - { - - public String getName() - { - return "GOST3410ParameterEncodeDecode"; - } - - - private SimpleTestResult encodeRecodePrivateKeyGost2006() - { - try - { - ASN1ObjectIdentifier oid = ECGOST3410NamedCurves.getOID("GostR3410-2001-CryptoPro-A"); - ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGOST3410NamedCurves.getByOID(oid)); - ECGOST3410Parameters gostParams = new ECGOST3410Parameters(ecp, oid, CryptoProObjectIdentifiers.gostR3411); - ECKeyGenerationParameters params = new ECKeyGenerationParameters(gostParams, new SecureRandom()); - ECKeyPairGenerator engine = new ECKeyPairGenerator(); - engine.init(params); - AsymmetricCipherKeyPair pair = engine.generateKeyPair(); - - ECPrivateKeyParameters generatedKeyParameters = (ECPrivateKeyParameters)pair.getPrivate(); - ECPrivateKeyParameters keyParameters = generatedKeyParameters; - - - // - // Continuously encode/decode the key and check for loss of information. - // - - - for (int t = 0; t < 3; t++) - { - PrivateKeyInfo info = PrivateKeyInfoFactory.createPrivateKeyInfo(keyParameters); - keyParameters = (ECPrivateKeyParameters)PrivateKeyFactory.createKey(info); - - { // Specifically cast and test gost parameters. - ECGOST3410Parameters gParam = (ECGOST3410Parameters)generatedKeyParameters.getParameters(); - ECGOST3410Parameters rParam = (ECGOST3410Parameters)keyParameters.getParameters(); - - boolean ok = safeEquals(gParam.getDigestParamSet(), rParam.getDigestParamSet()) && - safeEquals(gParam.getEncryptionParamSet(), rParam.getEncryptionParamSet()) && - safeEquals(gParam.getPublicKeyParamSet(), rParam.getPublicKeyParamSet()); - - if (!ok) - { - return new SimpleTestResult(false, "GOST parameters does not match"); - } - - } - - if (keyParameters.isPrivate() != generatedKeyParameters.isPrivate()) - { - return new SimpleTestResult(false, "isPrivate does not match"); - } - - if (!keyParameters.getD().equals(generatedKeyParameters.getD())) - { - return new SimpleTestResult(false, "D does not match"); - } - - if (!((ECGOST3410Parameters)keyParameters.getParameters()).getName().equals( - ((ECGOST3410Parameters)generatedKeyParameters.getParameters()).getName())) - { - return new SimpleTestResult(false, "Name does not match"); - } - - if (!keyParameters.getParameters().getCurve().equals(generatedKeyParameters.getParameters().getCurve())) - { - return new SimpleTestResult(false, "Curve does not match"); - } - - if (!Arrays.areEqual( - keyParameters.getParameters().getG().getEncoded(true), - generatedKeyParameters.getParameters().getG().getEncoded(true))) - { - return new SimpleTestResult(false, "G does not match"); - } - - if (!keyParameters.getParameters().getH().equals(generatedKeyParameters.getParameters().getH())) - { - return new SimpleTestResult(false, "H does not match"); - } - - if (!keyParameters.getParameters().getHInv().equals(generatedKeyParameters.getParameters().getHInv())) - { - return new SimpleTestResult(false, "Hinv does not match"); - } - - if (!keyParameters.getParameters().getN().equals(generatedKeyParameters.getParameters().getN())) - { - return new SimpleTestResult(false, "N does not match"); - } - - if (!Arrays.areEqual(keyParameters.getParameters().getSeed(), generatedKeyParameters.getParameters().getSeed())) - { - return new SimpleTestResult(false, "Seed does not match"); - } - } - - - } - catch (Exception ex) - { - return new SimpleTestResult(false, ex.getMessage(), ex); - } - - return new SimpleTestResult(true, null); - } - - - public SimpleTestResult encodeRecodePublicKeyGost2006() - { - ASN1ObjectIdentifier oid = ECGOST3410NamedCurves.getOID("GostR3410-2001-CryptoPro-A"); - ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGOST3410NamedCurves.getByOID(oid)); - ECGOST3410Parameters gostParams = new ECGOST3410Parameters(ecp, oid, CryptoProObjectIdentifiers.gostR3411); - ECKeyGenerationParameters params = new ECKeyGenerationParameters(gostParams, new SecureRandom()); - ECKeyPairGenerator engine = new ECKeyPairGenerator(); - engine.init(params); - AsymmetricCipherKeyPair pair = engine.generateKeyPair(); - - ECPublicKeyParameters generatedKeyParameters = (ECPublicKeyParameters)pair.getPublic(); - ECPublicKeyParameters keyParameters = generatedKeyParameters; - - try - { - for (int t = 0; t < 3; t++) - { - - SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(keyParameters); - keyParameters = (ECPublicKeyParameters)PublicKeyFactory.createKey(info); - - { // Specifically cast and test gost parameters. - ECGOST3410Parameters gParam = (ECGOST3410Parameters)generatedKeyParameters.getParameters(); - ECGOST3410Parameters rParam = (ECGOST3410Parameters)keyParameters.getParameters(); - - - boolean ok = safeEquals(gParam.getDigestParamSet(), rParam.getDigestParamSet()) && - safeEquals(gParam.getEncryptionParamSet(), rParam.getEncryptionParamSet()) && - safeEquals(gParam.getPublicKeyParamSet(), rParam.getPublicKeyParamSet()); - - if (!ok) - { - return new SimpleTestResult(false, "GOST parameters does not match"); - } - - } - - if (!((ECGOST3410Parameters)keyParameters.getParameters()).getName().equals( - ((ECGOST3410Parameters)generatedKeyParameters.getParameters()).getName())) - { - return new SimpleTestResult(false, "Name does not match"); - } - - - if (keyParameters.isPrivate() != generatedKeyParameters.isPrivate()) - { - return new SimpleTestResult(false, "isPrivate does not match"); - } - - if (!Arrays.areEqual(keyParameters.getQ().getEncoded(true), generatedKeyParameters.getQ().getEncoded(true))) - { - return new SimpleTestResult(false, "Q does not match"); - } - - if (!keyParameters.getParameters().getCurve().equals(generatedKeyParameters.getParameters().getCurve())) - { - return new SimpleTestResult(false, "Curve does not match"); - } - - if (!Arrays.areEqual( - keyParameters.getParameters().getG().getEncoded(true), - generatedKeyParameters.getParameters().getG().getEncoded(true))) - { - return new SimpleTestResult(false, "G does not match"); - } - - if (!keyParameters.getParameters().getH().equals(generatedKeyParameters.getParameters().getH())) - { - return new SimpleTestResult(false, "H does not match"); - } - - if (!keyParameters.getParameters().getHInv().equals(generatedKeyParameters.getParameters().getHInv())) - { - return new SimpleTestResult(false, "Hinv does not match"); - } - - if (!keyParameters.getParameters().getN().equals(generatedKeyParameters.getParameters().getN())) - { - return new SimpleTestResult(false, "N does not match"); - } - - if (!Arrays.areEqual(keyParameters.getParameters().getSeed(), generatedKeyParameters.getParameters().getSeed())) - { - return new SimpleTestResult(false, "Seed does not match"); - } - } - return new SimpleTestResult(true, null); - } - catch (Exception ex) - { - return new SimpleTestResult(false, ex.getMessage(), ex); - } - - - } - - - public SimpleTestResult encodeRecodePublicKey() - { - - ASN1ObjectIdentifier oid = ECGOST3410NamedCurves.getOID("Tc26-Gost-3410-12-512-paramSetA"); - ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGOST3410NamedCurves.getByOID(oid)); - ECGOST3410Parameters gostParams = new ECGOST3410Parameters(ecp, oid, RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512); - ECKeyGenerationParameters params = new ECKeyGenerationParameters(gostParams, new SecureRandom()); - ECKeyPairGenerator engine = new ECKeyPairGenerator(); - engine.init(params); - AsymmetricCipherKeyPair pair = engine.generateKeyPair(); - - ECPublicKeyParameters generatedKeyParameters = (ECPublicKeyParameters)pair.getPublic(); - ECPublicKeyParameters keyParameters = generatedKeyParameters; - - - // - // Continuously encode/decode the key and check for loss of information. - // - try - { - for (int t = 0; t < 3; t++) - { - - SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(keyParameters); - keyParameters = (ECPublicKeyParameters)PublicKeyFactory.createKey(info); - - { // Specifically cast and test gost parameters. - ECGOST3410Parameters gParam = (ECGOST3410Parameters)generatedKeyParameters.getParameters(); - ECGOST3410Parameters rParam = (ECGOST3410Parameters)keyParameters.getParameters(); - - - boolean ok = safeEquals(gParam.getDigestParamSet(), rParam.getDigestParamSet()) && - safeEquals(gParam.getEncryptionParamSet(), rParam.getEncryptionParamSet()) && - safeEquals(gParam.getPublicKeyParamSet(), rParam.getPublicKeyParamSet()); - - if (!ok) - { - return new SimpleTestResult(false, "GOST parameters does not match"); - } - - } - - if (!((ECGOST3410Parameters)keyParameters.getParameters()).getName().equals( - ((ECGOST3410Parameters)generatedKeyParameters.getParameters()).getName())) - { - return new SimpleTestResult(false, "Name does not match"); - } - - - if (keyParameters.isPrivate() != generatedKeyParameters.isPrivate()) - { - return new SimpleTestResult(false, "isPrivate does not match"); - } - - if (!Arrays.areEqual(keyParameters.getQ().getEncoded(true), generatedKeyParameters.getQ().getEncoded(true))) - { - return new SimpleTestResult(false, "Q does not match"); - } - - if (!keyParameters.getParameters().getCurve().equals(generatedKeyParameters.getParameters().getCurve())) - { - return new SimpleTestResult(false, "Curve does not match"); - } - - if (!Arrays.areEqual( - keyParameters.getParameters().getG().getEncoded(true), - generatedKeyParameters.getParameters().getG().getEncoded(true))) - { - return new SimpleTestResult(false, "G does not match"); - } - - if (!keyParameters.getParameters().getH().equals(generatedKeyParameters.getParameters().getH())) - { - return new SimpleTestResult(false, "H does not match"); - } - - if (!keyParameters.getParameters().getHInv().equals(generatedKeyParameters.getParameters().getHInv())) - { - return new SimpleTestResult(false, "Hinv does not match"); - } - - if (!keyParameters.getParameters().getN().equals(generatedKeyParameters.getParameters().getN())) - { - return new SimpleTestResult(false, "N does not match"); - } - - if (!Arrays.areEqual(keyParameters.getParameters().getSeed(), generatedKeyParameters.getParameters().getSeed())) - { - return new SimpleTestResult(false, "Seed does not match"); - } - } - return new SimpleTestResult(true, null); - } - catch (Exception ex) - { - return new SimpleTestResult(false, ex.getMessage(), ex); - } - - - } - - - private SimpleTestResult encodeRecodePrivateKey() - { - try - { - ASN1ObjectIdentifier oid = ECGOST3410NamedCurves.getOID("Tc26-Gost-3410-12-512-paramSetA"); - ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGOST3410NamedCurves.getByOID(oid)); - ECGOST3410Parameters gostParams = new ECGOST3410Parameters(ecp, oid, RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512); - ECKeyGenerationParameters params = new ECKeyGenerationParameters(gostParams, new SecureRandom()); - ECKeyPairGenerator engine = new ECKeyPairGenerator(); - engine.init(params); - AsymmetricCipherKeyPair pair = engine.generateKeyPair(); - - ECPrivateKeyParameters generatedKeyParameters = (ECPrivateKeyParameters)pair.getPrivate(); - ECPrivateKeyParameters keyParameters = generatedKeyParameters; - - - // - // Continuously encode/decode the key and check for loss of information. - // - - - for (int t = 0; t < 3; t++) - { - PrivateKeyInfo info = PrivateKeyInfoFactory.createPrivateKeyInfo(keyParameters); - keyParameters = (ECPrivateKeyParameters)PrivateKeyFactory.createKey(info); - - { // Specifically cast and test gost parameters. - ECGOST3410Parameters gParam = (ECGOST3410Parameters)generatedKeyParameters.getParameters(); - ECGOST3410Parameters rParam = (ECGOST3410Parameters)keyParameters.getParameters(); - - boolean ok = safeEquals(gParam.getDigestParamSet(), rParam.getDigestParamSet()) && - safeEquals(gParam.getEncryptionParamSet(), rParam.getEncryptionParamSet()) && - safeEquals(gParam.getPublicKeyParamSet(), rParam.getPublicKeyParamSet()); - - if (!ok) - { - return new SimpleTestResult(false, "GOST parameters does not match"); - } - - } - - if (keyParameters.isPrivate() != generatedKeyParameters.isPrivate()) - { - return new SimpleTestResult(false, "isPrivate does not match"); - } - - if (!keyParameters.getD().equals(generatedKeyParameters.getD())) - { - return new SimpleTestResult(false, "D does not match"); - } - - if (!((ECGOST3410Parameters)keyParameters.getParameters()).getName().equals( - ((ECGOST3410Parameters)generatedKeyParameters.getParameters()).getName())) - { - return new SimpleTestResult(false, "Name does not match"); - } - - if (!keyParameters.getParameters().getCurve().equals(generatedKeyParameters.getParameters().getCurve())) - { - return new SimpleTestResult(false, "Curve does not match"); - } - - if (!Arrays.areEqual( - keyParameters.getParameters().getG().getEncoded(true), - generatedKeyParameters.getParameters().getG().getEncoded(true))) - { - return new SimpleTestResult(false, "G does not match"); - } - - if (!keyParameters.getParameters().getH().equals(generatedKeyParameters.getParameters().getH())) - { - return new SimpleTestResult(false, "H does not match"); - } - - if (!keyParameters.getParameters().getHInv().equals(generatedKeyParameters.getParameters().getHInv())) - { - return new SimpleTestResult(false, "Hinv does not match"); - } - - if (!keyParameters.getParameters().getN().equals(generatedKeyParameters.getParameters().getN())) - { - return new SimpleTestResult(false, "N does not match"); - } - - if (!Arrays.areEqual(keyParameters.getParameters().getSeed(), generatedKeyParameters.getParameters().getSeed())) - { - return new SimpleTestResult(false, "Seed does not match"); - } - } - - - } - catch (Exception ex) - { - return new SimpleTestResult(false, ex.getMessage(), ex); - } - - return new SimpleTestResult(true, null); - } - - - private SimpleTestResult decodeJCEPublic() - { - byte[] pub256 = Hex.decode("3068302106082a85030701010101301506092a850307010201010106082a850307010102020343000440292335c87d892510c35a033819a13e2b0dc606d911676af2bad8872d74a4b7bae6c729e98ace04c3dee626343f794731e1489edb7bc26f1c8c56e1448c96501a"); - - try - { - ECPublicKeyParameters pkInfo = (ECPublicKeyParameters)PublicKeyFactory.createKey(pub256); - - if (pkInfo.isPrivate()) - { - return new SimpleTestResult(false, "isPrivate should be false"); - } - - if ( - !Arrays.areEqual( - pkInfo.getQ().getEncoded(true), - Hex.decode("02bab7a4742d87d8baf26a6711d906c60d2b3ea11938035ac31025897dc8352329"))) - { - return new SimpleTestResult(false, "Q does not match"); - } - - if (!((ECGOST3410Parameters)pkInfo.getParameters()).getPublicKeyParamSet().toString().equals("1.2.643.7.1.2.1.1.1")) - { - return new SimpleTestResult(false, "PublicKeyParamSet does not match"); - } - - if (!((ECGOST3410Parameters)pkInfo.getParameters()).getDigestParamSet().toString().equals("1.2.643.7.1.1.2.2")) - { - return new SimpleTestResult(false, "DigestParamSet does not match"); - } - - if (((ECGOST3410Parameters)pkInfo.getParameters()).getEncryptionParamSet() != null) - { - return new SimpleTestResult(false, "EncryptionParamSet is not null"); - } - - - byte[] pub512 = Hex.decode("3081aa302106082a85030701010102301506092a850307010201020106082a850307010102030381840004818043ccc22692ee8a1870c7c9de0566d7e3a494cf0e3c80f9e8852a3d1ec10d2a829d357253e0864aee2eaacd5e2d327578dee771f62f24decfd6358e06199efe540e7912db43c4c80fe0fd31f7f67a862f9d44fd0075cfee6e3d638c7520063d26311ef962547e8129fb8c5b194e129370cd30313884b4a60872254a10772fe595"); - - pkInfo = (ECPublicKeyParameters)PublicKeyFactory.createKey(pub512); - - if (pkInfo.isPrivate()) - { - return new SimpleTestResult(false, "isPrivate should be true"); - } - - if ( - !Arrays.areEqual( - pkInfo.getQ().getEncoded(true), - Hex.decode("0254fe9e19068e35d6cfde242ff671e7de7875322d5ecdaa2eee4a86e05372359d822a0dc11e3d2a85e8f9803c0ecf94a4e3d76605dec9c770188aee9226c2cc43"))) - { - return new SimpleTestResult(false, "Q does not match"); - } - - - if (!((ECGOST3410Parameters)pkInfo.getParameters()).getPublicKeyParamSet().toString().equals("1.2.643.7.1.2.1.2.1")) - { - return new SimpleTestResult(false, "PublicKeyParamSet does not match"); - } - - if (!((ECGOST3410Parameters)pkInfo.getParameters()).getDigestParamSet().toString().equals("1.2.643.7.1.1.2.3")) - { - return new SimpleTestResult(false, "DigestParamSet does not match"); - } - - if (((ECGOST3410Parameters)pkInfo.getParameters()).getEncryptionParamSet() != null) - { - return new SimpleTestResult(false, "EncryptionParamSet is not null"); - } - - } - catch (Exception ex) - { - return new SimpleTestResult(false, ex.getMessage(), ex); - } - - return new SimpleTestResult(true, null); - } - - - private SimpleTestResult decodeJCEPrivate() - { - byte[] priv256 = Hex.decode("304a020100302106082a85030701010101301506092a850307010201010106082a8503070101020204220420fe75ba328d5439ed4859e6dc7e6ca2e9aab0818f094eddeb0d57d1c16a90762b"); - - try - { - ECPrivateKeyParameters pkInfo = (ECPrivateKeyParameters)PrivateKeyFactory.createKey(priv256); - - if (!pkInfo.isPrivate()) - { - return new SimpleTestResult(false, "isPrivate should be true"); - } - - if ( - !Arrays.areEqual( - Hex.decode("2b76906ac1d1570debdd4e098f81b0aae9a26c7edce65948ed39548d32ba75fe"), - pkInfo.getD().toByteArray())) - { - return new SimpleTestResult(false, "D does not match"); - } - - if (!((ECGOST3410Parameters)pkInfo.getParameters()).getPublicKeyParamSet().toString().equals("1.2.643.7.1.2.1.1.1")) - { - return new SimpleTestResult(false, "PublicKeyParamSet does not match"); - } - - if (!((ECGOST3410Parameters)pkInfo.getParameters()).getDigestParamSet().toString().equals("1.2.643.7.1.1.2.2")) - { - return new SimpleTestResult(false, "DigestParamSet does not match"); - } - - if (((ECGOST3410Parameters)pkInfo.getParameters()).getEncryptionParamSet() != null) - { - return new SimpleTestResult(false, "EncryptionParamSet is not null"); - } - - - byte[] priv512 = Hex.decode("306a020100302106082a85030701010102301506092a850307010201020106082a85030701010203044204402fc35576152f6e873236608b592b4b98d0793bf5184f8dc4a99512be703716991a96061ef46aceeae5319b5c69e6fcbfa7e339207878597ce50f9b7cbf857ff1"); - - pkInfo = (ECPrivateKeyParameters)PrivateKeyFactory.createKey(priv512); - - if (!pkInfo.isPrivate()) - { - return new SimpleTestResult(false, "isPrivate should be true"); - } - - if ( - !Arrays.areEqual( - Hex.decode("00f17f85bf7c9b0fe57c5978782039e3a7bffce6695c9b31e5eace6af41e06961a99163770be1295a9c48d4f18f53b79d0984b2b598b603632876e2f157655c32f"), - pkInfo.getD().toByteArray())) - { - return new SimpleTestResult(false, "D does not match"); - } - - if (!((ECGOST3410Parameters)pkInfo.getParameters()).getPublicKeyParamSet().toString().equals("1.2.643.7.1.2.1.2.1")) - { - return new SimpleTestResult(false, "PublicKeyParamSet does not match"); - } - - if (!((ECGOST3410Parameters)pkInfo.getParameters()).getDigestParamSet().toString().equals("1.2.643.7.1.1.2.3")) - { - return new SimpleTestResult(false, "DigestParamSet does not match"); - } - - if (((ECGOST3410Parameters)pkInfo.getParameters()).getEncryptionParamSet() != null) - { - return new SimpleTestResult(false, "EncryptionParamSet is not null"); - } - - } - catch (Exception ex) - { - return new SimpleTestResult(false, ex.getMessage(), ex); - } - - return new SimpleTestResult(true, null); - } - - - private SimpleTestResult encodeDecodePrivateLW(String oidStr, ASN1ObjectIdentifier digest) - { - try - { - ASN1ObjectIdentifier oid = ECGOST3410NamedCurves.getOID(oidStr); - ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGOST3410NamedCurves.getByOID(oid)); - ECGOST3410Parameters gostParams = new ECGOST3410Parameters(ecp, oid, digest); - ECKeyGenerationParameters params = new ECKeyGenerationParameters(gostParams, new SecureRandom()); - ECKeyPairGenerator engine = new ECKeyPairGenerator(); - engine.init(params); - AsymmetricCipherKeyPair pair = engine.generateKeyPair(); - - ECPrivateKeyParameters generatedKeyParameters = (ECPrivateKeyParameters)pair.getPrivate(); - - PrivateKeyInfo info = PrivateKeyInfoFactory.createPrivateKeyInfo(generatedKeyParameters); - - ECPrivateKeyParameters recoveredKeyParameters = (ECPrivateKeyParameters)PrivateKeyFactory.createKey(info); - - { // Specifically cast and test gost parameters. - ECGOST3410Parameters gParam = (ECGOST3410Parameters)generatedKeyParameters.getParameters(); - ECGOST3410Parameters rParam = (ECGOST3410Parameters)recoveredKeyParameters.getParameters(); - - boolean ok = safeEquals(gParam.getDigestParamSet(), rParam.getDigestParamSet()) && - safeEquals(gParam.getEncryptionParamSet(), rParam.getEncryptionParamSet()) && - safeEquals(gParam.getPublicKeyParamSet(), rParam.getPublicKeyParamSet()); - - if (!ok) - { - return new SimpleTestResult(false, "GOST parameters does not match"); - } - - } - - - if (recoveredKeyParameters.isPrivate() != generatedKeyParameters.isPrivate()) - { - return new SimpleTestResult(false, "isPrivate does not match"); - } - - if (!((ECGOST3410Parameters)recoveredKeyParameters.getParameters()).getName().equals( - ((ECGOST3410Parameters)generatedKeyParameters.getParameters()).getName())) - { - return new SimpleTestResult(false, "Name does not match"); - } - - - if (!recoveredKeyParameters.getD().equals(generatedKeyParameters.getD())) - { - return new SimpleTestResult(false, "D does not match"); - } - - if (!recoveredKeyParameters.getParameters().getCurve().equals(generatedKeyParameters.getParameters().getCurve())) - { - return new SimpleTestResult(false, "Curve does not match"); - } - - if (!Arrays.areEqual( - recoveredKeyParameters.getParameters().getG().getEncoded(true), - generatedKeyParameters.getParameters().getG().getEncoded(true))) - { - return new SimpleTestResult(false, "G does not match"); - } - - if (!recoveredKeyParameters.getParameters().getH().equals(generatedKeyParameters.getParameters().getH())) - { - return new SimpleTestResult(false, "H does not match"); - } - - if (!recoveredKeyParameters.getParameters().getHInv().equals(generatedKeyParameters.getParameters().getHInv())) - { - return new SimpleTestResult(false, "Hinv does not match"); - } - - if (!recoveredKeyParameters.getParameters().getN().equals(generatedKeyParameters.getParameters().getN())) - { - return new SimpleTestResult(false, "N does not match"); - } - - if (!Arrays.areEqual(recoveredKeyParameters.getParameters().getSeed(), generatedKeyParameters.getParameters().getSeed())) - { - return new SimpleTestResult(false, "Seed does not match"); - } - - return new SimpleTestResult(true, null); - } - catch (Exception t) - { - // Any exception is bad. - return new SimpleTestResult(false, t.getMessage(), t); - } - } - - - private SimpleTestResult encodeDecodePublicLW(String oidStr, ASN1ObjectIdentifier digest) - { - try - { - ASN1ObjectIdentifier oid = ECGOST3410NamedCurves.getOID(oidStr); - ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGOST3410NamedCurves.getByOID(oid)); - ECGOST3410Parameters gostParams = new ECGOST3410Parameters(ecp, oid, digest); - ECKeyGenerationParameters params = new ECKeyGenerationParameters(gostParams, new SecureRandom()); - ECKeyPairGenerator engine = new ECKeyPairGenerator(); - engine.init(params); - AsymmetricCipherKeyPair pair = engine.generateKeyPair(); - - ECPublicKeyParameters generatedKeyParameters = (ECPublicKeyParameters)pair.getPublic(); - - SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(generatedKeyParameters); - - ECPublicKeyParameters recoveredKeyParameters = (ECPublicKeyParameters)PublicKeyFactory.createKey(info); - - { // Specifically cast and test gost parameters. - ECGOST3410Parameters gParam = (ECGOST3410Parameters)generatedKeyParameters.getParameters(); - ECGOST3410Parameters rParam = (ECGOST3410Parameters)recoveredKeyParameters.getParameters(); - - - boolean ok = safeEquals(gParam.getDigestParamSet(), rParam.getDigestParamSet()) && - safeEquals(gParam.getEncryptionParamSet(), rParam.getEncryptionParamSet()) && - safeEquals(gParam.getPublicKeyParamSet(), rParam.getPublicKeyParamSet()); - - if (!ok) - { - return new SimpleTestResult(false, "GOST parameters does not match"); - } - - } - - if (!((ECGOST3410Parameters)recoveredKeyParameters.getParameters()).getName().equals( - ((ECGOST3410Parameters)generatedKeyParameters.getParameters()).getName())) - { - return new SimpleTestResult(false, "Name does not match"); - } - - - if (recoveredKeyParameters.isPrivate() != generatedKeyParameters.isPrivate()) - { - return new SimpleTestResult(false, "isPrivate does not match"); - } - - if (!Arrays.areEqual(recoveredKeyParameters.getQ().getEncoded(true), generatedKeyParameters.getQ().getEncoded(true))) - { - return new SimpleTestResult(false, "Q does not match"); - } - - if (!recoveredKeyParameters.getParameters().getCurve().equals(generatedKeyParameters.getParameters().getCurve())) - { - return new SimpleTestResult(false, "Curve does not match"); - } - - if (!Arrays.areEqual( - recoveredKeyParameters.getParameters().getG().getEncoded(true), - generatedKeyParameters.getParameters().getG().getEncoded(true))) - { - return new SimpleTestResult(false, "G does not match"); - } - - if (!recoveredKeyParameters.getParameters().getH().equals(generatedKeyParameters.getParameters().getH())) - { - return new SimpleTestResult(false, "H does not match"); - } - - if (!recoveredKeyParameters.getParameters().getHInv().equals(generatedKeyParameters.getParameters().getHInv())) - { - return new SimpleTestResult(false, "Hinv does not match"); - } - - if (!recoveredKeyParameters.getParameters().getN().equals(generatedKeyParameters.getParameters().getN())) - { - return new SimpleTestResult(false, "N does not match"); - } - - if (!Arrays.areEqual(recoveredKeyParameters.getParameters().getSeed(), generatedKeyParameters.getParameters().getSeed())) - { - return new SimpleTestResult(false, "Seed does not match"); - } - - return new SimpleTestResult(true, null); - } - catch (Exception t) - { - // Any exception is bad. - return new SimpleTestResult(false, t.getMessage(), t); - } - } - - - private boolean safeEquals(Object left, Object right) - { - if (left == null || right == null) - { - return left == null && right == null; - } - - return left.equals(right); - } - - public TestResult perform() - { - - SimpleTestResult str = encodeDecodePublicLW("Tc26-Gost-3410-12-512-paramSetA", RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512); - if (!str.isSuccessful()) - { - return str; - } - - str = encodeDecodePrivateLW("Tc26-Gost-3410-12-512-paramSetA", RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512); - if (!str.isSuccessful()) - { - return str; - } - - - str = encodeDecodePublicLW("Tc26-Gost-3410-12-256-paramSetA", RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256); - if (!str.isSuccessful()) - { - return str; - } - - str = encodeDecodePrivateLW("Tc26-Gost-3410-12-256-paramSetA", RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256); - if (!str.isSuccessful()) - { - return str; - } - - str = decodeJCEPrivate(); - if (!str.isSuccessful()) - { - return str; - } - - str = decodeJCEPublic(); - if (!str.isSuccessful()) - { - return str; - } - - str = encodeRecodePrivateKey(); - if (!str.isSuccessful()) - { - return str; - } - - str = encodeRecodePublicKey(); - if (!str.isSuccessful()) - { - return str; - } - - - str = encodeRecodePublicKeyGost2006(); - if (!str.isSuccessful()) - { - return str; - } - - str = encodeRecodePrivateKeyGost2006(); - if (!str.isSuccessful()) - { - return str; - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - } - - private class GOST3410_TEST1_512 - implements Test - { - public String getName() - { - return "GOST3410-TEST1-512"; - } - - FixedSecureRandom init_random = new FixedSecureRandom( - new FixedSecureRandom.Source[]{new FixedSecureRandom.Data(Hex.decode("00005EC900007341")), new FixedSecureRandom.Data(zeroTwo(64))}); - FixedSecureRandom random = new TestRandomData(Hex.decode("90F3A564439242F5186EBB224C8E223811B7105C64E4F5390807E6362DF4C72A")); - FixedSecureRandom keyRandom = new TestRandomData(Hex.decode("3036314538303830343630454235324435324234314132373832433138443046")); - - BigInteger pValue = new BigInteger("EE8172AE8996608FB69359B89EB82A69854510E2977A4D63BC97322CE5DC3386EA0A12B343E9190F23177539845839786BB0C345D165976EF2195EC9B1C379E3", 16); - BigInteger qValue = new BigInteger("98915E7EC8265EDFCDA31E88F24809DDB064BDC7285DD50D7289F0AC6F49DD2D", 16); - - public TestResult perform() - { - BigInteger r = new BigInteger("3e5f895e276d81d2d52c0763270a458157b784c57abdbd807bc44fd43a32ac06", 16); - BigInteger s = new BigInteger("3f0dd5d4400d47c08e4ce505ff7434b6dbf729592e37c74856dab85115a60955", 16); - GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator(); - - pGen.init(512, 1, init_random); - - GOST3410Parameters params = pGen.generateParameters(); - - if (params.getValidationParameters() == null) - { - return new SimpleTestResult(false, getName() + "validation parameters wrong"); - } - if (params.getValidationParameters().getC() != 29505 - || params.getValidationParameters().getX0() != 24265) - { - return new SimpleTestResult(false, getName() + "validation parameters values wrong"); - } - if (!init_random.isExhausted()) - { - return new SimpleTestResult(false, getName() - + ": unexpected number of bytes used from 'init_random'."); - } - - if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ())) - { - return new SimpleTestResult(false, getName() + ": p or q wrong"); - } - - GOST3410KeyPairGenerator GOST3410KeyGen = new GOST3410KeyPairGenerator(); - GOST3410KeyGenerationParameters genParam = new GOST3410KeyGenerationParameters(keyRandom, params); - - GOST3410KeyGen.init(genParam); - - AsymmetricCipherKeyPair pair = GOST3410KeyGen.generateKeyPair(); - - if (!keyRandom.isExhausted()) - { - return new SimpleTestResult(false, getName() - + ": unexpected number of bytes used from 'keyRandom'."); - } - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - GOST3410Signer gost3410 = new GOST3410Signer(); - - gost3410.init(true, param); - - BigInteger[] sig = gost3410.generateSignature(hashmessage); - - if (!random.isExhausted()) - { - return new SimpleTestResult(false, getName() - + ": unexpected number of bytes used from 'random'."); - } - - if (!r.equals(sig[0])) - { - return new SimpleTestResult(false, getName() - + ": r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sig[0].toString(16)); - } - - if (!s.equals(sig[1])) - { - return new SimpleTestResult(false, getName() - + ": s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sig[1].toString(16)); - } - - gost3410.init(false, pair.getPublic()); - - if (gost3410.verifySignature(hashmessage, sig[0], sig[1])) - { - return new SimpleTestResult(true, getName() + ": Okay"); - } - else - { - return new SimpleTestResult(false, getName() + ": verification fails"); - } - } - } - - private class GOST3410_TEST2_512 - implements Test - { - public String getName() - { - return "GOST3410-TEST2-512"; - } - - FixedSecureRandom init_random = new FixedSecureRandom( - new FixedSecureRandom.Source[]{new FixedSecureRandom.Data(Hex.decode("000000003DFC46F1000000000000000D")), new FixedSecureRandom.Data(zeroTwo(64))}); - FixedSecureRandom random = new TestRandomData(Hex.decode("90F3A564439242F5186EBB224C8E223811B7105C64E4F5390807E6362DF4C72A")); - FixedSecureRandom keyRandom = new TestRandomData(Hex.decode("3036314538303830343630454235324435324234314132373832433138443046")); - - BigInteger pValue = new BigInteger("8b08eb135af966aab39df294538580c7da26765d6d38d30cf1c06aae0d1228c3316a0e29198460fad2b19dc381c15c888c6dfd0fc2c565abb0bf1faff9518f85", 16); - BigInteger qValue = new BigInteger("931a58fb6f0dcdf2fe7549bc3f19f4724b56898f7f921a076601edb18c93dc75", 16); - - public TestResult perform() - { - BigInteger r = new BigInteger("7c07c8cf035c2a1cb2b7fae5807ac7cd623dfca7a1a68f6d858317822f1ea00d", 16); - BigInteger s = new BigInteger("7e9e036a6ff87dbf9b004818252b1f6fc310bdd4d17cb8c37d9c36c7884de60c", 16); - GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator(); - - pGen.init(512, 2, init_random); - - GOST3410Parameters params = pGen.generateParameters(); - - if (!init_random.isExhausted()) - { - return new SimpleTestResult(false, getName() - + ": unexpected number of bytes used from 'init_random'."); - } - - if (params.getValidationParameters() == null) - { - return new SimpleTestResult(false, getName() + ": validation parameters wrong"); - } - - if (params.getValidationParameters().getCL() != 13 - || params.getValidationParameters().getX0L() != 1039943409) - { - return new SimpleTestResult(false, getName() + ": validation parameters values wrong"); - } - - if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ())) - { - return new SimpleTestResult(false, getName() + ": p or q wrong"); - } - - GOST3410KeyPairGenerator GOST3410KeyGen = new GOST3410KeyPairGenerator(); - GOST3410KeyGenerationParameters genParam = new GOST3410KeyGenerationParameters(keyRandom, params); - - GOST3410KeyGen.init(genParam); - - AsymmetricCipherKeyPair pair = GOST3410KeyGen.generateKeyPair(); - - if (!keyRandom.isExhausted()) - { - return new SimpleTestResult(false, getName() - + ": unexpected number of bytes used from 'keyRandom'."); - } - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - GOST3410Signer GOST3410 = new GOST3410Signer(); - - GOST3410.init(true, param); - - BigInteger[] sig = GOST3410.generateSignature(hashmessage); - - if (!random.isExhausted()) - { - return new SimpleTestResult(false, getName() - + ": unexpected number of bytes used from 'random'."); - } - - if (!r.equals(sig[0])) - { - return new SimpleTestResult(false, getName() - + ": r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sig[0].toString(16)); - } - - if (!s.equals(sig[1])) - { - return new SimpleTestResult(false, getName() - + ": s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sig[1].toString(16)); - } - - GOST3410.init(false, pair.getPublic()); - - if (GOST3410.verifySignature(hashmessage, sig[0], sig[1])) - { - return new SimpleTestResult(true, getName() + ": Okay"); - } - else - { - return new SimpleTestResult(false, getName() + ": verification fails"); - } - } - } - - private class GOST3410_TEST1_1024 - implements Test - { - public String getName() - { - return "GOST3410-TEST1-1024"; - } - - SecureRandom init_random = new SecureRandom() - { - boolean firstInt = true; - - public int nextInt() - { - String x0 = "0xA565"; - String c = "0x538B"; - - if (firstInt) - { - firstInt = false; - return NumberParsing.decodeIntFromHex(x0); - } - return NumberParsing.decodeIntFromHex(c); - } - - public void nextBytes(byte[] bytes) - { - - byte[] d = Hex.decode("02"); - - System.arraycopy(d, 0, bytes, bytes.length - d.length, d.length); - } - }; - - SecureRandom random = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] k = Hex.decode("90F3A564439242F5186EBB224C8E223811B7105C64E4F5390807E6362DF4C72A"); - - int i; - - for (i = 0; i < (bytes.length - k.length); i += k.length) - { - System.arraycopy(k, 0, bytes, i, k.length); - } - - if (i > bytes.length) - { - System.arraycopy(k, 0, bytes, i - k.length, bytes.length - (i - k.length)); - } - else - { - System.arraycopy(k, 0, bytes, i, bytes.length - i); - } - } - }; - - SecureRandom keyRandom = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] x = Hex.decode("3036314538303830343630454235324435324234314132373832433138443046"); - - int i; - - for (i = 0; i < (bytes.length - x.length); i += x.length) - { - System.arraycopy(x, 0, bytes, i, x.length); - } - - if (i > bytes.length) - { - System.arraycopy(x, 0, bytes, i - x.length, bytes.length - (i - x.length)); - } - else - { - System.arraycopy(x, 0, bytes, i, bytes.length - i); - } - } - }; - - BigInteger pValue = new BigInteger("ab8f37938356529e871514c1f48c5cbce77b2f4fc9a2673ac2c1653da8984090c0ac73775159a26bef59909d4c9846631270e16653a6234668f2a52a01a39b921490e694c0f104b58d2e14970fccb478f98d01e975a1028b9536d912de5236d2dd2fc396b77153594d4178780e5f16f718471e2111c8ce64a7d7e196fa57142d", 16); - BigInteger qValue = new BigInteger("bcc02ca0ce4f0753ec16105ee5d530aa00d39f3171842ab2c334a26b5f576e0f", 16); - - public TestResult perform() - { - BigInteger r = new BigInteger("a8790aabbd5a998ff524bad048ac69cd1faff2dab048265c8d60d1471c44a9ee", 16); - BigInteger s = new BigInteger("30df5ba32ac77170b9632559bef7d37620017756dff3fea1088b4267db0944b8", 16); - GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator(); - - pGen.init(1024, 1, init_random); - - GOST3410Parameters params = pGen.generateParameters(); - - if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ())) - { - return new SimpleTestResult(false, getName() + ": p or q wrong"); - } - - GOST3410KeyPairGenerator GOST3410KeyGen = new GOST3410KeyPairGenerator(); - GOST3410KeyGenerationParameters genParam = new GOST3410KeyGenerationParameters(keyRandom, params); - - GOST3410KeyGen.init(genParam); - - AsymmetricCipherKeyPair pair = GOST3410KeyGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - GOST3410Signer GOST3410 = new GOST3410Signer(); - - GOST3410.init(true, param); - - BigInteger[] sig = GOST3410.generateSignature(hashmessage); - - if (!r.equals(sig[0])) - { - return new SimpleTestResult(false, getName() - + ": r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sig[0].toString(16)); - } - - if (!s.equals(sig[1])) - { - return new SimpleTestResult(false, getName() - + ": s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sig[1].toString(16)); - } - - GOST3410.init(false, pair.getPublic()); - - if (GOST3410.verifySignature(hashmessage, sig[0], sig[1])) - { - return new SimpleTestResult(true, getName() + ": Okay"); - } - else - { - return new SimpleTestResult(false, getName() + ": verification fails"); - } - } - } - - private class GOST3410_TEST2_1024 - implements Test - { - public String getName() - { - return "GOST3410-TEST2-1024"; - } - - SecureRandom init_random = new SecureRandom() - { - boolean firstLong = true; - - public long nextLong() - { - String x0 = "0x3DFC46F1"; - String c = "0xD"; - - if (firstLong) - { - firstLong = false; - return NumberParsing.decodeLongFromHex(x0); - } - return NumberParsing.decodeLongFromHex(c); - } - - public void nextBytes(byte[] bytes) - { - - byte[] d = Hex.decode("02"); - - System.arraycopy(d, 0, bytes, bytes.length - d.length, d.length); - } - }; - - SecureRandom random = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] k = Hex.decode("90F3A564439242F5186EBB224C8E223811B7105C64E4F5390807E6362DF4C72A"); - - int i; - - for (i = 0; i < (bytes.length - k.length); i += k.length) - { - System.arraycopy(k, 0, bytes, i, k.length); - } - - if (i > bytes.length) - { - System.arraycopy(k, 0, bytes, i - k.length, bytes.length - (i - k.length)); - } - else - { - System.arraycopy(k, 0, bytes, i, bytes.length - i); - } - } - }; - - SecureRandom keyRandom = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] x = Hex.decode("3036314538303830343630454235324435324234314132373832433138443046"); - - int i; - - for (i = 0; i < (bytes.length - x.length); i += x.length) - { - System.arraycopy(x, 0, bytes, i, x.length); - } - - if (i > bytes.length) - { - System.arraycopy(x, 0, bytes, i - x.length, bytes.length - (i - x.length)); - } - else - { - System.arraycopy(x, 0, bytes, i, bytes.length - i); - } - } - }; - - BigInteger pValue = new BigInteger("e2c4191c4b5f222f9ac2732562f6d9b4f18e7fb67a290ea1e03d750f0b9806755fc730d975bf3faa606d05c218b35a6c3706919aab92e0c58b1de4531c8fa8e7af43c2bff016251e21b2870897f6a27ac4450bca235a5b748ad386e4a0e4dfcb09152435abcfe48bd0b126a8122c7382f285a9864615c66decddf6afd355dfb7", 16); - BigInteger qValue = new BigInteger("931a58fb6f0dcdf2fe7549bc3f19f4724b56898f7f921a076601edb18c93dc75", 16); - - public TestResult perform() - { - BigInteger r = new BigInteger("81d69a192e9c7ac21fc07da41bd07e230ba6a94eb9f3c1fd104c7bd976733ca5", 16); - BigInteger s = new BigInteger("315c879c8414f35feb4deb15e7cc0278c48e6ca1596325d6959338d860b0c47a", 16); - GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator(); - - pGen.init(1024, 2, init_random); - - GOST3410Parameters params = pGen.generateParameters(); - - if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ())) - { - return new SimpleTestResult(false, getName() + ": p or q wrong"); - } - - GOST3410KeyPairGenerator GOST3410KeyGen = new GOST3410KeyPairGenerator(); - GOST3410KeyGenerationParameters genParam = new GOST3410KeyGenerationParameters(keyRandom, params); - - GOST3410KeyGen.init(genParam); - - AsymmetricCipherKeyPair pair = GOST3410KeyGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - GOST3410Signer GOST3410 = new GOST3410Signer(); - - GOST3410.init(true, param); - - BigInteger[] sig = GOST3410.generateSignature(hashmessage); - - if (!r.equals(sig[0])) - { - return new SimpleTestResult(false, getName() - + ": r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sig[0].toString(16)); - } - - if (!s.equals(sig[1])) - { - return new SimpleTestResult(false, getName() - + ": s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sig[1].toString(16)); - } - - GOST3410.init(false, pair.getPublic()); - - if (GOST3410.verifySignature(hashmessage, sig[0], sig[1])) - { - return new SimpleTestResult(true, getName() + ": Okay"); - } - else - { - return new SimpleTestResult(false, getName() + ": verification fails"); - } - } - } - - private class GOST3410_AParam - implements Test - { - public String getName() - { - return "GOST3410-AParam"; - } - - SecureRandom init_random = new SecureRandom() - { - boolean firstLong = true; - - public long nextLong() - { - String x0 = "0x520874F5"; - String c = "0xEE39ADB3"; - - if (firstLong) - { - firstLong = false; - return NumberParsing.decodeLongFromHex(x0); - } - return NumberParsing.decodeLongFromHex(c); - } - - public void nextBytes(byte[] bytes) - { - - byte[] d = Hex.decode("02"); - - System.arraycopy(d, 0, bytes, bytes.length - d.length, d.length); - } - }; - - SecureRandom random = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] k = Hex.decode("90F3A564439242F5186EBB224C8E223811B7105C64E4F5390807E6362DF4C72A"); - - int i; - - for (i = 0; i < (bytes.length - k.length); i += k.length) - { - System.arraycopy(k, 0, bytes, i, k.length); - } - - if (i > bytes.length) - { - System.arraycopy(k, 0, bytes, i - k.length, bytes.length - (i - k.length)); - } - else - { - System.arraycopy(k, 0, bytes, i, bytes.length - i); - } - } - }; - - SecureRandom keyRandom = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] x = Hex.decode("3036314538303830343630454235324435324234314132373832433138443046"); - - int i; - - for (i = 0; i < (bytes.length - x.length); i += x.length) - { - System.arraycopy(x, 0, bytes, i, x.length); - } - - if (i > bytes.length) - { - System.arraycopy(x, 0, bytes, i - x.length, bytes.length - (i - x.length)); - } - else - { - System.arraycopy(x, 0, bytes, i, bytes.length - i); - } - } - }; - - BigInteger pValue = new BigInteger("b4e25efb018e3c8b87505e2a67553c5edc56c2914b7e4f89d23f03f03377e70a2903489dd60e78418d3d851edb5317c4871e40b04228c3b7902963c4b7d85d52b9aa88f2afdbeb28da8869d6df846a1d98924e925561bd69300b9ddd05d247b5922d967cbb02671881c57d10e5ef72d3e6dad4223dc82aa1f7d0294651a480df", 16); - BigInteger qValue = new BigInteger("972432a437178b30bd96195b773789ab2fff15594b176dd175b63256ee5af2cf", 16); - - public TestResult perform() - { - BigInteger r = new BigInteger("64a8856628e5669d85f62cd763dd4a99bc56d33dc0e1859122855d141e9e4774", 16); - BigInteger s = new BigInteger("319ebac97092b288d469a4b988248794f60c865bc97858d9a3135c6d1a1bf2dd", 16); - GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator(); - - pGen.init(1024, 2, init_random); - - GOST3410Parameters params = pGen.generateParameters(); - - if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ())) - { - return new SimpleTestResult(false, getName() + ": p or q wrong"); - } - - GOST3410KeyPairGenerator GOST3410KeyGen = new GOST3410KeyPairGenerator(); - GOST3410KeyGenerationParameters genParam = new GOST3410KeyGenerationParameters(keyRandom, params); - - GOST3410KeyGen.init(genParam); - - AsymmetricCipherKeyPair pair = GOST3410KeyGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - GOST3410Signer GOST3410 = new GOST3410Signer(); - - GOST3410.init(true, param); - - BigInteger[] sig = GOST3410.generateSignature(hashmessage); - - if (!r.equals(sig[0])) - { - return new SimpleTestResult(false, getName() - + ": r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sig[0].toString(16)); - } - - if (!s.equals(sig[1])) - { - return new SimpleTestResult(false, getName() - + ": s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sig[1].toString(16)); - } - - GOST3410.init(false, pair.getPublic()); - - if (GOST3410.verifySignature(hashmessage, sig[0], sig[1])) - { - return new SimpleTestResult(true, getName() + ": Okay"); - } - else - { - return new SimpleTestResult(false, getName() + ": verification fails"); - } - } - } - - private class GOST3410_BParam - implements Test - { - public String getName() - { - return "GOST3410-BParam"; - } - - SecureRandom init_random = new SecureRandom() - { - boolean firstLong = true; - - public long nextLong() - { - String x0 = "0x5B977CDB"; - String c = "0x6E9692DD"; - - if (firstLong) - { - firstLong = false; - return NumberParsing.decodeLongFromHex(x0); - } - return NumberParsing.decodeLongFromHex(c); - } - - public void nextBytes(byte[] bytes) - { - byte[] d = Hex.decode("bc3cbbdb7e6f848286e19ad9a27a8e297e5b71c53dd974cdf60f937356df69cbc97a300ccc71685c553046147f11568c4fddf363d9d886438345a62c3b75963d6546adfabf31b31290d12cae65ecb8309ef66782"); - - System.arraycopy(d, 0, bytes, bytes.length - d.length, d.length); - } - }; - - SecureRandom random = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] k = Hex.decode("90F3A564439242F5186EBB224C8E223811B7105C64E4F5390807E6362DF4C72A"); - - int i; - - for (i = 0; i < (bytes.length - k.length); i += k.length) - { - System.arraycopy(k, 0, bytes, i, k.length); - } - - if (i > bytes.length) - { - System.arraycopy(k, 0, bytes, i - k.length, bytes.length - (i - k.length)); - } - else - { - System.arraycopy(k, 0, bytes, i, bytes.length - i); - } - } - }; - - SecureRandom keyRandom = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] x = Hex.decode("3036314538303830343630454235324435324234314132373832433138443046"); - - int i; - - for (i = 0; i < (bytes.length - x.length); i += x.length) - { - System.arraycopy(x, 0, bytes, i, x.length); - } - - if (i > bytes.length) - { - System.arraycopy(x, 0, bytes, i - x.length, bytes.length - (i - x.length)); - } - else - { - System.arraycopy(x, 0, bytes, i, bytes.length - i); - } - } - }; - - BigInteger pValue = new BigInteger("c6971fc57524b30c9018c5e621de15499736854f56a6f8aee65a7a404632b3540f09020f67f04dc2e6783b141dceffd21a703035b7d0187c6e12cb4229922bafdb2225b73e6b23a0de36e20047065aea000c1a374283d0ad8dc1981e3995f0bb8c72526041fcb98ae6163e1e71a669d8364e9c4c3188f673c5f8ee6fadb41abf", 16); - BigInteger qValue = new BigInteger("b09d634c10899cd7d4c3a7657403e05810b07c61a688bab2c37f475e308b0607", 16); - - public TestResult perform() - { - BigInteger r = new BigInteger("860d82c60e9502cd00c0e9e1f6563feafec304801974d745c5e02079946f729e", 16); - BigInteger s = new BigInteger("7ef49264ef022801aaa03033cd97915235fbab4c823ed936b0f360c22114688a", 16); - GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator(); - - pGen.init(1024, 2, init_random); - - GOST3410Parameters params = pGen.generateParameters(); - - if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ())) - { - return new SimpleTestResult(false, getName() + ": p or q wrong"); - } - - GOST3410KeyPairGenerator GOST3410KeyGen = new GOST3410KeyPairGenerator(); - GOST3410KeyGenerationParameters genParam = new GOST3410KeyGenerationParameters(keyRandom, params); - - GOST3410KeyGen.init(genParam); - - AsymmetricCipherKeyPair pair = GOST3410KeyGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - GOST3410Signer GOST3410 = new GOST3410Signer(); - - GOST3410.init(true, param); - - BigInteger[] sig = GOST3410.generateSignature(hashmessage); - - if (!r.equals(sig[0])) - { - return new SimpleTestResult(false, getName() - + ": r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sig[0].toString(16)); - } - - if (!s.equals(sig[1])) - { - return new SimpleTestResult(false, getName() - + ": s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sig[1].toString(16)); - } - - GOST3410.init(false, pair.getPublic()); - - if (GOST3410.verifySignature(hashmessage, sig[0], sig[1])) - { - return new SimpleTestResult(true, getName() + ": Okay"); - } - else - { - return new SimpleTestResult(false, getName() + ": verification fails"); - } - } - } - - private class GOST3410_CParam - implements Test - { - public String getName() - { - return "GOST3410-CParam"; - } - - SecureRandom init_random = new SecureRandom() - { - boolean firstLong = true; - - public long nextLong() - { - String x0 = "0x43848744"; - String c = "0xB50A826D"; - - if (firstLong) - { - firstLong = false; - return NumberParsing.decodeLongFromHex(x0); - } - return NumberParsing.decodeLongFromHex(c); - } - - public void nextBytes(byte[] bytes) - { - byte[] d = Hex.decode("7F575E8194BC5BDF"); - - System.arraycopy(d, 0, bytes, bytes.length - d.length, d.length); - } - }; - - SecureRandom random = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] k = Hex.decode("90F3A564439242F5186EBB224C8E223811B7105C64E4F5390807E6362DF4C72A"); - - int i; - - for (i = 0; i < (bytes.length - k.length); i += k.length) - { - System.arraycopy(k, 0, bytes, i, k.length); - } - - if (i > bytes.length) - { - System.arraycopy(k, 0, bytes, i - k.length, bytes.length - (i - k.length)); - } - else - { - System.arraycopy(k, 0, bytes, i, bytes.length - i); - } - } - }; - - SecureRandom keyRandom = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] x = Hex.decode("3036314538303830343630454235324435324234314132373832433138443046"); - - int i; - - for (i = 0; i < (bytes.length - x.length); i += x.length) - { - System.arraycopy(x, 0, bytes, i, x.length); - } - - if (i > bytes.length) - { - System.arraycopy(x, 0, bytes, i - x.length, bytes.length - (i - x.length)); - } - else - { - System.arraycopy(x, 0, bytes, i, bytes.length - i); - } - } - }; - - BigInteger pValue = new BigInteger("9d88e6d7fe3313bd2e745c7cdd2ab9ee4af3c8899e847de74a33783ea68bc30588ba1f738c6aaf8ab350531f1854c3837cc3c860ffd7e2e106c3f63b3d8a4c034ce73942a6c3d585b599cf695ed7a3c4a93b2b947b7157bb1a1c043ab41ec8566c6145e938a611906de0d32e562494569d7e999a0dda5c879bdd91fe124df1e9", 16); - BigInteger qValue = new BigInteger("fadd197abd19a1b4653eecf7eca4d6a22b1f7f893b641f901641fbb555354faf", 16); - - public TestResult perform() - { - BigInteger r = new BigInteger("4deb95a0b35e7ed7edebe9bef5a0f93739e16b7ff27fe794d989d0c13159cfbc", 16); - BigInteger s = new BigInteger("e1d0d30345c24cfeb33efde3deee5fbbda78ddc822b719d860cd0ba1fb6bd43b", 16); - GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator(); - - pGen.init(1024, 2, init_random); - - GOST3410Parameters params = pGen.generateParameters(); - - if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ())) - { - return new SimpleTestResult(false, getName() + ": p or q wrong"); - } - - GOST3410KeyPairGenerator GOST3410KeyGen = new GOST3410KeyPairGenerator(); - GOST3410KeyGenerationParameters genParam = new GOST3410KeyGenerationParameters(keyRandom, params); - - GOST3410KeyGen.init(genParam); - - AsymmetricCipherKeyPair pair = GOST3410KeyGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - GOST3410Signer GOST3410 = new GOST3410Signer(); - - GOST3410.init(true, param); - - BigInteger[] sig = GOST3410.generateSignature(hashmessage); - - if (!r.equals(sig[0])) - { - return new SimpleTestResult(false, getName() - + ": r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sig[0].toString(16)); - } - - if (!s.equals(sig[1])) - { - return new SimpleTestResult(false, getName() - + ": s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sig[1].toString(16)); - } - - GOST3410.init(false, pair.getPublic()); - - if (GOST3410.verifySignature(hashmessage, sig[0], sig[1])) - { - return new SimpleTestResult(true, getName() + ": Okay"); - } - else - { - return new SimpleTestResult(false, getName() + ": verification fails"); - } - } - } - - private class GOST3410_DParam - implements Test - { - public String getName() - { - return "GOST3410-DParam"; - } - - SecureRandom init_random = new SecureRandom() - { - boolean firstLong = true; - - public long nextLong() - { - String x0 = "0x13DA8B9D"; - String c = "0xA0E9DE4B"; - - if (firstLong) - { - firstLong = false; - return NumberParsing.decodeLongFromHex(x0); - } - return NumberParsing.decodeLongFromHex(c); - } - - public void nextBytes(byte[] bytes) - { - - byte[] d = Hex.decode("41ab97857f42614355d32db0b1069f109a4da283676c7c53a68185b4"); - - System.arraycopy(d, 0, bytes, bytes.length - d.length, d.length); - } - }; - - SecureRandom random = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] k = Hex.decode("90F3A564439242F5186EBB224C8E223811B7105C64E4F5390807E6362DF4C72A"); - - int i; - - for (i = 0; i < (bytes.length - k.length); i += k.length) - { - System.arraycopy(k, 0, bytes, i, k.length); - } - - if (i > bytes.length) - { - System.arraycopy(k, 0, bytes, i - k.length, bytes.length - (i - k.length)); - } - else - { - System.arraycopy(k, 0, bytes, i, bytes.length - i); - } - } - }; - - SecureRandom keyRandom = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] x = Hex.decode("3036314538303830343630454235324435324234314132373832433138443046"); - - int i; - - for (i = 0; i < (bytes.length - x.length); i += x.length) - { - System.arraycopy(x, 0, bytes, i, x.length); - } - - if (i > bytes.length) - { - System.arraycopy(x, 0, bytes, i - x.length, bytes.length - (i - x.length)); - } - else - { - System.arraycopy(x, 0, bytes, i, bytes.length - i); - } - } - }; - - BigInteger pValue = new BigInteger("80f102d32b0fd167d069c27a307adad2c466091904dbaa55d5b8cc7026f2f7a1919b890cb652c40e054e1e9306735b43d7b279eddf9102001cd9e1a831fe8a163eed89ab07cf2abe8242ac9dedddbf98d62cddd1ea4f5f15d3a42a6677bdd293b24260c0f27c0f1d15948614d567b66fa902baa11a69ae3bceadbb83e399c9b5", 16); - BigInteger qValue = new BigInteger("f0f544c418aac234f683f033511b65c21651a6078bda2d69bb9f732867502149", 16); - - public TestResult perform() - { - BigInteger r = new BigInteger("712592d285b792e33b8a9a11e8e6c4f512ddf0042972bbfd1abb0a93e8fc6f54", 16); - BigInteger s = new BigInteger("2cf26758321258b130d5612111339f09ceb8668241f3482e38baa56529963f07", 16); - GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator(); - - pGen.init(1024, 2, init_random); - - GOST3410Parameters params = pGen.generateParameters(); - - if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ())) - { - return new SimpleTestResult(false, getName() + ": p or q wrong"); - } - - GOST3410KeyPairGenerator GOST3410KeyGen = new GOST3410KeyPairGenerator(); - GOST3410KeyGenerationParameters genParam = new GOST3410KeyGenerationParameters(keyRandom, params); - - GOST3410KeyGen.init(genParam); - - AsymmetricCipherKeyPair pair = GOST3410KeyGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - GOST3410Signer GOST3410 = new GOST3410Signer(); - - GOST3410.init(true, param); - - BigInteger[] sig = GOST3410.generateSignature(hashmessage); - - if (!r.equals(sig[0])) - { - return new SimpleTestResult(false, getName() - + ": r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sig[0].toString(16)); - } - - if (!s.equals(sig[1])) - { - return new SimpleTestResult(false, getName() - + ": s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sig[1].toString(16)); - } - - GOST3410.init(false, pair.getPublic()); - - if (GOST3410.verifySignature(hashmessage, sig[0], sig[1])) - { - return new SimpleTestResult(true, getName() + ": Okay"); - } - else - { - return new SimpleTestResult(false, getName() + ": verification fails"); - } - } - } - - private class GOST3410_AExParam - implements Test - { - public String getName() - { - return "GOST3410-AExParam"; - } - - SecureRandom init_random = new SecureRandom() - { - boolean firstLong = true; - - public long nextLong() - { - String x0 = "0xD05E9F14"; - String c = "0x46304C5F"; - - if (firstLong) - { - firstLong = false; - return NumberParsing.decodeLongFromHex(x0); - } - return NumberParsing.decodeLongFromHex(c); - } - - public void nextBytes(byte[] bytes) - { - byte[] d = Hex.decode("35ab875399cda33c146ca629660e5a5e5c07714ca326db032dd6751995cdb90a612b9228932d8302704ec24a5def7739c5813d83"); - - System.arraycopy(d, 0, bytes, bytes.length - d.length, d.length); - } - }; - - SecureRandom random = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] k = Hex.decode("90F3A564439242F5186EBB224C8E223811B7105C64E4F5390807E6362DF4C72A"); - - int i; - - for (i = 0; i < (bytes.length - k.length); i += k.length) - { - System.arraycopy(k, 0, bytes, i, k.length); - } - - if (i > bytes.length) - { - System.arraycopy(k, 0, bytes, i - k.length, bytes.length - (i - k.length)); - } - else - { - System.arraycopy(k, 0, bytes, i, bytes.length - i); - } - } - }; - - SecureRandom keyRandom = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] x = Hex.decode("3036314538303830343630454235324435324234314132373832433138443046"); - - int i; - - for (i = 0; i < (bytes.length - x.length); i += x.length) - { - System.arraycopy(x, 0, bytes, i, x.length); - } - - if (i > bytes.length) - { - System.arraycopy(x, 0, bytes, i - x.length, bytes.length - (i - x.length)); - } - else - { - System.arraycopy(x, 0, bytes, i, bytes.length - i); - } - } - }; - - BigInteger pValue = new BigInteger("ca3b3f2eee9fd46317d49595a9e7518e6c63d8f4eb4d22d10d28af0b8839f079f8289e603b03530784b9bb5a1e76859e4850c670c7b71c0df84ca3e0d6c177fe9f78a9d8433230a883cd82a2b2b5c7a3306980278570cdb79bf01074a69c9623348824b0c53791d53c6a78cab69e1cfb28368611a397f50f541e16db348dbe5f", 16); - BigInteger qValue = new BigInteger("cae4d85f80c147704b0ca48e85fb00a9057aa4acc44668e17f1996d7152690d9", 16); - - public TestResult perform() - { - BigInteger r = new BigInteger("90892707282f433398488f19d31ac48523a8e2ded68944e0da91c6895ee7045e", 16); - BigInteger s = new BigInteger("3be4620ee88f1ee8f9dd63c7d145b7e554839feeca125049118262ea4651e9de", 16); - GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator(); - - pGen.init(1024, 2, init_random); - - GOST3410Parameters params = pGen.generateParameters(); - - if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ())) - { - return new SimpleTestResult(false, getName() + ": p or q wrong"); - } - - GOST3410KeyPairGenerator GOST3410KeyGen = new GOST3410KeyPairGenerator(); - GOST3410KeyGenerationParameters genParam = new GOST3410KeyGenerationParameters(keyRandom, params); - - GOST3410KeyGen.init(genParam); - - AsymmetricCipherKeyPair pair = GOST3410KeyGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - GOST3410Signer GOST3410 = new GOST3410Signer(); - - GOST3410.init(true, param); - - BigInteger[] sig = GOST3410.generateSignature(hashmessage); - - if (!r.equals(sig[0])) - { - return new SimpleTestResult(false, getName() - + ": r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sig[0].toString(16)); - } - - if (!s.equals(sig[1])) - { - return new SimpleTestResult(false, getName() - + ": s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sig[1].toString(16)); - } - - GOST3410.init(false, pair.getPublic()); - - if (GOST3410.verifySignature(hashmessage, sig[0], sig[1])) - { - return new SimpleTestResult(true, getName() + ": Okay"); - } - else - { - return new SimpleTestResult(false, getName() + ": verification fails"); - } - } - } - - public String getName() - { - return "GOST3410"; - } - - private class GOST3410_BExParam - implements Test - { - public String getName() - { - return "GOST3410-BExParam"; - } - - SecureRandom init_random = new SecureRandom() - { - boolean firstLong = true; - - public long nextLong() - { - String x0 = "0x7A007804"; - String c = "0xD31A4FF7"; - - if (firstLong) - { - firstLong = false; - return NumberParsing.decodeLongFromHex(x0); - } - return NumberParsing.decodeLongFromHex(c); - } - - public void nextBytes(byte[] bytes) - { - byte[] d = Hex.decode("7ec123d161477762838c2bea9dbdf33074af6d41d108a066a1e7a07ab3048de2"); - - System.arraycopy(d, 0, bytes, bytes.length - d.length, d.length); - } - }; - - SecureRandom random = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] k = Hex.decode("90F3A564439242F5186EBB224C8E223811B7105C64E4F5390807E6362DF4C72A"); - - int i; - - for (i = 0; i < (bytes.length - k.length); i += k.length) - { - System.arraycopy(k, 0, bytes, i, k.length); - } - - if (i > bytes.length) - { - System.arraycopy(k, 0, bytes, i - k.length, bytes.length - (i - k.length)); - } - else - { - System.arraycopy(k, 0, bytes, i, bytes.length - i); - } - } - }; - - SecureRandom keyRandom = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] x = Hex.decode("3036314538303830343630454235324435324234314132373832433138443046"); - - int i; - - for (i = 0; i < (bytes.length - x.length); i += x.length) - { - System.arraycopy(x, 0, bytes, i, x.length); - } - - if (i > bytes.length) - { - System.arraycopy(x, 0, bytes, i - x.length, bytes.length - (i - x.length)); - } - else - { - System.arraycopy(x, 0, bytes, i, bytes.length - i); - } - } - }; - - BigInteger pValue = new BigInteger("9286dbda91eccfc3060aa5598318e2a639f5ba90a4ca656157b2673fb191cd0589ee05f4cef1bd13508408271458c30851ce7a4ef534742bfb11f4743c8f787b11193ba304c0e6bca25701bf88af1cb9b8fd4711d89f88e32b37d95316541bf1e5dbb4989b3df13659b88c0f97a3c1087b9f2d5317d557dcd4afc6d0a754e279", 16); - BigInteger qValue = new BigInteger("c966e9b3b8b7cdd82ff0f83af87036c38f42238ec50a876cd390e43d67b6013f", 16); - - public TestResult perform() - { - BigInteger r = new BigInteger("8f79a582513df84dc247bcb624340cc0e5a34c4324a20ce7fe3ab8ff38a9db71", 16); - BigInteger s = new BigInteger("7508d22fd6cbb45efd438cb875e43f137247088d0f54b29a7c91f68a65b5fa85", 16); - GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator(); - - pGen.init(1024, 2, init_random); - - GOST3410Parameters params = pGen.generateParameters(); - - if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ())) - { - return new SimpleTestResult(false, getName() + ": p or q wrong"); - } - - GOST3410KeyPairGenerator GOST3410KeyGen = new GOST3410KeyPairGenerator(); - GOST3410KeyGenerationParameters genParam = new GOST3410KeyGenerationParameters(keyRandom, params); - - GOST3410KeyGen.init(genParam); - - AsymmetricCipherKeyPair pair = GOST3410KeyGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - GOST3410Signer GOST3410 = new GOST3410Signer(); - - GOST3410.init(true, param); - - BigInteger[] sig = GOST3410.generateSignature(hashmessage); - - if (!r.equals(sig[0])) - { - return new SimpleTestResult(false, getName() - + ": r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sig[0].toString(16)); - } - - if (!s.equals(sig[1])) - { - return new SimpleTestResult(false, getName() - + ": s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sig[1].toString(16)); - } - - GOST3410.init(false, pair.getPublic()); - - if (GOST3410.verifySignature(hashmessage, sig[0], sig[1])) - { - return new SimpleTestResult(true, getName() + ": Okay"); - } - else - { - return new SimpleTestResult(false, getName() + ": verification fails"); - } - } - } - - private class GOST3410_CExParam - implements Test - { - public String getName() - { - return "GOST3410-CExParam"; - } - - SecureRandom init_random = new SecureRandom() - { - boolean firstLong = true; - - public long nextLong() - { - String x0 = "0x162AB910"; - String c = "0x93F828D3"; - - if (firstLong) - { - firstLong = false; - return NumberParsing.decodeLongFromHex(x0); - } - return NumberParsing.decodeLongFromHex(c); - } - - public void nextBytes(byte[] bytes) - { - byte[] d = Hex.decode("ca82cce78a738bc46f103d53b9bf809745ec845e4f6da462606c51f60ecf302e31204b81"); - - System.arraycopy(d, 0, bytes, bytes.length - d.length, d.length); - } - }; - - SecureRandom random = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] k = Hex.decode("90F3A564439242F5186EBB224C8E223811B7105C64E4F5390807E6362DF4C72A"); - - int i; - - for (i = 0; i < (bytes.length - k.length); i += k.length) - { - System.arraycopy(k, 0, bytes, i, k.length); - } - - if (i > bytes.length) - { - System.arraycopy(k, 0, bytes, i - k.length, bytes.length - (i - k.length)); - } - else - { - System.arraycopy(k, 0, bytes, i, bytes.length - i); - } - } - }; - - SecureRandom keyRandom = new SecureRandom() - { - public void nextBytes(byte[] bytes) - { - byte[] x = Hex.decode("3036314538303830343630454235324435324234314132373832433138443046"); - - int i; - - for (i = 0; i < (bytes.length - x.length); i += x.length) - { - System.arraycopy(x, 0, bytes, i, x.length); - } - - if (i > bytes.length) - { - System.arraycopy(x, 0, bytes, i - x.length, bytes.length - (i - x.length)); - } - else - { - System.arraycopy(x, 0, bytes, i, bytes.length - i); - } - } - }; - - BigInteger pValue = new BigInteger("b194036ace14139d36d64295ae6c50fc4b7d65d8b340711366ca93f383653908ee637be428051d86612670ad7b402c09b820fa77d9da29c8111a8496da6c261a53ed252e4d8a69a20376e6addb3bdcd331749a491a184b8fda6d84c31cf05f9119b5ed35246ea4562d85928ba1136a8d0e5a7e5c764ba8902029a1336c631a1d", 16); - BigInteger qValue = new BigInteger("96120477df0f3896628e6f4a88d83c93204c210ff262bccb7dae450355125259", 16); - - public TestResult perform() - { - BigInteger r = new BigInteger("169fdb2dc09f690b71332432bfec806042e258fa9a21dafe73c6abfbc71407d9", 16); - BigInteger s = new BigInteger("9002551808ae40d19f6f31fb67e4563101243cf07cffd5f2f8ff4c537b0c9866", 16); - GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator(); - - pGen.init(1024, 2, init_random); - - GOST3410Parameters params = pGen.generateParameters(); - - if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ())) - { - return new SimpleTestResult(false, getName() + ": p or q wrong"); - } - - GOST3410KeyPairGenerator GOST3410KeyGen = new GOST3410KeyPairGenerator(); - GOST3410KeyGenerationParameters genParam = new GOST3410KeyGenerationParameters(keyRandom, params); - - GOST3410KeyGen.init(genParam); - - AsymmetricCipherKeyPair pair = GOST3410KeyGen.generateKeyPair(); - - ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random); - - GOST3410Signer GOST3410 = new GOST3410Signer(); - - GOST3410.init(true, param); - - BigInteger[] sig = GOST3410.generateSignature(hashmessage); - - if (!r.equals(sig[0])) - { - return new SimpleTestResult(false, getName() - + ": r component wrong." + Strings.lineSeparator() - + " expecting: " + r.toString(16) + Strings.lineSeparator() - + " got : " + sig[0].toString(16)); - } - - if (!s.equals(sig[1])) - { - return new SimpleTestResult(false, getName() - + ": s component wrong." + Strings.lineSeparator() - + " expecting: " + s.toString(16) + Strings.lineSeparator() - + " got : " + sig[1].toString(16)); - } - - GOST3410.init(false, pair.getPublic()); - - if (GOST3410.verifySignature(hashmessage, sig[0], sig[1])) - { - return new SimpleTestResult(true, getName() + ": Okay"); - } - else - { - return new SimpleTestResult(false, getName() + ": verification fails"); - } - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3411DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3411DigestTest.java deleted file mode 100644 index 6d70e8780..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3411DigestTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.GOST3411Digest; -import com.fr.third.org.bouncycastle.crypto.generators.PKCS5S1ParametersGenerator; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - -public class GOST3411DigestTest - extends DigestTest -{ - private static final String[] messages = - { - "", - "This is message, length=32 bytes", - "Suppose the original message has length = 50 bytes", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" - }; - -// If S-box = D-A (see: digest/GOST3411Digest.java; function: E(byte[] in, byte[] key); string: CipherParameters param = new GOST28147Parameters(key,"D-A");) - private static final String[] digests = - { - "981e5f3ca30c841487830f84fb433e13ac1101569b9c13584ac483234cd656c0", - "2cefc2f7b7bdc514e18ea57fa74ff357e7fa17d652c75f69cb1be7893ede48eb", - "c3730c5cbccacf915ac292676f21e8bd4ef75331d9405e5f1a61dc3130a65011", - "73b70a39497de53a6e08c67b6d4db853540f03e9389299d9b0156ef7e85d0f61" - }; - -// If S-box = D-Test (see: digest/GOST3411Digest.java; function:E(byte[] in, byte[] key); string: CipherParameters param = new GOST28147Parameters(key,"D-Test");) -// private static final String[] digests = -// { -// "ce85b99cc46752fffee35cab9a7b0278abb4c2d2055cff685af4912c49490f8d", -// "b1c466d37519b82e8319819ff32595e047a28cb6f83eff1c6916a815a637fffa", -// "471aba57a60a770d3a76130635c1fbea4ef14de51f78b4ae57dd893b62f55208", -// "95c1af627c356496d80274330b2cff6a10c67b5f597087202f94d06d2338cf8e" -// }; - - // 1 million 'a' - static private String million_a_digest = "8693287aa62f9478f7cb312ec0866b6c4e4a0f11160441e8f4ffcd2715dd554f"; - - GOST3411DigestTest() - { - super(new GOST3411Digest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - millionATest(million_a_digest); - - HMac gMac = new HMac(new GOST3411Digest()); - - gMac.init(new KeyParameter(PKCS5S1ParametersGenerator.PKCS5PasswordToUTF8Bytes("1".toCharArray()))); - - byte[] data = Strings.toByteArray("fred"); - - gMac.update(data, 0, data.length); - byte[] mac = new byte[gMac.getMacSize()]; - - gMac.doFinal(mac, 0); - - if (!Arrays.areEqual(Hex.decode("e9f98610cfc80084462b175a15d2b4ec10b2ab892eae5a6179d572d9b1db6b72"), mac)) - { - fail("mac calculation failed."); - } - } - - protected Digest cloneDigest(Digest digest) - { - return new GOST3411Digest((GOST3411Digest)digest); - } - - public static void main( - String[] args) - { - runTest(new GOST3411DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3411_2012_256DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3411_2012_256DigestTest.java deleted file mode 100644 index 4501d13ed..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3411_2012_256DigestTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.util.ArrayList; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.GOST3411_2012_256Digest; -import com.fr.third.org.bouncycastle.crypto.digests.GOST3411_2012_512Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - -public class GOST3411_2012_256DigestTest - extends DigestTest -{ - private static final String[] messages; - - private static char[] M1 = - { - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x30, 0x31, 0x32 - }; - - private static char[] M2= - { - 0xd1,0xe5,0x20,0xe2,0xe5,0xf2,0xf0,0xe8,0x2c,0x20,0xd1,0xf2,0xf0,0xe8,0xe1,0xee,0xe6,0xe8,0x20,0xe2, - 0xed,0xf3,0xf6,0xe8,0x2c,0x20,0xe2,0xe5,0xfe,0xf2,0xfa,0x20,0xf1,0x20,0xec,0xee,0xf0,0xff,0x20,0xf1, - 0xf2,0xf0,0xe5,0xeb,0xe0,0xec,0xe8,0x20,0xed,0xe0,0x20,0xf5,0xf0,0xe0,0xe1,0xf0,0xfb,0xff,0x20,0xef, - 0xeb,0xfa,0xea,0xfb,0x20,0xc8,0xe3,0xee,0xf0,0xe5,0xe2,0xfb - }; - - static - { - - ArrayList
strList = new ArrayList (); - - strList.add(new String(M1)); - strList.add(new String(M2)); - - messages = new String[strList.size()]; - for (int i = 0; i < strList.size(); i++) - { - messages[i] = (String)strList.get(i); - } - } - - private static final String[] digests = { - "9d151eefd8590b89daa6ba6cb74af9275dd051026bb149a452fd84e5e57b5500", - "9dd2fe4e90409e5da87f53976d7405b0c0cac628fc669a741d50063c557e8f50" - }; - - GOST3411_2012_256DigestTest() - { - super(new GOST3411_2012_256Digest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - HMac gMac = new HMac(new GOST3411_2012_256Digest()); - - gMac.init(new KeyParameter(Hex.decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"))); - - byte[] data = Hex.decode("0126bdb87800af214341456563780100"); - - gMac.update(data, 0, data.length); - byte[] mac = new byte[gMac.getMacSize()]; - - gMac.doFinal(mac, 0); - - if (!Arrays.areEqual(Hex.decode("a1aa5f7de402d7b3d323f2991c8d4534013137010a83754fd0af6d7cd4922ed9"), mac)) - { - fail("mac calculation failed."); - } - } - - protected Digest cloneDigest(Digest digest) - { - return new GOST3411_2012_256Digest((GOST3411_2012_256Digest)digest); - } - - public static void main(String[] args) - { - runTest(new GOST3411_2012_256DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3411_2012_512DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3411_2012_512DigestTest.java deleted file mode 100644 index cbe20a666..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3411_2012_512DigestTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.util.ArrayList; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.GOST3411Digest; -import com.fr.third.org.bouncycastle.crypto.digests.GOST3411_2012_512Digest; -import com.fr.third.org.bouncycastle.crypto.generators.PKCS5S1ParametersGenerator; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - -public class GOST3411_2012_512DigestTest - extends DigestTest -{ - private static final String[] messages; - - private static char[] M1 = - { - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x30, 0x31, 0x32 - }; - - private static char[] M2= - { - 0xd1,0xe5,0x20,0xe2,0xe5,0xf2,0xf0,0xe8,0x2c,0x20,0xd1,0xf2,0xf0,0xe8,0xe1,0xee,0xe6,0xe8,0x20,0xe2, - 0xed,0xf3,0xf6,0xe8,0x2c,0x20,0xe2,0xe5,0xfe,0xf2,0xfa,0x20,0xf1,0x20,0xec,0xee,0xf0,0xff,0x20,0xf1, - 0xf2,0xf0,0xe5,0xeb,0xe0,0xec,0xe8,0x20,0xed,0xe0,0x20,0xf5,0xf0,0xe0,0xe1,0xf0,0xfb,0xff,0x20,0xef, - 0xeb,0xfa,0xea,0xfb,0x20,0xc8,0xe3,0xee,0xf0,0xe5,0xe2,0xfb - }; - - static - { - ArrayList strList = new ArrayList (); - - strList.add(new String(M1)); - strList.add(new String(M2)); - messages = new String[strList.size()]; - for (int i = 0; i < strList.size(); i++) - { - messages[i] = (String)strList.get(i); - } - } - - private static final String[] digests = { - "1b54d01a4af5b9d5cc3d86d68d285462b19abc2475222f35c085122be4ba1ffa00ad30f8767b3a82384c6574f024c311e2a481332b08ef7f41797891c1646f48", - "1e88e62226bfca6f9994f1f2d51569e0daf8475a3b0fe61a5300eee46d961376035fe83549ada2b8620fcd7c496ce5b33f0cb9dddc2b6460143b03dabac9fb28", - }; - - public GOST3411_2012_512DigestTest() - { - super(new GOST3411_2012_512Digest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - HMac gMac = new HMac(new GOST3411_2012_512Digest()); - - gMac.init(new KeyParameter(Hex.decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"))); - - byte[] data = Hex.decode("0126bdb87800af214341456563780100"); - - gMac.update(data, 0, data.length); - byte[] mac = new byte[gMac.getMacSize()]; - - gMac.doFinal(mac, 0); - - if (!Arrays.areEqual(Hex.decode("a59bab22ecae19c65fbde6e5f4e9f5d8549d31f037f9df9b905500e171923a773d5f1530f2ed7e964cb2eedc29e9ad2f3afe93b2814f79f5000ffc0366c251e6"), mac)) - { - fail("mac calculation failed."); - } - } - - protected Digest cloneDigest(Digest digest) - { - return new GOST3411_2012_512Digest((GOST3411_2012_512Digest)digest); - } - - public static void main(String[] args) - { - runTest(new GOST3411_2012_512DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3412MacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3412MacTest.java deleted file mode 100644 index 94902617b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3412MacTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.engines.GOST3412_2015Engine; -import com.fr.third.org.bouncycastle.crypto.macs.CMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * see GOST_R_3413-2015 - */ -public class GOST3412MacTest - implements Test -{ - - public String getName() - { - return "GOST 3412 2015 MAC test"; - } - - public TestResult perform() - { - - - byte[][] inputs = new byte[][]{ - Hex.decode("1122334455667700ffeeddccbbaa9988"), - Hex.decode("00112233445566778899aabbcceeff0a"), - Hex.decode("112233445566778899aabbcceeff0a00"), - Hex.decode("2233445566778899aabbcceeff0a0011"), - }; - Mac mac = new CMac(new GOST3412_2015Engine(), 64); - - byte[] output = Hex.decode("336f4d296059fbe3"); - - KeyParameter key = - new KeyParameter(Hex.decode("8899aabbccddeeff0011223344556677fedcba98765432100123456789abcdef")); - mac.init(key); - - for (int i = 0; i != inputs.length; i++) - { - mac.update(inputs[i], 0, inputs[i].length); - } - - byte[] out = new byte[8]; - - mac.doFinal(out, 0); - - if (!Arrays.areEqual(out, output)) - { - return new SimpleTestResult(false, getName() + ": Failed test 1 - expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - - } - - - public static void main(String[] args) - { - GOST3412MacTest test = new GOST3412MacTest(); - TestResult result = test.perform(); - - System.out.println(result); - } - - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3412Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3412Test.java deleted file mode 100644 index 197269812..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GOST3412Test.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.GOST3412_2015Engine; -import com.fr.third.org.bouncycastle.crypto.modes.G3413CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.G3413CFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.G3413CTRBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.G3413OFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class GOST3412Test - extends CipherTest -{ - - private byte[][] inputs = new byte[][]{ - Hex.decode("1122334455667700ffeeddccbbaa9988"), - Hex.decode("00112233445566778899aabbcceeff0a"), - Hex.decode("112233445566778899aabbcceeff0a00"), - Hex.decode("2233445566778899aabbcceeff0a0011") - }; - - - static SimpleTest[] tests = { - -// ECB - new BlockCipherVectorTest(1, new GOST3412_2015Engine(), - new KeyParameter(Hex.decode("8899aabbccddeeff0011223344556677fedcba98765432100123456789abcdef")), - "1122334455667700ffeeddccbbaa9988", "7f679d90bebc24305a468d42b9d4edcd"), - - // CFB - new BlockCipherVectorTest(2, new G3413CFBBlockCipher(new GOST3412_2015Engine()), - new ParametersWithIV(new KeyParameter(Hex.decode("8899aabbccddeeff0011223344556677fedcba98765432100123456789abcdef")), - Hex.decode("1234567890abcef0a1b2c3d4e5f0011223344556677889901213141516171819")), - "1122334455667700ffeeddccbbaa998800112233445566778899aabbcceeff0a112233445566778899aabbcceeff0a002233445566778899aabbcceeff0a0011", - "81800a59b1842b24ff1f795e897abd95ed5b47a7048cfab48fb521369d9326bf79f2a8eb5cc68d38842d264e97a238b54ffebecd4e922de6c75bd9dd44fbf4d1"), - - new BlockCipherVectorTest(3, new G3413CFBBlockCipher(new GOST3412_2015Engine(), 8), - new ParametersWithIV( - new KeyParameter(Hex.decode("8899aabbccddeeff0011223344556677fedcba98765432100123456789abcdef")), - Hex.decode("1234567890abcef0a1b2c3d4e5f0011223344556677889901213141516171819")), - "1122334455667700ffeeddccbbaa998800112233445566778899aabbcceeff0a112233445566778899aabbcceeff0a002233445566778899aabbcceeff0a0011", - "819b19c5867e61f1cf1b16f664f66e46ed8fcb82b1110b1e7ec03bfa6611f2eabd7a32363691cbdc3bbe403bc80552d822c2cdf483981cd71d5595453d7f057d"), - - // OFB - new BlockCipherVectorTest(4, new G3413OFBBlockCipher(new GOST3412_2015Engine()), - new ParametersWithIV( - new KeyParameter(Hex.decode("8899aabbccddeeff0011223344556677fedcba98765432100123456789abcdef")), - Hex.decode("1234567890abcef0a1b2c3d4e5f0011223344556677889901213141516171819")), - "1122334455667700ffeeddccbbaa998800112233445566778899aabbcceeff0a112233445566778899aabbcceeff0a002233445566778899aabbcceeff0a0011", - "81800a59b1842b24ff1f795e897abd95ed5b47a7048cfab48fb521369d9326bf66a257ac3ca0b8b1c80fe7fc10288a13203ebbc066138660a0292243f6903150"), - -//CBC - new BlockCipherVectorTest(5, new G3413CBCBlockCipher(new GOST3412_2015Engine()), - new ParametersWithIV(new KeyParameter(Hex.decode("8899aabbccddeeff0011223344556677fedcba98765432100123456789abcdef")), Hex.decode("1234567890abcef0a1b2c3d4e5f0011223344556677889901213141516171819")), - "1122334455667700ffeeddccbbaa998800112233445566778899aabbcceeff0a112233445566778899aabbcceeff0a002233445566778899aabbcceeff0a0011", - "689972d4a085fa4d90e52e3d6d7dcc272826e661b478eca6af1e8e448d5ea5acfe7babf1e91999e85640e8b0f49d90d0167688065a895c631a2d9a1560b63970"), -//CTR - new BlockCipherVectorTest(6, new G3413CTRBlockCipher(new GOST3412_2015Engine()), - new ParametersWithIV(new KeyParameter(Hex.decode("8899aabbccddeeff0011223344556677fedcba98765432100123456789abcdef")), - Hex.decode("1234567890abcef0")), - "1122334455667700ffeeddccbbaa998800112233445566778899aabbcceeff0a112233445566778899aabbcceeff0a002233445566778899aabbcceeff0a0011", - "f195d8bec10ed1dbd57b5fa240bda1b885eee733f6a13e5df33ce4b33c45dee4a5eae88be6356ed3d5e877f13564a3a5cb91fab1f20cbab6d1c6d15820bdba73"), - new BlockCipherVectorTest(7, new G3413CTRBlockCipher(new GOST3412_2015Engine(), 8), - new ParametersWithIV(new KeyParameter(Hex.decode("8899aabbccddeeff0011223344556677fedcba98765432100123456789abcdef")), - Hex.decode("1234567890abcef0")), - "1122334455667700ffeeddccbbaa998800112233445566778899aabbcceeff0a112233445566778899aabbcceeff0a002233445566778899aabbcceeff0a0011", - "f1a787ad3a88f9a0bc735293f98c12c3eb31621b9b2e6461c7ef73a2e6a6b1793ddf722f7b1d22a722ec4d3edbc313bcd356b313d37af9e5ef934fa223c13fe2") - - - }; - - - protected GOST3412Test() - { - super(tests, new GOST3412_2015Engine(), new KeyParameter(new byte[32])); - } - - public String getName() - { - return "GOST 34.12 2015"; - } - - public void performTest() - throws Exception - { - super.performTest(); - -// cfbTest(); -// ofbTest(); - } - - public static void main( - String[] args) - { - runTest(new GOST3412Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GSKKDFTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GSKKDFTest.java deleted file mode 100644 index 1c810532a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/GSKKDFTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.agreement.kdf.GSKKDFParameters; -import com.fr.third.org.bouncycastle.crypto.agreement.kdf.GSKKFDGenerator; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class GSKKDFTest - extends SimpleTest -{ - public String getName() - { - return "GSKKDFTest"; - } - - public void performTest() - throws Exception - { - GSKKFDGenerator gen = new GSKKFDGenerator(new SHA256Digest()); - - byte[] key = new byte[16]; - - gen.init(new GSKKDFParameters(Hex.decode("0102030405060708090a"), 1, Hex.decode("27252622"))); - - gen.generateBytes(key, 0, key.length); - areEqual(Hex.decode("bd9ff24b9cc4d91b70af951989b4d719"), key); - - gen.generateBytes(key, 0, key.length); - areEqual(Hex.decode("d5934f681ad1e860981eb1792af68e20"), key); - - gen = new GSKKFDGenerator(new SHA256Digest()); - - gen.init(new GSKKDFParameters(Hex.decode("0102030405060708090a"), 2, Hex.decode("27252622"))); - - gen.generateBytes(key, 0, key.length); - areEqual(Hex.decode("d5934f681ad1e860981eb1792af68e20"), key); - - gen.init(new GSKKDFParameters(Hex.decode("0102030405060708090a"), 1)); - - gen.generateBytes(key, 0, key.length); - areEqual(Hex.decode("3c6e999b2cb08d8d8dd261cd23f15ed6"), key); - - gen.generateBytes(key, 0, key.length); - areEqual(Hex.decode("019ce1fcf81b94602f2f8678be905e0e"), key); - - try - { - gen.generateBytes(key, 1, key.length); - } - catch (DataLengthException e) - { - isEquals("output buffer too small", e.getMessage()); - } - } - - public static void main( - String[] args) - { - runTest(new GSKKDFTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Grain128Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Grain128Test.java deleted file mode 100644 index 02a902066..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Grain128Test.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.crypto.engines.Grain128Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Grain-128 Test - */ -public class Grain128Test - extends SimpleTest -{ - - String keyStream1 = "f09b7bf7d7f6b5c2de2ffc73ac21397f"; - String keyStream2 = "afb5babfa8de896b4b9c6acaf7c4fbfd"; - - public String getName() - { - return "Grain-128"; - } - - public void performTest() - { - Grain128Test1(new ParametersWithIV(new KeyParameter(Hex - .decode("00000000000000000000000000000000")), Hex - .decode("000000000000000000000000"))); - Grain128Test2(new ParametersWithIV(new KeyParameter(Hex - .decode("0123456789abcdef123456789abcdef0")), Hex - .decode("0123456789abcdef12345678"))); - Grain128Test3(new ParametersWithIV(new KeyParameter(Hex - .decode("0123456789abcdef123456789abcdef0")), Hex - .decode("0123456789abcdef12345678"))); - } - - private void Grain128Test1(CipherParameters params) - { - StreamCipher grain = new Grain128Engine(); - byte[] in = new byte[16]; - byte[] out = new byte[16]; - - grain.init(true, params); - - grain.processBytes(in, 0, in.length, out, 0); - - if (!areEqual(out, Hex.decode(keyStream1))) - { - mismatch("Keystream 1", keyStream1, out); - } - - grain.reset(); - - grain.processBytes(in, 0, in.length, out, 0); - - if (!areEqual(out, Hex.decode(keyStream1))) - { - mismatch("Keystream 1", keyStream1, out); - } - } - - private void Grain128Test2(CipherParameters params) - { - StreamCipher grain = new Grain128Engine(); - byte[] in = new byte[16]; - byte[] out = new byte[16]; - - grain.init(true, params); - - grain.processBytes(in, 0, in.length, out, 0); - - if (!areEqual(out, Hex.decode(keyStream2))) - { - mismatch("Keystream 2", keyStream2, out); - } - - grain.reset(); - - grain.processBytes(in, 0, in.length, out, 0); - - if (!areEqual(out, Hex.decode(keyStream2))) - { - mismatch("Keystream 2", keyStream2, out); - } - } - - private void Grain128Test3(CipherParameters params) - { - StreamCipher grain = new Grain128Engine(); - byte[] in = "Encrypt me!".getBytes(); - byte[] cipher = new byte[in.length]; - byte[] clear = new byte[in.length]; - - grain.init(true, params); - - grain.processBytes(in, 0, in.length, cipher, 0); - grain.reset(); - grain.processBytes(cipher, 0, cipher.length, clear, 0); - - if (!areEqual(in, clear)) - { - mismatch("Test 3", new String(Hex.encode(in)), clear); - } - } - - private void mismatch(String name, String expected, byte[] found) - { - fail("mismatch on " + name, expected, new String(Hex.encode(found))); - } - - public static void main(String[] args) - { - runTest(new Grain128Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Grainv1Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Grainv1Test.java deleted file mode 100644 index 1b6a8ad92..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Grainv1Test.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.crypto.engines.Grainv1Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Grain v1 Test - */ -public class Grainv1Test - extends SimpleTest -{ - - String keyStream1 = "dee931cf1662a72f77d0"; - String keyStream2 = "7f362bd3f7abae203664"; - String keyStream4 = "017D13ECB20AE0C9ACF784CB06525F72" - + "CE6D52BEBB948F124668C35064559024" - + "49EEA505C19F3EE4D052C3D19DA9C4D1" - + "B92DBC7F07AFEA6A3D845DE60D8471FD"; - - public String getName() - { - return "Grain v1"; - } - - public void performTest() - { - Grainv1Test1(new ParametersWithIV(new KeyParameter(Hex - .decode("00000000000000000000")), Hex - .decode("0000000000000000"))); - Grainv1Test2(new ParametersWithIV(new KeyParameter(Hex - .decode("0123456789abcdef1234")), Hex - .decode("0123456789abcdef"))); - Grainv1Test3(new ParametersWithIV(new KeyParameter(Hex - .decode("0123456789abcdef1234")), Hex - .decode("0123456789abcdef"))); - Grainv1Test4(new ParametersWithIV(new KeyParameter(Hex - .decode("0F62B5085BAE0154A7FA")), Hex - .decode("288FF65DC42B92F9"))); - } - - private void Grainv1Test1(CipherParameters params) - { - StreamCipher grain = new Grainv1Engine(); - byte[] in = new byte[10]; - byte[] out = new byte[10]; - - grain.init(true, params); - - grain.processBytes(in, 0, in.length, out, 0); - - if (!areEqual(out, Hex.decode(keyStream1))) - { - mismatch("Keystream 1", keyStream1, out); - } - - grain.reset(); - - grain.processBytes(in, 0, in.length, out, 0); - - if (!areEqual(out, Hex.decode(keyStream1))) - { - mismatch("Keystream 1", keyStream1, out); - } - } - - private void Grainv1Test2(CipherParameters params) - { - StreamCipher grain = new Grainv1Engine(); - byte[] in = new byte[10]; - byte[] out = new byte[10]; - - grain.init(true, params); - - grain.processBytes(in, 0, in.length, out, 0); - - if (!areEqual(out, Hex.decode(keyStream2))) - { - mismatch("Keystream 2", keyStream2, out); - } - - grain.reset(); - - grain.processBytes(in, 0, in.length, out, 0); - - if (!areEqual(out, Hex.decode(keyStream2))) - { - mismatch("Keystream 2", keyStream2, out); - } - } - - private void Grainv1Test3(CipherParameters params) - { - StreamCipher grain = new Grainv1Engine(); - byte[] in = "Encrypt me!".getBytes(); - byte[] cipher = new byte[in.length]; - byte[] clear = new byte[in.length]; - - grain.init(true, params); - - grain.processBytes(in, 0, in.length, cipher, 0); - grain.reset(); - grain.processBytes(cipher, 0, cipher.length, clear, 0); - - if (!areEqual(in, clear)) - { - mismatch("Test 3", new String(Hex.encode(in)), clear); - } - } - - private void Grainv1Test4(CipherParameters params) - { - StreamCipher grain = new Grainv1Engine(); - byte[] in = new byte[keyStream4.length() / 2]; - byte[] out = new byte[in.length]; - - grain.init(true, params); - - grain.processBytes(in, 0, in.length, out, 0); - - if (!areEqual(out, Hex.decode(keyStream4))) - { - mismatch("Keystream 4", keyStream4, out); - } - } - - private void mismatch(String name, String expected, byte[] found) - { - fail("mismatch on " + name, expected, new String(Hex.encode(found))); - } - - public static void main(String[] args) - { - runTest(new Grainv1Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/HCFamilyTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/HCFamilyTest.java deleted file mode 100644 index b4d7f2bf5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/HCFamilyTest.java +++ /dev/null @@ -1,192 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.crypto.engines.HC128Engine; -import com.fr.third.org.bouncycastle.crypto.engines.HC256Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * HC-128 and HC-256 Tests. Based on the test vectors in the official reference - * papers, respectively: - * - * http://www.ecrypt.eu.org/stream/p3ciphers/hc/hc128_p3.pdf - * http://www.ecrypt.eu.org/stream/p3ciphers/hc/hc256_p3.pdf - *- * See HCFamilyVecTest for a more exhaustive test based on the ecrypt vectors. - */ -public class HCFamilyTest - extends SimpleTest -{ - private static final byte[] MSG = new byte[64]; - - private static String[][] HC128_VerifiedTest = - { - { - "Set 2, vector# 0", - "00000000000000000000000000000000", - "00000000000000000000000000000000", - "82001573A003FD3B7FD72FFB0EAF63AA" + - "C62F12DEB629DCA72785A66268EC758B" + - "1EDB36900560898178E0AD009ABF1F49" + - "1330DC1C246E3D6CB264F6900271D59C" - }, - { - "Set 6, vector# 0", - "0053A6F94C9FF24598EB3E91E4378ADD", - "0D74DB42A91077DE45AC137AE148AF16", - "2E1ED12A8551C05AF41FF39D8F9DF933" + - "122B5235D48FC2A6F20037E69BDBBCE8" + - "05782EFC16C455A4B3FF06142317535E" + - "F876104C32445138CB26EBC2F88A684C" - }, - { - "Set 6, vector# 1", - "0558ABFE51A4F74A9DF04396E93C8FE2", - "167DE44BB21980E74EB51C83EA51B81F", - "4F864BF3C96D0363B1903F0739189138" + - "F6ED2BC0AF583FEEA0CEA66BA7E06E63" + - "FB28BF8B3CA0031D24ABB511C57DD17B" + - "FC2861C32400072CB680DF2E58A5CECC" - }, - { - "Set 6, vector# 2", - "0A5DB00356A9FC4FA2F5489BEE4194E7", - "1F86ED54BB2289F057BE258CF35AC128", - "82168AB0023B79AAF1E6B4D823855E14" + - "A7084378036A951B1CFEF35173875ED8" + - "6CB66AB8410491A08582BE40080C3102" + - "193BA567F9E95D096C3CC60927DD7901" - }, - { - "Set 6, vector# 3", - "0F62B5085BAE0154A7FA4DA0F34699EC", - "288FF65DC42B92F960C72E95FC63CA31", - "1CD8AEDDFE52E217E835D0B7E84E2922" + - "D04B1ADBCA53C4522B1AA604C42856A9" + - "0AF83E2614BCE65C0AECABDD8975B557" + - "00D6A26D52FFF0888DA38F1DE20B77B7" - } - }; - - private static String[][] HC256_VerifiedTest = - { - { - "Set 2, vector# 0", - "00000000000000000000000000000000", - "00000000000000000000000000000000", - "5B078985D8F6F30D42C5C02FA6B67951" + - "53F06534801F89F24E74248B720B4818" + - "CD9227ECEBCF4DBF8DBF6977E4AE14FA" + - "E8504C7BC8A9F3EA6C0106F5327E6981" - }, - { - "Set 2, vector# 9", - "09090909090909090909090909090909", - "00000000000000000000000000000000", - "F5C2926651AEED9AF1A9C2F04C03D081" + - "2145B56AEA46EB283A25A4C9E3D8BEB4" + - "821B418F06F2B9DCDF1A85AB8C02CD14" + - "62E1BBCAEC9AB0E99AA6AFF918BA627C" - }, - { - "Set 2, vector#135", - "87878787878787878787878787878787", - "00000000000000000000000000000000", - "CEC0C3852E3B98233EBCB975C10B1191" + - "3C69F2275EB97A1402EDF16C6FBE19BE" + - "79D65360445BCB63676E6553B609A065" + - "0155C3B22DD1975AC0F3F65063A2E16E" - }, - { - "Set 6, vector# 0", - "0053A6F94C9FF24598EB3E91E4378ADD" + - "3083D6297CCF2275C81B6EC11467BA0D", - "0D74DB42A91077DE45AC137AE148AF16" + - "7DE44BB21980E74EB51C83EA51B81F86", - "23D9E70A45EB0127884D66D9F6F23C01" + - "D1F88AFD629270127247256C1FFF91E9" + - "1A797BD98ADD23AE15BEE6EEA3CEFDBF" + - "A3ED6D22D9C4F459DB10C40CDF4F4DFF" - }, - { - "Set 6, vector# 1", - "0558ABFE51A4F74A9DF04396E93C8FE2" + - "3588DB2E81D4277ACD2073C6196CBF12", - "167DE44BB21980E74EB51C83EA51B81F" + - "86ED54BB2289F057BE258CF35AC1288F", - "C44B5262F2EAD9C018213127686DB742" + - "A72D3F2D61D18F0F4E7DE5B4F7ADABE0" + - "7E0C82033B139F02BAACB4E2F2D0BE30" + - "110C3A8A2B621523756692877C905DD0" - }, - { - "Set 6, vector# 2", - "0A5DB00356A9FC4FA2F5489BEE4194E7" + - "3A8DE03386D92C7FD22578CB1E71C417", - "1F86ED54BB2289F057BE258CF35AC128" + - "8FF65DC42B92F960C72E95FC63CA3198", - "9D13AA06122F4F03AE60D507701F1ED0" + - "63D7530FF35EE76CAEDCBFB01D8A239E" + - "FA4A44B272DE9B4092E2AD56E87C3A60" + - "89F5A074D1F6E5B8FC6FABEE0C936F06" - }, - { - "Set 6, vector# 3", - "0F62B5085BAE0154A7FA4DA0F34699EC" + - "3F92E5388BDE3184D72A7DD02376C91C", - "288FF65DC42B92F960C72E95FC63CA31" + - "98FF66CD349B0269D0379E056CD33AA1", - "C8632038DA61679C4685288B37D3E232" + - "7BC2D28C266B041FE0CA0D3CFEED8FD5" + - "753259BAB757168F85EA96ADABD823CA" + - "4684E918423E091565713FEDDE2CCFE0" - } - }; - - public String getName() - { - return "HC-128 and HC-256"; - } - - public void performTest() - { - StreamCipher hc = new HC256Engine(); - - for (int i = 0; i != HC256_VerifiedTest.length; i++) - { - String[] test = HC256_VerifiedTest[i]; - HCTest(hc, "HC-256 - " + test[0], Hex.decode(test[1]), Hex.decode(test[2]), Hex.decode(test[3])); - } - - hc = new HC128Engine(); - - for (int i = 0; i != HC128_VerifiedTest.length; i++) - { - String[] test = HC128_VerifiedTest[i]; - HCTest(hc, "HC-128 - " + test[0], Hex.decode(test[1]), Hex.decode(test[2]), Hex.decode(test[3])); - } - } - - private void HCTest(StreamCipher hc, String test, byte[] key, byte[] IV, byte[] expected) - { - KeyParameter kp = new KeyParameter(key); - ParametersWithIV ivp = new ParametersWithIV(kp, IV); - - hc.init(true, ivp); - for (int i = 0; i < 64; i++) - { - if (hc.returnByte(MSG[i]) != expected[i]) - { - fail(test + " failure at byte " + i); - } - } - } - - public static void main(String[] args) - { - runTest(new HCFamilyTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/HCFamilyVecTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/HCFamilyVecTest.java deleted file mode 100644 index 3e886ba2d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/HCFamilyVecTest.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.crypto.engines.HC128Engine; -import com.fr.third.org.bouncycastle.crypto.engines.HC256Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * HC-128 and HC-256 Tests. Based on the test vectors in the official reference - * papers, respectively: - * - * http://www.ecrypt.eu.org/stream/p3ciphers/hc/hc128_p3.pdf - * http://www.ecrypt.eu.org/stream/p3ciphers/hc/hc256_p3.pdf - */ -public class HCFamilyVecTest - extends SimpleTest -{ - private static class PeekableLineReader extends BufferedReader - { - public PeekableLineReader(Reader r) throws IOException - { - super(r); - - peek = super.readLine(); - } - - public String peekLine() - { - return peek; - } - - public String readLine() throws IOException - { - String tmp = peek; - peek = super.readLine(); - return tmp; - } - - private String peek; - } - - public String getName() - { - return "HC-128 and HC-256 (ecrypt)"; - } - - public void performTest() throws Exception - { - runTests(new HC128Engine(), "ecrypt_HC-128.txt"); - runTests(new HC256Engine(), "ecrypt_HC-256_128K_128IV.txt"); - runTests(new HC256Engine(), "ecrypt_HC-256_256K_128IV.txt"); - runTests(new HC256Engine(), "ecrypt_HC-256_128K_256IV.txt"); - runTests(new HC256Engine(), "ecrypt_HC-256_256K_256IV.txt"); - } - - private void runTests(StreamCipher hc, String fileName) throws IOException - { - Reader resource = new InputStreamReader(getClass().getResourceAsStream(fileName)); - PeekableLineReader r = new PeekableLineReader(resource); - runAllVectors(hc, fileName, r); - } - - private void runAllVectors(StreamCipher hc, String fileName, PeekableLineReader r) - throws IOException - { - for (;;) - { - String line = r.readLine(); - if (line == null) - { - break; - } - - line = line.trim(); - - if (line.startsWith("Set ")) - { - runVector(hc, fileName, r, dellChar(line, ':')); - } - } - } - - private String dellChar(String s, char c) - { - StringBuffer b = new StringBuffer(); - - for (int i = 0; i != s.length(); i++) - { - if (s.charAt(i) != c) - { - b.append(s.charAt(i)); - } - } - - return b.toString(); - } - - private void runVector(StreamCipher hc, String fileName, PeekableLineReader r, String vectorName) - throws IOException - { -// System.out.println(fileName + " => " + vectorName); - String hexKey = readBlock(r); - String hexIV = readBlock(r); - - CipherParameters cp = new KeyParameter(Hex.decode(hexKey)); - cp = new ParametersWithIV(cp, Hex.decode(hexIV)); - hc.init(true, cp); - - byte[] input = new byte[64]; - byte[] output = new byte[64]; - byte[] digest = new byte[64]; - int pos = 0; - - for (;;) - { - String line1 = r.peekLine().trim(); - int equalsPos = line1.indexOf('='); - String lead = line1.substring(0, equalsPos - 1); - - String hexData = readBlock(r); - byte[] data = Hex.decode(hexData); - - if (lead.equals("xor-digest")) - { - if (!Arrays.areEqual(data, digest)) - { - fail("Failed in " + fileName + " for test vector: " + vectorName + " at " + lead); -// System.out.println(fileName + " => " + vectorName + " failed at " + lead); return; - } - break; - } - - int posA = lead.indexOf('['); - int posB = lead.indexOf(".."); - int posC = lead.indexOf(']'); - int start = Integer.parseInt(lead.substring(posA + 1, posB)); - int end = Integer.parseInt(lead.substring(posB + 2, posC)); - - if (start % 64 != 0 || (end - start != 63)) - { - throw new IllegalStateException(vectorName + ": " + lead + " not on 64 byte boundaries"); - } - - while (pos < end) - { - hc.processBytes(input, 0, input.length, output, 0); - xor(digest, output); - pos += 64; - } - - if (!Arrays.areEqual(data, output)) - { - fail("Failed in " + fileName + " for test vector: " + vectorName + " at " + lead); -// System.out.println(fileName + " => " + vectorName + " failed at " + lead); return; - } - } - } - - private static String readBlock(PeekableLineReader r) throws IOException - { - String first = r.readLine().trim(); - String result = first.substring(first.lastIndexOf(' ') + 1); - - for (;;) - { - String peek = r.peekLine().trim(); - if (peek.length() < 1 || peek.indexOf('=') >= 0) - { - break; - } - result += r.readLine().trim(); - } - - return result; - } - - private static void xor(byte[] digest, byte[] block) - { - for (int i = 0; i < digest.length; ++i) - { - digest[i] ^= block[i]; - } - } - - public static void main(String[] args) - { - runTest(new HCFamilyVecTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/HKDFGeneratorTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/HKDFGeneratorTest.java deleted file mode 100644 index 83c596f57..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/HKDFGeneratorTest.java +++ /dev/null @@ -1,304 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.generators.HKDFBytesGenerator; -import com.fr.third.org.bouncycastle.crypto.params.HKDFParameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * HKDF tests - vectors from RFC 5869, + 2 more, 101 and 102 - */ -public class HKDFGeneratorTest - extends SimpleTest -{ - - public HKDFGeneratorTest() - { - } - - private void compareOKM(int test, byte[] calculatedOKM, byte[] testOKM) - { - - if (!areEqual(calculatedOKM, testOKM)) - { - fail("HKDF failed generator test " + test); - } - } - - public void performTest() - { - { - // === A.1. Test Case 1 - Basic test case with SHA-256 === - - Digest hash = new SHA256Digest(); - byte[] ikm = Hex - .decode("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"); - byte[] salt = Hex.decode("000102030405060708090a0b0c"); - byte[] info = Hex.decode("f0f1f2f3f4f5f6f7f8f9"); - int l = 42; - byte[] okm = new byte[l]; - - HKDFParameters params = new HKDFParameters(ikm, salt, info); - - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(hash); - hkdf.init(params); - hkdf.generateBytes(okm, 0, l); - - compareOKM(1, okm, Hex.decode( - "3cb25f25faacd57a90434f64d0362f2a" + - "2d2d0a90cf1a5a4c5db02d56ecc4c5bf" + - "34007208d5b887185865")); - } - - // === A.2. Test Case 2 - Test with SHA-256 and longer inputs/outputs - // === - { - Digest hash = new SHA256Digest(); - byte[] ikm = Hex.decode("000102030405060708090a0b0c0d0e0f" - + "101112131415161718191a1b1c1d1e1f" - + "202122232425262728292a2b2c2d2e2f" - + "303132333435363738393a3b3c3d3e3f" - + "404142434445464748494a4b4c4d4e4f"); - byte[] salt = Hex.decode("606162636465666768696a6b6c6d6e6f" - + "707172737475767778797a7b7c7d7e7f" - + "808182838485868788898a8b8c8d8e8f" - + "909192939495969798999a9b9c9d9e9f" - + "a0a1a2a3a4a5a6a7a8a9aaabacadaeaf"); - byte[] info = Hex.decode("b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" - + "c0c1c2c3c4c5c6c7c8c9cacbcccdcecf" - + "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf" - + "e0e1e2e3e4e5e6e7e8e9eaebecedeeef" - + "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"); - int l = 82; - byte[] okm = new byte[l]; - - HKDFParameters params = new HKDFParameters(ikm, salt, info); - - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(hash); - hkdf.init(params); - hkdf.generateBytes(okm, 0, l); - - compareOKM(2, okm, Hex.decode( - "b11e398dc80327a1c8e7f78c596a4934" + - "4f012eda2d4efad8a050cc4c19afa97c" + - "59045a99cac7827271cb41c65e590e09" + - "da3275600c2f09b8367793a9aca3db71" + - "cc30c58179ec3e87c14c01d5c1f3434f" + - "1d87")); - } - - { - // === A.3. Test Case 3 - Test with SHA-256 and zero-length - // salt/info === - - // setting salt to an empty byte array means that the salt is set to - // HashLen zero valued bytes - // setting info to null generates an empty byte array as info - // structure - - Digest hash = new SHA256Digest(); - byte[] ikm = Hex - .decode("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"); - byte[] salt = new byte[0]; - byte[] info = null; - int l = 42; - byte[] okm = new byte[l]; - - HKDFParameters params = new HKDFParameters(ikm, salt, info); - - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(hash); - hkdf.init(params); - hkdf.generateBytes(okm, 0, l); - - compareOKM(3, okm, Hex.decode( - "8da4e775a563c18f715f802a063c5a31" + - "b8a11f5c5ee1879ec3454e5f3c738d2d" + - "9d201395faa4b61a96c8")); - } - - { - // === A.4. Test Case 4 - Basic test case with SHA-1 === - - Digest hash = new SHA1Digest(); - byte[] ikm = Hex.decode("0b0b0b0b0b0b0b0b0b0b0b"); - byte[] salt = Hex.decode("000102030405060708090a0b0c"); - byte[] info = Hex.decode("f0f1f2f3f4f5f6f7f8f9"); - int l = 42; - byte[] okm = new byte[l]; - - HKDFParameters params = new HKDFParameters(ikm, salt, info); - - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(hash); - hkdf.init(params); - hkdf.generateBytes(okm, 0, l); - - compareOKM(4, okm, Hex.decode( - "085a01ea1b10f36933068b56efa5ad81" + - "a4f14b822f5b091568a9cdd4f155fda2" + - "c22e422478d305f3f896")); - } - - // === A.5. Test Case 5 - Test with SHA-1 and longer inputs/outputs === - { - Digest hash = new SHA1Digest(); - byte[] ikm = Hex.decode("000102030405060708090a0b0c0d0e0f" - + "101112131415161718191a1b1c1d1e1f" - + "202122232425262728292a2b2c2d2e2f" - + "303132333435363738393a3b3c3d3e3f" - + "404142434445464748494a4b4c4d4e4f"); - byte[] salt = Hex.decode("606162636465666768696a6b6c6d6e6f" - + "707172737475767778797a7b7c7d7e7f" - + "808182838485868788898a8b8c8d8e8f" - + "909192939495969798999a9b9c9d9e9f" - + "a0a1a2a3a4a5a6a7a8a9aaabacadaeaf"); - byte[] info = Hex.decode("b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" - + "c0c1c2c3c4c5c6c7c8c9cacbcccdcecf" - + "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf" - + "e0e1e2e3e4e5e6e7e8e9eaebecedeeef" - + "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"); - int l = 82; - byte[] okm = new byte[l]; - - HKDFParameters params = new HKDFParameters(ikm, salt, info); - - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(hash); - hkdf.init(params); - hkdf.generateBytes(okm, 0, l); - - compareOKM(5, okm, Hex.decode( - "0bd770a74d1160f7c9f12cd5912a06eb" + - "ff6adcae899d92191fe4305673ba2ffe" + - "8fa3f1a4e5ad79f3f334b3b202b2173c" + - "486ea37ce3d397ed034c7f9dfeb15c5e" + - "927336d0441f4c4300e2cff0d0900b52" + - "d3b4")); - } - - { - // === A.6. Test Case 6 - Test with SHA-1 and zero-length salt/info - // === - - // setting salt to null should generate a new salt of HashLen zero - // valued bytes - - Digest hash = new SHA1Digest(); - byte[] ikm = Hex - .decode("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"); - byte[] salt = null; - byte[] info = new byte[0]; - int l = 42; - byte[] okm = new byte[l]; - - HKDFParameters params = new HKDFParameters(ikm, salt, info); - - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(hash); - hkdf.init(params); - hkdf.generateBytes(okm, 0, l); - - compareOKM(6, okm, Hex.decode( - "0ac1af7002b3d761d1e55298da9d0506" + - "b9ae52057220a306e07b6b87e8df21d0" + - "ea00033de03984d34918")); - } - - { - // === A.7. Test Case 7 - Test with SHA-1, salt not provided, - // zero-length info === - // (salt defaults to HashLen zero octets) - - // this test is identical to test 6 in all ways bar the IKM value - - Digest hash = new SHA1Digest(); - byte[] ikm = Hex - .decode("0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c"); - byte[] salt = null; - byte[] info = new byte[0]; - int l = 42; - byte[] okm = new byte[l]; - - HKDFParameters params = new HKDFParameters(ikm, salt, info); - - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(hash); - hkdf.init(params); - hkdf.generateBytes(okm, 0, l); - - compareOKM(7, okm, Hex.decode( - "2c91117204d745f3500d636a62f64f0a" + - "b3bae548aa53d423b0d1f27ebba6f5e5" + - "673a081d70cce7acfc48")); - } - - { - // === A.101. Additional Test Case - Test with SHA-1, skipping extract - // zero-length info === - // (salt defaults to HashLen zero octets) - - // this test is identical to test 7 in all ways bar the IKM value - // which is set to the PRK value - - Digest hash = new SHA1Digest(); - byte[] ikm = Hex - .decode("2adccada18779e7c2077ad2eb19d3f3e731385dd"); - byte[] info = new byte[0]; - int l = 42; - byte[] okm = new byte[l]; - - HKDFParameters params = HKDFParameters.skipExtractParameters(ikm, info); - - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(hash); - hkdf.init(params); - hkdf.generateBytes(okm, 0, l); - - compareOKM(101, okm, Hex.decode( - "2c91117204d745f3500d636a62f64f0a" + - "b3bae548aa53d423b0d1f27ebba6f5e5" + - "673a081d70cce7acfc48")); - } - - // === A.102. Additional Test Case - Test with SHA-1, maximum output === - // (salt defaults to HashLen zero octets) - - // this test is identical to test 7 in all ways bar the IKM value - - Digest hash = new SHA1Digest(); - byte[] ikm = Hex - .decode("2adccada18779e7c2077ad2eb19d3f3e731385dd"); - byte[] info = new byte[0]; - int l = 255 * hash.getDigestSize(); - byte[] okm = new byte[l]; - - HKDFParameters params = HKDFParameters.skipExtractParameters(ikm, info); - - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(hash); - hkdf.init(params); - hkdf.generateBytes(okm, 0, l); - - int zeros = 0; - for (int i = 0; i < hash.getDigestSize(); i++) - { - if (okm[i] == 0) - { - zeros++; - } - } - - if (zeros == hash.getDigestSize()) - { - fail("HKDF failed generator test " + 102); - } - } - - public String getName() - { - return "HKDF"; - } - - public static void main( - String[] args) - { - runTest(new HKDFGeneratorTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Haraka256DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Haraka256DigestTest.java deleted file mode 100644 index 8f24d8549..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Haraka256DigestTest.java +++ /dev/null @@ -1,186 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.Haraka256Digest; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class Haraka256DigestTest - extends SimpleTest -{ - public String getName() - { - return "Haraka 256"; - } - - public void testKnownVector() - { - byte[] in = new byte[32]; - for (int t = 0; t < in.length; t++) - { - in[t] = (byte)t; - } - - // From Appendix B, Haraka-256 v2, https://eprint.iacr.org/2016/098.pdf - byte[] expected256 = Hex.decode("8027ccb87949774b78d0545fb72bf70c695c2a0923cbd47bba1159efbf2b2c1c"); - - Haraka256Digest haraka = new Haraka256Digest(); - haraka.update(in, 0, in.length); - byte[] out = new byte[haraka.getDigestSize()]; - haraka.doFinal(out, 0); - isTrue("Did not match vector", this.areEqual(expected256, out)); - } - - - public void testInputTooShort() - { - try - { - Haraka256Digest haraka = new Haraka256Digest(); - byte[] in = new byte[31]; - haraka.update(in, 0, in.length); - haraka.doFinal(null, 0); - fail("fail on input not 32 bytes."); - } - catch (IllegalStateException ilarex) - { - isTrue("message", contains(ilarex.getMessage(), "input must be exactly 32 bytes")); - } - } - - public void testInputTooLong() - { - try - { - Haraka256Digest haraka = new Haraka256Digest(); - byte[] in = new byte[33]; - haraka.update(in, 0, in.length); - haraka.doFinal(null, 0); - fail("fail on input not 32 bytes."); - } - catch (IllegalArgumentException ilarex) - { - isTrue("long message", contains(ilarex.getMessage(), "total input cannot be more than 32 bytes")); - } - } - - public void testOutput() - { - - // - // Buffer too short. - // - try - { - Haraka256Digest haraka = new Haraka256Digest(); - byte[] in = new byte[32]; - haraka.update(in, 0, in.length); - byte[] out = new byte[31]; - haraka.doFinal(out, 0); - fail("Output too short for digest result."); - } - catch (IllegalArgumentException ilarex) - { - isTrue("message 1", contains(ilarex.getMessage(), "output too short to receive digest")); - } - - // - // Offset puts end past length of buffer. - // - try - { - Haraka256Digest haraka = new Haraka256Digest(); - byte[] in = new byte[32]; - haraka.update(in, 0, in.length); - byte[] out = new byte[48]; - haraka.doFinal(out, 17); - fail("Output too short for digest result."); - } - catch (IllegalArgumentException ilarex) - { - isTrue("message 2", contains(ilarex.getMessage(), "output too short to receive digest")); - } - - - // - // Offset output.. - // - byte[] in = new byte[32]; - for (int t = 0; t < in.length; t++) - { - in[t] = (byte)t; - } - - byte[] expected256 = Hex.decode("000000008027ccb87949774b78d0545fb72bf70c695c2a0923cbd47bba1159efbf2b2c1c"); - - Haraka256Digest haraka = new Haraka256Digest(); - haraka.update(in, 0, in.length); - byte[] out = new byte[haraka.getDigestSize() + 4]; - haraka.doFinal(out, 4); - isTrue(this.areEqual(expected256, out)); - } - - void testMonty() - { - int c = 0; - String[][] vectors = new String[][]{ - { - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F", - "e78599d7163ab58f1c90f0171c6fc4e852eb4b8cc29a4af63194fd9977c1de84" - }, - { - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", - "c4cebda63c00c4cd312f36ea92afd4b0f6048507c5b367326ef9d8fdd2d5c09a" - } - }; - - for (int i = 0; i != vectors.length; i++) - { - // - // 1000 rounds of digest application, where alternative outputs are copied over alternate halves of the input. - // - String[] vector = vectors[i]; - - byte[] expected = Hex.decode(vector[1]); - - // Load initial message. - - Haraka256Digest haraka = new Haraka256Digest(); - byte[] result = Hex.decode(vector[0]); - for (int t = 0; t < 1000; t++) - { - haraka.update(result, 0, result.length); - haraka.doFinal(result, 0); - } - isTrue("Monte Carlo test: " + c, this.areEqual(expected, result)); - - // - // Deliberately introduce incorrect value. - // - - result[0] ^= 1; - isTrue("Monte Carlo test: " + c, !this.areEqual(expected, result)); - c++; - } - } - - private boolean contains(String message, String sub) - { - return message.indexOf(sub) >= 0; - } - - public void performTest() - throws Exception - { - testKnownVector(); - testInputTooLong(); - testInputTooShort(); - testOutput(); - testMonty(); - } - - public static void main( - String[] args) - { - runTest(new Haraka256DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Haraka512DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Haraka512DigestTest.java deleted file mode 100644 index 31c2738d0..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Haraka512DigestTest.java +++ /dev/null @@ -1,192 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.Haraka512Digest; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class Haraka512DigestTest - extends SimpleTest -{ - public String getName() - { - return "Haraka 512"; - } - - public void testKnownVector() - { - byte[] in = new byte[64]; - for (int t = 0; t < in.length; t++) - { - in[t] = (byte)t; - } - - // From Appendix B, Haraka-512 v2, https://eprint.iacr.org/2016/098.pdf - byte[] expected512 = Hex.decode("be7f723b4e80a99813b292287f306f625a6d57331cae5f34dd9277b0945be2aa"); - - Haraka512Digest haraka = new Haraka512Digest(); - haraka.update(in, 0, in.length); - byte[] out = new byte[haraka.getDigestSize()]; - haraka.doFinal(out, 0); - isTrue("Did not match vector",this.areEqual(expected512, out)); - } - - public void testInputTooShort() - { - try - { - Haraka512Digest haraka = new Haraka512Digest(); - byte[] in = new byte[63]; - haraka.update(in, 0, in.length); - haraka.doFinal(null, 0); - fail("fail on input not 64 bytes."); - } - catch (IllegalStateException ilarex) - { - isTrue("message", contains(ilarex.getMessage(), "input must be exactly 64 bytes")); - } - } - - public void testInputTooLong() - { - try - { - Haraka512Digest haraka = new Haraka512Digest(); - byte[] in = new byte[65]; - haraka.update(in, 0, in.length); - haraka.doFinal(null, 0); - fail("fail on input not 64 bytes."); - } - catch (IllegalArgumentException ilarex) - { - isTrue("message", contains(ilarex.getMessage(), "total input cannot be more than 64 bytes")); - } - } - - public void testOutput() - { - // - // Buffer too short. - // - try - { - Haraka512Digest haraka = new Haraka512Digest(); - byte[] in = new byte[64]; - haraka.update(in, 0, in.length); - byte[] out = new byte[31]; - haraka.doFinal(out, 0); - fail("Output too short for digest result."); - } - catch (IllegalArgumentException ilarex) - { - isTrue("message", contains(ilarex.getMessage(), "output too short to receive digest")); - } - - // - // Offset puts end past length of buffer. - // - try - { - Haraka512Digest haraka = new Haraka512Digest(); - byte[] in = new byte[64]; - haraka.update(in, 0, in.length); - byte[] out = new byte[48]; - haraka.doFinal(out, 17); - fail("Output too short for digest result."); - } - catch (IllegalArgumentException ilarex) - { - isTrue("message", contains(ilarex.getMessage(), "output too short to receive digest")); - } - - // - // Offset output.. - // - byte[] in = new byte[64]; - for (int t = 0; t < in.length; t++) - { - in[t] = (byte)t; - } - - byte[] expected512 = Hex.decode("00000000be7f723b4e80a99813b292287f306f625a6d57331cae5f34dd9277b0945be2aa"); - - Haraka512Digest haraka = new Haraka512Digest(); - haraka.update(in, 0, in.length); - byte[] out = new byte[haraka.getDigestSize() + 4]; - haraka.doFinal(out, 4); - isTrue(this.areEqual(expected512, out)); - } - - void testMonty() - { - int c = 0; - String[][] vectors = new String[][]{ - { - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F", - "ABE210FE673F3B28E70E5100C476D82F61A7E2BDB3D8423FB0A15E5DE3D3A4DE" - }, - { - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", - "5F5ECB52C61F5036C96BE555D2E18C520AB3ED093954700C283A322D14DBFE02" - } - }; - - for (int i = 0; i != vectors.length; i++) - { - // - // 1000 rounds of digest application, where alternative outputs are copied over alternate halves of the input. - // - String[] vector = vectors[i]; - - byte[] expected = Hex.decode(vector[1]); - - // Load initial message. - byte[] in = Hex.decode(vector[0]); - Haraka512Digest haraka = new Haraka512Digest(); - byte[] result = new byte[haraka.getDigestSize()]; - for (int t = 0; t < 1000; t++) - { - haraka.update(in, 0, in.length); - haraka.doFinal(result, 0); - - if ((t & 0x01) == 1) - { - System.arraycopy(result, 0, in, 0, result.length); - } - else - { - System.arraycopy(result, 0, in, result.length, result.length); - } - } - isTrue("Monte Carlo test: " + c, this.areEqual(expected, result)); - - // - // Deliberately introduce incorrect value. - // - - result[0] ^= 1; - isTrue("Monte Carlo test: " + c, !this.areEqual(expected, result)); - c++; - } - } - - private boolean contains(String message, String sub) - { - return message.indexOf(sub) >= 0; - } - - public void performTest() - throws Exception - { - testKnownVector(); - testInputTooLong(); - testInputTooShort(); - testOutput(); - testMonty(); - } - - public static void main( - String[] args) - { - runTest(new Haraka512DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/HashCommitmentTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/HashCommitmentTest.java deleted file mode 100644 index 4095187af..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/HashCommitmentTest.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.Commitment; -import com.fr.third.org.bouncycastle.crypto.Committer; -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.commitments.GeneralHashCommitter; -import com.fr.third.org.bouncycastle.crypto.commitments.HashCommitter; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class HashCommitmentTest - extends SimpleTest -{ - public String getName() - { - return "HashCommitmentTest"; - } - - public void performBasicTest() - throws Exception - { - byte[] data = Hex.decode("4e6f77206973207468652074696d6520666f7220616c6c20"); - - Committer committer = new HashCommitter(new SHA256Digest(), new SecureRandom()); - - Commitment c = committer.commit(data); - - committer = new HashCommitter(new SHA256Digest(), new SecureRandom()); - - if (!committer.isRevealed(c, data)) - { - fail("commitment failed to validate"); - } - - committer = new HashCommitter(new SHA1Digest(), new SecureRandom()); - - if (committer.isRevealed(c, data)) - { - fail("commitment validated!!"); - } - - try - { - committer.isRevealed(c, new byte[data.length + 1]); - } - catch (Exception e) - { - if (!e.getMessage().equals("Message and witness secret lengths do not match.")) - { - fail("exception thrown but wrong message"); - } - } - - // SHA1 has a block size of 512 bits, try a message that's too big - - try - { - c = committer.commit(new byte[33]); - } - catch (DataLengthException e) - { - if (!e.getMessage().equals("Message to be committed to too large for digest.")) - { - fail("exception thrown but wrong message"); - } - } - } - - public void performGeneralTest() - throws Exception - { - byte[] data = Hex.decode("4e6f77206973207468652074696d6520666f7220616c6c20"); - - Committer committer = new GeneralHashCommitter(new SHA256Digest(), new SecureRandom()); - - Commitment c = committer.commit(data); - - committer = new GeneralHashCommitter(new SHA256Digest(), new SecureRandom()); - - if (!committer.isRevealed(c, data)) - { - fail("general commitment failed to validate"); - } - - committer = new GeneralHashCommitter(new SHA1Digest(), new SecureRandom()); - - if (committer.isRevealed(c, data)) - { - fail("general commitment validated!!"); - } - - c = committer.commit(data); - - // try and fool it. - byte[] s = c.getSecret(); - byte[] newS = Arrays.copyOfRange(s, 0, s.length - 1); - byte[] newData = new byte[data.length + 1]; - - newData[0] = s[s.length - 1]; - System.arraycopy(data, 0, newData, 1, data.length); - - c = new Commitment(newS, c.getCommitment()); - - if (committer.isRevealed(c, newData)) - { - fail("general commitment validated!!"); - } - - try - { - committer.isRevealed(c, new byte[data.length + 1]); - } - catch (Exception e) - { - if (!e.getMessage().equals("Message and witness secret lengths do not match.")) - { - fail("exception thrown but wrong message"); - } - } - - // SHA1 has a block size of 512 bits, try a message that's too big - - try - { - c = committer.commit(new byte[33]); - } - catch (DataLengthException e) - { - if (!e.getMessage().equals("Message to be committed to too large for digest.")) - { - fail("exception thrown but wrong message"); - } - } - } - - public void performTest() - throws Exception - { - performBasicTest(); - performGeneralTest(); - } - - public static void main(String[] args) - { - runTest(new HashCommitmentTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/IDEATest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/IDEATest.java deleted file mode 100644 index f2bee4370..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/IDEATest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.IDEAEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - */ -public class IDEATest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new IDEAEngine(), - new KeyParameter(Hex.decode("00112233445566778899AABBCCDDEEFF")), - "000102030405060708090a0b0c0d0e0f", "ed732271a7b39f475b4b2b6719f194bf"), - new BlockCipherVectorTest(0, new IDEAEngine(), - new KeyParameter(Hex.decode("00112233445566778899AABBCCDDEEFF")), - "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", "b8bc6ed5c899265d2bcfad1fc6d4287d") - }; - - IDEATest() - { - super(tests, new IDEAEngine(), new KeyParameter(new byte[32])); - } - - public String getName() - { - return "IDEA"; - } - - public static void main( - String[] args) - { - runTest(new IDEATest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ISAACTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ISAACTest.java deleted file mode 100644 index d480a8a66..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ISAACTest.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.ISAACEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * ISAAC Test - see http://www.burtleburtle.net/bob/rand/isaacafa.html - */ -public class ISAACTest - extends SimpleTest -{ - byte[] out = Hex.decode( - "f650e4c8e448e96d98db2fb4f5fad54f433f1afbedec154ad837048746ca4f9a" + - "5de3743e88381097f1d444eb823cedb66a83e1e04a5f6355c744243325890e2e" + - "7452e31957161df638a824f3002ed71329f5544951c08d83d78cb99ea0cc74f3" + - "8f651659cbc8b7c2f5f71c6912ad6419e5792e1b860536b809b3ce98d45d6d81" + - "f3b2612917e38f8529cf72ce349947b0c998f9ffb5e13dae32ae2a2bf7cf814c" + - "8ebfa303cf22e0640b923200eca4d58aef53cec4d0f7b37d9c411a2affdf8a80" + - "b40e27bcb4d2f97644b89b08f37c71d51a70e7e90bdb9c3060dc5207b3c3f24b" + - "d7386806229749b54e232cd091dabc65a70e11018b87437e5781414fcdbc62e2" + - "8107c9ff69d2e4ae3b18e752b143b6886f4e077295138769943c3c74afc17a97" + - "0fd439636a529b0bd8c58a6aa8bcc22d2db35dfea7a2f4026cb167db538e1f4e" + - "7275e2771d3b8e97ecc5dc9115e3a5b90369661430ab93ecac9fe69d7bc76811" + - "60eda8da28833522d5295ebc5adb60e7f7e1cdd097166d14b67ec13a210f3925" + - "64af0fef0d0286843aea3decb058bafbb8b0ccfcf2b5cc05e3a662d9814bc24c" + - "2364a1aa37c0ed052b36505c451e7ec85d2a542fe43d0fbb91c8d92560d4d5f8" + - "12a0594b9e8a51dacd49ebdb1b0dcdc1cd57c7f7e63444517ded386f2f36fa86" + - "a6d1210133bc405db388d96cdb6dbe96fe29661c13edc0cbcb0eee4a70cc94ae" + - "de11ed340606cf9f3a6ce38923d74f4ea37f63ff917bdec2d73f72d40e7e0e67" + - "3d77d9a213add9228891b3db01a9bd7056a001e3d51f093dcc033ce35ad0d3b0" + - "34105a8c6a123f57bd2e50247364944be89b1a3b21835c4d9f39e2d9d405ded8" + - "294d37e5bccaaeed35a124b56708a2bcb00960ba2a98121a4d8fae820bb3263f" + - "12595a196a1075890809e49421c171ec884d682514c8009bb0b84e7b03fb88f4" + - "28e7cb789388b13bdd2dc1d5848f520a07c28cd168a3935872c9137d127dd430" + - "c613f1578c2f0d55f7d3f39f309bfb788406b13746c0a6f53718d59708607f04" + - "76904b6d04db4e13cd7411a7b510ce0ebfc7f7ccb83f957afdfef62dc35e4580" + - "3ff1e5244112d96c02c9b944d5990dfbe7e265810d9c7e7e826dfa8966f1e0ab" + - "30bcc764eadebeaced35e5ee0c571a7de4f3a26af7f58f7badf6bc235d023e65" + - "1ed3ff4eec46b0b6d2a93b51e75b41c97e315aeb61119a5a53245b7933f6d7b1" + - "cae8deba50fc8194afa92a6dc87c80064188bfcd8bace62e78ffa5685597ec0f" + - "b4415f7d08294766ad56764309c36f903dde9f394a0a283c18080c8e080c79ec" + - "79ae4c10cb9e15637cdd662f62d31911a4ca0cf15cf824cd3b708f991e16614c" + - "b6b9d7665de87abb7229ea81d5b2d75056e6cd21fe1e42d596da2655c2b9aa36" + - "b8f6fd4a6a158d1001913fd3af7d1fb80b5e435f90c107576554abda7a68710f" + - "82ac484fd7e1c7be95c85eaa94a302f44d3cfbda786b29081010b27582d53d12" + - "21e2a51c3d1e9150b059261dd0638e1a31860f0581f2864dff4cfc350451516d" + - "bd086f26bc5654c165dfa427a82427f5582e3014b8d2486dc79a17499a1d7745" + - "8766bb541e04a7f73d3dff8ad5ec6bf4dbef7d9f36ec0ea31feb2e4f15cfcc5c" + - "d8c423fbd0ef3cc9eb244925ba5590c8a5f48ac433c5321c613b67b2479c3a22" + - "e21339cc10d210aa931dd7e2ef05ee06b82f2703a385cb2c5d67133c877eb7b4" + - "1e3437f75afb43ae53c078f394d904811d96458908063a85e13222281956b1e5" + - "31860f132e7b022f21182ca396f703ac46819e2e0d28fe523724d4dca0eabe6b" + - "c66699fdc6112fdd19c1e69c04d3658a4b55dd9931907d62f854b5224d678f26" + - "22ae0582eafed133e4a51d2184bd6dd6c1a513753f28ee63fb737b1a70a1660e" + - "8a8dfaa31be79937f7476978513c1764531ac6bf12c06908001cdb951a4b6a53" + - "d067fce512b2cfb69ddb477f740e006639ddf25acc8bfa2df1b20eaf64f2632c" + - "9783cdee63bfd4d80084cfe575f4e9e219b48fd06c48ddd87a36af9371865c4c" + - "9ce0199d867027d72cb7b77f84ef01da72f5972f040f7074df9afa29c921f94e" + - "75c08a3618c1ef9ad649a428c5b719378a30738ad97cd348858129a6239e3b0a" + - "bbb8abc480fac4c2ecfcf20bd9d711f9e2a4ef71b5fe87c0be8b06b2aafef5a7" + - "9c15db3b0aeb81654389a84a253b1d7a19047c797cdc78a2d20adf0356f55a71" + - "3e730fa8fd8650d8959e234eb7546681dad1b22a142a6e858ef4bce668235b9d" + - "85a13f8574096ae7a949bea229322d0dd568385882846526403dae086dd1943a" + - "e1279bff9e7e4f041c3a4524484525e481d4cc5fe24124c0037464c0bf1bd691" + - "26ceb003275ead3ac5bde90826414ff3a30519add7b43abe2ce5d3d588412761" + - "97ca2070e5fbb9c7276df0b4308f751f37a97df6c9cd808cfe4cb3803d469303" + - "aee19096c0d5d42a4e823ad3f5f9cc3b4286619c9ca45e1c66c97340891aec49" + - "45bae606c798f04752649d6cce86fdfc80c6e402d6ec2f2b27c822821fe26ce0" + - "92f57ea7de462f4d07497cae5a48755c721502dd6cbe7935836d80039ead7f70" + - "9ab3a42f4c8652d632e39273e8fa38601da4f25a0cd6ef8102503f7d8854a0a1" + - "9a30c4e88815715305efe29457c4c9252887d96fc1a71e3ce9f841632d0985de" + - "d21e796c6fb5ce5602614abfc3c7be2cb54fed6fa617a083c3142d8f6079e4ce" + - "ceffc1471d0cb81bdc153e5fe36ef5bbd531161a165b10157aa114ed3f7579b3" + - "f7f395f1bc6172c7a86f875e0e6c51b3cdfec2af73c0e762824c2009c5a87748" + - "94d401258aba3ffbd32be0608c17eff021e2547e07cffad905340e15f3310c92" + - "9d8d190886ba527ff943f672ef73fbf046d95ca5c54cd95b9d855e894bb5af29"); - - byte[] outFFFFFFFF = Hex.decode( - "de3b3f3c19e0629c1fc8b7836695d523e7804edd86ff7ce9b106f52caebae9d9" + - "72f845d49ce17d7da44e49bae954aac0d0b1284b98a88eec1524fb6bc91a16b5" + - "1192ac5334131446ac2442de9ff3d5867b9b9148881ee30a6e87dd88e5d1f7cd" + - "98db31ff36f70d9850cfefaef42abb00ecc39ed308bf4b8030cdc2b6b7e42f0e" + - "908030dd282f96edacc888b3a986e109c129998f89baa1b5da8970b07a6ab012" + - "f10264f23c315c9c8e0c164955c68517b6a4f982b2626db70787f869ac6d551b" + - "e34931627c7058e965c502e18d2cd370e6db3b70d947d61aa9717cf8394f48c6" + - "3c796f3a154950846badb28b70d982f29bc670254e3e5e0f8e36b0a5f6da0a04" + - "6b235ed6a42988c012bde74d879fa8eb5d59f5f40ed5e76601c9847b3edb2690"); - - byte[] outFFFF0000 = Hex.decode( - "26c54b1f8c4e3fc582e9e8180f7aba5380463dcf58b03cbeda0ecc8ba90ccff8" + - "5bd50896313d7efed44015faeac6964b241a7fb8a2e37127a7cbea0fd7c020f2" + - "406371b87ef5185089504751e5e44352eff63e00e5c28f5dff0616a9a3a00f1f" + - "4a1350e3a17be9abddfc2c94571450a0dc4c3c0c7c7f98e80c95f607d50c676a" + - "9a3006f9d279a79a4d66b2ab0c52930c9ee84bc09895e70fa041b1a3a2966f11" + - "6a47fd09705124b1f5c7ae055e54536e66584b1608f3612d81b72f109a385831" + - "121945b207b90ac72437a248f27a121c2801f4153a8699fb047e193f7ba69e1b" + - "b117869675d4c963e6070c2ca3d332ce830cb5e3d9ed2eee7faf0acc20fbe154" + - "188ae789e95bd5c1f459dbd150aab6eb833170257084bc5d44e9df09f5624f9d" + - "afecd0c9340ac8587f8625d343f7efd1cc8abcf7a6f90eabd4e8e2d906278d6e" + - "431fcade165c8c467887fbf5c26d341557b064b98c60dd40ab262dc046d69647" + - "56f3ddc1a07ae5f87be878b9334fcde40add68d2ca1dc05fb1670f998c7c4607" + - "9a6e48bdb330ad8d30b61b5cc8dc156f5733905931949783f89ac396b65aa4b8" + - "51f746b53ed8ea66130e1d75e8eab136e60450e3e600226bc8e17d03744ce94c" + - "0eec9234fea5f18eef65d81f2f10cfbc0b112b8cde17c32eb33ed81d7356eac3" + - "eb1cb9cefa6604c2d707949b6e5a83e60705bf6aae76dcc7d35d68ff149c1ac5" + - "424bb4a39e2f496f886637fce3db4ba4ad12c1a32d25e1606f6635ff636486f6" + - "714997b45477f38813c02afce4bebf196b813332f0decd567c745f441e736364"); - - byte[] out0000FFFF = Hex.decode( - "bc31712f2a2f467a5abc737c57ce0f8d49d2f775eb850fc8f856daf19310fee2"+ - "5bab40e78403c9ef4ccd971418992faf4e85ca643fa6b482f30c4659066158a6"+ - "5bc3e620ba7ea5c34dd0eac5aabb2cf078d915fd1f8c437ed00423076c10f701"+ - "eefa7fc7c461aca5db8a87be29d925c4212d4adcfa71ff5b06af15c048aa0dfd"+ - "f0e645bc09fea200c430a88eb38c466ff358b836f1159656a078f6fc752f6db1"+ - "6680bb30fc771a6a785bbb2298e947d7b3500e557775962248bedf4e82c16e66"+ - "f39283ccb95e5399061056a11c4a280f00f7487888199487905273c7aa13012b"+ - "4849eca626cbf071c782e084f9fded57de92313e5f61a6e81117fb1115eff275"+ - "66fd5c755bb3b01bba69aeb8f1b1b1cc9709734be31b35bc707d372ba6fe70d1"+ - "e2c3b0e5e74a7058faff6b11d3a168f19fecc9fcb36b3e6a5f828c01c22ac0c2"+ - "5da2a3a9eec7e0ebbbf51472e430ed4cf1c7ab57ef9aea511e40250846d260b6"+ - "17a3fdeba16cf4afaf700144d3296b58b22a3c79ed96f3e2fc8d9e3c660ae153"+ - "8e0c285ccdc48b59117e80413bd0ad24c6a8d4f133fe1496f14351bb89904fa5"+ - "e10c4b8d50e0604578389c336a9ab3d292beb90ce640fc028e697cf54e021e2f"+ - "c0ca3fe0471fde5e5462f221739a74f5a13ae0621fe2a82e752bc294f63de48d"+ - "e85430af71307a30441b861ab5380e6a6dbe1251c9baa567da14e38e5a0ccddf"+ - "0127205c38fc3b77065e98101d219246103438d223ec7f8f533d4bb3a3d3407a"+ - "944910f11e8e5492e86de7a0471250eca32f0838b3db02fffe71898712af3261"); - - public String getName() - { - return "ISAAC"; - } - - public void performTest() - { - ISAACEngine engine = new ISAACEngine(); - - doTest(engine, Hex.decode("00000000"), out); - doTest(engine, Hex.decode("ffffffff"), outFFFFFFFF); - - byte[] k = new byte[256 * 4]; - for (int i = 0; i != k.length; i++) - { - k[i] = (byte)((i % 4 == 0 || i % 4 == 1) ? 0xff : 0x00); - } - doTest(engine, k, outFFFF0000); - k = new byte[256 * 4]; - for (int i = 0; i != k.length; i++) - { - k[i] = (byte)((i % 4 == 2 || i % 4 == 3) ? 0xff : 0x00); - } - doTest(engine, k, out0000FFFF); - } - - private void doTest(ISAACEngine engine, byte[] key, byte[] output) - { - byte[] in = new byte[output.length]; - byte[] enc = new byte[output.length]; - engine.init(true, new KeyParameter(key)); - engine.processBytes(in, 0, in.length, enc, 0); - if (!areEqual(enc, output)) - { - fail("ciphertext mismatch"); - } - engine.init(false, new KeyParameter(key)); - engine.processBytes(enc, 0, enc.length, enc, 0); - if (!areEqual(enc, in)) - { - fail("plaintext mismatch"); - } - } - - public static void main( - String[] args) - { - runTest(new ISAACTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ISO9796Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ISO9796Test.java deleted file mode 100644 index 60950f3c6..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ISO9796Test.java +++ /dev/null @@ -1,1028 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricBlockCipher; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.RIPEMD128Digest; -import com.fr.third.org.bouncycastle.crypto.digests.RIPEMD160Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.encodings.ISO9796d1Encoding; -import com.fr.third.org.bouncycastle.crypto.engines.RSABlindedEngine; -import com.fr.third.org.bouncycastle.crypto.engines.RSAEngine; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithSalt; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.signers.ISO9796d2PSSSigner; -import com.fr.third.org.bouncycastle.crypto.signers.ISO9796d2Signer; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * test vectors from ISO 9796-1 and ISO 9796-2 edition 1. - */ -public class ISO9796Test - extends SimpleTest -{ - static BigInteger mod1 = new BigInteger("0100000000000000000000000000000000bba2d15dbb303c8a21c5ebbcbae52b7125087920dd7cdf358ea119fd66fb064012ec8ce692f0a0b8e8321b041acd40b7", 16); - - static BigInteger pub1 = new BigInteger("03", 16); - - static BigInteger pri1 = new BigInteger("2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac9f0783a49dd5f6c5af651f4c9d0dc9281c96a3f16a85f9572d7cc3f2d0f25a9dbf1149e4cdc32273faadd3fda5dcda7", 16); - - static BigInteger mod2 = new BigInteger("ffffff7fa27087c35ebead78412d2bdffe0301edd494df13458974ea89b364708f7d0f5a00a50779ddf9f7d4cb80b8891324da251a860c4ec9ef288104b3858d", 16); - - static BigInteger pub2 = new BigInteger("03", 16); - - static BigInteger pri2 = new BigInteger("2aaaaa9545bd6bf5e51fc7940adcdca5550080524e18cfd88b96e8d1c19de6121b13fac0eb0495d47928e047724d91d1740f6968457ce53ec8e24c9362ce84b5", 16); - - static byte msg1[] = Hex.decode("0cbbaa99887766554433221100"); - - // - // you'll need to see the ISO 9796 to make sense of this - // - static byte sig1[] = mod1.subtract(new BigInteger("309f873d8ded8379490f6097eaafdabc137d3ebfd8f25ab5f138d56a719cdc526bdd022ea65dabab920a81013a85d092e04d3e421caab717c90d89ea45a8d23a", 16)).toByteArray(); - - static byte msg2[] = Hex.decode("fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210"); - - static byte sig2[] = new BigInteger("319bb9becb49f3ed1bca26d0fcf09b0b0a508e4d0bd43b350f959b72cd25b3af47d608fdcd248eada74fbe19990dbeb9bf0da4b4e1200243a14e5cab3f7e610c", 16).toByteArray(); - - static byte msg3[] = Hex.decode("0112233445566778899aabbccd"); - - static byte sig3[] = mod2.subtract(new BigInteger("58e59ffb4b1fb1bcdbf8d1fe9afa3730c78a318a1134f5791b7313d480ff07ac319b068edf8f212945cb09cf33df30ace54f4a063fcca0b732f4b662dc4e2454", 16)).toByteArray(); - - // - // ISO 9796-2 - // - static BigInteger mod3 = new BigInteger("ffffffff78f6c55506c59785e871211ee120b0b5dd644aa796d82413a47b24573f1be5745b5cd9950f6b389b52350d4e01e90009669a8720bf265a2865994190a661dea3c7828e2e7ca1b19651adc2d5", 16); - - static BigInteger pub3 = new BigInteger("03", 16); - - static BigInteger pri3 = new BigInteger("2aaaaaaa942920e38120ee965168302fd0301d73a4e60c7143ceb0adf0bf30b9352f50e8b9e4ceedd65343b2179005b2f099915e4b0c37e41314bb0821ad8330d23cba7f589e0f129b04c46b67dfce9d", 16); - - static BigInteger mod4 = new BigInteger("FFFFFFFF45f1903ebb83d4d363f70dc647b839f2a84e119b8830b2dec424a1ce0c9fd667966b81407e89278283f27ca8857d40979407fc6da4cc8a20ecb4b8913b5813332409bc1f391a94c9c328dfe46695daf922259174544e2bfbe45cc5cd", 16); - static BigInteger pub4 = new BigInteger("02", 16); - static BigInteger pri4 = new BigInteger("1fffffffe8be3207d7707a9a6c7ee1b8c8f7073e5509c2337106165bd8849439c193faccf2cd70280fd124f0507e4f94cb66447680c6b87b6599d1b61c8f3600854a618262e9c1cb1438e485e47437be036d94b906087a61ee74ab0d9a1accd8", 16); - - static byte msg4[] = Hex.decode("6162636462636465636465666465666765666768666768696768696a68696a6b696a6b6c6a6b6c6d6b6c6d6e6c6d6e6f6d6e6f706e6f7071"); - static byte sig4[] = Hex.decode("374695b7ee8b273925b4656cc2e008d41463996534aa5aa5afe72a52ffd84e118085f8558f36631471d043ad342de268b94b080bee18a068c10965f581e7f32899ad378835477064abed8ef3bd530fce"); - - static byte msg5[] = Hex.decode("fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210"); - static byte sig5[] = Hex.decode("5cf9a01854dbacaec83aae8efc563d74538192e95466babacd361d7c86000fe42dcb4581e48e4feb862d04698da9203b1803b262105104d510b365ee9c660857ba1c001aa57abfd1c8de92e47c275cae"); - - // - // scheme 2 data - // - static BigInteger mod6 = new BigInteger("b259d2d6e627a768c94be36164c2d9fc79d97aab9253140e5bf17751197731d6f7540d2509e7b9ffee0a70a6e26d56e92d2edd7f85aba85600b69089f35f6bdbf3c298e05842535d9f064e6b0391cb7d306e0a2d20c4dfb4e7b49a9640bdea26c10ad69c3f05007ce2513cee44cfe01998e62b6c3637d3fc0391079b26ee36d5", 16); - static BigInteger pub6 = new BigInteger("11", 16); - static BigInteger pri6 = new BigInteger("92e08f83cc9920746989ca5034dcb384a094fb9c5a6288fcc4304424ab8f56388f72652d8fafc65a4b9020896f2cde297080f2a540e7b7ce5af0b3446e1258d1dd7f245cf54124b4c6e17da21b90a0ebd22605e6f45c9f136d7a13eaac1c0f7487de8bd6d924972408ebb58af71e76fd7b012a8d0e165f3ae2e5077a8648e619", 16); - - static byte sig6[] = new BigInteger("0073FEAF13EB12914A43FE635022BB4AB8188A8F3ABD8D8A9E4AD6C355EE920359C7F237AE36B1212FE947F676C68FE362247D27D1F298CA9302EB21F4A64C26CE44471EF8C0DFE1A54606F0BA8E63E87CDACA993BFA62973B567473B4D38FAE73AB228600934A9CC1D3263E632E21FD52D2B95C5F7023DA63DE9509C01F6C7BBC", 16).modPow(pri6, mod6).toByteArray(); - - static byte msg7[] = Hex.decode("6162636462636465636465666465666765666768666768696768696A68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F70716F70717270717273"); - static byte sig7[] = new BigInteger("296B06224010E1EC230D4560A5F88F03550AAFCE31C805CE81E811E5E53E5F71AE64FC2A2A486B193E87972D90C54B807A862F21A21919A43ECF067240A8C8C641DE8DCDF1942CF790D136728FFC0D98FB906E7939C1EC0E64C0E067F0A7443D6170E411DF91F797D1FFD74009C4638462E69D5923E7433AEC028B9A90E633CC", 16).modPow(pri6, mod6).toByteArray(); - - static byte msg8[] = Hex.decode("FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA98"); - static byte sig8[] = new BigInteger("01402B29ABA104079677CE7FC3D5A84DB24494D6F9508B4596484F5B3CC7E8AFCC4DDE7081F21CAE9D4F94D6D2CCCB43FCEDA0988FFD4EF2EAE72CFDEB4A2638F0A34A0C49664CD9DB723315759D758836C8BA26AC4348B66958AC94AE0B5A75195B57ABFB9971E21337A4B517F2E820B81F26BCE7C66F48A2DB12A8F3D731CC", 16).modPow(pri6, mod6).toByteArray(); - - static byte msg9[] = Hex.decode("6162636462636465636465666465666765666768666768696768696A68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F70716F707172707172737172737472737475737475767475767775767778767778797778797A78797A61797A61627A6162636162636462636465"); - static byte sig9[] = new BigInteger("6F2BB97571FE2EF205B66000E9DD06656655C1977F374E8666D636556A5FEEEEAF645555B25F45567C4EE5341F96FED86508C90A9E3F11B26E8D496139ED3E55ECE42860A6FB3A0817DAFBF13019D93E1D382DA07264FE99D9797D2F0B7779357CA7E74EE440D8855B7DDF15F000AC58EE3FFF144845E771907C0C83324A6FBC", 16).modPow(pri6, mod6).toByteArray(); - - public String getName() - { - return "ISO9796"; - } - - private boolean isSameAs( - byte[] a, - int off, - byte[] b) - { - if ((a.length - off) != b.length) - { - return false; - } - - for (int i = 0; i != b.length; i++) - { - if (a[i + off] != b[i]) - { - return false; - } - } - - return true; - } - - private boolean startsWith( - byte[] a, - byte[] b) - { - if (a.length < b.length) - { - return false; - } - - for (int i = 0; i != b.length; i++) - { - if (a[i] != b[i]) - { - return false; - } - } - - return true; - } - - private void doTest1() - throws Exception - { - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod1, pub1); - RSAKeyParameters privParameters = new RSAKeyParameters(true, mod1, pri1); - RSAEngine rsa = new RSAEngine(); - byte[] data; - - // - // ISO 9796-1 - public encrypt, private decrypt - // - ISO9796d1Encoding eng = new ISO9796d1Encoding(rsa); - - eng.init(true, privParameters); - - eng.setPadBits(4); - - data = eng.processBlock(msg1, 0, msg1.length); - - eng.init(false, pubParameters); - - if (!areEqual(sig1, data)) - { - fail("failed ISO9796-1 generation Test 1"); - } - - data = eng.processBlock(data, 0, data.length); - - if (!areEqual(msg1, data)) - { - fail("failed ISO9796-1 retrieve Test 1"); - } - } - - private void doTest2() - throws Exception - { - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod1, pub1); - RSAKeyParameters privParameters = new RSAKeyParameters(true, mod1, pri1); - RSAEngine rsa = new RSAEngine(); - byte[] data; - - // - // ISO 9796-1 - public encrypt, private decrypt - // - ISO9796d1Encoding eng = new ISO9796d1Encoding(rsa); - - eng.init(true, privParameters); - - data = eng.processBlock(msg2, 0, msg2.length); - - eng.init(false, pubParameters); - - if (!isSameAs(data, 1, sig2)) - { - fail("failed ISO9796-1 generation Test 2"); - } - - data = eng.processBlock(data, 0, data.length); - - - if (!areEqual(msg2, data)) - { - fail("failed ISO9796-1 retrieve Test 2"); - } - } - - public void doTest3() - throws Exception - { - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod2, pub2); - RSAKeyParameters privParameters = new RSAKeyParameters(true, mod2, pri2); - RSAEngine rsa = new RSAEngine(); - byte[] data; - - // - // ISO 9796-1 - public encrypt, private decrypt - // - ISO9796d1Encoding eng = new ISO9796d1Encoding(rsa); - - eng.init(true, privParameters); - - eng.setPadBits(4); - - data = eng.processBlock(msg3, 0, msg3.length); - - eng.init(false, pubParameters); - - if (!isSameAs(sig3, 1, data)) - { - fail("failed ISO9796-1 generation Test 3"); - } - - data = eng.processBlock(data, 0, data.length); - - if (!isSameAs(msg3, 0, data)) - { - fail("failed ISO9796-1 retrieve Test 3"); - } - } - - public void doTest4() - throws Exception - { - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod3, pub3); - RSAKeyParameters privParameters = new RSAKeyParameters(true, mod3, pri3); - RSAEngine rsa = new RSAEngine(); - byte[] data; - - // - // ISO 9796-2 - Signing - // - ISO9796d2Signer eng = new ISO9796d2Signer(rsa, new RIPEMD128Digest()); - - eng.init(true, privParameters); - - eng.update(msg4[0]); - eng.update(msg4, 1, msg4.length - 1); - - data = eng.generateSignature(); - - byte[] recovered = new byte[eng.getRecoveredMessage().length]; - - if (!eng.hasFullMessage()) - { - fail("full message not detected"); - } - - System.arraycopy(eng.getRecoveredMessage(), 0, recovered, 0, recovered.length); - - eng.init(false, pubParameters); - - if (!isSameAs(sig4, 0, data)) - { - fail("failed ISO9796-2 generation Test 4"); - } - - eng.update(msg4[0]); - eng.update(msg4, 1, msg4.length - 1); - - if (!eng.verifySignature(sig4)) - { - fail("failed ISO9796-2 verify Test 4"); - } - - if (eng.hasFullMessage()) - { - eng = new ISO9796d2Signer(rsa, new RIPEMD128Digest()); - - eng.init(false, pubParameters); - - if (!eng.verifySignature(sig4)) - { - fail("failed ISO9796-2 verify and recover Test 4"); - } - - if (!isSameAs(eng.getRecoveredMessage(), 0, msg4)) - { - fail("failed ISO9796-2 recovered message Test 4"); - } - - // try update with recovered - eng.updateWithRecoveredMessage(sig4); - - if (!isSameAs(eng.getRecoveredMessage(), 0, msg4)) - { - fail("failed ISO9796-2 updateWithRecovered recovered message Test 4"); - } - - if (!eng.verifySignature(sig4)) - { - fail("failed ISO9796-2 updateWithRecovered verify and recover Test 4"); - } - - if (!isSameAs(eng.getRecoveredMessage(), 0, msg4)) - { - fail("failed ISO9796-2 updateWithRecovered recovered verify message Test 4"); - } - - if (!isSameAs(eng.getRecoveredMessage(), 0, recovered)) - { - fail("failed ISO9796-2 updateWithRecovered recovered verify message Test 4 generate check"); - } - - // should fail - eng.updateWithRecoveredMessage(sig4); - - eng.update(msg4, 0, msg4.length); - - if (eng.verifySignature(sig4)) - { - fail("failed ISO9796-2 updateWithRecovered verify and recover Test 4"); - } - } - else - { - fail("full message flag false - Test 4"); - } - } - - public void doTest5() - throws Exception - { - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod3, pub3); - RSAKeyParameters privParameters = new RSAKeyParameters(true, mod3, pri3); - RSAEngine rsa = new RSAEngine(); - byte[] data; - - // - // ISO 9796-2 - Signing - // - ISO9796d2Signer eng = new ISO9796d2Signer(rsa, new RIPEMD160Digest(), true); - - eng.init(true, privParameters); - - eng.update(msg5[0]); - eng.update(msg5, 1, msg5.length - 1); - - data = eng.generateSignature(); - - byte[] recovered = new byte[eng.getRecoveredMessage().length]; - - System.arraycopy(eng.getRecoveredMessage(), 0, recovered, 0, recovered.length); - - eng.init(false, pubParameters); - - if (!isSameAs(sig5, 0, data)) - { - fail("failed ISO9796-2 generation Test 5"); - } - - eng.update(msg5[0]); - eng.update(msg5, 1, msg5.length - 1); - - if (!eng.verifySignature(sig5)) - { - fail("failed ISO9796-2 verify Test 5"); - } - - if (eng.hasFullMessage()) - { - fail("fullMessage true - Test 5"); - } - - if (!startsWith(msg5, eng.getRecoveredMessage())) - { - fail("failed ISO9796-2 partial recovered message Test 5"); - } - - int length = eng.getRecoveredMessage().length; - - if (length >= msg5.length) - { - fail("Test 5 recovered message too long"); - } - - eng = new ISO9796d2Signer(rsa, new RIPEMD160Digest(), true); - - eng.init(false, pubParameters); - - eng.updateWithRecoveredMessage(sig5); - - if (!startsWith(msg5, eng.getRecoveredMessage())) - { - fail("failed ISO9796-2 updateWithRecovered partial recovered message Test 5"); - } - - if (!isSameAs(recovered, 0, eng.getRecoveredMessage())) - { - fail("failed ISO9796-2 updateWithRecovered partial recovered message Test 5 recovery check"); - } - - if (eng.hasFullMessage()) - { - fail("fullMessage updateWithRecovered true - Test 5"); - } - - for (int i = length; i != msg5.length; i++) - { - eng.update(msg5[i]); - } - - if (!eng.verifySignature(sig5)) - { - fail("failed ISO9796-2 verify Test 5"); - } - - if (eng.hasFullMessage()) - { - fail("fullMessage updateWithRecovered true - Test 5"); - } - - // should fail - eng.updateWithRecoveredMessage(sig5); - - eng.update(msg5, 0, msg5.length); - - if (eng.verifySignature(sig5)) - { - fail("failed ISO9796-2 updateWithRecovered verify fail Test 5"); - } - } - - // - // against a zero length string - // - - public void doTest6() - throws Exception - { - byte[] salt = Hex.decode("61DF870C4890FE85D6E3DD87C3DCE3723F91DB49"); - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod6, pub6); - RSAKeyParameters privParameters = new RSAKeyParameters(true, mod6, pri6); - ParametersWithSalt sigParameters = new ParametersWithSalt(privParameters, salt); - RSAEngine rsa = new RSAEngine(); - byte[] data; - - // - // ISO 9796-2 - PSS Signing - // - ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa, new RIPEMD160Digest(), 20, true); - - eng.init(true, sigParameters); - - data = eng.generateSignature(); - - if (eng.getRecoveredMessage().length != 0) - { - fail("failed zero check"); - } - - eng.init(false, pubParameters); - - if (!isSameAs(sig6, 1, data)) - { - fail("failed ISO9796-2 generation Test 6"); - } - - if (!eng.verifySignature(data)) - { - fail("failed ISO9796-2 verify Test 6"); - } - } - - public void doTest7() - throws Exception - { - byte[] salt = new byte[0]; - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod6, pub6); - RSAKeyParameters privParameters = new RSAKeyParameters(true, mod6, pri6); - ParametersWithSalt sigParameters = new ParametersWithSalt(privParameters, salt); - RSAEngine rsa = new RSAEngine(); - byte[] data; - - // - // ISO 9796-2 - PSS Signing - // - ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa, new SHA1Digest(), 0, false); - - eng.init(true, sigParameters); - - eng.update(msg7[0]); - eng.update(msg7, 1, msg7.length - 1); - - data = eng.generateSignature(); - - if (!eng.hasFullMessage()) - { - fail("full message not detected"); - } - - byte[] recovered = new byte[eng.getRecoveredMessage().length]; - - System.arraycopy(eng.getRecoveredMessage(), 0, recovered, 0, recovered.length); - - eng.init(false, pubParameters); - - if (!isSameAs(sig7, 0, data)) - { - fail("failed ISO9796-2 generation Test 7"); - } - - eng.update(msg7[0]); - eng.update(msg7, 1, msg7.length - 1); - - if (!eng.verifySignature(sig7)) - { - fail("failed ISO9796-2 verify Test 7"); - } - - if (!eng.hasFullMessage()) - { - fail("full message not detected"); - } - - if (!isSameAs(msg7, 0, eng.getRecoveredMessage())) - { - fail("failed ISO9796-2 recovery Test 7"); - } - - if (!isSameAs(recovered, 0, eng.getRecoveredMessage())) - { - fail("failed ISO9796-2 recovery Test 7 recover"); - } - } - - public void doTest8() - throws Exception - { - byte[] salt = Hex.decode("78E293203CBA1B7F92F05F4D171FF8CA3E738FF8"); - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod6, pub6); - RSAKeyParameters privParameters = new RSAKeyParameters(true, mod6, pri6); - ParametersWithSalt sigParameters = new ParametersWithSalt(privParameters, salt); - RSAEngine rsa = new RSAEngine(); - byte[] data; - - // - // ISO 9796-2 - PSS Signing - // - ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa, new RIPEMD160Digest(), 20, false); - - eng.init(true, sigParameters); - - eng.update(msg8[0]); - eng.update(msg8, 1, msg8.length - 1); - - data = eng.generateSignature(); - - eng.init(false, pubParameters); - - if (!isSameAs(sig8, 0, data)) - { - fail("failed ISO9796-2 generation Test 8"); - } - - eng.update(msg8[0]); - eng.update(msg8, 1, msg8.length - 1); - - if (!eng.verifySignature(sig8)) - { - fail("failed ISO9796-2 verify Test 8"); - } - } - - public void doTest9() - throws Exception - { - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod6, pub6); - RSAKeyParameters privParameters = new RSAKeyParameters(true, mod6, pri6); - RSAEngine rsa = new RSAEngine(); - byte[] data; - - // - // ISO 9796-2 - PSS Signing - // - ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa, new RIPEMD160Digest(), 0, true); - - eng.init(true, privParameters); - - eng.update(msg9[0]); - eng.update(msg9, 1, msg9.length - 1); - - data = eng.generateSignature(); - - byte[] recovered = new byte[eng.getRecoveredMessage().length]; - - System.arraycopy(eng.getRecoveredMessage(), 0, recovered, 0, recovered.length); - - eng.init(false, pubParameters); - - if (!isSameAs(sig9, 0, data)) - { - fail("failed ISO9796-2 generation Test 9"); - } - - eng.update(msg9[0]); - eng.update(msg9, 1, msg9.length - 1); - - if (!eng.verifySignature(sig9)) - { - fail("failed ISO9796-2 verify Test 9"); - } - - if (!isSameAs(recovered, 0, eng.getRecoveredMessage())) - { - fail("failed ISO9796-2 recovery Test 7 recover"); - } - } - - public void doTest10() - throws Exception - { - BigInteger mod = new BigInteger("B3ABE6D91A4020920F8B3847764ECB34C4EB64151A96FDE7B614DC986C810FF2FD73575BDF8532C06004C8B4C8B64F700A50AEC68C0701ED10E8D211A4EA554D", 16); - BigInteger pubExp = new BigInteger("65537", 10); - BigInteger priExp = new BigInteger("AEE76AE4716F77C5782838F328327012C097BD67E5E892E75C1356E372CCF8EE1AA2D2CBDFB4DA19F703743F7C0BA42B2D69202BA7338C294D1F8B6A5771FF41", 16); - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod, pubExp); - RSAKeyParameters privParameters = new RSAKeyParameters(true, mod, priExp); - RSAEngine rsa = new RSAEngine(); - byte[] data; - - // - // ISO 9796-2 - PSS Signing - // - Digest dig = new SHA1Digest(); - ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa, dig, dig.getDigestSize()); - - // - // as the padding is random this test needs to repeat a few times to - // make sure - // - for (int i = 0; i != 500; i++) - { - eng.init(true, privParameters); - - eng.update(msg9[0]); - eng.update(msg9, 1, msg9.length - 1); - - data = eng.generateSignature(); - - eng.init(false, pubParameters); - - eng.update(msg9[0]); - eng.update(msg9, 1, msg9.length - 1); - - if (!eng.verifySignature(data)) - { - fail("failed ISO9796-2 verify Test 10"); - } - } - } - - public void doTest11() - throws Exception - { - BigInteger mod = new BigInteger("B3ABE6D91A4020920F8B3847764ECB34C4EB64151A96FDE7B614DC986C810FF2FD73575BDF8532C06004C8B4C8B64F700A50AEC68C0701ED10E8D211A4EA554D", 16); - BigInteger pubExp = new BigInteger("65537", 10); - BigInteger priExp = new BigInteger("AEE76AE4716F77C5782838F328327012C097BD67E5E892E75C1356E372CCF8EE1AA2D2CBDFB4DA19F703743F7C0BA42B2D69202BA7338C294D1F8B6A5771FF41", 16); - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod, pubExp); - RSAKeyParameters privParameters = new RSAKeyParameters(true, mod, priExp); - RSAEngine rsa = new RSAEngine(); - byte[] data; - byte[] m1 = {1, 2, 3, 4, 5, 6, 7, 8, 9}; - byte[] m2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; - byte[] m3 = {1, 2, 3, 4, 5, 6, 7, 8}; - - // - // ISO 9796-2 - PSS Signing - // - Digest dig = new SHA1Digest(); - ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa, dig, dig.getDigestSize()); - - // - // check message bounds - // - eng.init(true, privParameters); - - eng.update(m1, 0, m1.length); - - data = eng.generateSignature(); - - eng.init(false, pubParameters); - - eng.update(m2, 0, m2.length); - - if (eng.verifySignature(data)) - { - fail("failed ISO9796-2 m2 verify Test 11"); - } - - eng.init(false, pubParameters); - - eng.update(m3, 0, m3.length); - - if (eng.verifySignature(data)) - { - fail("failed ISO9796-2 m3 verify Test 11"); - } - - eng.init(false, pubParameters); - - eng.update(m1, 0, m1.length); - - if (!eng.verifySignature(data)) - { - fail("failed ISO9796-2 verify Test 11"); - } - } - - public void doTest12() - throws Exception - { - BigInteger mod = new BigInteger("B3ABE6D91A4020920F8B3847764ECB34C4EB64151A96FDE7B614DC986C810FF2FD73575BDF8532C06004C8B4C8B64F700A50AEC68C0701ED10E8D211A4EA554D", 16); - BigInteger pubExp = new BigInteger("65537", 10); - BigInteger priExp = new BigInteger("AEE76AE4716F77C5782838F328327012C097BD67E5E892E75C1356E372CCF8EE1AA2D2CBDFB4DA19F703743F7C0BA42B2D69202BA7338C294D1F8B6A5771FF41", 16); - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod, pubExp); - RSAKeyParameters privParameters = new RSAKeyParameters(true, mod, priExp); - RSAEngine rsa = new RSAEngine(); - byte[] data; - byte[] m1 = {1, 2, 3, 4, 5, 6, 7, 8, 9}; - byte[] m2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; - byte[] m3 = {1, 2, 3, 4, 5, 6, 7, 8}; - - // - // ISO 9796-2 - Signing - // - Digest dig = new SHA1Digest(); - ISO9796d2Signer eng = new ISO9796d2Signer(rsa, dig); - - // - // check message bounds - // - eng.init(true, privParameters); - - eng.update(m1, 0, m1.length); - - data = eng.generateSignature(); - - eng.init(false, pubParameters); - - eng.update(m2, 0, m2.length); - - if (eng.verifySignature(data)) - { - fail("failed ISO9796-2 m2 verify Test 12"); - } - - eng.init(false, pubParameters); - - eng.update(m3, 0, m3.length); - - if (eng.verifySignature(data)) - { - fail("failed ISO9796-2 m3 verify Test 12"); - } - - eng.init(false, pubParameters); - - eng.update(m1, 0, m1.length); - - if (!eng.verifySignature(data)) - { - fail("failed ISO9796-2 verify Test 12"); - } - } - - private void doTest13() - throws Exception - { - BigInteger modulus = new BigInteger(1, Hex.decode("CDCBDABBF93BE8E8294E32B055256BBD0397735189BF75816341BB0D488D05D627991221DF7D59835C76A4BB4808ADEEB779E7794504E956ADC2A661B46904CDC71337DD29DDDD454124EF79CFDD7BC2C21952573CEFBA485CC38C6BD2428809B5A31A898A6B5648CAA4ED678D9743B589134B7187478996300EDBA16271A861")); - BigInteger pubExp = new BigInteger(1, Hex.decode("010001")); - BigInteger privExp = new BigInteger(1, Hex.decode("4BA6432AD42C74AA5AFCB6DF60FD57846CBC909489994ABD9C59FE439CC6D23D6DE2F3EA65B8335E796FD7904CA37C248367997257AFBD82B26F1A30525C447A236C65E6ADE43ECAAF7283584B2570FA07B340D9C9380D88EAACFFAEEFE7F472DBC9735C3FF3A3211E8A6BBFD94456B6A33C17A2C4EC18CE6335150548ED126D")); - - RSAKeyParameters pubParams = new RSAKeyParameters(false, modulus, pubExp); - RSAKeyParameters privParams = new RSAKeyParameters(true, modulus, privExp); - - AsymmetricBlockCipher rsaEngine = new RSABlindedEngine(); - Digest digest = new SHA256Digest(); - - // set challenge to all zero's for verification - byte[] challenge = new byte[8]; - - // DOES NOT USE FINAL BOOLEAN TO INDICATE RECOVERY - ISO9796d2Signer signer = new ISO9796d2Signer(rsaEngine, digest, false); - - // sign - signer.init(true, privParams); - signer.update(challenge, 0, challenge.length); - - byte[] sig = signer.generateSignature(); - - // verify - signer.init(false, pubParams); - signer.update(challenge, 0, challenge.length); - - if (!signer.verifySignature(sig)) - { - fail("basic verification failed"); - } - - // === LETS ACTUALLY DO SOME RECOVERY, USING INPUT FROM INTERNAL AUTHENTICATE === - - signer.reset(); - - final String args0 = "482E20D1EDDED34359C38F5E7C01203F9D6B2641CDCA5C404D49ADAEDE034C7481D781D043722587761C90468DE69C6585A1E8B9C322F90E1B580EEDAB3F6007D0C366CF92B4DB8B41C8314929DCE2BE889C0129123484D2FD3D12763D2EBFD12AC8E51D7061AFCA1A53DEDEC7B9A617472A78C952CCC72467AE008E5F132994"; - - digest = new SHA1Digest(); - - signer = new ISO9796d2Signer(rsaEngine, digest, true); - - - signer.init(false, pubParams); - final byte[] signature = Hex.decode(args0); - signer.updateWithRecoveredMessage(signature); - signer.update(challenge, 0, challenge.length); - - if (!signer.verifySignature(signature)) - { - fail("recovered + challenge signature failed"); - } - - // === FINALLY, USING SHA-256 === - - signer.reset(); - - digest = new SHA256Digest(); - - // NOTE setting implit to false does not actually do anything for verification !!! - signer = new ISO9796d2Signer(rsaEngine, digest, false); - - - signer.init(true, privParams); - // generate NONCE of correct length using some inner knowledge - int nonceLength = modulus.bitLength() / 8 - 1 - digest.getDigestSize() - 2; - final byte[] nonce = new byte[nonceLength]; - SecureRandom rnd = new SecureRandom(); - - rnd.nextBytes(nonce); - - signer.update(nonce, 0, nonce.length); - signer.update(challenge, 0, challenge.length); - byte[] sig3 = signer.generateSignature(); - - signer.init(false, pubParams); - signer.updateWithRecoveredMessage(sig3); - signer.update(challenge, 0, challenge.length); - if (signer.verifySignature(sig3)) - { - if (signer.hasFullMessage()) - { - fail("signer indicates full message"); - } - byte[] recoverableMessage = signer.getRecoveredMessage(); - - // sanity check, normally the nonce is ignored in eMRTD specs (PKI Technical Report) - if (!Arrays.areEqual(nonce, recoverableMessage)) - { - fail("Nonce compare with recoverable part of message failed"); - } - } - else - { - fail("recoverable + nonce failed."); - } - } - - private static final byte[] longMessage = Base64.decode( - "VVNIKzErU0U2ODAxNTMyOTcxOSsyKzErNisyKzErMTo6OTk5OTk5OTk5OTk5" - + "OTo6OSsyOjo3Nzc3Nzc3Nzc3Nzc3Ojo5Kys1OjIwMTMwNDA1OjExMzUyMCdV" - + "U0ErMTo6OjE2OjEnVVNDKzRmYjk3YzFhNDI5ZGIyZDYnVVNBKzY6MTY6MTox" - + "MDoxKzE0OjIwNDgrMTI6/vn3S0h96eNhfmPN6OZUxXhd815h0tP871Hl+V1r" - + "fHHUXvrPXmjHV0vdb8fYY1zxwvnQUcFBWXT43PFi7Xbow0/9e9l6/mhs1UJq" - + "VPvp+ELbeXfn4Nj02ttk0e3H5Hfa69NYRuHv1WBO6lfizNnM9m9XYmh9TOrg" - + "f9rDRtd+ZNbf4lz9fPTt9OXyxOJWRPr/0FLzxUVsddplfHxM3ndETFD7ffjI" - + "/mhRYuL8WXZ733LeWFRCeOzKzmDz/HvT3GZx/XJMbFpqyOZjedzh6vZr1vrD" - + "615TQfN7wtJJ29bN2Hvzb2f1xGHaXl7af0/w9dpR2dr7/HzuZEJKYc7JSkv4" - + "/k37yERIbcrfbVTeVtR+dcVoeeRT41fmzMfzf8RnWOX4YMNifl0rMTM68EFA" - + "QSdCR00rMzgwKzk5OTk5OTk5J0RUTSsxMzc6MjAxMzA0MDU6MTAyJ0ZUWCtB" - + "QUkrKytJTlZPSUNFIFRFU1QnUkZGK09OOjEyMzQ1NidSRkYrRFE6MjIyMjIy" - + "MjIyJ0RUTSsxNzE6MjAxMzA0MDE6MTAyJ05BRCtTVSs5OTk5OTk5OTk5OTk5" - + "Ojo5KytURVNUIFNVUFBMSUVSOjpUcmFzZSByZWdpc3RlciBYWFhYWFhYK1Rl" - + "c3QgYWRkcmVzcyBzdXBwbGllcitDaXR5KysxMjM0NStERSdSRkYrVkE6QTEy" - + "MzQ1Njc4J05BRCtTQ08rOTk5OTk5OTk5OTk5OTo6OSsrVEVTVCBTVVBQTElF" - + "Ujo6VHJhc2UgcmVnaXN0ZXIgWFhYWFhYWCtUZXN0IGFkZHJlc3Mgc3VwcGxp" - + "ZXIrQ2l0eSsrMTIzNDUrREUnUkZGK1ZBOkExMjM0NTY3OCdOQUQrQlkrODg4" - + "ODg4ODg4ODg4ODo6OSdOQUQrSVYrNzc3Nzc3Nzc3Nzc3Nzo6OSsrVEVTVCBC" - + "VVlFUitUZXN0IGFkZHJlc3MgYnV5ZXIrQ2l0eTIrKzU0MzIxK0RFJ1JGRitW" - + "QTpKODc2NTQzMjEnTkFEK0JDTys3Nzc3Nzc3Nzc3Nzc3Ojo5KytURVNUIEJV" - + "WUVSK1Rlc3QgYWRkcmVzcyBidXllcitDaXR5MisrNTQzMjErREUnUkZGK1ZB" - + "Oko4NzY1NDMyMSdOQUQrRFArODg4ODg4ODg4ODg4ODo6OSdOQUQrUFIrNzc3" - + "Nzc3Nzc3Nzc3Nzo6OSdDVVgrMjpFVVI6NCdQQVQrMzUnRFRNKzEzOjIwMTMw" - + "NjI0OjEwMidMSU4rMSsrMTExMTExMTExMTExMTpFTidQSUErMStBQUFBQUFB" - + "OlNBJ0lNRCtGK00rOjo6UFJPRFVDVCBURVNUIDEnUVRZKzQ3OjEwLjAwMCdN" - + "T0ErNjY6Ny4wMCdQUkkrQUFCOjEuMDAnUFJJK0FBQTowLjcwJ1JGRitPTjox" - + "MjM0NTYnUkZGK0RROjIyMjIyMjIyMidUQVgrNytWQVQrKys6OjoyMS4wMDAn" - + "QUxDK0ErKysxK1REJ1BDRCsxOjMwLjAwMCdNT0ErMjA0OjMuMDAnTElOKzIr" - + "KzIyMjIyMjIyMjIyMjI6RU4nUElBKzErQkJCQkJCQjpTQSdJTUQrRitNKzo6" - + "OlBST0RVQ1QgVEVTVCAyJ1FUWSs0NzoyMC4wMDAnTU9BKzY2OjgwLjAwJ1BS" - + "SStBQUI6NS4wMCdQUkkrQUFBOjQuMDAnUkZGK09OOjEyMzQ1NidSRkYrRFE6" - + "MjIyMjIyMjIyJ1RBWCs3K1ZBVCsrKzo6OjIxLjAwMCdBTEMrQSsrKzErVEQn" - + "UENEKzE6MjAuMDAwJ01PQSsyMDQ6MjAuMDAnVU5TK1MnQ05UKzI6MidNT0Er" - + "Nzk6ODcuMDAnTU9BKzEzOToxMDUuMjcnTU9BKzEyNTo4Ny4wMCdNT0ErMjYw" - + "OjAuMDAnTU9BKzI1OTowLjAwJ01PQSsxNzY6MTguMjcnVEFYKzcrVkFUKysr" - + "Ojo6MjEuMDAwJ01PQSsxNzY6MTguMjcnTU9BKzEyNTo4Ny4wMCc="); - - private static final byte[] shortPartialSig = Base64.decode( - "sb8yyKk6HM1cJhICScMx7QRQunRyrZ1fbI42+T+TBGNjOknvzKuvG7aftGX7" - + "O/RXuYgk6LTxpXv7+O5noUhMBsR2PKaHveuylU1WSPmDxDCui3kp4frqVH0w" - + "8Vjpl5CsKqBsmKkbGCKE+smM0xFXhYxV8QUTB2XsWNCQiFiHPgwbpfWzZUNY" - + "QPWd0A99P64EuUIYz1tkkDnLFmwQ19/PJu1a8orIQInmkVYWSsBsZ/7Ks6lx" - + "nDHpAvgiRe+OXmJ/yuQy1O3FJYdyoqvjYRPBu3qYeBK9+9L3lExLilImH5aD" - + "nJznaXcO8QFOxVPbrF2s4GdPIMDonEyAHdrnzoghlg=="); - - private void doShortPartialTest() - throws Exception - { - byte[] recovered = Hex.decode("5553482b312b534536383031353332393731392b322b312b362b322b312b313a3a393939393939393939393939393a3a392b323a3a373737373737373737373737373a3a392b2b353a32303133303430353a313133"); - BigInteger exp = new BigInteger("10001", 16); - BigInteger mod = new BigInteger("b9b70b083da9e37e23cde8e654855db31e21d2d3fc11a5f91d2b3c311efa8f5e28c757dd6fc798631cb1b9d051c14119749cb122ad76e8c3fd7bd93abe282c026a14fba9f8023977a7a0d8b49a24d1ad87e4379a931846a1ef9520ea57e28c998cf65722683d0caaa0da8306973e2496a25cbd3cb4adb4b284e25604fabf12f385456c75da7c3c4cde37440cfb7db8c8fe6851e2bc59767b9f7218540238ac8acef3bc7bd3dc6671320c2c1a2ac8a6799ce1eaf62b9683ab1e1341b37b9249dbd6cd987b2f27b5c4619a1eda7f0fb0b59a519afbbc3cee640261cec90a4bb8fefbc844082dca9f549e56943e758579a453a357e6ccb37fc46718a5b8c3227e5d", 16); - - AsymmetricKeyParameter pubKey = new RSAKeyParameters(false, mod, exp); - - ISO9796d2PSSSigner pssSign = new ISO9796d2PSSSigner(new RSAEngine(), new SHA1Digest(), 20); - - pssSign.init(false, pubKey); - - pssSign.updateWithRecoveredMessage(shortPartialSig); - - pssSign.update(longMessage, pssSign.getRecoveredMessage().length, longMessage.length - pssSign.getRecoveredMessage().length); - - if (!pssSign.verifySignature(shortPartialSig)) - { - fail("short partial PSS sig verification failed."); - } - - byte[] mm = pssSign.getRecoveredMessage(); - - if (!Arrays.areEqual(recovered, mm)) - { - fail("short partial PSS recovery failed"); - } - } - - private void doFullMessageTest() - throws Exception - { - BigInteger modulus = new BigInteger(1, Hex.decode("CDCBDABBF93BE8E8294E32B055256BBD0397735189BF75816341BB0D488D05D627991221DF7D59835C76A4BB4808ADEEB779E7794504E956ADC2A661B46904CDC71337DD29DDDD454124EF79CFDD7BC2C21952573CEFBA485CC38C6BD2428809B5A31A898A6B5648CAA4ED678D9743B589134B7187478996300EDBA16271A861")); - BigInteger pubExp = new BigInteger(1, Hex.decode("010001")); - BigInteger privExp = new BigInteger(1, Hex.decode("4BA6432AD42C74AA5AFCB6DF60FD57846CBC909489994ABD9C59FE439CC6D23D6DE2F3EA65B8335E796FD7904CA37C248367997257AFBD82B26F1A30525C447A236C65E6ADE43ECAAF7283584B2570FA07B340D9C9380D88EAACFFAEEFE7F472DBC9735C3FF3A3211E8A6BBFD94456B6A33C17A2C4EC18CE6335150548ED126D")); - - RSAKeyParameters pubParams = new RSAKeyParameters(false, modulus, pubExp); - RSAKeyParameters privParams = new RSAKeyParameters(true, modulus, privExp); - - AsymmetricBlockCipher rsaEngine = new RSABlindedEngine(); - - // set challenge to all zero's for verification - byte[] challenge = new byte[8]; - - ISO9796d2PSSSigner pssSign = new ISO9796d2PSSSigner(new RSAEngine(), new SHA256Digest(), 20, true); - - pssSign.init(true, privParams); - - pssSign.update(challenge, 0, challenge.length); - - byte[] sig = pssSign.generateSignature(); - - pssSign.init(false, pubParams); - - pssSign.updateWithRecoveredMessage(sig); - - if (!pssSign.verifySignature(sig)) - { - fail("challenge PSS sig verification failed."); - } - - byte[] mm = pssSign.getRecoveredMessage(); - - if (!Arrays.areEqual(challenge, mm)) - { - fail("challenge partial PSS recovery failed"); - } - } - - public void performTest() - throws Exception - { - doTest1(); - doTest2(); - doTest3(); - doTest4(); - doTest5(); - doTest6(); - doTest7(); - doTest8(); - doTest9(); - doTest10(); - doTest11(); - doTest12(); - doTest13(); - doShortPartialTest(); - doFullMessageTest(); - } - - public static void main( - String[] args) - { - runTest(new ISO9796Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ISO9797Alg3MacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ISO9797Alg3MacTest.java deleted file mode 100644 index 87075b34d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ISO9797Alg3MacTest.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.macs.ISO9797Alg3Mac; -import com.fr.third.org.bouncycastle.crypto.paddings.ISO7816d4Padding; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class ISO9797Alg3MacTest - extends SimpleTest -{ - static byte[] keyBytes = Hex.decode("7CA110454A1A6E570131D9619DC1376E"); - - static byte[] input1 = "Hello World !!!!".getBytes(); - - static byte[] output1 = Hex.decode("F09B856213BAB83B"); - - public ISO9797Alg3MacTest() - { - } - - public void performTest() - { - KeyParameter key = new KeyParameter(keyBytes); - BlockCipher cipher = new DESEngine(); - Mac mac = new ISO9797Alg3Mac(cipher); - - // - // standard DAC - zero IV - // - mac.init(key); - - mac.update(input1, 0, input1.length); - - byte[] out = new byte[8]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output1)) - { - fail("Failed - expected " + new String(Hex.encode(output1)) + " got " + new String(Hex.encode(out))); - } - - // - // reset - // - mac.reset(); - - mac.init(key); - - for (int i = 0; i != input1.length / 2; i++) - { - mac.update(input1[i]); - } - - mac.update(input1, input1.length / 2, input1.length - (input1.length / 2)); - - mac.doFinal(out, 0); - - if (!areEqual(out, output1)) - { - fail("Reset failed - expected " + new String(Hex.encode(output1)) + " got " + new String(Hex.encode(out))); - } - - testMacWithIv(); - } - - private void testMacWithIv() - { - byte[] inputData = new byte[]{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8}; - byte[] key = new byte[]{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8}; - byte[] zeroIv = new byte[8]; - byte[] nonZeroIv = new byte[]{0x5, 0x6, 0x7, 0x8, 0x1, 0x2, 0x3, 0x4}; - - KeyParameter simpleParameter = new KeyParameter(key); - ParametersWithIV zeroIvParameter = new ParametersWithIV(new KeyParameter(key), zeroIv); - - ISO9797Alg3Mac mac1 = new ISO9797Alg3Mac(new DESEngine(), new ISO7816d4Padding()); - - // we calculate a reference MAC with a null IV - mac1.init(simpleParameter); - mac1.update(inputData, 0, inputData.length); - byte[] output1 = new byte[mac1.getMacSize()]; - mac1.doFinal(output1, 0); - - // we then check that passing a vector of 0s is the same as not using any IV - ISO9797Alg3Mac mac2 = new ISO9797Alg3Mac(new DESEngine(), new ISO7816d4Padding()); - mac2.init(zeroIvParameter); - mac2.update(inputData, 0, inputData.length); - byte[] output2 = new byte[mac2.getMacSize()]; - mac2.doFinal(output2, 0); - if (!Arrays.areEqual(output1, output2)) - { - fail("zero IV test failed"); - } - - // and then check that a non zero IV parameter produces a different results. - ParametersWithIV nonZeroIvParameter = new ParametersWithIV(new KeyParameter(key), nonZeroIv); - mac2 = new ISO9797Alg3Mac(new DESEngine(), new ISO7816d4Padding()); - mac2.init(nonZeroIvParameter); - mac2.update(inputData, 0, inputData.length); - output2 = new byte[mac2.getMacSize()]; - mac2.doFinal(output2, 0); - if (Arrays.areEqual(output1, output2)) - { - fail("non-zero IV test failed"); - } - } - - public String getName() - { - return "ISO9797Alg3Mac"; - } - - public static void main( - String[] args) - { - runTest(new ISO9797Alg3MacTest()); - } -} - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/IsoTrailerTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/IsoTrailerTest.java deleted file mode 100644 index f44d527e3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/IsoTrailerTest.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA512tDigest; -import com.fr.third.org.bouncycastle.crypto.engines.RSAEngine; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.signers.ISO9796d2PSSSigner; -import com.fr.third.org.bouncycastle.crypto.signers.ISO9796d2Signer; -import com.fr.third.org.bouncycastle.crypto.signers.X931Signer; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class IsoTrailerTest - extends SimpleTest -{ - private static final byte[] x931SigOld = Hex.decode("33156b44e30640d14940d5f4534de6a91c945fe8355b01f66a896c41c78482ba02457d079327bd7015a875c353c6a0db356d6c568edb07dbbdb0500705e3f8aff9269f8535c1ed27edb09a1c246a366c4f638fd224389bcaebeb2dedc400990b91cddfda4ee0abc67ae1e39b139183dd6193aee9aa3616285ba928af20f89d5c"); - private static final byte[] x931SigCorrect = Hex.decode("3ff8d8c371503a153bb99edb1064984680ef7f70f73d08d28205b8e1ae90d7a00d78d6f16994b872bf613aafb41dd7b60fc9e964d280bde07637ec278b9491ddeeecae53e2b55302801577b20cda4ef2d4a42868de579fa5a50f2f2feb50688d893d9210469bb47134475515a7745744ba99e23d4490400e7a734e00ef2c5476"); - - private static final byte[] iso9796d2Old = Hex.decode("07f7c6a8726aeed821ce7af09b5eb260ade66913c5548438f5f7a613f5e96e1638c36d22d968c24abfa7b5879cbdf55985e7928553fe33a9c7e53b85daab87cc661e33cc1290832c3cfda59256f9501657efead29ee45cc06df1e1c0f3e06110e46377c6ed5ec78327d1c7787af79287e50c810ed17a2b43c56d27ec695b4dbf"); - private static final byte[] iso9796d2Correct = Hex.decode("530c8949deb24d138b175db5be846481f8b22598fcc44476caf87fe4f5f8c9b71f9456791bf47aaafa20650fedc000251f4eee1bcaed57bd5d1b1e64b5d0e460df88e4a5266eb3969577d29a80d7d0038044247ae6fe7705f9d20d0ef42f525445de0560c9c3972c6443be779c762cfb08e403fc2f06bc8e2d7b8f3bf022160a"); - - private static final byte[] iso9796d2PSSOld = Hex.decode("274dbd6e3d93672ee5121022843e37f66b1ff12bb7f04cff059d76932ce9116e8b12efcd19d98a78f8c9d3f262fd3ce7c3bca0edc223f3af54e1401b37f807ef5b6d71591a22a40a34ce8abc10164138835bb63ac8eeb0223d1e1d8c5d18da2acac7f7061023597aa338c4af96bebe6c7935e0b5603cb87977b9e345f697ff98"); - private static final byte[] iso9796d2PSSCorrect = Hex.decode("3a5c1248652cd6fd4419064b894379ad48c8596a3a5a0bdf98b6d6a9d25f5df164591beddff9e2ae88100dd165053f0edd2e4154834ea7b7c1f56312c4fe23a5407cf73a2c4540c8c19e91187f709529ebb779db2f8fa39f6bef923c392abecf9e7596927a71f62990dafd8bf00d298863d07680e75b1bb9bb655ba25ff48d1e"); - - public String getName() - { - return "IsoTrailerTest"; - } - - private void x931Sha512_256Test() - { - BigInteger rsaPubMod = new BigInteger(Base64.decode("AIASoe2PQb1IP7bTyC9usjHP7FvnUMVpKW49iuFtrw/dMpYlsMMoIU2jupfifDpdFxIktSB4P+6Ymg5WjvHKTIrvQ7SR4zV4jaPTu56Ys0pZ9EDA6gb3HLjtU+8Bb1mfWM+yjKxcPDuFjwEtjGlPHg1Vq+CA9HNcMSKNn2+tW6qt")); - BigInteger rsaPubExp = new BigInteger(Base64.decode("EQ==")); - - RSAKeyParameters rsaPublic = new RSAKeyParameters(false, rsaPubMod, rsaPubExp); - - byte[] msg = new byte[] { 1, 6, 3, 32, 7, 43, 2, 5, 7, 78, 4, 23 }; - - X931Signer signer = new X931Signer(new RSAEngine(), new SHA512tDigest(256)); - signer.init(false, rsaPublic); - signer.update(msg, 0, msg.length); - if (!signer.verifySignature(x931SigCorrect)) - { - fail("X9.31 Signer failed."); - } - - signer.init(false, rsaPublic); - signer.update(msg, 0, msg.length); - if (!signer.verifySignature(x931SigOld)) - { - fail("X9.31 old Signer failed."); - } - } - - private void iso9796_2Sha512_256Test() - { - BigInteger rsaPubMod = new BigInteger(Base64.decode("AIASoe2PQb1IP7bTyC9usjHP7FvnUMVpKW49iuFtrw/dMpYlsMMoIU2jupfifDpdFxIktSB4P+6Ymg5WjvHKTIrvQ7SR4zV4jaPTu56Ys0pZ9EDA6gb3HLjtU+8Bb1mfWM+yjKxcPDuFjwEtjGlPHg1Vq+CA9HNcMSKNn2+tW6qt")); - BigInteger rsaPubExp = new BigInteger(Base64.decode("EQ==")); - - RSAKeyParameters rsaPublic = new RSAKeyParameters(false, rsaPubMod, rsaPubExp); - - byte[] msg = new byte[] { 1, 6, 3, 32, 7, 43, 2, 5, 7, 78, 4, 23 }; - - ISO9796d2Signer signer = new ISO9796d2Signer(new RSAEngine(), new SHA512tDigest(256)); - - signer.init(false, rsaPublic); - signer.update(msg, 0, msg.length); - if (!signer.verifySignature(iso9796d2Correct)) - { - fail("ISO9796-2 Signer failed."); - } - - signer.init(false, rsaPublic); - signer.update(msg, 0, msg.length); - if (!signer.verifySignature(iso9796d2Old)) - { - fail("ISO9796-2 old Signer failed."); - } - } - - private void iso9796_2PSSSha512_256Test() - { - BigInteger rsaPubMod = new BigInteger(Base64.decode("AIASoe2PQb1IP7bTyC9usjHP7FvnUMVpKW49iuFtrw/dMpYlsMMoIU2jupfifDpdFxIktSB4P+6Ymg5WjvHKTIrvQ7SR4zV4jaPTu56Ys0pZ9EDA6gb3HLjtU+8Bb1mfWM+yjKxcPDuFjwEtjGlPHg1Vq+CA9HNcMSKNn2+tW6qt")); - BigInteger rsaPubExp = new BigInteger(Base64.decode("EQ==")); - - RSAKeyParameters rsaPublic = new RSAKeyParameters(false, rsaPubMod, rsaPubExp); - - byte[] msg = new byte[] { 1, 6, 3, 32, 7, 43, 2, 5, 7, 78, 4, 23 }; - - ISO9796d2PSSSigner signer = new ISO9796d2PSSSigner(new RSAEngine(), new SHA512tDigest(256), 32); - - signer.init(false, rsaPublic); - signer.update(msg, 0, msg.length); - if (!signer.verifySignature(iso9796d2PSSCorrect)) - { - fail("ISO9796-2PSS Signer failed."); - } - - signer.init(false, rsaPublic); - signer.update(msg, 0, msg.length); - if (!signer.verifySignature(iso9796d2PSSOld)) - { - fail("ISO9796-2PSS old Signer failed."); - } - } - - public void performTest() - throws Exception - { - x931Sha512_256Test(); - iso9796_2Sha512_256Test(); - iso9796_2PSSSha512_256Test(); - } - - public static void main( - String[] args) - { - runTest(new IsoTrailerTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/JournalingSecureRandomTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/JournalingSecureRandomTest.java deleted file mode 100644 index b8ac8a926..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/JournalingSecureRandomTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.util.JournalingSecureRandom; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class JournalingSecureRandomTest - extends SimpleTest -{ - public String getName() - { - return "JournalingSecureRandom"; - } - - public void performTest() - throws Exception - { - SecureRandom rand = new SecureRandom(); - - JournalingSecureRandom jRandom1 = new JournalingSecureRandom(rand); - - byte[] base = new byte[1024]; - - jRandom1.nextBytes(base); - - byte[] transcript = jRandom1.getTranscript(); - - byte[] block = new byte[512]; - - JournalingSecureRandom jRandom2 = new JournalingSecureRandom(transcript, rand); - - jRandom2.nextBytes(block); - - areEqual(Arrays.copyOfRange(base, 0, 512), block); - - jRandom2.nextBytes(block); - - areEqual(Arrays.copyOfRange(base, 512, 1024), block); - - jRandom2.nextBytes(block); - - isTrue(!Arrays.areEqual(Arrays.copyOfRange(base, 0, 512), block)); - - } - - public static void main( - String[] args) - { - runTest(new JournalingSecureRandomTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDF1GeneratorTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDF1GeneratorTest.java deleted file mode 100644 index 272d8937e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDF1GeneratorTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.DerivationFunction; -import com.fr.third.org.bouncycastle.crypto.digests.ShortenedDigest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.generators.KDF1BytesGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ISO18033KDFParameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * KDF1 tests - vectors from ISO 18033. - */ -public class KDF1GeneratorTest - extends SimpleTest -{ - private byte[] seed1 = Hex.decode("d6e168c5f256a2dcff7ef12facd390f393c7a88d"); - private byte[] mask1 = Hex.decode( - "0742ba966813af75536bb6149cc44fc256fd6406df79665bc31dc5" - + "a62f70535e52c53015b9d37d412ff3c1193439599e1b628774c50d9c" - + "cb78d82c425e4521ee47b8c36a4bcffe8b8112a89312fc04420a39de" - + "99223890e74ce10378bc515a212b97b8a6447ba6a8870278"); - - private byte[] seed2 = Hex.decode( - "032e45326fa859a72ec235acff929b15d1372e30b207255f0611b8f785d7643741" - + "52e0ac009e509e7ba30cd2f1778e113b64e135cf4e2292c75efe5288edfda4"); - private byte[] mask2 = Hex.decode( - "5f8de105b5e96b2e490ddecbd147dd1def7e3b8e0e6a26eb7b956ccb8b3bdc1ca9" - + "75bc57c3989e8fbad31a224655d800c46954840ff32052cdf0d640562bdfadfa263c" - + "fccf3c52b29f2af4a1869959bc77f854cf15bd7a25192985a842dbff8e13efee5b7e" - + "7e55bbe4d389647c686a9a9ab3fb889b2d7767d3837eea4e0a2f04"); - - private byte[] seed3 = seed2; - private byte[] mask3= Hex.decode( - "09e2decf2a6e1666c2f6071ff4298305e2643fd510a2403db42a8743cb989de86e" - + "668d168cbe604611ac179f819a3d18412e9eb45668f2923c087c12fee0c5a0d2a8aa" - + "70185401fbbd99379ec76c663e875a60b4aacb1319fa11c3365a8b79a44669f26fb5" - + "55c80391847b05eca1cb5cf8c2d531448d33fbaca19f6410ee1fcb"); - - - public KDF1GeneratorTest() - { - } - - public void performTest() - { - checkMask(1, new KDF1BytesGenerator(new ShortenedDigest(new SHA256Digest(), 20)), seed1, mask1); - checkMask(2, new KDF1BytesGenerator(new SHA1Digest()), seed2, mask2); - checkMask(3, new KDF1BytesGenerator(new ShortenedDigest(new SHA256Digest(), 20)), seed3, mask3); - - try - { - new KDF1BytesGenerator(new SHA1Digest()).generateBytes(new byte[10], 0, 20); - - fail("short input array not caught"); - } - catch (DataLengthException e) - { - // expected - } - } - - private void checkMask( - int count, - DerivationFunction kdf, - byte[] seed, - byte[] result) - { - byte[] data = new byte[result.length]; - - kdf.init(new ISO18033KDFParameters(seed)); - - kdf.generateBytes(data, 0, data.length); - - if (!areEqual(result, data)) - { - fail("KDF1 failed generator test " + count); - } - } - - public String getName() - { - return "KDF1"; - } - - public static void main( - String[] args) - { - runTest(new KDF1GeneratorTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDF2GeneratorTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDF2GeneratorTest.java deleted file mode 100644 index 1950066cb..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDF2GeneratorTest.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.DerivationFunction; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.digests.ShortenedDigest; -import com.fr.third.org.bouncycastle.crypto.generators.KDF2BytesGenerator; -import com.fr.third.org.bouncycastle.crypto.params.KDFParameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * KDF2 tests - vectors from ISO 18033. - */ -public class KDF2GeneratorTest - extends SimpleTest -{ - private byte[] seed1 = Hex.decode("d6e168c5f256a2dcff7ef12facd390f393c7a88d"); - private byte[] mask1 = Hex.decode( - "df79665bc31dc5a62f70535e52c53015b9d37d412ff3c119343959" - + "9e1b628774c50d9ccb78d82c425e4521ee47b8c36a4bcffe8b8112a8" - + "9312fc04420a39de99223890e74ce10378bc515a212b97b8a6447ba6" - + "a8870278f0262727ca041fa1aa9f7b5d1cf7f308232fe861"); - - private byte[] seed2 = Hex.decode( - "032e45326fa859a72ec235acff929b15d1372e30b207255f0611b8f785d7643741" - + "52e0ac009e509e7ba30cd2f1778e113b64e135cf4e2292c75efe5288edfda4"); - private byte[] mask2 = Hex.decode( - "10a2403db42a8743cb989de86e668d168cbe604611ac179f819a3d18412e9eb456" - + "68f2923c087c12fee0c5a0d2a8aa70185401fbbd99379ec76c663e875a60b4aacb13" - + "19fa11c3365a8b79a44669f26fb555c80391847b05eca1cb5cf8c2d531448d33fbac" - + "a19f6410ee1fcb260892670e0814c348664f6a7248aaf998a3acc6"); - private byte[] adjustedMask2 = Hex.decode( - "10a2403db42a8743cb989de86e668d168cbe6046e23ff26f741e87949a3bba1311ac1" - + "79f819a3d18412e9eb45668f2923c087c1299005f8d5fd42ca257bc93e8fee0c5a0d2" - + "a8aa70185401fbbd99379ec76c663e9a29d0b70f3fe261a59cdc24875a60b4aacb131" - + "9fa11c3365a8b79a44669f26fba933d012db213d7e3b16349"); - - private byte[] sha1Mask = Hex.decode( - "0e6a26eb7b956ccb8b3bdc1ca975bc57c3989e8fbad31a224655d800c46954840ff32" - + "052cdf0d640562bdfadfa263cfccf3c52b29f2af4a1869959bc77f854cf15bd7a2519" - + "2985a842dbff8e13efee5b7e7e55bbe4d389647c686a9a9ab3fb889b2d7767d3837ee" - + "a4e0a2f04b53ca8f50fb31225c1be2d0126c8c7a4753b0807"); - - private byte[] seed3 = Hex.decode("CA7C0F8C3FFA87A96E1B74AC8E6AF594347BB40A"); - private byte[] mask3 = Hex.decode("744AB703F5BC082E59185F6D049D2D367DB245C2"); - - private byte[] seed4 = Hex.decode("0499B502FC8B5BAFB0F4047E731D1F9FD8CD0D8881"); - private byte[] mask4 = Hex.decode("03C62280C894E103C680B13CD4B4AE740A5EF0C72547292F82DC6B1777F47D63BA9D1EA732DBF386"); - - public KDF2GeneratorTest() - { - } - - public void performTest() - { - checkMask(1, new KDF2BytesGenerator(new ShortenedDigest(new SHA256Digest(), 20)), seed1, mask1); - checkMask(2, new KDF2BytesGenerator(new ShortenedDigest(new SHA256Digest(), 20)), seed2, mask2); - checkMask(3, new KDF2BytesGenerator(new SHA256Digest()), seed2, adjustedMask2); - checkMask(4, new KDF2BytesGenerator(new SHA1Digest()), seed2, sha1Mask); - checkMask(5, new KDF2BytesGenerator(new SHA1Digest()), seed3, mask3); - checkMask(6, new KDF2BytesGenerator(new SHA1Digest()), seed4, mask4); - - try - { - new KDF2BytesGenerator(new SHA1Digest()).generateBytes(new byte[10], 0, 20); - - fail("short input array not caught"); - } - catch (DataLengthException e) - { - // expected - } - } - - private void checkMask( - int count, - DerivationFunction kdf, - byte[] seed, - byte[] result) - { - byte[] data = new byte[result.length]; - - kdf.init(new KDFParameters(seed, new byte[0])); - - kdf.generateBytes(data, 0, data.length); - - if (!areEqual(result, data)) - { - fail("KDF2 failed generator test " + count); - } - } - - public String getName() - { - return "KDF2"; - } - - public static void main( - String[] args) - { - runTest(new KDF2GeneratorTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDFCounterGeneratorTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDFCounterGeneratorTest.java deleted file mode 100644 index b4b2beb1d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDFCounterGeneratorTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.charset.Charset; - -import com.fr.third.org.bouncycastle.crypto.test.cavp.CAVPReader; -import com.fr.third.org.bouncycastle.crypto.test.cavp.KDFCounterTests; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class KDFCounterGeneratorTest - extends SimpleTest -{ - - private static void testCounter() - { - - CAVPReader cavpReader = new CAVPReader(new KDFCounterTests()); - - final InputStream stream = CAVPReader.class.getResourceAsStream("KDFCTR_gen.rsp"); - final Reader reader = new InputStreamReader(stream, Charset.forName("UTF-8")); - cavpReader.setInput("KDFCounter", reader); - - try - { - cavpReader.readAll(); - } - catch (IOException e) - { - throw new IllegalStateException("Something is rotten in the state of Denmark", e); - } - } - - public String getName() - { - return this.getClass().getSimpleName(); - } - - public void performTest() - throws Exception - { - testCounter(); - } - - public static void main(String[] args) - { - runTest(new KDFCounterGeneratorTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDFDoublePipelineIteratorGeneratorTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDFDoublePipelineIteratorGeneratorTest.java deleted file mode 100644 index 305012106..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDFDoublePipelineIteratorGeneratorTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.charset.Charset; - -import com.fr.third.org.bouncycastle.crypto.test.cavp.CAVPReader; -import com.fr.third.org.bouncycastle.crypto.test.cavp.KDFDoublePipelineCounterTests; -import com.fr.third.org.bouncycastle.crypto.test.cavp.KDFDoublePipelineIterationNoCounterTests; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class KDFDoublePipelineIteratorGeneratorTest - extends SimpleTest -{ - public String getName() - { - return this.getClass().getSimpleName(); - } - - public void performTest() - throws Exception - { - testDoublePipelineIterationCounter(); - testDoublePipelineIterationNoCounter(); - } - - private static void testDoublePipelineIterationCounter() - { - - CAVPReader cavpReader = new CAVPReader(new KDFDoublePipelineCounterTests()); - - final InputStream stream = CAVPReader.class.getResourceAsStream("KDFDblPipelineCounter_gen.rsp"); - final Reader reader = new InputStreamReader(stream, Charset.forName("UTF-8")); - cavpReader.setInput("KDFDoublePipelineIterationCounter", reader); - - try - { - cavpReader.readAll(); - } - catch (IOException e) - { - throw new IllegalStateException("Something is rotten in the state of Denmark", e); - } - } - - private static void testDoublePipelineIterationNoCounter() - { - - CAVPReader cavpReader = new CAVPReader(new KDFDoublePipelineIterationNoCounterTests()); - - final InputStream stream = CAVPReader.class.getResourceAsStream("KDFDblPipelineNoCounter_gen.rsp"); - final Reader reader = new InputStreamReader(stream, Charset.forName("UTF-8")); - cavpReader.setInput("KDFDblPipelineIterationNoCounter", reader); - - try - { - cavpReader.readAll(); - } - catch (IOException e) - { - throw new IllegalStateException("Something is rotten in the state of Denmark", e); - } - } - - public static void main(String[] args) - { - runTest(new KDFDoublePipelineIteratorGeneratorTest()); - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDFFeedbackGeneratorTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDFFeedbackGeneratorTest.java deleted file mode 100644 index 3e672c23f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KDFFeedbackGeneratorTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.charset.Charset; - -import com.fr.third.org.bouncycastle.crypto.test.cavp.CAVPReader; -import com.fr.third.org.bouncycastle.crypto.test.cavp.KDFFeedbackCounterTests; -import com.fr.third.org.bouncycastle.crypto.test.cavp.KDFFeedbackNoCounterTests; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class KDFFeedbackGeneratorTest - extends SimpleTest -{ - public String getName() - { - return this.getClass().getSimpleName(); - } - - public void performTest() - throws Exception - { - testFeedbackCounter(); - testFeedbackNoCounter(); - } - - private static void testFeedbackCounter() - { - - CAVPReader cavpReader = new CAVPReader(new KDFFeedbackCounterTests()); - - final InputStream stream = CAVPReader.class.getResourceAsStream("KDFFeedbackCounter_gen.rsp"); - final Reader reader = new InputStreamReader(stream, Charset.forName("UTF-8")); - cavpReader.setInput("KDFFeedbackCounter", reader); - - try - { - cavpReader.readAll(); - } - catch (IOException e) - { - throw new IllegalStateException("Something is rotten in the state of Denmark ", e); - } - } - - private static void testFeedbackNoCounter() - { - - CAVPReader cavpReader = new CAVPReader(new KDFFeedbackNoCounterTests()); - - final InputStream stream = CAVPReader.class.getResourceAsStream("KDFFeedbackNoCounter_gen.rsp"); - final Reader reader = new InputStreamReader(stream, Charset.forName("UTF-8")); - cavpReader.setInput("KDFFeedbackNoCounter", reader); - - try - { - cavpReader.readAll(); - } - catch (IOException e) - { - throw new IllegalStateException("Something is rotten in the state of Denmark", e); - } - } - - public static void main(String[] args) - { - runTest(new KDFDoublePipelineIteratorGeneratorTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KeccakDigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KeccakDigestTest.java deleted file mode 100644 index 3b80189f8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/KeccakDigestTest.java +++ /dev/null @@ -1,364 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.digests.KeccakDigest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Keccak Digest Test - */ -public class KeccakDigestTest - extends SimpleTest -{ - final static String[] messages = { - "", - "54686520717569636b2062726f776e20666f78206a756d7073206f76657220746865206c617a7920646f67", - "54686520717569636b2062726f776e20666f78206a756d7073206f76657220746865206c617a7920646f672e" - }; - - final static String[] digests288 = { // the default settings - "6753e3380c09e385d0339eb6b050a68f66cfd60a73476e6fd6adeb72f5edd7c6f04a5d01", // message[0] - "0bbe6afae0d7e89054085c1cc47b1689772c89a41796891e197d1ca1b76f288154933ded", // message[1] - "82558a209b960ddeb531e6dcb281885b2400ca160472462486e79f071e88a3330a8a303d", // message[2] - "94049e1ad7ef5d5b0df2b880489e7ab09ec937c3bfc1b04470e503e1ac7b1133c18f86da", // 64k a-test - "a9cb5a75b5b81b7528301e72553ed6770214fa963956e790528afe420de33c074e6f4220", // random alphabet test - "eadaf5ba2ad6a2f6f338fce0e1efdad2a61bb38f6be6068b01093977acf99e97a5d5827c" // extremely long data test - }; - - final static String[] digests224 = { - "f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd", - "310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe", - "c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab", - "f621e11c142fbf35fa8c22841c3a812ba1e0151be4f38d80b9f1ff53", - "68b5fc8c87193155bba68a2485377e809ee4f81a85ef023b9e64add0", - "c42e4aee858e1a8ad2976896b9d23dd187f64436ee15969afdbc68c5" - }; - - final static String[] digests256 = { - "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", - "4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15", - "578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d", - "0047a916daa1f92130d870b542e22d3108444f5a7e4429f05762fb647e6ed9ed", - "db368762253ede6d4f1db87e0b799b96e554eae005747a2ea687456ca8bcbd03", - "5f313c39963dcf792b5470d4ade9f3a356a3e4021748690a958372e2b06f82a4" - }; - - final static String[] digests384 = { - "2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff", - "283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3", - "9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b", - "c704cfe7a1a53208ca9526cd24251e0acdc252ecd978eee05acd16425cfb404ea81f5a9e2e5e97784d63ee6a0618a398", - "d4fe8586fd8f858dd2e4dee0bafc19b4c12b4e2a856054abc4b14927354931675cdcaf942267f204ea706c19f7beefc4", - "9b7168b4494a80a86408e6b9dc4e5a1837c85dd8ff452ed410f2832959c08c8c0d040a892eb9a755776372d4a8732315" - }; - - final static String[] digests512 = { - "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", - "d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609", - "ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760", - "34341ead153aa1d1fdcf6cf624c2b4f6894b6fd16dc38bd4ec971ac0385ad54fafcb2e0ed86a1e509456f4246fdcb02c3172824cd649d9ad54c51f7fb49ea67c", - "dc44d4f4d36b07ab5fc04016cbe53548e5a7778671c58a43cb379fd00c06719b8073141fc22191ffc3db5f8b8983ae8341fa37f18c1c969664393aa5ceade64e", - "3e122edaf37398231cfaca4c7c216c9d66d5b899ec1d7ac617c40c7261906a45fc01617a021e5da3bd8d4182695b5cb785a28237cbb167590e34718e56d8aab8" - }; - - // test vectors from http://www.di-mgt.com.au/hmac_sha3_testvectors.html - final static byte[][] macKeys = - { - Hex.decode("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"), - Hex.decode("4a656665"), - Hex.decode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), - Hex.decode("0102030405060708090a0b0c0d0e0f10111213141516171819"), - Hex.decode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaa"), - Hex.decode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaa"), - Hex.decode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") - }; - - final static String[] macData = - { - "4869205468657265", - "7768617420646f2079612077616e7420666f72206e6f7468696e673f", - "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" + - "dddddddddddddddddddddddddddddddddddd", - "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + - "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd", - "54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a" + - "65204b6579202d2048617368204b6579204669727374", - "5468697320697320612074657374207573696e672061206c6172676572207468" + - "616e20626c6f636b2d73697a65206b657920616e642061206c61726765722074" + - "68616e20626c6f636b2d73697a6520646174612e20546865206b6579206e6565" + - "647320746f20626520686173686564206265666f7265206265696e6720757365" + - "642062792074686520484d414320616c676f726974686d2e", - "5468697320697320612074657374207573696e672061206c6172676572207468" + - "616e20626c6f636b2d73697a65206b657920616e642061206c61726765722074" + - "68616e20626c6f636b2d73697a6520646174612e20546865206b6579206e6565" + - "647320746f20626520686173686564206265666f7265206265696e6720757365\n" + - "642062792074686520484d414320616c676f726974686d2e" - }; - - final static String[] mac224 = - { - "b73d595a2ba9af815e9f2b4e53e78581ebd34a80b3bbaac4e702c4cc", - "e824fec96c074f22f99235bb942da1982664ab692ca8501053cbd414", - "770df38c99d6e2bacd68056dcfe07d4c89ae20b2686a6185e1faa449", - "305a8f2dfb94bad28861a03cbc4d590febe775c58cb4961c28428a0b", - "e7a52dfa45f95a217c100066b239aa8ad519be9b35d667268b1b57ff", - "ba13009405a929f398b348885caa5419191bb948ada32194afc84104", - "92649468be236c3c72c189909c063b13f994be05749dc91310db639e" - }; - - final static String[] mac256 = - { - "9663d10c73ee294054dc9faf95647cb99731d12210ff7075fb3d3395abfb9821", - "aa9aed448c7abc8b5e326ffa6a01cdedf7b4b831881468c044ba8dd4566369a1", - "95f43e50f8df80a21977d51a8db3ba572dcd71db24687e6f86f47c1139b26260", - "6331ba9b4af5804a68725b3663eb74814494b63c6093e35fb320a85d507936fd", - "b4d0cdee7ec2ba81a88b86918958312300a15622377929a054a9ce3ae1fac2b6", - "1fdc8cb4e27d07c10d897dec39c217792a6e64fa9c63a77ce42ad106ef284e02", - "fdaa10a0299aecff9bb411cf2d7748a4022e4a26be3fb5b11b33d8c2b7ef5484" - }; - - final static String[] mac384 = - { - "892dfdf5d51e4679bf320cd16d4c9dc6f749744608e003add7fba894acff87361efa4e5799be06b6461f43b60ae97048", - "5af5c9a77a23a6a93d80649e562ab77f4f3552e3c5caffd93bdf8b3cfc6920e3023fc26775d9df1f3c94613146ad2c9d", - "4243c29f2201992ff96441e3b91ff81d8c601d706fbc83252684a4bc51101ca9b2c06ddd03677303c502ac5331752a3c", - "b730724d3d4090cda1be799f63acbbe389fef7792fc18676fa5453aab398664650ed029c3498bbe8056f06c658e1e693", - "d62482ef601d7847439b55236e9679388ffcd53c62cd126f39be6ea63de762e26cd5974cb9a8de401b786b5555040f6f", - "4860ea191ac34994cf88957afe5a836ef36e4cc1a66d75bf77defb7576122d75f60660e4cf731c6effac06402787e2b9", - "fe9357e3cfa538eb0373a2ce8f1e26ad6590afdaf266f1300522e8896d27e73f654d0631c8fa598d4bb82af6b744f4f5" - }; - - final static String[] mac512 = - { - "8852c63be8cfc21541a4ee5e5a9a852fc2f7a9adec2ff3a13718ab4ed81aaea0b87b7eb397323548e261a64e7fc75198f6663a11b22cd957f7c8ec858a1c7755", - "c2962e5bbe1238007852f79d814dbbecd4682e6f097d37a363587c03bfa2eb0859d8d9c701e04cececfd3dd7bfd438f20b8b648e01bf8c11d26824b96cebbdcb", - "eb0ed9580e0ec11fc66cbb646b1be904eaff6da4556d9334f65ee4b2c85739157bae9027c51505e49d1bb81cfa55e6822db55262d5a252c088a29a5e95b84a66", - "b46193bb59f4f696bf702597616da91e2a4558a593f4b015e69141ba81e1e50ea580834c2b87f87baa25a3a03bfc9bb389847f2dc820beae69d30c4bb75369cb", - "d05888a6ebf8460423ea7bc85ea4ffda847b32df32291d2ce115fd187707325c7ce4f71880d91008084ce24a38795d20e6a28328a0f0712dc38253370da3ebb5", - "2c6b9748d35c4c8db0b4407dd2ed2381f133bdbd1dfaa69e30051eb6badfcca64299b88ae05fdbd3dd3dd7fe627e42e39e48b0fe8c7f1e85f2dbd52c2d753572", - "6adc502f14e27812402fc81a807b28bf8a53c87bea7a1df6256bf66f5de1a4cb741407ad15ab8abc136846057f881969fbb159c321c904bfb557b77afb7778c8" - }; - - final static KeyParameter truncKey = new KeyParameter(Hex.decode("0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c")); - final static byte[] truncData = Hex.decode("546573742057697468205472756e636174696f6e"); - - final static byte[] trunc224 = Hex.decode("f52bbcfd654264e7133085c5e69b72c3"); - final static byte[] trunc256 = Hex.decode("745e7e687f8335280d54202ef13cecc6"); - final static byte[] trunc384 = Hex.decode("fa9aea2bc1e181e47cbb8c3df243814d"); - final static byte[] trunc512 = Hex.decode("04c929fead434bba190dacfa554ce3f5"); - - final static byte[] xtremeData = Hex.decode("61626364656667686263646566676869636465666768696a6465666768696a6b65666768696a6b6c666768696a6b6c6d6768696a6b6c6d6e68696a6b6c6d6e6f"); - - KeccakDigestTest() - { - } - - public String getName() - { - return "Keccak"; - } - - private void testDigest(Digest digest, String[] expected) - { - byte[] hash = new byte[digest.getDigestSize()]; - - for (int i = 0; i != messages.length; i++) - { - if (messages.length != 0) - { - byte[] data = Hex.decode(messages[i]); - - digest.update(data, 0, data.length); - } - - digest.doFinal(hash, 0); - - if (!Arrays.areEqual(Hex.decode(expected[i]), hash)) - { - fail("Keccak mismatch on " + digest.getAlgorithmName() + " index " + i); - } - } - - byte[] k64 = new byte[1024 * 64]; - - for (int i = 0; i != k64.length; i++) - { - k64[i] = (byte)'a'; - } - - digest.update(k64, 0, k64.length); - - digest.doFinal(hash, 0); - - if (!Arrays.areEqual(Hex.decode(expected[messages.length]), hash)) - { - fail("Keccak mismatch on " + digest.getAlgorithmName() + " 64k a"); - } - - for (int i = 0; i != k64.length; i++) - { - digest.update((byte)'a'); - } - - digest.doFinal(hash, 0); - - if (!Arrays.areEqual(Hex.decode(expected[messages.length]), hash)) - { - fail("Keccak mismatch on " + digest.getAlgorithmName() + " 64k a single"); - } - - - for (int i = 0; i != k64.length; i++) - { - k64[i] = (byte)('a' + (i % 26)); - } - - digest.update(k64, 0, k64.length); - - digest.doFinal(hash, 0); - - if (!Arrays.areEqual(Hex.decode(expected[messages.length + 1]), hash)) - { - fail("Keccak mismatch on " + digest.getAlgorithmName() + " 64k alpha"); - } - - for (int i = 0; i != 64; i++) - { - digest.update(k64[i * 1024]); - digest.update(k64, i * 1024 + 1, 1023); - } - - digest.doFinal(hash, 0); - - if (!Arrays.areEqual(Hex.decode(expected[messages.length + 1]), hash)) - { - fail("Keccak mismatch on " + digest.getAlgorithmName() + " 64k chunked alpha"); - } - - testDigestDoFinal(digest); - - // - // extremely long data test - // -// long start = System.currentTimeMillis(); -// System.out.println("Starting very long"); -// for (int i = 0; i != 16384; i++) -// { -// for (int j = 0; j != 1024; j++) -// { -// digest.update(xtremeData, 0, xtremeData.length); -// } -// } -// -// digest.doFinal(hash, 0); -// -// if (!Arrays.areEqual(Hex.decode(expected[messages.length + 2]), hash)) -// { -// fail("Keccak mismatch on " + digest.getAlgorithmName() + " extreme data test"); -// } -// System.out.println("Done " + (System.currentTimeMillis() - start)); - } - - private void testDigestDoFinal(Digest digest) - { - byte[] hash = new byte[digest.getDigestSize()]; - digest.doFinal(hash, 0); - - for (int i = 0; i <= digest.getDigestSize(); ++i) - { - byte[] cmp = new byte[2 * digest.getDigestSize()]; - System.arraycopy(hash, 0, cmp, i, hash.length); - - byte[] buf = new byte[2 * digest.getDigestSize()]; - digest.doFinal(buf, i); - - if (!Arrays.areEqual(cmp, buf)) - { - fail("Keccak offset doFinal on " + digest.getAlgorithmName()); - } - } - } - - private void testMac(Digest digest, byte[][] keys, String[] data, String[] expected, byte[] truncExpected) - { - Mac mac = new HMac(digest); - - for (int i = 0; i != keys.length; i++) - { - mac.init(new KeyParameter(keys[i])); - - byte[] mData = Hex.decode(data[i]); - - mac.update(mData, 0, mData.length); - - byte[] macV = new byte[mac.getMacSize()]; - - mac.doFinal(macV, 0); - - if (!Arrays.areEqual(Hex.decode(expected[i]), macV)) - { - fail("Keccak HMAC mismatch on " + digest.getAlgorithmName()); - } - } - - mac = new HMac(digest); - - mac.init(truncKey); - - mac.update(truncData, 0, truncData.length); - - byte[] macV = new byte[mac.getMacSize()]; - - mac.doFinal(macV, 0); - - for (int i = 0; i != truncExpected.length; i++) - { - if (macV[i] != truncExpected[i]) - { - fail("mismatch on truncated HMAC for " + digest.getAlgorithmName()); - } - } - } - - public void performTest() throws Exception - { - testDigest(new KeccakDigest(), digests288); - testDigest(new KeccakDigest(224), digests224); - testDigest(new KeccakDigest(256), digests256); - testDigest(new KeccakDigest(384), digests384); - testDigest(new KeccakDigest(512), digests512); - - testMac(new KeccakDigest(224), macKeys, macData, mac224, trunc224); - testMac(new KeccakDigest(256), macKeys, macData, mac256, trunc256); - testMac(new KeccakDigest(384), macKeys, macData, mac384, trunc384); - testMac(new KeccakDigest(512), macKeys, macData, mac512, trunc512); - } - - protected Digest cloneDigest(Digest digest) - { - return new KeccakDigest((KeccakDigest)digest); - } - - public static void main( - String[] args) - { - runTest(new KeccakDigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MD2DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MD2DigestTest.java deleted file mode 100644 index 43307c38c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MD2DigestTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.MD2Digest; - -/** - * standard vector test for MD2 - * from RFC1319 by B.Kaliski of RSA Laboratories April 1992 - * - */ -public class MD2DigestTest - extends DigestTest -{ - static final String messages[] = - { - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890" - }; - - static final String digests[] = - { - "8350e5a3e24c153df2275c9f80692773", - "32ec01ec4a6dac72c0ab96fb34c0b5d1", - "da853b0d3f88d99b30283a69e6ded6bb", - "ab4f496bfb2a530b219ff33031fe06b0", - "4e8ddff3650292ab5a4108c3aa47940b", - "da33def2a42df13975352846c30338cd", - "d5976f79d83d3a0dc9806c3c66f3efd8" - }; - - MD2DigestTest() - { - super(new MD2Digest(), messages, digests); - } - - protected Digest cloneDigest( - Digest digest) - { - return new MD2Digest((MD2Digest)digest); - } - - public static void main( - String[] args) - { - runTest(new MD2DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MD4DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MD4DigestTest.java deleted file mode 100644 index c9f6678a5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MD4DigestTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.MD4Digest; - -/** - * standard vector test for MD4 from RFC 1320. - */ -public class MD4DigestTest - extends DigestTest -{ - static private String[] messages = - { - "", - "a", - "abc", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890" - }; - - static private String[] digests = - { - "31d6cfe0d16ae931b73c59d7e0c089c0", - "bde52cb31de33e46245e05fbdbd6fb24", - "a448017aaf21d8525fc10ae87aa6729d", - "e33b4ddc9c38f2199c3e7b164fcc0536" - }; - - MD4DigestTest() - { - super(new MD4Digest(), messages, digests); - } - - protected Digest cloneDigest(Digest digest) - { - return new MD4Digest((MD4Digest)digest); - } - - public static void main( - String[] args) - { - runTest(new MD4DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MD5DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MD5DigestTest.java deleted file mode 100644 index a393cb56b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MD5DigestTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.MD5Digest; - -/** - * standard vector test for MD5 from "Handbook of Applied Cryptography", page 345. - */ -public class MD5DigestTest - extends DigestTest -{ - static final String[] messages = - { - "", - "a", - "abc", - "abcdefghijklmnopqrstuvwxyz" - }; - - static final String[] digests = - { - "d41d8cd98f00b204e9800998ecf8427e", - "0cc175b9c0f1b6a831c399e269772661", - "900150983cd24fb0d6963f7d28e17f72", - "c3fcd3d76192e4007dfb496cca67e13b" - }; - - MD5DigestTest() - { - super(new MD5Digest(), messages, digests); - } - - protected Digest cloneDigest(Digest digest) - { - return new MD5Digest((MD5Digest)digest); - } - - protected Digest cloneDigest(byte[] encodedState) - { - return new MD5Digest(encodedState); - } - - public static void main( - String[] args) - { - runTest(new MD5DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MD5HMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MD5HMacTest.java deleted file mode 100644 index 5e467965e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MD5HMacTest.java +++ /dev/null @@ -1,98 +0,0 @@ - -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.MD5Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * MD5 HMac Test, test vectors from RFC 2202 - */ -public class MD5HMacTest - extends SimpleTest -{ - final static String[] keys = { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4a656665", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "0102030405060708090a0b0c0d0e0f10111213141516171819", - "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - }; - - final static String[] digests = { - "9294727a3638bb1c13f48ef8158bfc9d", - "750c783e6ab0b503eaa86e310a5db738", - "56be34521d144c88dbb8c733f0e8b3f6", - "697eaf0aca3a3aea3a75164746ffaa79", - "56461ef2342edc00f9bab995690efd4c", - "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd", - "6f630fad67cda0ee1fb1f562db3aa53e" - }; - - final static String[] messages = { - "Hi There", - "what do ya want for nothing?", - "0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", - "0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd", - "Test With Truncation", - "Test Using Larger Than Block-Size Key - Hash Key First", - "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data" - }; - - public String getName() - { - return "MD5HMac"; - } - - public void performTest() - { - HMac hmac = new HMac(new MD5Digest()); - byte[] resBuf = new byte[hmac.getMacSize()]; - - for (int i = 0; i < messages.length; i++) - { - byte[] m = messages[i].getBytes(); - if (messages[i].startsWith("0x")) - { - m = Hex.decode(messages[i].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[i]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!areEqual(resBuf, Hex.decode(digests[i]))) - { - fail("Vector " + i + " failed"); - } - } - - // test reset - int vector = 0; // vector used for test - byte[] m = messages[vector].getBytes(); - if (messages[vector].startsWith("0x")) - { - m = Hex.decode(messages[vector].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[vector]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - hmac.reset(); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!areEqual(resBuf, Hex.decode(digests[vector]))) - { - fail("Reset with vector " + vector + " failed"); - } - } - - public static void main( - String[] args) - { - runTest(new MD5HMacTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MGF1GeneratorTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MGF1GeneratorTest.java deleted file mode 100644 index a8fcc035b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MGF1GeneratorTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.DerivationFunction; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.digests.ShortenedDigest; -import com.fr.third.org.bouncycastle.crypto.generators.MGF1BytesGenerator; -import com.fr.third.org.bouncycastle.crypto.params.MGFParameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * MGF1 tests - vectors from ISO 18033 for KDF1 (equivalent). - */ -public class MGF1GeneratorTest - extends SimpleTest -{ - private byte[] seed1 = Hex.decode("d6e168c5f256a2dcff7ef12facd390f393c7a88d"); - private byte[] mask1 = Hex.decode( - "0742ba966813af75536bb6149cc44fc256fd6406df79665bc31dc5" - + "a62f70535e52c53015b9d37d412ff3c1193439599e1b628774c50d9c" - + "cb78d82c425e4521ee47b8c36a4bcffe8b8112a89312fc04420a39de" - + "99223890e74ce10378bc515a212b97b8a6447ba6a8870278"); - - private byte[] seed2 = Hex.decode( - "032e45326fa859a72ec235acff929b15d1372e30b207255f0611b8f785d7643741" - + "52e0ac009e509e7ba30cd2f1778e113b64e135cf4e2292c75efe5288edfda4"); - private byte[] mask2 = Hex.decode( - "5f8de105b5e96b2e490ddecbd147dd1def7e3b8e0e6a26eb7b956ccb8b3bdc1ca9" - + "75bc57c3989e8fbad31a224655d800c46954840ff32052cdf0d640562bdfadfa263c" - + "fccf3c52b29f2af4a1869959bc77f854cf15bd7a25192985a842dbff8e13efee5b7e" - + "7e55bbe4d389647c686a9a9ab3fb889b2d7767d3837eea4e0a2f04"); - - private byte[] seed3 = seed2; - private byte[] mask3= Hex.decode( - "09e2decf2a6e1666c2f6071ff4298305e2643fd510a2403db42a8743cb989de86e" - + "668d168cbe604611ac179f819a3d18412e9eb45668f2923c087c12fee0c5a0d2a8aa" - + "70185401fbbd99379ec76c663e875a60b4aacb1319fa11c3365a8b79a44669f26fb5" - + "55c80391847b05eca1cb5cf8c2d531448d33fbaca19f6410ee1fcb"); - - public void performTest() - { - checkMask(1, new MGF1BytesGenerator(new ShortenedDigest(new SHA256Digest(), 20)), seed1, mask1); - checkMask(2, new MGF1BytesGenerator(new SHA1Digest()), seed2, mask2); - checkMask(3, new MGF1BytesGenerator(new ShortenedDigest(new SHA256Digest(), 20)), seed3, mask3); - - try - { - new MGF1BytesGenerator(new SHA1Digest()).generateBytes(new byte[10], 0, 20); - - fail("short input array not caught"); - } - catch (DataLengthException e) - { - // expected - } - } - - private void checkMask( - int count, - DerivationFunction kdf, - byte[] seed, - byte[] result) - { - byte[] data = new byte[result.length]; - - kdf.init(new MGFParameters(seed)); - - kdf.generateBytes(data, 0, data.length); - - if (!areEqual(result, data)) - { - fail("MGF1 failed generator test " + count); - } - } - - public String getName() - { - return "MGF1"; - } - - public static void main( - String[] args) - { - runTest(new MGF1GeneratorTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MacTest.java deleted file mode 100644 index 36dd993a8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/MacTest.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.macs.CBCBlockCipherMac; -import com.fr.third.org.bouncycastle.crypto.macs.CFBBlockCipherMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.crypto.paddings.PKCS7Padding; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * MAC tester - vectors from - * FIP 81 and - * FIP 113. - */ -public class MacTest - extends SimpleTest -{ - static byte[] keyBytes = Hex.decode("0123456789abcdef"); - static byte[] ivBytes = Hex.decode("1234567890abcdef"); - - static byte[] input1 = Hex.decode("37363534333231204e6f77206973207468652074696d6520666f7220"); - - static byte[] output1 = Hex.decode("f1d30f68"); - static byte[] output2 = Hex.decode("58d2e77e"); - static byte[] output3 = Hex.decode("cd647403"); - - // - // these aren't NIST vectors, just for regression testing. - // - static byte[] input2 = Hex.decode("3736353433323120"); - - static byte[] output4 = Hex.decode("3af549c9"); - static byte[] output5 = Hex.decode("188fbdd5"); - static byte[] output6 = Hex.decode("7045eecd"); - - public MacTest() - { - } - - public void performTest() - { - KeyParameter key = new KeyParameter(keyBytes); - BlockCipher cipher = new DESEngine(); - Mac mac = new CBCBlockCipherMac(cipher); - - // - // standard DAC - zero IV - // - mac.init(key); - - mac.update(input1, 0, input1.length); - - byte[] out = new byte[4]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output1)) - { - fail("Failed - expected " + new String(Hex.encode(output1)) + " got " + new String(Hex.encode(out))); - } - - // - // mac with IV. - // - ParametersWithIV param = new ParametersWithIV(key, ivBytes); - - mac.init(param); - - mac.update(input1, 0, input1.length); - - out = new byte[4]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output2)) - { - fail("Failed - expected " + new String(Hex.encode(output2)) + " got " + new String(Hex.encode(out))); - } - - // - // CFB mac with IV - 8 bit CFB mode - // - param = new ParametersWithIV(key, ivBytes); - - mac = new CFBBlockCipherMac(cipher); - - mac.init(param); - - mac.update(input1, 0, input1.length); - - out = new byte[4]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output3)) - { - fail("Failed - expected " + new String(Hex.encode(output3)) + " got " + new String(Hex.encode(out))); - } - - // - // word aligned data - zero IV - // - mac.init(key); - - mac.update(input2, 0, input2.length); - - out = new byte[4]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output4)) - { - fail("Failed - expected " + new String(Hex.encode(output4)) + " got " + new String(Hex.encode(out))); - } - - // - // word aligned data - zero IV - CBC padding - // - mac = new CBCBlockCipherMac(cipher, new PKCS7Padding()); - - mac.init(key); - - mac.update(input2, 0, input2.length); - - out = new byte[4]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output5)) - { - fail("Failed - expected " + new String(Hex.encode(output5)) + " got " + new String(Hex.encode(out))); - } - - // - // non-word aligned data - zero IV - CBC padding - // - mac.reset(); - - mac.update(input1, 0, input1.length); - - out = new byte[4]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output6)) - { - fail("Failed - expected " + new String(Hex.encode(output6)) + " got " + new String(Hex.encode(out))); - } - - // - // non-word aligned data - zero IV - CBC padding - // - mac.init(key); - - mac.update(input1, 0, input1.length); - - out = new byte[4]; - - mac.doFinal(out, 0); - - if (!areEqual(out, output6)) - { - fail("Failed - expected " + new String(Hex.encode(output6)) + " got " + new String(Hex.encode(out))); - } - } - - public String getName() - { - return "Mac"; - } - - public static void main( - String[] args) - { - runTest(new MacTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ModeTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ModeTest.java deleted file mode 100644 index 2ec69a058..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ModeTest.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.modes.CFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.OFBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * CFB/OFB Mode test of IV padding. - */ -public class ModeTest - implements Test -{ - public ModeTest() - { - } - - private boolean isEqualTo( - byte[] a, - byte[] b) - { - for (int i = 0; i != a.length; i++) - { - if (a[i] != b[i]) - { - return false; - } - } - - return true; - } - - public TestResult perform() - { - KeyParameter key = new KeyParameter(Hex.decode("0011223344556677")); - byte[] input = Hex.decode("4e6f7720"); - byte[] out1 = new byte[4]; - byte[] out2 = new byte[4]; - - - BlockCipher ofb = new OFBBlockCipher(new DESEngine(), 32); - - ofb.init(true, new ParametersWithIV(key, Hex.decode("1122334455667788"))); - - ofb.processBlock(input, 0, out1, 0); - - ofb.init(false, new ParametersWithIV(key, Hex.decode("1122334455667788"))); - ofb.processBlock(out1, 0, out2, 0); - - if (!isEqualTo(out2, input)) - { - return new SimpleTestResult(false, getName() + ": test 1 - in != out"); - } - - ofb.init(true, new ParametersWithIV(key, Hex.decode("11223344"))); - - ofb.processBlock(input, 0, out1, 0); - - ofb.init(false, new ParametersWithIV(key, Hex.decode("0000000011223344"))); - ofb.processBlock(out1, 0, out2, 0); - - if (!isEqualTo(out2, input)) - { - return new SimpleTestResult(false, getName() + ": test 2 - in != out"); - } - - BlockCipher cfb = new CFBBlockCipher(new DESEngine(), 32); - - cfb.init(true, new ParametersWithIV(key, Hex.decode("1122334455667788"))); - - cfb.processBlock(input, 0, out1, 0); - - cfb.init(false, new ParametersWithIV(key, Hex.decode("1122334455667788"))); - cfb.processBlock(out1, 0, out2, 0); - - if (!isEqualTo(out2, input)) - { - return new SimpleTestResult(false, getName() + ": test 3 - in != out"); - } - - cfb.init(true, new ParametersWithIV(key, Hex.decode("11223344"))); - - cfb.processBlock(input, 0, out1, 0); - - cfb.init(false, new ParametersWithIV(key, Hex.decode("0000000011223344"))); - cfb.processBlock(out1, 0, out2, 0); - - if (!isEqualTo(out2, input)) - { - return new SimpleTestResult(false, getName() + ": test 4 - in != out"); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public String getName() - { - return "ModeTest"; - } - - public static void main( - String[] args) - { - ModeTest test = new ModeTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NISTCTSTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NISTCTSTest.java deleted file mode 100644 index f0bb0948b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NISTCTSTest.java +++ /dev/null @@ -1,170 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.BufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.modes.NISTCTSBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * CTS tester - */ -public class NISTCTSTest - extends SimpleTest -{ - private static KeyParameter key = new KeyParameter(Hex.decode("000102030405060708090a0b0c0d0e0f")); - private static byte[] iv = Hex.decode("101112131415161718191a1b1c1d1e1f"); - - private static byte[] singleBlock = Hex.decode("4920616d206f6e6520626c6f636b2e2e"); - private static byte[] singleOut = Hex.decode("8aad2098847a2d74ac87de22745d2537"); - - private static byte[] twoBlock = Hex.decode("4920616d206174206c656173742074776f20626c6f636b73206c6f6e672e2e2e"); - - private static byte[] cs1TwoBlockOut = Hex.decode("3f07fd5816c3b96349eb9f6a074909d67237eb8aa9a7467b8a388c61d0e8f35a"); - private static byte[] cs2TwoBlockOut = Hex.decode("3f07fd5816c3b96349eb9f6a074909d67237eb8aa9a7467b8a388c61d0e8f35a"); - private static byte[] cs3TwoBlockOut = Hex.decode("7237eb8aa9a7467b8a388c61d0e8f35a3f07fd5816c3b96349eb9f6a074909d6"); - - private static byte[] notQuiteTwo = Hex.decode("4920616d206e6f742071756974652074776f2e2e2e"); - - private static byte[] cs1NotQuiteTwoBlockOut = Hex.decode("22ecf2ac77f098097ca69b72e3a46e9ca21bb5ebbc"); - private static byte[] cs2NotQuiteTwoBlockOut = Hex.decode("f098097ca69b72e3a46e9ca21bb5ebbc22ecf2ac77"); - private static byte[] cs3NotQuiteTwoBlockOut = Hex.decode("f098097ca69b72e3a46e9ca21bb5ebbc22ecf2ac77"); - - static byte[] in1 = Hex.decode("4e6f7720697320746865207420"); - static byte[] in2 = Hex.decode("000102030405060708090a0b0c0d0e0fff0102030405060708090a0b0c0d0e0f0aaa"); - static byte[] out1 = Hex.decode("9952f131588465033fa40e8a98"); - static byte[] out2 = Hex.decode("358f84d01eb42988dc34efb994"); - static byte[] out3 = Hex.decode("170171cfad3f04530c509b0c1f0be0aefbd45a8e3755a873bff5ea198504b71683c6"); - - private void testCTS( - int id, - int type, - BlockCipher cipher, - CipherParameters params, - byte[] input, - byte[] output) - throws Exception - { - byte[] out = new byte[input.length]; - BufferedBlockCipher engine = new NISTCTSBlockCipher(type, cipher); - - engine.init(true, params); - - int len = engine.processBytes(input, 0, input.length, out, 0); - - engine.doFinal(out, len); - - if (!areEqual(output, out)) - { - fail(id + " failed encryption expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - - engine.init(false, params); - - len = engine.processBytes(output, 0, output.length, out, 0); - - engine.doFinal(out, len); - - if (!areEqual(input, out)) - { - fail(id + " failed decryption expected " + new String(Hex.encode(input)) + " got " + new String(Hex.encode(out))); - } - } - - private void testExceptions() throws InvalidCipherTextException - { - BufferedBlockCipher engine = new NISTCTSBlockCipher(NISTCTSBlockCipher.CS1, new AESEngine()); - CipherParameters params = new KeyParameter(new byte[engine.getBlockSize()]); - engine.init(true, params); - - byte[] out = new byte[engine.getOutputSize(engine.getBlockSize())]; - - engine.processBytes(new byte[engine.getBlockSize() - 1], 0, engine.getBlockSize() - 1, out, 0); - try - { - engine.doFinal(out, 0); - fail("Expected CTS encrypt error on < 1 block input"); - } catch(DataLengthException e) - { - // Expected - } - - engine.init(true, params); - engine.processBytes(new byte[engine.getBlockSize()], 0, engine.getBlockSize(), out, 0); - try - { - engine.doFinal(out, 0); - } catch(DataLengthException e) - { - fail("Unexpected CTS encrypt error on == 1 block input"); - } - - engine.init(false, params); - engine.processBytes(new byte[engine.getBlockSize() - 1], 0, engine.getBlockSize() - 1, out, 0); - try - { - engine.doFinal(out, 0); - fail("Expected CTS decrypt error on < 1 block input"); - } catch(DataLengthException e) - { - // Expected - } - - engine.init(false, params); - engine.processBytes(new byte[engine.getBlockSize()], 0, engine.getBlockSize(), out, 0); - try - { - engine.doFinal(out, 0); - } catch(DataLengthException e) - { - fail("Unexpected CTS decrypt error on == 1 block input"); - } - - } - - public String getName() - { - return "NISTCTS"; - } - - public void performTest() - throws Exception - { - testCTS(1, NISTCTSBlockCipher.CS1, new AESEngine(), new ParametersWithIV(key, iv), singleBlock, singleOut); - testCTS(2, NISTCTSBlockCipher.CS2, new AESEngine(), new ParametersWithIV(key, iv), singleBlock, singleOut); - testCTS(3, NISTCTSBlockCipher.CS3, new AESEngine(), new ParametersWithIV(key, iv), singleBlock, singleOut); - - testCTS(4, NISTCTSBlockCipher.CS1, new AESEngine(), new ParametersWithIV(key, iv), twoBlock, cs1TwoBlockOut); - testCTS(5, NISTCTSBlockCipher.CS2, new AESEngine(), new ParametersWithIV(key, iv), twoBlock, cs2TwoBlockOut); - testCTS(6, NISTCTSBlockCipher.CS3, new AESEngine(), new ParametersWithIV(key, iv), twoBlock, cs3TwoBlockOut); - - testCTS(7, NISTCTSBlockCipher.CS1, new AESEngine(), new ParametersWithIV(key, iv), notQuiteTwo, cs1NotQuiteTwoBlockOut); - testCTS(8, NISTCTSBlockCipher.CS2, new AESEngine(), new ParametersWithIV(key, iv), notQuiteTwo, cs2NotQuiteTwoBlockOut); - testCTS(9, NISTCTSBlockCipher.CS3, new AESEngine(), new ParametersWithIV(key, iv), notQuiteTwo, cs3NotQuiteTwoBlockOut); - - byte[] aes128b = Hex.decode("aafd12f659cae63489b479e5076ddec2f06cb58faafd12f6"); - byte[] aesIn1b = Hex.decode("000102030405060708090a0b0c0d0e0fff0102030405060708090a0b0c0d0e0f"); - byte[] aesOut1b = Hex.decode("6db2f802d99e1ef0a5940f306079e083cf87f4d8bb9d1abb36cdd9f44ead7d04"); - - testCTS(10, NISTCTSBlockCipher.CS3, new AESEngine(), new ParametersWithIV(new KeyParameter(aes128b), Hex.decode("aafd12f659cae63489b479e5076ddec2")), aesIn1b, aesOut1b); - - byte[] aes128c = Hex.decode("aafd12f659cae63489b479e5076ddec2"); - byte[] aesOut1c = Hex.decode("0af33c005a337af55a5149effc5108eaa1ea87de8a8556e8786b8f230da64e56"); - - testCTS(11, NISTCTSBlockCipher.CS3, new AESEngine(), new ParametersWithIV(new KeyParameter(aes128c), Hex.decode("aafd12f659cae63489b479e5076ddec2")), aesIn1b, aesOut1c); - - testExceptions(); - } - - public static void main( - String[] args) - { - runTest(new NISTCTSTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NaccacheSternTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NaccacheSternTest.java deleted file mode 100644 index 5199a79cb..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NaccacheSternTest.java +++ /dev/null @@ -1,354 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.engines.NaccacheSternEngine; -import com.fr.third.org.bouncycastle.crypto.generators.NaccacheSternKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.NaccacheSternKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.NaccacheSternKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.NaccacheSternPrivateKeyParameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test case for NaccacheStern cipher. For details on this cipher, please see - * - * http://www.gemplus.com/smart/rd/publications/pdf/NS98pkcs.pdf - * - * Performs the following tests: - *- *
- */ -public class NaccacheSternTest - extends SimpleTest -{ - static final boolean debug = false; - - static final NaccacheSternEngine cryptEng = new NaccacheSternEngine(); - - static final NaccacheSternEngine decryptEng = new NaccacheSternEngine(); - - // Values from NaccacheStern paper - static final BigInteger a = BigInteger.valueOf(101); - - static final BigInteger u1 = BigInteger.valueOf(3); - - static final BigInteger u2 = BigInteger.valueOf(5); - - static final BigInteger u3 = BigInteger.valueOf(7); - - static final BigInteger b = BigInteger.valueOf(191); - - static final BigInteger v1 = BigInteger.valueOf(11); - - static final BigInteger v2 = BigInteger.valueOf(13); - - static final BigInteger v3 = BigInteger.valueOf(17); - - static final BigInteger ONE = BigInteger.valueOf(1); - - static final BigInteger TWO = BigInteger.valueOf(2); - - static final BigInteger sigma = u1.multiply(u2).multiply(u3).multiply(v1) - .multiply(v2).multiply(v3); - - static final BigInteger p = TWO.multiply(a).multiply(u1).multiply(u2) - .multiply(u3).add(ONE); - - static final BigInteger q = TWO.multiply(b).multiply(v1).multiply(v2) - .multiply(v3).add(ONE); - - static final BigInteger n = p.multiply(q); - - static final BigInteger phi_n = p.subtract(ONE).multiply(q.subtract(ONE)); - - static final BigInteger g = BigInteger.valueOf(131); - - static final Vector smallPrimes = new Vector(); - - // static final BigInteger paperTest = BigInteger.valueOf(202); - - static final String input = "4e6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"; - - static final BigInteger paperTest = BigInteger.valueOf(202); - - // - // to check that we handling byte extension by big number correctly. - // - static final String edgeInput = "ff6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"; - - static - { - cryptEng.setDebug(debug); - decryptEng.setDebug(debug); - - // First the Parameters from the NaccacheStern Paper - // (see http://www.gemplus.com/smart/rd/publications/pdf/NS98pkcs.pdf ) - - smallPrimes.addElement(u1); - smallPrimes.addElement(u2); - smallPrimes.addElement(u3); - smallPrimes.addElement(v1); - smallPrimes.addElement(v2); - smallPrimes.addElement(v3); - } - - public String getName() - { - return "NaccacheStern"; - } - - public void performTest() - { - // Test with given key from NaccacheSternPaper (totally insecure) - - NaccacheSternKeyParameters pubParameters = new NaccacheSternKeyParameters(false, g, n, sigma.bitLength()); - - NaccacheSternPrivateKeyParameters privParameters = new NaccacheSternPrivateKeyParameters(g, n, sigma.bitLength(), smallPrimes, phi_n); - - AsymmetricCipherKeyPair pair = new AsymmetricCipherKeyPair(pubParameters, privParameters); - - // Initialize Engines with KeyPair - - if (debug) - { - System.out.println("initializing encryption engine"); - } - cryptEng.init(true, pair.getPublic()); - - if (debug) - { - System.out.println("initializing decryption engine"); - } - decryptEng.init(false, pair.getPrivate()); - - byte[] data = paperTest.toByteArray(); - - if (!new BigInteger(data).equals(new BigInteger(enDeCrypt(data)))) - { - fail("failed NaccacheStern paper test"); - } - - // - // key generation test - // - - // - // 768 Bit test - // - - if (debug) - { - System.out.println(); - System.out.println("768 Bit TEST"); - } - - // specify key generation parameters - NaccacheSternKeyGenerationParameters genParam - = new NaccacheSternKeyGenerationParameters(new SecureRandom(), 768, 8, 30, debug); - - // Initialize Key generator and generate key pair - NaccacheSternKeyPairGenerator pGen = new NaccacheSternKeyPairGenerator(); - pGen.init(genParam); - - pair = pGen.generateKeyPair(); - - if (((NaccacheSternKeyParameters)pair.getPublic()).getModulus().bitLength() < 768) - { - System.out.println("FAILED: key size is <786 bit, exactly " - + ((NaccacheSternKeyParameters)pair.getPublic()).getModulus().bitLength() + " bit"); - fail("failed key generation (768) length test"); - } - - // Initialize Engines with KeyPair - - if (debug) - { - System.out.println("initializing " + genParam.getStrength() + " bit encryption engine"); - } - cryptEng.init(true, pair.getPublic()); - - if (debug) - { - System.out.println("initializing " + genParam.getStrength() + " bit decryption engine"); - } - decryptEng.init(false, pair.getPrivate()); - - // Basic data input - data = Hex.decode(input); - - if (!new BigInteger(1, data).equals(new BigInteger(1, enDeCrypt(data)))) - { - fail("failed encryption decryption (" + genParam.getStrength() + ") basic test"); - } - - // Data starting with FF byte (would be interpreted as negative - // BigInteger) - - data = Hex.decode(edgeInput); - - if (!new BigInteger(1, data).equals(new BigInteger(1, enDeCrypt(data)))) - { - fail("failed encryption decryption (" + genParam.getStrength() + ") edgeInput test"); - } - - // - // 1024 Bit Test - // -/* - if (debug) - { - System.out.println(); - System.out.println("1024 Bit TEST"); - } - - // specify key generation parameters - genParam = new NaccacheSternKeyGenerationParameters(new SecureRandom(), 1024, 8, 40); - - pGen.init(genParam); - pair = pGen.generateKeyPair(); - - if (((NaccacheSternKeyParameters)pair.getPublic()).getModulus().bitLength() < 1024) - { - if (debug) - { - System.out.println("FAILED: key size is <1024 bit, exactly " - + ((NaccacheSternKeyParameters)pair.getPublic()).getModulus().bitLength() + " bit"); - } - fail("failed key generation (1024) length test"); - } - - // Initialize Engines with KeyPair - - if (debug) - { - System.out.println("initializing " + genParam.getStrength() + " bit encryption engine"); - } - cryptEng.init(true, pair.getPublic()); - - if (debug) - { - System.out.println("initializing " + genParam.getStrength() + " bit decryption engine"); - } - decryptEng.init(false, pair.getPrivate()); - - if (debug) - { - System.out.println("Data is " + new BigInteger(1, data)); - } - - // Basic data input - data = Hex.decode(input); - - if (!new BigInteger(1, data).equals(new BigInteger(1, enDeCrypt(data)))) - { - fail("failed encryption decryption (" + genParam.getStrength() + ") basic test"); - } - - // Data starting with FF byte (would be interpreted as negative - // BigInteger) - - data = Hex.decode(edgeInput); - - if (!new BigInteger(1, data).equals(new BigInteger(1, enDeCrypt(data)))) - { - fail("failed encryption decryption (" + genParam.getStrength() + ") edgeInput test"); - } -*/ - // END OF TEST CASE - - try - { - new NaccacheSternEngine().processBlock(new byte[]{ 1 }, 0, 1); - fail("failed initialisation check"); - } - catch (IllegalStateException e) - { - // expected - } - catch (InvalidCipherTextException e) - { - fail("failed initialisation check"); - } - - if (debug) - { - System.out.println("All tests successful"); - } - } - - private byte[] enDeCrypt(byte[] input) - { - - // create work array - byte[] data = new byte[input.length]; - System.arraycopy(input, 0, data, 0, data.length); - - // Perform encryption like in the paper from Naccache-Stern - if (debug) - { - System.out.println("encrypting data. Data representation\n" - // + "As String:.... " + new String(data) + "\n" - + "As BigInteger: " + new BigInteger(1, data)); - System.out.println("data length is " + data.length); - } - - try - { - data = cryptEng.processData(data); - } - catch (InvalidCipherTextException e) - { - if (debug) - { - System.out.println("failed - exception " + e.toString() + "\n" + e.getMessage()); - } - fail("failed - exception " + e.toString() + "\n" + e.getMessage()); - } - - if (debug) - { - System.out.println("enrypted data representation\n" - // + "As String:.... " + new String(data) + "\n" - + "As BigInteger: " + new BigInteger(1, data)); - System.out.println("data length is " + data.length); - } - - try - { - data = decryptEng.processData(data); - } - catch (InvalidCipherTextException e) - { - if (debug) - { - System.out.println("failed - exception " + e.toString() + "\n" + e.getMessage()); - } - fail("failed - exception " + e.toString() + "\n" + e.getMessage()); - } - - if (debug) - { - System.out.println("decrypted data representation\n" - // + "As String:.... " + new String(data) + "\n" - + "As BigInteger: " + new BigInteger(1, data)); - System.out.println("data length is " + data.length); - } - - return data; - - } - - public static void main(String[] args) - { - runTest(new NaccacheSternTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NoekeonTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NoekeonTest.java deleted file mode 100644 index 28a9c1383..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NoekeonTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.NoekeonEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Noekeon tester - */ -public class NoekeonTest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new NoekeonEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", - "b1656851699e29fa24b70148503d2dfc"), - new BlockCipherVectorTest(1, new NoekeonEngine(), - new KeyParameter(Hex.decode("ffffffffffffffffffffffffffffffff")), - "ffffffffffffffffffffffffffffffff", - "2a78421b87c7d0924f26113f1d1349b2"), - new BlockCipherVectorTest(2, new NoekeonEngine(), - new KeyParameter(Hex.decode("b1656851699e29fa24b70148503d2dfc")), - "2a78421b87c7d0924f26113f1d1349b2", - "e2f687e07b75660ffc372233bc47532c") - }; - - NoekeonTest() - { - super(tests, new NoekeonEngine(), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "Noekeon"; - } - - public static void main( - String[] args) - { - runTest(new NoekeonTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NonMemoableDigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NonMemoableDigestTest.java deleted file mode 100644 index d1c18deae..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NonMemoableDigestTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.NonMemoableDigest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * SHA1 HMac Test, test vectors from RFC 2202 - */ -public class NonMemoableDigestTest - implements Test -{ - final static String[] keys = { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4a656665", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "0102030405060708090a0b0c0d0e0f10111213141516171819", - "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - }; - - final static String[] digests = { - "b617318655057264e28bc0b6fb378c8ef146be00", - "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79", - "125d7342b9ac11cd91a39af48aa17b4f63f175d3", - "4c9007f4026250c6bc8414f9bf50c86c2d7235da", - "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04", - "aa4ae5e15272d00e95705637ce8a3b55ed402112", - "e8e99d0f45237d786d6bbaa7965c7808bbff1a91", - "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04", - "aa4ae5e15272d00e95705637ce8a3b55ed402112", - "e8e99d0f45237d786d6bbaa7965c7808bbff1a91" - }; - - final static String[] messages = { - "Hi There", - "what do ya want for nothing?", - "0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", - "0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd", - "Test With Truncation", - "Test Using Larger Than Block-Size Key - Hash Key First", - "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data" - }; - - public String getName() - { - return "NonMemoableDigest"; - } - - public TestResult perform() - { - HMac hmac = new HMac(new NonMemoableDigest(new SHA1Digest())); - byte[] resBuf = new byte[hmac.getMacSize()]; - - for (int i = 0; i < messages.length; i++) - { - byte[] m = Strings.toByteArray(messages[i]); - if (messages[i].startsWith("0x")) - { - m = Hex.decode(messages[i].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[i]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[i]))) - { - return new SimpleTestResult(false, getName() + ": Vector " + i + " failed"); - } - } - - // - // test reset - // - int vector = 0; // vector used for test - byte[] m = Strings.toByteArray(messages[vector]); - if (messages[vector].startsWith("0x")) - { - m = Hex.decode(messages[vector].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[vector]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - hmac.reset(); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[vector]))) - { - return new SimpleTestResult(false, getName() + - ": Reset with vector " + vector + " failed"); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public static void main( - String[] args) - { - NonMemoableDigestTest test = new NonMemoableDigestTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NullTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NullTest.java deleted file mode 100644 index ce87c97ca..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/NullTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.engines.NullEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class NullTest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new NullEngine(), - new KeyParameter(Hex.decode("00")), "00", "00") - }; - - NullTest() - { - super(tests, new NullEngine(), new KeyParameter(new byte[2])); - } - - public String getName() - { - return "Null"; - } - - public void performTest() - throws Exception - { - super.performTest(); - - BlockCipher engine = new NullEngine(); - - engine.init(true, null); - - byte[] buf = new byte[1]; - - engine.processBlock(buf, 0, buf, 0); - - if (buf[0] != 0) - { - fail("NullCipher changed data!"); - } - - byte[] shortBuf = new byte[0]; - - try - { - engine.processBlock(shortBuf, 0, buf, 0); - - fail("failed short input check"); - } - catch (DataLengthException e) - { - // expected - } - - try - { - engine.processBlock(buf, 0, shortBuf, 0); - - fail("failed short output check"); - } - catch (DataLengthException e) - { - // expected - } - } - - public static void main( - String[] args) - { - runTest(new NullTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/OAEPTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/OAEPTest.java deleted file mode 100644 index 2c01fdfa3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/OAEPTest.java +++ /dev/null @@ -1,907 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.ByteArrayInputStream; -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.pkcs.PrivateKeyInfo; -import com.fr.third.org.bouncycastle.asn1.pkcs.RSAPrivateKey; -import com.fr.third.org.bouncycastle.asn1.pkcs.RSAPublicKey; -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.crypto.AsymmetricBlockCipher; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.encodings.OAEPEncoding; -import com.fr.third.org.bouncycastle.crypto.engines.RSAEngine; -import com.fr.third.org.bouncycastle.crypto.generators.RSAKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters; -import com.fr.third.org.bouncycastle.util.BigIntegers; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class OAEPTest - extends SimpleTest -{ - static byte[] pubKeyEnc1 = - { - (byte)0x30, (byte)0x5a, (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, (byte)0x86, - (byte)0x48, (byte)0x86, (byte)0xf7, (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x05, - (byte)0x00, (byte)0x03, (byte)0x49, (byte)0x00, (byte)0x30, (byte)0x46, (byte)0x02, (byte)0x41, - (byte)0x00, (byte)0xaa, (byte)0x36, (byte)0xab, (byte)0xce, (byte)0x88, (byte)0xac, (byte)0xfd, - (byte)0xff, (byte)0x55, (byte)0x52, (byte)0x3c, (byte)0x7f, (byte)0xc4, (byte)0x52, (byte)0x3f, - (byte)0x90, (byte)0xef, (byte)0xa0, (byte)0x0d, (byte)0xf3, (byte)0x77, (byte)0x4a, (byte)0x25, - (byte)0x9f, (byte)0x2e, (byte)0x62, (byte)0xb4, (byte)0xc5, (byte)0xd9, (byte)0x9c, (byte)0xb5, - (byte)0xad, (byte)0xb3, (byte)0x00, (byte)0xa0, (byte)0x28, (byte)0x5e, (byte)0x53, (byte)0x01, - (byte)0x93, (byte)0x0e, (byte)0x0c, (byte)0x70, (byte)0xfb, (byte)0x68, (byte)0x76, (byte)0x93, - (byte)0x9c, (byte)0xe6, (byte)0x16, (byte)0xce, (byte)0x62, (byte)0x4a, (byte)0x11, (byte)0xe0, - (byte)0x08, (byte)0x6d, (byte)0x34, (byte)0x1e, (byte)0xbc, (byte)0xac, (byte)0xa0, (byte)0xa1, - (byte)0xf5, (byte)0x02, (byte)0x01, (byte)0x11 - }; - - static byte[] privKeyEnc1 = - { - (byte)0x30, (byte)0x82, (byte)0x01, (byte)0x52, (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x30, - (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7, - (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x05, (byte)0x00, (byte)0x04, (byte)0x82, - (byte)0x01, (byte)0x3c, (byte)0x30, (byte)0x82, (byte)0x01, (byte)0x38, (byte)0x02, (byte)0x01, - (byte)0x00, (byte)0x02, (byte)0x41, (byte)0x00, (byte)0xaa, (byte)0x36, (byte)0xab, (byte)0xce, - (byte)0x88, (byte)0xac, (byte)0xfd, (byte)0xff, (byte)0x55, (byte)0x52, (byte)0x3c, (byte)0x7f, - (byte)0xc4, (byte)0x52, (byte)0x3f, (byte)0x90, (byte)0xef, (byte)0xa0, (byte)0x0d, (byte)0xf3, - (byte)0x77, (byte)0x4a, (byte)0x25, (byte)0x9f, (byte)0x2e, (byte)0x62, (byte)0xb4, (byte)0xc5, - (byte)0xd9, (byte)0x9c, (byte)0xb5, (byte)0xad, (byte)0xb3, (byte)0x00, (byte)0xa0, (byte)0x28, - (byte)0x5e, (byte)0x53, (byte)0x01, (byte)0x93, (byte)0x0e, (byte)0x0c, (byte)0x70, (byte)0xfb, - (byte)0x68, (byte)0x76, (byte)0x93, (byte)0x9c, (byte)0xe6, (byte)0x16, (byte)0xce, (byte)0x62, - (byte)0x4a, (byte)0x11, (byte)0xe0, (byte)0x08, (byte)0x6d, (byte)0x34, (byte)0x1e, (byte)0xbc, - (byte)0xac, (byte)0xa0, (byte)0xa1, (byte)0xf5, (byte)0x02, (byte)0x01, (byte)0x11, (byte)0x02, - (byte)0x40, (byte)0x0a, (byte)0x03, (byte)0x37, (byte)0x48, (byte)0x62, (byte)0x64, (byte)0x87, - (byte)0x69, (byte)0x5f, (byte)0x5f, (byte)0x30, (byte)0xbc, (byte)0x38, (byte)0xb9, (byte)0x8b, - (byte)0x44, (byte)0xc2, (byte)0xcd, (byte)0x2d, (byte)0xff, (byte)0x43, (byte)0x40, (byte)0x98, - (byte)0xcd, (byte)0x20, (byte)0xd8, (byte)0xa1, (byte)0x38, (byte)0xd0, (byte)0x90, (byte)0xbf, - (byte)0x64, (byte)0x79, (byte)0x7c, (byte)0x3f, (byte)0xa7, (byte)0xa2, (byte)0xcd, (byte)0xcb, - (byte)0x3c, (byte)0xd1, (byte)0xe0, (byte)0xbd, (byte)0xba, (byte)0x26, (byte)0x54, (byte)0xb4, - (byte)0xf9, (byte)0xdf, (byte)0x8e, (byte)0x8a, (byte)0xe5, (byte)0x9d, (byte)0x73, (byte)0x3d, - (byte)0x9f, (byte)0x33, (byte)0xb3, (byte)0x01, (byte)0x62, (byte)0x4a, (byte)0xfd, (byte)0x1d, - (byte)0x51, (byte)0x02, (byte)0x21, (byte)0x00, (byte)0xd8, (byte)0x40, (byte)0xb4, (byte)0x16, - (byte)0x66, (byte)0xb4, (byte)0x2e, (byte)0x92, (byte)0xea, (byte)0x0d, (byte)0xa3, (byte)0xb4, - (byte)0x32, (byte)0x04, (byte)0xb5, (byte)0xcf, (byte)0xce, (byte)0x33, (byte)0x52, (byte)0x52, - (byte)0x4d, (byte)0x04, (byte)0x16, (byte)0xa5, (byte)0xa4, (byte)0x41, (byte)0xe7, (byte)0x00, - (byte)0xaf, (byte)0x46, (byte)0x12, (byte)0x0d, (byte)0x02, (byte)0x21, (byte)0x00, (byte)0xc9, - (byte)0x7f, (byte)0xb1, (byte)0xf0, (byte)0x27, (byte)0xf4, (byte)0x53, (byte)0xf6, (byte)0x34, - (byte)0x12, (byte)0x33, (byte)0xea, (byte)0xaa, (byte)0xd1, (byte)0xd9, (byte)0x35, (byte)0x3f, - (byte)0x6c, (byte)0x42, (byte)0xd0, (byte)0x88, (byte)0x66, (byte)0xb1, (byte)0xd0, (byte)0x5a, - (byte)0x0f, (byte)0x20, (byte)0x35, (byte)0x02, (byte)0x8b, (byte)0x9d, (byte)0x89, (byte)0x02, - (byte)0x20, (byte)0x59, (byte)0x0b, (byte)0x95, (byte)0x72, (byte)0xa2, (byte)0xc2, (byte)0xa9, - (byte)0xc4, (byte)0x06, (byte)0x05, (byte)0x9d, (byte)0xc2, (byte)0xab, (byte)0x2f, (byte)0x1d, - (byte)0xaf, (byte)0xeb, (byte)0x7e, (byte)0x8b, (byte)0x4f, (byte)0x10, (byte)0xa7, (byte)0x54, - (byte)0x9e, (byte)0x8e, (byte)0xed, (byte)0xf5, (byte)0xb4, (byte)0xfc, (byte)0xe0, (byte)0x9e, - (byte)0x05, (byte)0x02, (byte)0x21, (byte)0x00, (byte)0x8e, (byte)0x3c, (byte)0x05, (byte)0x21, - (byte)0xfe, (byte)0x15, (byte)0xe0, (byte)0xea, (byte)0x06, (byte)0xa3, (byte)0x6f, (byte)0xf0, - (byte)0xf1, (byte)0x0c, (byte)0x99, (byte)0x52, (byte)0xc3, (byte)0x5b, (byte)0x7a, (byte)0x75, - (byte)0x14, (byte)0xfd, (byte)0x32, (byte)0x38, (byte)0xb8, (byte)0x0a, (byte)0xad, (byte)0x52, - (byte)0x98, (byte)0x62, (byte)0x8d, (byte)0x51, (byte)0x02, (byte)0x20, (byte)0x36, (byte)0x3f, - (byte)0xf7, (byte)0x18, (byte)0x9d, (byte)0xa8, (byte)0xe9, (byte)0x0b, (byte)0x1d, (byte)0x34, - (byte)0x1f, (byte)0x71, (byte)0xd0, (byte)0x9b, (byte)0x76, (byte)0xa8, (byte)0xa9, (byte)0x43, - (byte)0xe1, (byte)0x1d, (byte)0x10, (byte)0xb2, (byte)0x4d, (byte)0x24, (byte)0x9f, (byte)0x2d, - (byte)0xea, (byte)0xfe, (byte)0xf8, (byte)0x0c, (byte)0x18, (byte)0x26 - }; - - static byte[] output1 = - { - (byte)0x1b, (byte)0x8f, (byte)0x05, (byte)0xf9, (byte)0xca, (byte)0x1a, (byte)0x79, (byte)0x52, - (byte)0x6e, (byte)0x53, (byte)0xf3, (byte)0xcc, (byte)0x51, (byte)0x4f, (byte)0xdb, (byte)0x89, - (byte)0x2b, (byte)0xfb, (byte)0x91, (byte)0x93, (byte)0x23, (byte)0x1e, (byte)0x78, (byte)0xb9, - (byte)0x92, (byte)0xe6, (byte)0x8d, (byte)0x50, (byte)0xa4, (byte)0x80, (byte)0xcb, (byte)0x52, - (byte)0x33, (byte)0x89, (byte)0x5c, (byte)0x74, (byte)0x95, (byte)0x8d, (byte)0x5d, (byte)0x02, - (byte)0xab, (byte)0x8c, (byte)0x0f, (byte)0xd0, (byte)0x40, (byte)0xeb, (byte)0x58, (byte)0x44, - (byte)0xb0, (byte)0x05, (byte)0xc3, (byte)0x9e, (byte)0xd8, (byte)0x27, (byte)0x4a, (byte)0x9d, - (byte)0xbf, (byte)0xa8, (byte)0x06, (byte)0x71, (byte)0x40, (byte)0x94, (byte)0x39, (byte)0xd2 - }; - - static byte[] pubKeyEnc2 = - { - (byte)0x30, (byte)0x4c, (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, (byte)0x86, - (byte)0x48, (byte)0x86, (byte)0xf7, (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x05, - (byte)0x00, (byte)0x03, (byte)0x3b, (byte)0x00, (byte)0x30, (byte)0x38, (byte)0x02, (byte)0x33, - (byte)0x00, (byte)0xa3, (byte)0x07, (byte)0x9a, (byte)0x90, (byte)0xdf, (byte)0x0d, (byte)0xfd, - (byte)0x72, (byte)0xac, (byte)0x09, (byte)0x0c, (byte)0xcc, (byte)0x2a, (byte)0x78, (byte)0xb8, - (byte)0x74, (byte)0x13, (byte)0x13, (byte)0x3e, (byte)0x40, (byte)0x75, (byte)0x9c, (byte)0x98, - (byte)0xfa, (byte)0xf8, (byte)0x20, (byte)0x4f, (byte)0x35, (byte)0x8a, (byte)0x0b, (byte)0x26, - (byte)0x3c, (byte)0x67, (byte)0x70, (byte)0xe7, (byte)0x83, (byte)0xa9, (byte)0x3b, (byte)0x69, - (byte)0x71, (byte)0xb7, (byte)0x37, (byte)0x79, (byte)0xd2, (byte)0x71, (byte)0x7b, (byte)0xe8, - (byte)0x34, (byte)0x77, (byte)0xcf, (byte)0x02, (byte)0x01, (byte)0x03 - }; - - static byte[] privKeyEnc2 = - { - (byte)0x30, (byte)0x82, (byte)0x01, (byte)0x13, (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x30, - (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7, - (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x05, (byte)0x00, (byte)0x04, (byte)0x81, - (byte)0xfe, (byte)0x30, (byte)0x81, (byte)0xfb, (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x02, - (byte)0x33, (byte)0x00, (byte)0xa3, (byte)0x07, (byte)0x9a, (byte)0x90, (byte)0xdf, (byte)0x0d, - (byte)0xfd, (byte)0x72, (byte)0xac, (byte)0x09, (byte)0x0c, (byte)0xcc, (byte)0x2a, (byte)0x78, - (byte)0xb8, (byte)0x74, (byte)0x13, (byte)0x13, (byte)0x3e, (byte)0x40, (byte)0x75, (byte)0x9c, - (byte)0x98, (byte)0xfa, (byte)0xf8, (byte)0x20, (byte)0x4f, (byte)0x35, (byte)0x8a, (byte)0x0b, - (byte)0x26, (byte)0x3c, (byte)0x67, (byte)0x70, (byte)0xe7, (byte)0x83, (byte)0xa9, (byte)0x3b, - (byte)0x69, (byte)0x71, (byte)0xb7, (byte)0x37, (byte)0x79, (byte)0xd2, (byte)0x71, (byte)0x7b, - (byte)0xe8, (byte)0x34, (byte)0x77, (byte)0xcf, (byte)0x02, (byte)0x01, (byte)0x03, (byte)0x02, - (byte)0x32, (byte)0x6c, (byte)0xaf, (byte)0xbc, (byte)0x60, (byte)0x94, (byte)0xb3, (byte)0xfe, - (byte)0x4c, (byte)0x72, (byte)0xb0, (byte)0xb3, (byte)0x32, (byte)0xc6, (byte)0xfb, (byte)0x25, - (byte)0xa2, (byte)0xb7, (byte)0x62, (byte)0x29, (byte)0x80, (byte)0x4e, (byte)0x68, (byte)0x65, - (byte)0xfc, (byte)0xa4, (byte)0x5a, (byte)0x74, (byte)0xdf, (byte)0x0f, (byte)0x8f, (byte)0xb8, - (byte)0x41, (byte)0x3b, (byte)0x52, (byte)0xc0, (byte)0xd0, (byte)0xe5, (byte)0x3d, (byte)0x9b, - (byte)0x59, (byte)0x0f, (byte)0xf1, (byte)0x9b, (byte)0xe7, (byte)0x9f, (byte)0x49, (byte)0xdd, - (byte)0x21, (byte)0xe5, (byte)0xeb, (byte)0x02, (byte)0x1a, (byte)0x00, (byte)0xcf, (byte)0x20, - (byte)0x35, (byte)0x02, (byte)0x8b, (byte)0x9d, (byte)0x86, (byte)0x98, (byte)0x40, (byte)0xb4, - (byte)0x16, (byte)0x66, (byte)0xb4, (byte)0x2e, (byte)0x92, (byte)0xea, (byte)0x0d, (byte)0xa3, - (byte)0xb4, (byte)0x32, (byte)0x04, (byte)0xb5, (byte)0xcf, (byte)0xce, (byte)0x91, (byte)0x02, - (byte)0x1a, (byte)0x00, (byte)0xc9, (byte)0x7f, (byte)0xb1, (byte)0xf0, (byte)0x27, (byte)0xf4, - (byte)0x53, (byte)0xf6, (byte)0x34, (byte)0x12, (byte)0x33, (byte)0xea, (byte)0xaa, (byte)0xd1, - (byte)0xd9, (byte)0x35, (byte)0x3f, (byte)0x6c, (byte)0x42, (byte)0xd0, (byte)0x88, (byte)0x66, - (byte)0xb1, (byte)0xd0, (byte)0x5f, (byte)0x02, (byte)0x1a, (byte)0x00, (byte)0x8a, (byte)0x15, - (byte)0x78, (byte)0xac, (byte)0x5d, (byte)0x13, (byte)0xaf, (byte)0x10, (byte)0x2b, (byte)0x22, - (byte)0xb9, (byte)0x99, (byte)0xcd, (byte)0x74, (byte)0x61, (byte)0xf1, (byte)0x5e, (byte)0x6d, - (byte)0x22, (byte)0xcc, (byte)0x03, (byte)0x23, (byte)0xdf, (byte)0xdf, (byte)0x0b, (byte)0x02, - (byte)0x1a, (byte)0x00, (byte)0x86, (byte)0x55, (byte)0x21, (byte)0x4a, (byte)0xc5, (byte)0x4d, - (byte)0x8d, (byte)0x4e, (byte)0xcd, (byte)0x61, (byte)0x77, (byte)0xf1, (byte)0xc7, (byte)0x36, - (byte)0x90, (byte)0xce, (byte)0x2a, (byte)0x48, (byte)0x2c, (byte)0x8b, (byte)0x05, (byte)0x99, - (byte)0xcb, (byte)0xe0, (byte)0x3f, (byte)0x02, (byte)0x1a, (byte)0x00, (byte)0x83, (byte)0xef, - (byte)0xef, (byte)0xb8, (byte)0xa9, (byte)0xa4, (byte)0x0d, (byte)0x1d, (byte)0xb6, (byte)0xed, - (byte)0x98, (byte)0xad, (byte)0x84, (byte)0xed, (byte)0x13, (byte)0x35, (byte)0xdc, (byte)0xc1, - (byte)0x08, (byte)0xf3, (byte)0x22, (byte)0xd0, (byte)0x57, (byte)0xcf, (byte)0x8d - }; - - static byte[] output2 = - { - (byte)0x14, (byte)0xbd, (byte)0xdd, (byte)0x28, (byte)0xc9, (byte)0x83, (byte)0x35, (byte)0x19, - (byte)0x23, (byte)0x80, (byte)0xe8, (byte)0xe5, (byte)0x49, (byte)0xb1, (byte)0x58, (byte)0x2a, - (byte)0x8b, (byte)0x40, (byte)0xb4, (byte)0x48, (byte)0x6d, (byte)0x03, (byte)0xa6, (byte)0xa5, - (byte)0x31, (byte)0x1f, (byte)0x1f, (byte)0xd5, (byte)0xf0, (byte)0xa1, (byte)0x80, (byte)0xe4, - (byte)0x17, (byte)0x53, (byte)0x03, (byte)0x29, (byte)0xa9, (byte)0x34, (byte)0x90, (byte)0x74, - (byte)0xb1, (byte)0x52, (byte)0x13, (byte)0x54, (byte)0x29, (byte)0x08, (byte)0x24, (byte)0x52, - (byte)0x62, (byte)0x51 - }; - - static byte[] pubKeyEnc3 = - { - (byte)0x30, (byte)0x81, (byte)0x9d, (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, - (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7, (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01, - (byte)0x05, (byte)0x00, (byte)0x03, (byte)0x81, (byte)0x8b, (byte)0x00, (byte)0x30, (byte)0x81, - (byte)0x87, (byte)0x02, (byte)0x81, (byte)0x81, (byte)0x00, (byte)0xbb, (byte)0xf8, (byte)0x2f, - (byte)0x09, (byte)0x06, (byte)0x82, (byte)0xce, (byte)0x9c, (byte)0x23, (byte)0x38, (byte)0xac, - (byte)0x2b, (byte)0x9d, (byte)0xa8, (byte)0x71, (byte)0xf7, (byte)0x36, (byte)0x8d, (byte)0x07, - (byte)0xee, (byte)0xd4, (byte)0x10, (byte)0x43, (byte)0xa4, (byte)0x40, (byte)0xd6, (byte)0xb6, - (byte)0xf0, (byte)0x74, (byte)0x54, (byte)0xf5, (byte)0x1f, (byte)0xb8, (byte)0xdf, (byte)0xba, - (byte)0xaf, (byte)0x03, (byte)0x5c, (byte)0x02, (byte)0xab, (byte)0x61, (byte)0xea, (byte)0x48, - (byte)0xce, (byte)0xeb, (byte)0x6f, (byte)0xcd, (byte)0x48, (byte)0x76, (byte)0xed, (byte)0x52, - (byte)0x0d, (byte)0x60, (byte)0xe1, (byte)0xec, (byte)0x46, (byte)0x19, (byte)0x71, (byte)0x9d, - (byte)0x8a, (byte)0x5b, (byte)0x8b, (byte)0x80, (byte)0x7f, (byte)0xaf, (byte)0xb8, (byte)0xe0, - (byte)0xa3, (byte)0xdf, (byte)0xc7, (byte)0x37, (byte)0x72, (byte)0x3e, (byte)0xe6, (byte)0xb4, - (byte)0xb7, (byte)0xd9, (byte)0x3a, (byte)0x25, (byte)0x84, (byte)0xee, (byte)0x6a, (byte)0x64, - (byte)0x9d, (byte)0x06, (byte)0x09, (byte)0x53, (byte)0x74, (byte)0x88, (byte)0x34, (byte)0xb2, - (byte)0x45, (byte)0x45, (byte)0x98, (byte)0x39, (byte)0x4e, (byte)0xe0, (byte)0xaa, (byte)0xb1, - (byte)0x2d, (byte)0x7b, (byte)0x61, (byte)0xa5, (byte)0x1f, (byte)0x52, (byte)0x7a, (byte)0x9a, - (byte)0x41, (byte)0xf6, (byte)0xc1, (byte)0x68, (byte)0x7f, (byte)0xe2, (byte)0x53, (byte)0x72, - (byte)0x98, (byte)0xca, (byte)0x2a, (byte)0x8f, (byte)0x59, (byte)0x46, (byte)0xf8, (byte)0xe5, - (byte)0xfd, (byte)0x09, (byte)0x1d, (byte)0xbd, (byte)0xcb, (byte)0x02, (byte)0x01, (byte)0x11 - }; - - static byte[] privKeyEnc3 = - { - (byte)0x30, (byte)0x82, (byte)0x02, (byte)0x75, (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x30, - (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7, - (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x05, (byte)0x00, (byte)0x04, (byte)0x82, - (byte)0x02, (byte)0x5f, (byte)0x30, (byte)0x82, (byte)0x02, (byte)0x5b, (byte)0x02, (byte)0x01, - (byte)0x00, (byte)0x02, (byte)0x81, (byte)0x81, (byte)0x00, (byte)0xbb, (byte)0xf8, (byte)0x2f, - (byte)0x09, (byte)0x06, (byte)0x82, (byte)0xce, (byte)0x9c, (byte)0x23, (byte)0x38, (byte)0xac, - (byte)0x2b, (byte)0x9d, (byte)0xa8, (byte)0x71, (byte)0xf7, (byte)0x36, (byte)0x8d, (byte)0x07, - (byte)0xee, (byte)0xd4, (byte)0x10, (byte)0x43, (byte)0xa4, (byte)0x40, (byte)0xd6, (byte)0xb6, - (byte)0xf0, (byte)0x74, (byte)0x54, (byte)0xf5, (byte)0x1f, (byte)0xb8, (byte)0xdf, (byte)0xba, - (byte)0xaf, (byte)0x03, (byte)0x5c, (byte)0x02, (byte)0xab, (byte)0x61, (byte)0xea, (byte)0x48, - (byte)0xce, (byte)0xeb, (byte)0x6f, (byte)0xcd, (byte)0x48, (byte)0x76, (byte)0xed, (byte)0x52, - (byte)0x0d, (byte)0x60, (byte)0xe1, (byte)0xec, (byte)0x46, (byte)0x19, (byte)0x71, (byte)0x9d, - (byte)0x8a, (byte)0x5b, (byte)0x8b, (byte)0x80, (byte)0x7f, (byte)0xaf, (byte)0xb8, (byte)0xe0, - (byte)0xa3, (byte)0xdf, (byte)0xc7, (byte)0x37, (byte)0x72, (byte)0x3e, (byte)0xe6, (byte)0xb4, - (byte)0xb7, (byte)0xd9, (byte)0x3a, (byte)0x25, (byte)0x84, (byte)0xee, (byte)0x6a, (byte)0x64, - (byte)0x9d, (byte)0x06, (byte)0x09, (byte)0x53, (byte)0x74, (byte)0x88, (byte)0x34, (byte)0xb2, - (byte)0x45, (byte)0x45, (byte)0x98, (byte)0x39, (byte)0x4e, (byte)0xe0, (byte)0xaa, (byte)0xb1, - (byte)0x2d, (byte)0x7b, (byte)0x61, (byte)0xa5, (byte)0x1f, (byte)0x52, (byte)0x7a, (byte)0x9a, - (byte)0x41, (byte)0xf6, (byte)0xc1, (byte)0x68, (byte)0x7f, (byte)0xe2, (byte)0x53, (byte)0x72, - (byte)0x98, (byte)0xca, (byte)0x2a, (byte)0x8f, (byte)0x59, (byte)0x46, (byte)0xf8, (byte)0xe5, - (byte)0xfd, (byte)0x09, (byte)0x1d, (byte)0xbd, (byte)0xcb, (byte)0x02, (byte)0x01, (byte)0x11, - (byte)0x02, (byte)0x81, (byte)0x81, (byte)0x00, (byte)0xa5, (byte)0xda, (byte)0xfc, (byte)0x53, - (byte)0x41, (byte)0xfa, (byte)0xf2, (byte)0x89, (byte)0xc4, (byte)0xb9, (byte)0x88, (byte)0xdb, - (byte)0x30, (byte)0xc1, (byte)0xcd, (byte)0xf8, (byte)0x3f, (byte)0x31, (byte)0x25, (byte)0x1e, - (byte)0x06, (byte)0x68, (byte)0xb4, (byte)0x27, (byte)0x84, (byte)0x81, (byte)0x38, (byte)0x01, - (byte)0x57, (byte)0x96, (byte)0x41, (byte)0xb2, (byte)0x94, (byte)0x10, (byte)0xb3, (byte)0xc7, - (byte)0x99, (byte)0x8d, (byte)0x6b, (byte)0xc4, (byte)0x65, (byte)0x74, (byte)0x5e, (byte)0x5c, - (byte)0x39, (byte)0x26, (byte)0x69, (byte)0xd6, (byte)0x87, (byte)0x0d, (byte)0xa2, (byte)0xc0, - (byte)0x82, (byte)0xa9, (byte)0x39, (byte)0xe3, (byte)0x7f, (byte)0xdc, (byte)0xb8, (byte)0x2e, - (byte)0xc9, (byte)0x3e, (byte)0xda, (byte)0xc9, (byte)0x7f, (byte)0xf3, (byte)0xad, (byte)0x59, - (byte)0x50, (byte)0xac, (byte)0xcf, (byte)0xbc, (byte)0x11, (byte)0x1c, (byte)0x76, (byte)0xf1, - (byte)0xa9, (byte)0x52, (byte)0x94, (byte)0x44, (byte)0xe5, (byte)0x6a, (byte)0xaf, (byte)0x68, - (byte)0xc5, (byte)0x6c, (byte)0x09, (byte)0x2c, (byte)0xd3, (byte)0x8d, (byte)0xc3, (byte)0xbe, - (byte)0xf5, (byte)0xd2, (byte)0x0a, (byte)0x93, (byte)0x99, (byte)0x26, (byte)0xed, (byte)0x4f, - (byte)0x74, (byte)0xa1, (byte)0x3e, (byte)0xdd, (byte)0xfb, (byte)0xe1, (byte)0xa1, (byte)0xce, - (byte)0xcc, (byte)0x48, (byte)0x94, (byte)0xaf, (byte)0x94, (byte)0x28, (byte)0xc2, (byte)0xb7, - (byte)0xb8, (byte)0x88, (byte)0x3f, (byte)0xe4, (byte)0x46, (byte)0x3a, (byte)0x4b, (byte)0xc8, - (byte)0x5b, (byte)0x1c, (byte)0xb3, (byte)0xc1, (byte)0x02, (byte)0x41, (byte)0x00, (byte)0xee, - (byte)0xcf, (byte)0xae, (byte)0x81, (byte)0xb1, (byte)0xb9, (byte)0xb3, (byte)0xc9, (byte)0x08, - (byte)0x81, (byte)0x0b, (byte)0x10, (byte)0xa1, (byte)0xb5, (byte)0x60, (byte)0x01, (byte)0x99, - (byte)0xeb, (byte)0x9f, (byte)0x44, (byte)0xae, (byte)0xf4, (byte)0xfd, (byte)0xa4, (byte)0x93, - (byte)0xb8, (byte)0x1a, (byte)0x9e, (byte)0x3d, (byte)0x84, (byte)0xf6, (byte)0x32, (byte)0x12, - (byte)0x4e, (byte)0xf0, (byte)0x23, (byte)0x6e, (byte)0x5d, (byte)0x1e, (byte)0x3b, (byte)0x7e, - (byte)0x28, (byte)0xfa, (byte)0xe7, (byte)0xaa, (byte)0x04, (byte)0x0a, (byte)0x2d, (byte)0x5b, - (byte)0x25, (byte)0x21, (byte)0x76, (byte)0x45, (byte)0x9d, (byte)0x1f, (byte)0x39, (byte)0x75, - (byte)0x41, (byte)0xba, (byte)0x2a, (byte)0x58, (byte)0xfb, (byte)0x65, (byte)0x99, (byte)0x02, - (byte)0x41, (byte)0x00, (byte)0xc9, (byte)0x7f, (byte)0xb1, (byte)0xf0, (byte)0x27, (byte)0xf4, - (byte)0x53, (byte)0xf6, (byte)0x34, (byte)0x12, (byte)0x33, (byte)0xea, (byte)0xaa, (byte)0xd1, - (byte)0xd9, (byte)0x35, (byte)0x3f, (byte)0x6c, (byte)0x42, (byte)0xd0, (byte)0x88, (byte)0x66, - (byte)0xb1, (byte)0xd0, (byte)0x5a, (byte)0x0f, (byte)0x20, (byte)0x35, (byte)0x02, (byte)0x8b, - (byte)0x9d, (byte)0x86, (byte)0x98, (byte)0x40, (byte)0xb4, (byte)0x16, (byte)0x66, (byte)0xb4, - (byte)0x2e, (byte)0x92, (byte)0xea, (byte)0x0d, (byte)0xa3, (byte)0xb4, (byte)0x32, (byte)0x04, - (byte)0xb5, (byte)0xcf, (byte)0xce, (byte)0x33, (byte)0x52, (byte)0x52, (byte)0x4d, (byte)0x04, - (byte)0x16, (byte)0xa5, (byte)0xa4, (byte)0x41, (byte)0xe7, (byte)0x00, (byte)0xaf, (byte)0x46, - (byte)0x15, (byte)0x03, (byte)0x02, (byte)0x40, (byte)0x54, (byte)0x49, (byte)0x4c, (byte)0xa6, - (byte)0x3e, (byte)0xba, (byte)0x03, (byte)0x37, (byte)0xe4, (byte)0xe2, (byte)0x40, (byte)0x23, - (byte)0xfc, (byte)0xd6, (byte)0x9a, (byte)0x5a, (byte)0xeb, (byte)0x07, (byte)0xdd, (byte)0xdc, - (byte)0x01, (byte)0x83, (byte)0xa4, (byte)0xd0, (byte)0xac, (byte)0x9b, (byte)0x54, (byte)0xb0, - (byte)0x51, (byte)0xf2, (byte)0xb1, (byte)0x3e, (byte)0xd9, (byte)0x49, (byte)0x09, (byte)0x75, - (byte)0xea, (byte)0xb7, (byte)0x74, (byte)0x14, (byte)0xff, (byte)0x59, (byte)0xc1, (byte)0xf7, - (byte)0x69, (byte)0x2e, (byte)0x9a, (byte)0x2e, (byte)0x20, (byte)0x2b, (byte)0x38, (byte)0xfc, - (byte)0x91, (byte)0x0a, (byte)0x47, (byte)0x41, (byte)0x74, (byte)0xad, (byte)0xc9, (byte)0x3c, - (byte)0x1f, (byte)0x67, (byte)0xc9, (byte)0x81, (byte)0x02, (byte)0x40, (byte)0x47, (byte)0x1e, - (byte)0x02, (byte)0x90, (byte)0xff, (byte)0x0a, (byte)0xf0, (byte)0x75, (byte)0x03, (byte)0x51, - (byte)0xb7, (byte)0xf8, (byte)0x78, (byte)0x86, (byte)0x4c, (byte)0xa9, (byte)0x61, (byte)0xad, - (byte)0xbd, (byte)0x3a, (byte)0x8a, (byte)0x7e, (byte)0x99, (byte)0x1c, (byte)0x5c, (byte)0x05, - (byte)0x56, (byte)0xa9, (byte)0x4c, (byte)0x31, (byte)0x46, (byte)0xa7, (byte)0xf9, (byte)0x80, - (byte)0x3f, (byte)0x8f, (byte)0x6f, (byte)0x8a, (byte)0xe3, (byte)0x42, (byte)0xe9, (byte)0x31, - (byte)0xfd, (byte)0x8a, (byte)0xe4, (byte)0x7a, (byte)0x22, (byte)0x0d, (byte)0x1b, (byte)0x99, - (byte)0xa4, (byte)0x95, (byte)0x84, (byte)0x98, (byte)0x07, (byte)0xfe, (byte)0x39, (byte)0xf9, - (byte)0x24, (byte)0x5a, (byte)0x98, (byte)0x36, (byte)0xda, (byte)0x3d, (byte)0x02, (byte)0x41, - (byte)0x00, (byte)0xb0, (byte)0x6c, (byte)0x4f, (byte)0xda, (byte)0xbb, (byte)0x63, (byte)0x01, - (byte)0x19, (byte)0x8d, (byte)0x26, (byte)0x5b, (byte)0xdb, (byte)0xae, (byte)0x94, (byte)0x23, - (byte)0xb3, (byte)0x80, (byte)0xf2, (byte)0x71, (byte)0xf7, (byte)0x34, (byte)0x53, (byte)0x88, - (byte)0x50, (byte)0x93, (byte)0x07, (byte)0x7f, (byte)0xcd, (byte)0x39, (byte)0xe2, (byte)0x11, - (byte)0x9f, (byte)0xc9, (byte)0x86, (byte)0x32, (byte)0x15, (byte)0x4f, (byte)0x58, (byte)0x83, - (byte)0xb1, (byte)0x67, (byte)0xa9, (byte)0x67, (byte)0xbf, (byte)0x40, (byte)0x2b, (byte)0x4e, - (byte)0x9e, (byte)0x2e, (byte)0x0f, (byte)0x96, (byte)0x56, (byte)0xe6, (byte)0x98, (byte)0xea, - (byte)0x36, (byte)0x66, (byte)0xed, (byte)0xfb, (byte)0x25, (byte)0x79, (byte)0x80, (byte)0x39, - (byte)0xf7 - }; - - static byte[] output3 = Hex.decode( - "b8246b56a6ed5881aeb585d9a25b2ad790c417e080681bf1ac2bc3deb69d8bce" - + "f0c4366fec400af052a72e9b0effb5b3f2f192dbeaca03c12740057113bf1f06" - + "69ac22e9f3a7852e3c15d913cab0b8863a95c99294ce8674214954610346f4d4" - + "74b26f7c48b42ee68e1f572a1fc4026ac456b4f59f7b621ea1b9d88f64202fb1"); - - byte[] seed = { - (byte)0xaa, (byte)0xfd, (byte)0x12, (byte)0xf6, (byte)0x59, - (byte)0xca, (byte)0xe6, (byte)0x34, (byte)0x89, (byte)0xb4, - (byte)0x79, (byte)0xe5, (byte)0x07, (byte)0x6d, (byte)0xde, - (byte)0xc2, (byte)0xf0, (byte)0x6c, (byte)0xb5, (byte)0x8f - }; - - private class VecRand extends SecureRandom - { - byte[] seed; - - VecRand(byte[] seed) - { - this.seed = seed; - } - - public void nextBytes( - byte[] bytes) - { - System.arraycopy(seed, 0, bytes, 0, bytes.length); - } - } - - private void baseOaepTest( - int id, - byte[] pubKeyEnc, - byte[] privKeyEnc, - byte[] output) - throws Exception - { - ByteArrayInputStream bIn = new ByteArrayInputStream(pubKeyEnc); - ASN1InputStream dIn = new ASN1InputStream(bIn); - - // - // extract the public key info. - // - RSAPublicKey pubStruct; - - pubStruct = RSAPublicKey.getInstance(SubjectPublicKeyInfo.getInstance(dIn.readObject()).parsePublicKey()); - - - bIn = new ByteArrayInputStream(privKeyEnc); - dIn = new ASN1InputStream(bIn); - - // - // extract the private key info. - // - RSAPrivateKey privStruct; - - privStruct = RSAPrivateKey.getInstance(PrivateKeyInfo.getInstance(dIn.readObject()).parsePrivateKey()); - - RSAKeyParameters pubParameters = new RSAKeyParameters( - false, - pubStruct.getModulus(), - pubStruct.getPublicExponent()); - - RSAKeyParameters privParameters = new RSAPrivateCrtKeyParameters( - privStruct.getModulus(), - privStruct.getPublicExponent(), - privStruct.getPrivateExponent(), - privStruct.getPrime1(), - privStruct.getPrime2(), - privStruct.getExponent1(), - privStruct.getExponent2(), - privStruct.getCoefficient()); - - byte[] input = new byte[] - { (byte)0x54, (byte)0x85, (byte)0x9b, (byte)0x34, (byte)0x2c, (byte)0x49, (byte)0xea, (byte)0x2a }; - - encDec("id(" + id + ")", pubParameters, privParameters, seed, input, output); - - } - - private void encDec( - String label, - RSAKeyParameters pubParameters, - RSAKeyParameters privParameters, - byte[] seed, - byte[] input, - byte[] output) - throws InvalidCipherTextException - { - AsymmetricBlockCipher cipher = new OAEPEncoding(new RSAEngine()); - - cipher.init(true, new ParametersWithRandom(pubParameters, new VecRand(seed))); - - byte[] out; - - out = cipher.processBlock(input, 0, input.length); - - for (int i = 0; i != output.length; i++) - { - if (out[i] != output[i]) - { - fail(label + " failed encryption"); - } - } - - cipher.init(false, privParameters); - - out = cipher.processBlock(output, 0, output.length); - - for (int i = 0; i != input.length; i++) - { - if (out[i] != input[i]) - { - fail(label + " failed decoding"); - } - } - } - - /* - * RSA vector tests from PKCS#1 page - */ - byte[] modulus_1024 = Hex.decode( - "a8b3b284af8eb50b387034a860f146c4" - + "919f318763cd6c5598c8ae4811a1e0ab" - + "c4c7e0b082d693a5e7fced675cf46685" - + "12772c0cbc64a742c6c630f533c8cc72" - + "f62ae833c40bf25842e984bb78bdbf97" - + "c0107d55bdb662f5c4e0fab9845cb514" - + "8ef7392dd3aaff93ae1e6b667bb3d424" - + "7616d4f5ba10d4cfd226de88d39f16fb"); - - byte[] pubExp_1024 = Hex.decode( - "010001"); - - byte[] privExp_1024 = Hex.decode( - "53339cfdb79fc8466a655c7316aca85c" - + "55fd8f6dd898fdaf119517ef4f52e8fd" - + "8e258df93fee180fa0e4ab29693cd83b" - + "152a553d4ac4d1812b8b9fa5af0e7f55" - + "fe7304df41570926f3311f15c4d65a73" - + "2c483116ee3d3d2d0af3549ad9bf7cbf" - + "b78ad884f84d5beb04724dc7369b31de" - + "f37d0cf539e9cfcdd3de653729ead5d1"); - - byte[] prime1_1024 = Hex.decode( - "d32737e7267ffe1341b2d5c0d150a81b" - + "586fb3132bed2f8d5262864a9cb9f30a" - + "f38be448598d413a172efb802c21acf1" - + "c11c520c2f26a471dcad212eac7ca39d"); - - byte[] prime2_1024 = Hex.decode( - "cc8853d1d54da630fac004f471f281c7" - + "b8982d8224a490edbeb33d3e3d5cc93c" - + "4765703d1dd791642f1f116a0dd852be" - + "2419b2af72bfe9a030e860b0288b5d77"); - - byte[] primeExp1_1024 = Hex.decode( - "0e12bf1718e9cef5599ba1c3882fe804" - + "6a90874eefce8f2ccc20e4f2741fb0a3" - + "3a3848aec9c9305fbecbd2d76819967d" - + "4671acc6431e4037968db37878e695c1"); - - byte[] primeExp2_1024 = Hex.decode( - "95297b0f95a2fa67d00707d609dfd4fc" - + "05c89dafc2ef6d6ea55bec771ea33373" - + "4d9251e79082ecda866efef13c459e1a" - + "631386b7e354c899f5f112ca85d71583"); - - byte[] crtCoef_1024 = Hex.decode( - "4f456c502493bdc0ed2ab756a3a6ed4d" - + "67352a697d4216e93212b127a63d5411" - + "ce6fa98d5dbefd73263e372814274381" - + "8166ed7dd63687dd2a8ca1d2f4fbd8e1"); - - byte[] input_1024_1 = Hex.decode( - "6628194e12073db03ba94cda9ef95323" - + "97d50dba79b987004afefe34"); - - byte[] seed_1024_1 = Hex.decode( - "18b776ea21069d69776a33e96bad48e1" - + "dda0a5ef"); - - byte[] output_1024_1 = Hex.decode( - "354fe67b4a126d5d35fe36c777791a3f" - + "7ba13def484e2d3908aff722fad468fb" - + "21696de95d0be911c2d3174f8afcc201" - + "035f7b6d8e69402de5451618c21a535f" - + "a9d7bfc5b8dd9fc243f8cf927db31322" - + "d6e881eaa91a996170e657a05a266426" - + "d98c88003f8477c1227094a0d9fa1e8c" - + "4024309ce1ecccb5210035d47ac72e8a"); - - byte[] input_1024_2 = Hex.decode( - "750c4047f547e8e41411856523298ac9" - + "bae245efaf1397fbe56f9dd5"); - - byte[] seed_1024_2 = Hex.decode( - "0cc742ce4a9b7f32f951bcb251efd925" - + "fe4fe35f"); - - byte[] output_1024_2 = Hex.decode( - "640db1acc58e0568fe5407e5f9b701df" - + "f8c3c91e716c536fc7fcec6cb5b71c11" - + "65988d4a279e1577d730fc7a29932e3f" - + "00c81515236d8d8e31017a7a09df4352" - + "d904cdeb79aa583adcc31ea698a4c052" - + "83daba9089be5491f67c1a4ee48dc74b" - + "bbe6643aef846679b4cb395a352d5ed1" - + "15912df696ffe0702932946d71492b44"); - - byte[] input_1024_3 = Hex.decode( - "d94ae0832e6445ce42331cb06d531a82" - + "b1db4baad30f746dc916df24d4e3c245" - + "1fff59a6423eb0e1d02d4fe646cf699d" - + "fd818c6e97b051"); - - byte[] seed_1024_3 = Hex.decode( - "2514df4695755a67b288eaf4905c36ee" - + "c66fd2fd"); - - byte[] output_1024_3 = Hex.decode( - "423736ed035f6026af276c35c0b3741b" - + "365e5f76ca091b4e8c29e2f0befee603" - + "595aa8322d602d2e625e95eb81b2f1c9" - + "724e822eca76db8618cf09c5343503a4" - + "360835b5903bc637e3879fb05e0ef326" - + "85d5aec5067cd7cc96fe4b2670b6eac3" - + "066b1fcf5686b68589aafb7d629b02d8" - + "f8625ca3833624d4800fb081b1cf94eb"); - - byte[] input_1024_4 = Hex.decode( - "52e650d98e7f2a048b4f86852153b97e" - + "01dd316f346a19f67a85"); - - byte[] seed_1024_4 = Hex.decode( - "c4435a3e1a18a68b6820436290a37cef" - + "b85db3fb"); - - byte[] output_1024_4 = Hex.decode( - "45ead4ca551e662c9800f1aca8283b05" - + "25e6abae30be4b4aba762fa40fd3d38e" - + "22abefc69794f6ebbbc05ddbb1121624" - + "7d2f412fd0fba87c6e3acd888813646f" - + "d0e48e785204f9c3f73d6d8239562722" - + "dddd8771fec48b83a31ee6f592c4cfd4" - + "bc88174f3b13a112aae3b9f7b80e0fc6" - + "f7255ba880dc7d8021e22ad6a85f0755"); - - byte[] input_1024_5 = Hex.decode( - "8da89fd9e5f974a29feffb462b49180f" - + "6cf9e802"); - - byte[] seed_1024_5 = Hex.decode( - "b318c42df3be0f83fea823f5a7b47ed5" - + "e425a3b5"); - - byte[] output_1024_5 = Hex.decode( - "36f6e34d94a8d34daacba33a2139d00a" - + "d85a9345a86051e73071620056b920e2" - + "19005855a213a0f23897cdcd731b4525" - + "7c777fe908202befdd0b58386b1244ea" - + "0cf539a05d5d10329da44e13030fd760" - + "dcd644cfef2094d1910d3f433e1c7c6d" - + "d18bc1f2df7f643d662fb9dd37ead905" - + "9190f4fa66ca39e869c4eb449cbdc439"); - - byte[] input_1024_6 = Hex.decode( - "26521050844271"); - - byte[] seed_1024_6 = Hex.decode( - "e4ec0982c2336f3a677f6a356174eb0c" - + "e887abc2"); - - byte[] output_1024_6 = Hex.decode( - "42cee2617b1ecea4db3f4829386fbd61" - + "dafbf038e180d837c96366df24c097b4" - + "ab0fac6bdf590d821c9f10642e681ad0" - + "5b8d78b378c0f46ce2fad63f74e0ad3d" - + "f06b075d7eb5f5636f8d403b9059ca76" - + "1b5c62bb52aa45002ea70baace08ded2" - + "43b9d8cbd62a68ade265832b56564e43" - + "a6fa42ed199a099769742df1539e8255"); - - byte[] modulus_1027 = Hex.decode( - "051240b6cc0004fa48d0134671c078c7" - + "c8dec3b3e2f25bc2564467339db38853" - + "d06b85eea5b2de353bff42ac2e46bc97" - + "fae6ac9618da9537a5c8f553c1e35762" - + "5991d6108dcd7885fb3a25413f53efca" - + "d948cb35cd9b9ae9c1c67626d113d57d" - + "de4c5bea76bb5bb7de96c00d07372e96" - + "85a6d75cf9d239fa148d70931b5f3fb0" - + "39"); - - byte[] pubExp_1027 = Hex.decode( - "010001"); - - byte[] privExp_1027 = Hex.decode( - "0411ffca3b7ca5e9e9be7fe38a85105e" - + "353896db05c5796aecd2a725161eb365" - + "1c8629a9b862b904d7b0c7b37f8cb5a1" - + "c2b54001018a00a1eb2cafe4ee4e9492" - + "c348bc2bedab4b9ebbf064e8eff322b9" - + "009f8eec653905f40df88a3cdc49d456" - + "7f75627d41aca624129b46a0b7c698e5" - + "e65f2b7ba102c749a10135b6540d0401"); - - byte[] prime1_1027 = Hex.decode( - "027458c19ec1636919e736c9af25d609" - + "a51b8f561d19c6bf6943dd1ee1ab8a4a" - + "3f232100bd40b88decc6ba235548b6ef" - + "792a11c9de823d0a7922c7095b6eba57" - + "01"); - - byte[] prime2_1027 = Hex.decode( - "0210ee9b33ab61716e27d251bd465f4b" - + "35a1a232e2da00901c294bf22350ce49" - + "0d099f642b5375612db63ba1f2038649" - + "2bf04d34b3c22bceb909d13441b53b51" - + "39"); - - byte[] primeExp1_1027 = Hex.decode( - "39fa028b826e88c1121b750a8b242fa9" - + "a35c5b66bdfd1fa637d3cc48a84a4f45" - + "7a194e7727e49f7bcc6e5a5a412657fc" - + "470c7322ebc37416ef458c307a8c0901"); - - byte[] primeExp2_1027 = Hex.decode( - "015d99a84195943979fa9e1be2c3c1b6" - + "9f432f46fd03e47d5befbbbfd6b1d137" - + "1d83efb330a3e020942b2fed115e5d02" - + "be24fd92c9019d1cecd6dd4cf1e54cc8" - + "99"); - - byte[] crtCoef_1027 = Hex.decode( - "01f0b7015170b3f5e42223ba30301c41" - + "a6d87cbb70e30cb7d3c67d25473db1f6" - + "cbf03e3f9126e3e97968279a865b2c2b" - + "426524cfc52a683d31ed30eb984be412" - + "ba"); - - byte[] input_1027_1 = Hex.decode( - "4a86609534ee434a6cbca3f7e962e76d" - + "455e3264c19f605f6e5ff6137c65c56d" - + "7fb344cd52bc93374f3d166c9f0c6f9c" - + "506bad19330972d2"); - - byte[] seed_1027_1 = Hex.decode( - "1cac19ce993def55f98203f6852896c9" - + "5ccca1f3"); - - byte[] output_1027_1 = Hex.decode( - "04cce19614845e094152a3fe18e54e33" - + "30c44e5efbc64ae16886cb1869014cc5" - + "781b1f8f9e045384d0112a135ca0d12e" - + "9c88a8e4063416deaae3844f60d6e96f" - + "e155145f4525b9a34431ca3766180f70" - + "e15a5e5d8e8b1a516ff870609f13f896" - + "935ced188279a58ed13d07114277d75c" - + "6568607e0ab092fd803a223e4a8ee0b1" - + "a8"); - - byte[] input_1027_2 = Hex.decode( - "b0adc4f3fe11da59ce992773d9059943" - + "c03046497ee9d9f9a06df1166db46d98" - + "f58d27ec074c02eee6cbe2449c8b9fc5" - + "080c5c3f4433092512ec46aa793743c8"); - - byte[] seed_1027_2 = Hex.decode( - "f545d5897585e3db71aa0cb8da76c51d" - + "032ae963"); - - byte[] output_1027_2 = Hex.decode( - "0097b698c6165645b303486fbf5a2a44" - + "79c0ee85889b541a6f0b858d6b6597b1" - + "3b854eb4f839af03399a80d79bda6578" - + "c841f90d645715b280d37143992dd186" - + "c80b949b775cae97370e4ec97443136c" - + "6da484e970ffdb1323a20847821d3b18" - + "381de13bb49aaea66530c4a4b8271f3e" - + "ae172cd366e07e6636f1019d2a28aed1" - + "5e"); - - byte[] input_1027_3 = Hex.decode( - "bf6d42e701707b1d0206b0c8b45a1c72" - + "641ff12889219a82bdea965b5e79a96b" - + "0d0163ed9d578ec9ada20f2fbcf1ea3c" - + "4089d83419ba81b0c60f3606da99"); - - byte[] seed_1027_3 = Hex.decode( - "ad997feef730d6ea7be60d0dc52e72ea" - + "cbfdd275"); - - byte[] output_1027_3 = Hex.decode( - "0301f935e9c47abcb48acbbe09895d9f" - + "5971af14839da4ff95417ee453d1fd77" - + "319072bb7297e1b55d7561cd9d1bb24c" - + "1a9a37c619864308242804879d86ebd0" - + "01dce5183975e1506989b70e5a834341" - + "54d5cbfd6a24787e60eb0c658d2ac193" - + "302d1192c6e622d4a12ad4b53923bca2" - + "46df31c6395e37702c6a78ae081fb9d0" - + "65"); - - byte[] input_1027_4 = Hex.decode( - "fb2ef112f5e766eb94019297934794f7" - + "be2f6fc1c58e"); - - byte[] seed_1027_4 = Hex.decode( - "136454df5730f73c807a7e40d8c1a312" - + "ac5b9dd3"); - - byte[] output_1027_4 = Hex.decode( - "02d110ad30afb727beb691dd0cf17d0a" - + "f1a1e7fa0cc040ec1a4ba26a42c59d0a" - + "796a2e22c8f357ccc98b6519aceb682e" - + "945e62cb734614a529407cd452bee3e4" - + "4fece8423cc19e55548b8b994b849c7e" - + "cde4933e76037e1d0ce44275b08710c6" - + "8e430130b929730ed77e09b015642c55" - + "93f04e4ffb9410798102a8e96ffdfe11" - + "e4"); - - byte[] input_1027_5 = Hex.decode( - "28ccd447bb9e85166dabb9e5b7d1adad" - + "c4b9d39f204e96d5e440ce9ad928bc1c" - + "2284"); - - byte[] seed_1027_5 = Hex.decode( - "bca8057f824b2ea257f2861407eef63d" - + "33208681"); - - byte[] output_1027_5 = Hex.decode( - "00dbb8a7439d90efd919a377c54fae8f" - + "e11ec58c3b858362e23ad1b8a4431079" - + "9066b99347aa525691d2adc58d9b06e3" - + "4f288c170390c5f0e11c0aa3645959f1" - + "8ee79e8f2be8d7ac5c23d061f18dd74b" - + "8c5f2a58fcb5eb0c54f99f01a8324756" - + "8292536583340948d7a8c97c4acd1e98" - + "d1e29dc320e97a260532a8aa7a758a1e" - + "c2"); - - byte[] input_1027_6 = Hex.decode( - "f22242751ec6b1"); - - byte[] seed_1027_6 = Hex.decode( - "2e7e1e17f647b5ddd033e15472f90f68" - + "12f3ac4e"); - - byte[] output_1027_6 = Hex.decode( - "00a5ffa4768c8bbecaee2db77e8f2eec" - + "99595933545520835e5ba7db9493d3e1" - + "7cddefe6a5f567624471908db4e2d83a" - + "0fbee60608fc84049503b2234a07dc83" - + "b27b22847ad8920ff42f674ef79b7628" - + "0b00233d2b51b8cb2703a9d42bfbc825" - + "0c96ec32c051e57f1b4ba528db89c37e" - + "4c54e27e6e64ac69635ae887d9541619" - + "a9"); - - private void oaepVecTest( - int keySize, - int no, - RSAKeyParameters pubParam, - RSAKeyParameters privParam, - byte[] seed, - byte[] input, - byte[] output) - throws Exception - { - encDec(keySize + " " + no, pubParam, privParam, seed, input, output); - } - - public OAEPTest() - { - } - - public String getName() - { - return "OAEP"; - } - - public void performTest() throws Exception - { - baseOaepTest(1, pubKeyEnc1, privKeyEnc1, output1); - baseOaepTest(2, pubKeyEnc2, privKeyEnc2, output2); - baseOaepTest(3, pubKeyEnc3, privKeyEnc3, output3); - - RSAKeyParameters pubParam = new RSAKeyParameters(false, new BigInteger(1, modulus_1024), new BigInteger(1, pubExp_1024)); - RSAKeyParameters privParam = new RSAPrivateCrtKeyParameters(pubParam.getModulus(), pubParam.getExponent(), new BigInteger(1, privExp_1024), new BigInteger(1, prime1_1024), new BigInteger(1, prime2_1024), new BigInteger(1, primeExp1_1024), new BigInteger(1, primeExp2_1024), new BigInteger(1, crtCoef_1024)); - - oaepVecTest(1024, 1, pubParam, privParam, seed_1024_1, input_1024_1, output_1024_1); - oaepVecTest(1024, 2, pubParam, privParam, seed_1024_2, input_1024_2, output_1024_2); - oaepVecTest(1024, 3, pubParam, privParam, seed_1024_3, input_1024_3, output_1024_3); - oaepVecTest(1024, 4, pubParam, privParam, seed_1024_4, input_1024_4, output_1024_4); - oaepVecTest(1024, 5, pubParam, privParam, seed_1024_5, input_1024_5, output_1024_5); - oaepVecTest(1024, 6, pubParam, privParam, seed_1024_6, input_1024_6, output_1024_6); - - pubParam = new RSAKeyParameters(false, new BigInteger(1, modulus_1027), new BigInteger(1, pubExp_1027)); - privParam = new RSAPrivateCrtKeyParameters(pubParam.getModulus(), pubParam.getExponent(), new BigInteger(1, privExp_1027), new BigInteger(1, prime1_1027), new BigInteger(1, prime2_1027), new BigInteger(1, primeExp1_1027), new BigInteger(1, primeExp2_1027), new BigInteger(1, crtCoef_1027)); - - oaepVecTest(1027, 1, pubParam, privParam, seed_1027_1, input_1027_1, output_1027_1); - oaepVecTest(1027, 2, pubParam, privParam, seed_1027_2, input_1027_2, output_1027_2); - oaepVecTest(1027, 3, pubParam, privParam, seed_1027_3, input_1027_3, output_1027_3); - oaepVecTest(1027, 4, pubParam, privParam, seed_1027_4, input_1027_4, output_1027_4); - oaepVecTest(1027, 5, pubParam, privParam, seed_1027_5, input_1027_5, output_1027_5); - oaepVecTest(1027, 6, pubParam, privParam, seed_1027_6, input_1027_6, output_1027_6); - - testForHighByteError("invalidCiphertextOaepTest 1024", 1024); - - // - // OAEP - public encrypt, private decrypt, differing hashes - // - AsymmetricBlockCipher cipher = new OAEPEncoding(new RSAEngine(), new SHA256Digest(), new SHA1Digest(), new byte[10]); - - cipher.init(true, new ParametersWithRandom(pubParam, new SecureRandom())); - - byte[] input = new byte[10]; - - byte[] out = cipher.processBlock(input, 0, input.length); - - cipher.init(false, privParam); - - out = cipher.processBlock(out, 0, out.length); - - for (int i = 0; i != input.length; i++) - { - if (out[i] != input[i]) - { - fail("mixed digest failed decoding"); - } - } - - cipher = new OAEPEncoding(new RSAEngine(), new SHA1Digest(), new SHA256Digest(), new byte[10]); - - cipher.init(true, new ParametersWithRandom(pubParam, new SecureRandom())); - - out = cipher.processBlock(input, 0, input.length); - - cipher.init(false, privParam); - - out = cipher.processBlock(out, 0, out.length); - - for (int i = 0; i != input.length; i++) - { - if (out[i] != input[i]) - { - fail("mixed digest failed decoding"); - } - } - } - - private void testForHighByteError(String label, int keySizeBits) throws Exception - { - // draw a key of the size asked - BigInteger e = BigIntegers.ONE.shiftLeft(16).add(BigIntegers.ONE); - - AsymmetricCipherKeyPairGenerator kpGen = new RSAKeyPairGenerator(); - - kpGen.init(new RSAKeyGenerationParameters(e, new SecureRandom(), keySizeBits, 100)); - - AsymmetricCipherKeyPair kp = kpGen.generateKeyPair(); - - AsymmetricBlockCipher cipher = new OAEPEncoding(new RSAEngine()); - - // obtain a known good ciphertext - cipher.init(true, new ParametersWithRandom(kp.getPublic(), new VecRand(seed))); - byte[] m = { 42 }; - byte[] c = cipher.processBlock(m, 0, m.length); - int keySizeBytes = (keySizeBits+7)>>>3; - if (c.length!=keySizeBytes) - { - fail(label + " failed ciphertext size"); - } - - BigInteger n = ((RSAPrivateCrtKeyParameters)kp.getPrivate()).getModulus(); - - // decipher - cipher.init(false, kp.getPrivate()); - byte[] r = cipher.processBlock(c, 0, keySizeBytes); - if (r.length!=1 || r[0]!=42) - { - fail(label + " failed first decryption of test message"); - } - - // decipher again - r = cipher.processBlock(c, 0, keySizeBytes); - if (r.length!=1 || r[0]!=42) - { - fail(label + " failed second decryption of test message"); - } - - // check hapazard incorrect ciphertexts - for(int i=keySizeBytes*8; --i>=0;) - { - c[i>>>3] ^= 1<<(i&7); - boolean ko = true; - try - { - BigInteger cV = new BigInteger(1, c); - - // don't pass in c if it will be rejected trivially - if (cV.compareTo(n) < 0) - { - r = cipher.processBlock(c, 0, keySizeBytes); - } - else - { - ko = false; // size errors are picked up at start - } - } - catch (InvalidCipherTextException exception) - { - ko = false; - } - if (ko) - { - fail(label + " invalid ciphertext caused no exception"); - } - c[i>>>3] ^= 1<<(i&7); - } - } - - public static void main( - String[] args) - { - runTest(new OAEPTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/OCBTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/OCBTest.java deleted file mode 100644 index 789367888..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/OCBTest.java +++ /dev/null @@ -1,520 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.modes.AEADBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.OCBBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.AEADParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Times; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test vectors from RFC 7253 on The OCB - * Authenticated-Encryption Algorithm - */ -public class OCBTest - extends SimpleTest -{ - private static final String KEY_128 = "000102030405060708090A0B0C0D0E0F"; - private static final String KEY_96 = "0F0E0D0C0B0A09080706050403020100"; - - /* - * Test vectors from Appendix A of the specification, containing the strings N, A, P, C in order - */ - - private static final String[][] TEST_VECTORS_128 = new String[][]{ - { "BBAA99887766554433221100", - "", - "", - "785407BFFFC8AD9EDCC5520AC9111EE6" }, - { "BBAA99887766554433221101", - "0001020304050607", - "0001020304050607", - "6820B3657B6F615A5725BDA0D3B4EB3A257C9AF1F8F03009" }, - { "BBAA99887766554433221102", - "0001020304050607", - "", - "81017F8203F081277152FADE694A0A00" }, - { "BBAA99887766554433221103", - "", - "0001020304050607", - "45DD69F8F5AAE72414054CD1F35D82760B2CD00D2F99BFA9" }, - { "BBAA99887766554433221104", - "000102030405060708090A0B0C0D0E0F", - "000102030405060708090A0B0C0D0E0F", - "571D535B60B277188BE5147170A9A22C3AD7A4FF3835B8C5701C1CCEC8FC3358" }, - { "BBAA99887766554433221105", - "000102030405060708090A0B0C0D0E0F", - "", - "8CF761B6902EF764462AD86498CA6B97" }, - { "BBAA99887766554433221106", - "", - "000102030405060708090A0B0C0D0E0F", - "5CE88EC2E0692706A915C00AEB8B2396F40E1C743F52436BDF06D8FA1ECA343D" }, - { "BBAA99887766554433221107", - "000102030405060708090A0B0C0D0E0F1011121314151617", - "000102030405060708090A0B0C0D0E0F1011121314151617", - "1CA2207308C87C010756104D8840CE1952F09673A448A122C92C62241051F57356D7F3C90BB0E07F" }, - { "BBAA99887766554433221108", - "000102030405060708090A0B0C0D0E0F1011121314151617", - "", - "6DC225A071FC1B9F7C69F93B0F1E10DE" }, - { "BBAA99887766554433221109", - "", - "000102030405060708090A0B0C0D0E0F1011121314151617", - "221BD0DE7FA6FE993ECCD769460A0AF2D6CDED0C395B1C3CE725F32494B9F914D85C0B1EB38357FF" }, - { "BBAA9988776655443322110A", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F", - "BD6F6C496201C69296C11EFD138A467ABD3C707924B964DEAFFC40319AF5A48540FBBA186C5553C68AD9F592A79A4240" }, - { "BBAA9988776655443322110B", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F", - "", - "FE80690BEE8A485D11F32965BC9D2A32" }, - { "BBAA9988776655443322110C", - "", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F", - "2942BFC773BDA23CABC6ACFD9BFD5835BD300F0973792EF46040C53F1432BCDFB5E1DDE3BC18A5F840B52E653444D5DF" }, - { "BBAA9988776655443322110D", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627", - "D5CA91748410C1751FF8A2F618255B68A0A12E093FF454606E59F9C1D0DDC54B65E8628E568BAD7AED07BA06A4A69483A7035490C5769E60" }, - { "BBAA9988776655443322110E", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627", - "", - "C5CD9D1850C141E358649994EE701B68" }, - { "BBAA9988776655443322110F", - "", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627", - "4412923493C57D5DE0D700F753CCE0D1D2D95060122E9F15A5DDBFC5787E50B5CC55EE507BCB084E479AD363AC366B95A98CA5F3000B1479" }, - }; - - private static final String[][] TEST_VECTORS_96 = new String[][]{ - { "BBAA9988776655443322110D", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627", - "1792A4E31E0755FB03E31B22116E6C2DDF9EFD6E33D536F1A0124B0A55BAE884ED93481529C76B6AD0C515F4D1CDD4FDAC4F02AA" }, - }; - - public String getName() - { - return "OCB"; - } - - public void performTest() - throws Exception - { - byte[] K128 = Hex.decode(KEY_128); - for (int i = 0; i < TEST_VECTORS_128.length; ++i) - { - runTestCase("Test Case " + i, TEST_VECTORS_128[i], 128, K128); - } - - byte[] K96 = Hex.decode(KEY_96); - for (int i = 0; i < TEST_VECTORS_96.length; ++i) - { - runTestCase("Test Case " + i, TEST_VECTORS_96[i], 96, K96); - } - - runLongerTestCase(128, 128, "67E944D23256C5E0B6C61FA22FDF1EA2"); - runLongerTestCase(192, 128, "F673F2C3E7174AAE7BAE986CA9F29E17"); - runLongerTestCase(256, 128, "D90EB8E9C977C88B79DD793D7FFA161C"); - runLongerTestCase(128, 96, "77A3D8E73589158D25D01209"); - runLongerTestCase(192, 96, "05D56EAD2752C86BE6932C5E"); - runLongerTestCase(256, 96, "5458359AC23B0CBA9E6330DD"); - runLongerTestCase(128, 64, "192C9B7BD90BA06A"); - runLongerTestCase(192, 64, "0066BC6E0EF34E24"); - runLongerTestCase(256, 64, "7D4EA5D445501CBE"); - - randomTests(); - outputSizeTests(); - testExceptions(); - } - - private void testExceptions() throws InvalidCipherTextException - { - AEADBlockCipher ocb = createOCBCipher(); - - try - { - ocb = new OCBBlockCipher(new DESEngine(), new DESEngine()); - - fail("incorrect block size not picked up"); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - ocb.init(false, new KeyParameter(new byte[16])); - - fail("illegal argument not picked up"); - } - catch (IllegalArgumentException e) - { - // expected - } - - AEADTestUtil.testReset(this, createOCBCipher(), createOCBCipher(), new AEADParameters(new KeyParameter(new byte[16]), 128, new byte[15])); - AEADTestUtil.testTampering(this, ocb, new AEADParameters(new KeyParameter(new byte[16]), 128, new byte[15])); - AEADTestUtil.testOutputSizes(this, createOCBCipher(), new AEADParameters(new KeyParameter(new byte[16]), 128, - new byte[15])); - AEADTestUtil.testBufferSizeChecks(this, createOCBCipher(), new AEADParameters(new KeyParameter(new byte[16]), - 128, new byte[15])); - } - - private void runTestCase(String testName, String[] testVector, int macLengthBits, byte[] K) - throws InvalidCipherTextException - { - int pos = 0; - byte[] N = Hex.decode(testVector[pos++]); - byte[] A = Hex.decode(testVector[pos++]); - byte[] P = Hex.decode(testVector[pos++]); - byte[] C = Hex.decode(testVector[pos++]); - - int macLengthBytes = macLengthBits / 8; - - KeyParameter keyParameter = new KeyParameter(K); - AEADParameters parameters = new AEADParameters(keyParameter, macLengthBits, N, A); - - AEADBlockCipher encCipher = initOCBCipher(true, parameters); - AEADBlockCipher decCipher = initOCBCipher(false, parameters); - - checkTestCase(encCipher, decCipher, testName, macLengthBytes, P, C); - checkTestCase(encCipher, decCipher, testName + " (reused)", macLengthBytes, P, C); - - // Key reuse - AEADParameters keyReuseParams = AEADTestUtil.reuseKey(parameters); - encCipher.init(true, keyReuseParams); - decCipher.init(false, keyReuseParams); - checkTestCase(encCipher, decCipher, testName + " (key reuse)", macLengthBytes, P, C); - } - - private BlockCipher createUnderlyingCipher() - { - return new AESEngine(); - } - - private AEADBlockCipher createOCBCipher() - { - return new OCBBlockCipher(createUnderlyingCipher(), createUnderlyingCipher()); - } - - private AEADBlockCipher initOCBCipher(boolean forEncryption, AEADParameters parameters) - { - AEADBlockCipher c = createOCBCipher(); - c.init(forEncryption, parameters); - return c; - } - - private void checkTestCase(AEADBlockCipher encCipher, AEADBlockCipher decCipher, String testName, - int macLengthBytes, byte[] P, byte[] C) - throws InvalidCipherTextException - { - byte[] tag = Arrays.copyOfRange(C, C.length - macLengthBytes, C.length); - - { - byte[] enc = new byte[encCipher.getOutputSize(P.length)]; - int len = encCipher.processBytes(P, 0, P.length, enc, 0); - len += encCipher.doFinal(enc, len); - - if (enc.length != len) - { - fail("encryption reported incorrect length: " + testName); - } - - if (!areEqual(C, enc)) - { - fail("incorrect encrypt in: " + testName); - } - - if (!areEqual(tag, encCipher.getMac())) - { - fail("getMac() not the same as the appended tag: " + testName); - } - } - - { - byte[] dec = new byte[decCipher.getOutputSize(C.length)]; - int len = decCipher.processBytes(C, 0, C.length, dec, 0); - len += decCipher.doFinal(dec, len); - - if (dec.length != len) - { - fail("decryption reported incorrect length: " + testName); - } - - if (!areEqual(P, dec)) - { - fail("incorrect decrypt in: " + testName); - } - - if (!areEqual(tag, decCipher.getMac())) - { - fail("getMac() not the same as the appended tag: " + testName); - } - } - } - - private void runLongerTestCase(int keyLen, int tagLen, String expectedOutputHex) - throws InvalidCipherTextException - { - byte[] expectedOutput = Hex.decode(expectedOutputHex); - byte[] keyBytes = new byte[keyLen / 8]; - keyBytes[keyBytes.length - 1] = (byte)tagLen; - KeyParameter key = new KeyParameter(keyBytes); - - AEADBlockCipher c1 = initOCBCipher(true, new AEADParameters(key, tagLen, createNonce(385))); - AEADBlockCipher c2 = createOCBCipher(); - - long total = 0; - - byte[] S = new byte[128]; - - int n = 0; - for (int i = 0; i < 128; ++i) - { - c2.init(true, new AEADParameters(key, tagLen, createNonce(++n))); - total += updateCiphers(c1, c2, S, i, true, true); - c2.init(true, new AEADParameters(key, tagLen, createNonce(++n))); - total += updateCiphers(c1, c2, S, i, false, true); - c2.init(true, new AEADParameters(key, tagLen, createNonce(++n))); - total += updateCiphers(c1, c2, S, i, true, false); - } - - long expectedTotal = 16256 + (48 * tagLen); - - if (total != expectedTotal) - { - fail("test generated the wrong amount of input: " + total); - } - - byte[] output = new byte[c1.getOutputSize(0)]; - c1.doFinal(output, 0); - - if (!areEqual(expectedOutput, output)) - { - fail("incorrect encrypt in long-form test"); - } - } - - private byte[] createNonce(int n) - { - return new byte[]{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte)(n >>> 8), (byte)n }; - } - - private int updateCiphers(AEADBlockCipher c1, AEADBlockCipher c2, byte[] S, int i, - boolean includeAAD, boolean includePlaintext) - throws InvalidCipherTextException - { - int inputLen = includePlaintext ? i : 0; - int outputLen = c2.getOutputSize(inputLen); - - byte[] output = new byte[outputLen]; - - int len = 0; - - if (includeAAD) - { - c2.processAADBytes(S, 0, i); - } - - if (includePlaintext) - { - len += c2.processBytes(S, 0, i, output, len); - } - - len += c2.doFinal(output, len); - - c1.processAADBytes(output, 0, len); - - return len; - } - - private void randomTests() - throws InvalidCipherTextException - { - SecureRandom srng = new SecureRandom(); - srng.setSeed(Times.nanoTime()); - for (int i = 0; i < 10; ++i) - { - randomTest(srng); - } - } - - private void randomTest(SecureRandom srng) - throws InvalidCipherTextException - { - int kLength = 16 + 8 * (Math.abs(srng.nextInt()) % 3); - byte[] K = new byte[kLength]; - srng.nextBytes(K); - - int pLength = srng.nextInt() >>> 16; - byte[] P = new byte[pLength]; - srng.nextBytes(P); - - int aLength = srng.nextInt() >>> 24; - byte[] A = new byte[aLength]; - srng.nextBytes(A); - - int saLength = srng.nextInt() >>> 24; - byte[] SA = new byte[saLength]; - srng.nextBytes(SA); - - int ivLength = 1 + nextInt(srng, 15); - byte[] IV = new byte[ivLength]; - srng.nextBytes(IV); - - AEADParameters parameters = new AEADParameters(new KeyParameter(K), 16 * 8, IV, A); - AEADBlockCipher cipher = initOCBCipher(true, parameters); - byte[] C = new byte[cipher.getOutputSize(P.length)]; - int predicted = cipher.getUpdateOutputSize(P.length); - - int split = nextInt(srng, SA.length + 1); - cipher.processAADBytes(SA, 0, split); - int len = cipher.processBytes(P, 0, P.length, C, 0); - cipher.processAADBytes(SA, split, SA.length - split); - - if (predicted != len) - { - fail("encryption reported incorrect update length in randomised test"); - } - - len += cipher.doFinal(C, len); - - if (C.length != len) - { - fail("encryption reported incorrect length in randomised test"); - } - - byte[] encT = cipher.getMac(); - byte[] tail = new byte[C.length - P.length]; - System.arraycopy(C, P.length, tail, 0, tail.length); - - if (!areEqual(encT, tail)) - { - fail("stream contained wrong mac in randomised test"); - } - - cipher.init(false, parameters); - byte[] decP = new byte[cipher.getOutputSize(C.length)]; - predicted = cipher.getUpdateOutputSize(C.length); - - split = nextInt(srng, SA.length + 1); - cipher.processAADBytes(SA, 0, split); - len = cipher.processBytes(C, 0, C.length, decP, 0); - cipher.processAADBytes(SA, split, SA.length - split); - - if (predicted != len) - { - fail("decryption reported incorrect update length in randomised test"); - } - - len += cipher.doFinal(decP, len); - - if (!areEqual(P, decP)) - { - fail("incorrect decrypt in randomised test"); - } - - byte[] decT = cipher.getMac(); - if (!areEqual(encT, decT)) - { - fail("decryption produced different mac from encryption"); - } - - // - // key reuse test - // - cipher.init(false, AEADTestUtil.reuseKey(parameters)); - decP = new byte[cipher.getOutputSize(C.length)]; - - split = nextInt(srng, SA.length + 1); - cipher.processAADBytes(SA, 0, split); - len = cipher.processBytes(C, 0, C.length, decP, 0); - cipher.processAADBytes(SA, split, SA.length - split); - - len += cipher.doFinal(decP, len); - - if (!areEqual(P, decP)) - { - fail("incorrect decrypt in randomised test"); - } - - decT = cipher.getMac(); - if (!areEqual(encT, decT)) - { - fail("decryption produced different mac from encryption"); - } - } - - private void outputSizeTests() - { - byte[] K = new byte[16]; - byte[] A = null; - byte[] IV = new byte[15]; - - AEADParameters parameters = new AEADParameters(new KeyParameter(K), 16 * 8, IV, A); - AEADBlockCipher cipher = initOCBCipher(true, parameters); - - if (cipher.getUpdateOutputSize(0) != 0) - { - fail("incorrect getUpdateOutputSize for initial 0 bytes encryption"); - } - - if (cipher.getOutputSize(0) != 16) - { - fail("incorrect getOutputSize for initial 0 bytes encryption"); - } - - cipher.init(false, parameters); - - if (cipher.getUpdateOutputSize(0) != 0) - { - fail("incorrect getUpdateOutputSize for initial 0 bytes decryption"); - } - - // NOTE: 0 bytes would be truncated data, but we want it to fail in the doFinal, not here - if (cipher.getOutputSize(0) != 0) - { - fail("fragile getOutputSize for initial 0 bytes decryption"); - } - - if (cipher.getOutputSize(16) != 0) - { - fail("incorrect getOutputSize for initial MAC-size bytes decryption"); - } - } - - private static int nextInt(SecureRandom rand, int n) - { - if ((n & -n) == n) // i.e., n is a power of 2 - { - return (int)((n * (long)(rand.nextInt() >>> 1)) >> 31); - } - - int bits, value; - do - { - bits = rand.nextInt() >>> 1; - value = bits % n; - } - while (bits - value + (n - 1) < 0); - - return value; - } - - public static void main(String[] args) - { - runTest(new OCBTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/OpenBSDBCryptTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/OpenBSDBCryptTest.java deleted file mode 100644 index 3b39919c5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/OpenBSDBCryptTest.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.generators.OpenBSDBCrypt; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class OpenBSDBCryptTest - extends SimpleTest -{ - - private final static String[][] bcryptTest1 = // vectors from http://cvsweb.openwall.com/cgi/cvsweb.cgi/Owl/packages/glibc/crypt_blowfish/wrapper.c?rev=HEAD - { - {"$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW", - "U*U"}, - {"$2a$05$CCCCCCCCCCCCCCCCCCCCC.VGOzA784oUp/Z0DY336zx7pLYAy0lwK", - "U*U*"}, - {"$2a$05$XXXXXXXXXXXXXXXXXXXXXOAcXxm9kjPGEMsLznoKqmqw7tc8WCx4a", - "U*U*U"}, - {"$2a$05$CCCCCCCCCCCCCCCCCCCCC.7uG0VCzI2bS7j6ymqJi9CdcdxiRTWNy", - ""}, - {"$2a$05$abcdefghijklmnopqrstuu5s2v8.iXieOjg/.AySBTTZIIVFJeBui", - "0123456789abcdefghijklmnopqrstuvwxyz" - + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" - + "chars after 72 are ignored"}, - }; - - private final static String[] bcryptTest2 = { // from: http://openwall.info/wiki/john/sample-hashes - "$2a$05$bvIG6Nmid91Mu9RcmmWZfO5HJIMCT8riNW0hEp8f6/FuA2/mHZFpe", "password" - }; - - private final static String[] bcryptTest2b = { // from: http://stackoverflow.com/questions/11654684/verifying-a-bcrypt-hash - "$2a$10$.TtQJ4Jr6isd4Hp.mVfZeuh6Gws4rOQ/vdBczhDx.19NFK0Y84Dle", "\u03c0\u03c0\u03c0\u03c0\u03c0\u03c0\u03c0\u03c0" - }; - - private final static String[][] bcryptTest3 = // from: https://bitbucket.org/vadim/bcrypt.net/src/464c41416dc9/BCrypt.Net.Test/TestBCrypt.cs - plain - salt - expected - { - {"", "$2a$06$DCq7YPn5Rq63x1Lad4cll.", "$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s."}, - {"", "$2a$08$HqWuK6/Ng6sg9gQzbLrgb.", "$2a$08$HqWuK6/Ng6sg9gQzbLrgb.Tl.ZHfXLhvt/SgVyWhQqgqcZ7ZuUtye"}, - {"", "$2a$10$k1wbIrmNyFAPwPVPSVa/ze", "$2a$10$k1wbIrmNyFAPwPVPSVa/zecw2BCEnBwVS2GbrmgzxFUOqW9dk4TCW"}, - {"", "$2a$12$k42ZFHFWqBp3vWli.nIn8u", "$2a$12$k42ZFHFWqBp3vWli.nIn8uYyIkbvYRvodzbfbK18SSsY.CsIQPlxO"}, - {"a", "$2a$06$m0CrhHm10qJ3lXRY.5zDGO", "$2a$06$m0CrhHm10qJ3lXRY.5zDGO3rS2KdeeWLuGmsfGlMfOxih58VYVfxe"}, - {"a", "$2a$08$cfcvVd2aQ8CMvoMpP2EBfe", "$2a$08$cfcvVd2aQ8CMvoMpP2EBfeodLEkkFJ9umNEfPD18.hUF62qqlC/V."}, - {"a", "$2a$10$k87L/MF28Q673VKh8/cPi.", "$2a$10$k87L/MF28Q673VKh8/cPi.SUl7MU/rWuSiIDDFayrKk/1tBsSQu4u"}, - {"a", "$2a$12$8NJH3LsPrANStV6XtBakCe", "$2a$12$8NJH3LsPrANStV6XtBakCez0cKHXVxmvxIlcz785vxAIZrihHZpeS"}, - {"abc", "$2a$06$If6bvum7DFjUnE9p2uDeDu", "$2a$06$If6bvum7DFjUnE9p2uDeDu0YHzrHM6tf.iqN8.yx.jNN1ILEf7h0i"}, - {"abc", "$2a$08$Ro0CUfOqk6cXEKf3dyaM7O", "$2a$08$Ro0CUfOqk6cXEKf3dyaM7OhSCvnwM9s4wIX9JeLapehKK5YdLxKcm"}, - {"abc", "$2a$10$WvvTPHKwdBJ3uk0Z37EMR.", "$2a$10$WvvTPHKwdBJ3uk0Z37EMR.hLA2W6N9AEBhEgrAOljy2Ae5MtaSIUi"}, - {"abc", "$2a$12$EXRkfkdmXn2gzds2SSitu.", "$2a$12$EXRkfkdmXn2gzds2SSitu.MW9.gAVqa9eLS1//RYtYCmB1eLHg.9q"}, - {"abcdefghijklmnopqrstuvwxyz", "$2a$06$.rCVZVOThsIa97pEDOxvGu", "$2a$06$.rCVZVOThsIa97pEDOxvGuRRgzG64bvtJ0938xuqzv18d3ZpQhstC"}, - {"abcdefghijklmnopqrstuvwxyz", "$2a$08$aTsUwsyowQuzRrDqFflhge", "$2a$08$aTsUwsyowQuzRrDqFflhgekJ8d9/7Z3GV3UcgvzQW3J5zMyrTvlz."}, - {"abcdefghijklmnopqrstuvwxyz", "$2a$10$fVH8e28OQRj9tqiDXs1e1u", "$2a$10$fVH8e28OQRj9tqiDXs1e1uxpsjN0c7II7YPKXua2NAKYvM6iQk7dq"}, - {"abcdefghijklmnopqrstuvwxyz", "$2a$12$D4G5f18o7aMMfwasBL7Gpu", "$2a$12$D4G5f18o7aMMfwasBL7GpuQWuP3pkrZrOAnqP.bmezbMng.QwJ/pG"}, - {"~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2a$06$fPIsBO8qRqkjj273rfaOI.", "$2a$06$fPIsBO8qRqkjj273rfaOI.HtSV9jLDpTbZn782DC6/t7qT67P6FfO"}, - {"~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2a$08$Eq2r4G/76Wv39MzSX262hu", "$2a$08$Eq2r4G/76Wv39MzSX262huzPz612MZiYHVUJe/OcOql2jo4.9UxTW"}, - {"~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2a$10$LgfYWkbzEvQ4JakH7rOvHe", "$2a$10$LgfYWkbzEvQ4JakH7rOvHe0y8pHKF9OaFgwUZ2q7W2FFZmZzJYlfS"}, - {"~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2a$12$WApznUOJfkEGSmYRfnkrPO", "$2a$12$WApznUOJfkEGSmYRfnkrPOr466oFDCaj4b6HY3EXGvfxm43seyhgC"}, - }; - - private static final String[][] bcryptTest4 = { // from: https://github.com/ChrisMcKee/cryptsharp/blob/master/Tests/vectors/BCrypt.txt - {"n6HyjrYTo/r4lgjvM7L<`iM", "$2a$07$XPrYfnqc5ankSHnRfmPVu.A0trKq3VdczdbJjKaWIksKF.GfFCxv."}, - {"~s0quB/K8zRtRT:QtZr`s|^O", "$2a$07$5zzz8omiaStXwOetWwlmuePPRwUt0jhNBPYGGgAMcUDvqsGVqv9Cy"}, - {"r>8y3uE}6<7nI34?Q2rR0JEw", "$2a$07$k5AH9bO9aplPYdZMZ155qOcY1FewMXcupWewW6fViUtsVQ2Umg6LS"}, - {">l_7}xxH3|Cr{dCR[HTUN@k~", "$2a$05$24xz81ZZsMUMm940bbWMCeHsO.s6A3MG0JZzm4y3.Ti6P96bz6RN6"}, - {"D`lCFYTe9_8IW6nEB:oPjEk/S", "$2a$05$bA1xkp4NqFvDmtQJtDO9CugW0INxQLpMZha8AaHmBj9Zg9HlfQtBa"}, - {"UBGYU6|a|RpA:bp[;}p.ZY4f1", "$2a$08$gu4KBnkla.bEqHiwaJ8.z.0ixfzE1Q0/iPfmpfRmUA.NUhUdZboxa"}, - {"O9X[kP6{63F3rXKtN>n?zh2_", "$2a$04$yRZW9xEsqN9DL19jveqFyO1bljZ0r5KNCYqQzMqYpDB7XHWqDWNGC"}, - {":Sa:BknepsG}\\5dOj>kh0KAk", "$2a$04$KhDTFUlakUsPNuLQSgyr7.xQZxkTSIvo0nFw0XyjvrH6n5kZkYDLG"},// extra escape sequence added - {"2_9J6k:{z?SSjCzL/GT/5CMgc", "$2a$05$eN1jCXDxN9HmuIARJlwH4ewsEyYbAmq7Cw99gEHqGRXtWyrRNLScy"}, - - {"2KNy`Kodau14?s8XVru- Toy example from the NaccacheSternPaper
- *- 768 bit test with text "Now is the time for all good men." (ripped from RSA test) and - * the same test with the first byte replaced by 0xFF
- *- 1024 bit test analog to 768 bit test
- *E;h/kdCRd@T]fQiv`Vz]KC0zaIAIeyY4zcooQ0^DfP{hHsw9?atO}CxbkbnK-LxUe;|FiBEluVqO@ysHhXQDdXPt0p", "$2a$07$pNHi/IxrSUohtsD5/eIv4O324ZPGfJE7mUAaNpIPkpyxjW9kqIk76"}, - {"ilWj~2mLBa1Pq`sxrW8fNNq:XF0@KP5RLW9u?[E_wwkROmCSWudYoS5I2HGI-1-?Pd0zVxTIeNbF;nLDUGtce{8dHmx90:;N<8", "$2a$07$ePVgkQl8QKSG2Xv6o0bnOe4SZp4ejag5CP44tjxfmY17F5VzRgwF6"}, - {"dj~OsXmQGj6FXnPGgwg9]G@75~L@G[|e 3KWhz.Z~jUF0tt8[5U@8;5:=[v6pf.IEJ", "$2a$08$eXo9KDc1BZyybBgMurpcD.GA1/ch3XhgBnIH10Xvjc2ogZaGg3t/m"}, - }; - - - // 2y vectors generated from htpasswd -nB -C 12, nb leading username was removed. - private static final String[][] twoYVec = new String[][]{ - {"a", "$2y$12$DB3BUbYa/SsEL7kCOVji0OauTkPkB5Y1OeyfxJHM7jvMrbml5sgD2"}, - {"abc", "$2y$12$p.xODEbFcXUlHGbNxWZqAe6AA5FWupqXmN9tZea2ACDhwIx4EA2a6"}, - {"hello world", "$2y$12$wfkxITYXjNLVpEi9nOjz7uXMhCXKSTY7O2y7X4bwY89aGSvRziguq"}, - {"ABCDEFGHIJKLMNOPQRSTUVWXYABCDEFGHIJKLMNOPQRSTUVWXYABCDEFGHIJKLMNOPQRSTUVWXYABCDEFGHIJKLMNOPQRSTUVWXY", "$2y$12$QwAt5kuG68nW7v.87q0QPuwdki3romFc/RU/RV3Qqk4FPw6WdbQzu"} - }; - - // Same as 2y vectors only version changed to 2b to verify handling of that version. - private static final String[][] twoBVec = new String[][]{ - {"a", "$2b$12$DB3BUbYa/SsEL7kCOVji0OauTkPkB5Y1OeyfxJHM7jvMrbml5sgD2"}, - {"abc", "$2b$12$p.xODEbFcXUlHGbNxWZqAe6AA5FWupqXmN9tZea2ACDhwIx4EA2a6"}, - {"hello world", "$2b$12$wfkxITYXjNLVpEi9nOjz7uXMhCXKSTY7O2y7X4bwY89aGSvRziguq"}, - {"ABCDEFGHIJKLMNOPQRSTUVWXYABCDEFGHIJKLMNOPQRSTUVWXYABCDEFGHIJKLMNOPQRSTUVWXYABCDEFGHIJKLMNOPQRSTUVWXY", "$2b$12$QwAt5kuG68nW7v.87q0QPuwdki3romFc/RU/RV3Qqk4FPw6WdbQzu"} - }; - - public static void main(String[] args) - { - runTest(new OpenBSDBCryptTest()); - } - - public String getName() - { - return "OpenBSDBCrypt"; - } - - public void performTest() - throws Exception - { - for (int i = 0; i < bcryptTest1.length; i++) - { - String[] testString = bcryptTest1[i]; - String encoded = testString[0]; - String password = testString[1]; - if (!OpenBSDBCrypt.checkPassword(encoded, password.toCharArray())) - { - fail("test1 mismatch: " + "[" + i + "] " + password); - } - } - - String encoded = bcryptTest2[0]; - String password = bcryptTest2[1]; - if (!OpenBSDBCrypt.checkPassword(encoded, password.toCharArray())) - { - fail("bcryptTest2 mismatch: " + password); - } - - - encoded = bcryptTest2b[0]; - password = bcryptTest2b[1]; - if (!OpenBSDBCrypt.checkPassword(encoded, password.toCharArray())) - { - fail("bcryptTest2b mismatch: " + password); - } - - - for (int i = 0; i < bcryptTest3.length; i++) - { - String[] testString = bcryptTest3[i]; - encoded = testString[2]; - password = testString[0]; - if (!OpenBSDBCrypt.checkPassword(encoded, password.toCharArray())) - { - fail("test3 mismatch: " + "[" + i + "] " + password); - } - } - - - for (int i = 0; i < bcryptTest4.length; i++) - { - String[] testString = bcryptTest4[i]; - encoded = testString[1]; - password = testString[0]; - if (!OpenBSDBCrypt.checkPassword(encoded, password.toCharArray())) - { - fail("test4 mismatch: " + "[" + i + "] " + password); - } - } - - for (int i = 0; i < twoYVec.length; i++) - { - password = twoYVec[i][0]; - encoded = twoYVec[i][1]; - - if (!OpenBSDBCrypt.checkPassword(encoded, password.toCharArray())) - { - fail("twoYVec mismatch: " + "[" + i + "] " + password); - } - } - - for (int i = 0; i < twoBVec.length; i++) - { - password = twoBVec[i][0]; - encoded = twoBVec[i][1]; - - if (!OpenBSDBCrypt.checkPassword(encoded, password.toCharArray())) - { - fail("twoBVec mismatch: " + "[" + i + "] " + password); - } - } - } -} - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/OpenSSHKeyParsingTests.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/OpenSSHKeyParsingTests.java deleted file mode 100644 index 05e3eea56..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/OpenSSHKeyParsingTests.java +++ /dev/null @@ -1,233 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.StringReader; -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.engines.RSAEngine; -import com.fr.third.org.bouncycastle.crypto.signers.DSASigner; -import com.fr.third.org.bouncycastle.crypto.signers.ECDSASigner; -import com.fr.third.org.bouncycastle.crypto.signers.Ed25519Signer; -import com.fr.third.org.bouncycastle.crypto.util.OpenSSHPrivateKeyUtil; -import com.fr.third.org.bouncycastle.crypto.util.OpenSSHPublicKeyUtil; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.io.pem.PemReader; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class OpenSSHKeyParsingTests - extends SimpleTest -{ - private static SecureRandom secureRandom = new SecureRandom(); - - - public static void main( - String[] args) - { - runTest(new OpenSSHKeyParsingTests()); - } - - - public void testDSA() - throws Exception - { - CipherParameters pubSpec = OpenSSHPublicKeyUtil.parsePublicKey(Base64.decode("AAAAB3NzaC1kc3MAAACBAJBB5+S4kZZYZLswaQ/zm3GM7YWmHsumwo/Xxu+z6Cg2l5PUoiBBZ4ET9EhhQuL2ja/zrCMCi0ZwiSRuSp36ayPrHLbNJb3VdOuJg8xExRa6F3YfVZfcTPUEKh6FU72fI31HrQmi4rpyHnWxL/iDX496ZG2Hdq6UkPISQpQwj4TtAAAAFQCP9TXcVahR/2rpfEhvdXR0PfhbRwAAAIBdXzAVqoOtb9zog6lNF1cGS1S06W9W/clvuwq2xF1s3bkoI/xUbFSc0IAPsGl2kcB61PAZqcop50lgpvYzt8cq/tbqz3ypq1dCQ0xdmJHj975QsRFax+w6xQ0kgpBhwcS2EOizKb+C+tRzndGpcDSoSMuVXp9i4wn5pJSTZxAYFQAAAIEAhQZc687zYxrEDR/1q6m4hw5GFxuVvLsC+bSHtMF0c11Qy4IPg7mBeP7K5Kq4WyJPtmZhuc5Bb12bJQR6qgd1uLn692fe1UK2kM6eWXBzhlzZ54BslfSKHGNN4qH+ln3Zaf/4rpKE7fvoinkrgkOZmj0PMx9D6wlpHKkXMUxeXtc=")); - - CipherParameters privSpec = OpenSSHPrivateKeyUtil.parsePrivateKeyBlob(new PemReader(new StringReader("-----BEGIN DSA PRIVATE KEY-----\n" + - "MIIBuwIBAAKBgQCQQefkuJGWWGS7MGkP85txjO2Fph7LpsKP18bvs+goNpeT1KIg\n" + - "QWeBE/RIYULi9o2v86wjAotGcIkkbkqd+msj6xy2zSW91XTriYPMRMUWuhd2H1WX\n" + - "3Ez1BCoehVO9nyN9R60JouK6ch51sS/4g1+PemRth3aulJDyEkKUMI+E7QIVAI/1\n" + - "NdxVqFH/aul8SG91dHQ9+FtHAoGAXV8wFaqDrW/c6IOpTRdXBktUtOlvVv3Jb7sK\n" + - "tsRdbN25KCP8VGxUnNCAD7BpdpHAetTwGanKKedJYKb2M7fHKv7W6s98qatXQkNM\n" + - "XZiR4/e+ULERWsfsOsUNJIKQYcHEthDosym/gvrUc53RqXA0qEjLlV6fYuMJ+aSU\n" + - "k2cQGBUCgYEAhQZc687zYxrEDR/1q6m4hw5GFxuVvLsC+bSHtMF0c11Qy4IPg7mB\n" + - "eP7K5Kq4WyJPtmZhuc5Bb12bJQR6qgd1uLn692fe1UK2kM6eWXBzhlzZ54BslfSK\n" + - "HGNN4qH+ln3Zaf/4rpKE7fvoinkrgkOZmj0PMx9D6wlpHKkXMUxeXtcCFELnLOJ8\n" + - "D0akSCUFY/iDLo/KnOIH\n" + - "-----END DSA PRIVATE KEY-----\n")).readPemObject().getContent()); - - DSASigner signer = new DSASigner(); - signer.init(true, privSpec); - - byte[] originalMessage = new byte[10]; - secureRandom.nextBytes(originalMessage); - - BigInteger[] rs = signer.generateSignature(originalMessage); - - signer.init(false, pubSpec); - - isTrue("DSA test", signer.verifySignature(originalMessage, rs[0], rs[1])); - - } - - - public void testECDSA() - throws Exception - { - CipherParameters pubSpec = OpenSSHPublicKeyUtil.parsePublicKey(Base64.decode("AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHq5qxGqnh93Gpbj2w1Avx1UwBl6z5bZC3Viog1yNHDZYcV6Da4YQ3i0/hN7xY7sUy9dNF6g16tJSYXQQ4tvO3g=")); - - CipherParameters privSpec = OpenSSHPrivateKeyUtil.parsePrivateKeyBlob(new PemReader(new StringReader("-----BEGIN EC PRIVATE KEY-----\n" + - "MHcCAQEEIHeg/+m02j6nr4bO8ubfbzhs0fqOjiuIoWbvGnVg+FmpoAoGCCqGSM49\n" + - "AwEHoUQDQgAEermrEaqeH3caluPbDUC/HVTAGXrPltkLdWKiDXI0cNlhxXoNrhhD\n" + - "eLT+E3vFjuxTL100XqDXq0lJhdBDi287eA==\n" + - "-----END EC PRIVATE KEY-----\n")).readPemObject().getContent()); - - ECDSASigner signer = new ECDSASigner(); - signer.init(true, privSpec); - - byte[] originalMessage = new byte[10]; - secureRandom.nextBytes(originalMessage); - - BigInteger[] rs = signer.generateSignature(originalMessage); - - signer.init(false, pubSpec); - - isTrue("ECDSA test", signer.verifySignature(originalMessage, rs[0], rs[1])); - - } - - - public void testED25519() - throws Exception - { - - CipherParameters pubSpec = OpenSSHPublicKeyUtil.parsePublicKey(Base64.decode("AAAAC3NzaC1lZDI1NTE5AAAAIM4CaV7WQcy0lht0hclgXf4Olyvzvv2fnUvQ3J8IYsWF")); - - CipherParameters privSpec = OpenSSHPrivateKeyUtil.parsePrivateKeyBlob(new PemReader(new StringReader("-----BEGIN OPENSSH PRIVATE KEY-----\n" + - "b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\n" + - "QyNTUxOQAAACDOAmle1kHMtJYbdIXJYF3+Dpcr8779n51L0NyfCGLFhQAAAKBTr4PvU6+D\n" + - "7wAAAAtzc2gtZWQyNTUxOQAAACDOAmle1kHMtJYbdIXJYF3+Dpcr8779n51L0NyfCGLFhQ\n" + - "AAAED4BTHeR3YD7CFQqusztfL5K+YSD4mRGLBwb7jHiXxIJM4CaV7WQcy0lht0hclgXf4O\n" + - "lyvzvv2fnUvQ3J8IYsWFAAAAG21lZ2Fud29vZHNAdHljaGUtMzI2NS5sb2NhbAEC\n" + - "-----END OPENSSH PRIVATE KEY-----\n")).readPemObject().getContent()); - - Ed25519Signer signer = new Ed25519Signer(); - signer.init(true, privSpec); - - byte[] originalMessage = new byte[10]; - secureRandom.nextBytes(originalMessage); - signer.update(originalMessage, 0, originalMessage.length); - - byte[] sig = signer.generateSignature(); - - signer.init(false, pubSpec); - - signer.update(originalMessage, 0, originalMessage.length); - - - isTrue("ED25519Signer test", signer.verifySignature(sig)); - - } - - - public void testFailures() - throws Exception - { - byte[] blob = new PemReader(new StringReader("-----BEGIN OPENSSH PRIVATE KEY-----\n" + - "b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\n" + - "QyNTUxOQAAACDOAmle1kHMtJYbdIXJYF3+Dpcr8779n51L0NyfCGLFhQAAAKBTr4PvU6+D\n" + - "7wAAAAtzc2gtZWQyNTUxOQAAACDOAmle1kHMtJYbdIXJYF3+Dpcr8779n51L0NyfCGLFhQ\n" + - "AAAED4BTHeR3YD7CFQqusztfL5K+YSD4mRGLBwb7jHiXxIJM4CaV7WQcy0lht0hclgXf4O\n" + - "lyvzvv2fnUvQ3J8IYsWFAAAAG21lZ2Fud29vZHNAdHljaGUtMzI2NS5sb2NhbAEC\n" + - "-----END OPENSSH PRIVATE KEY-----\n")).readPemObject().getContent(); - - - // - // Altering the check value. - // - - blob[98] ^= 1; - - try - { - CipherParameters privSpec = OpenSSHPrivateKeyUtil.parsePrivateKeyBlob(blob); - fail("Change should trigger failure."); - } - catch (IllegalStateException iles) - { - isEquals("Check value mismatch ", iles.getMessage(), "private key check values are not the same"); - } - - - // - // Altering the cipher name. - // - - - blob = new PemReader(new StringReader("-----BEGIN OPENSSH PRIVATE KEY-----\n" + - "b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\n" + - "QyNTUxOQAAACDOAmle1kHMtJYbdIXJYF3+Dpcr8779n51L0NyfCGLFhQAAAKBTr4PvU6+D\n" + - "7wAAAAtzc2gtZWQyNTUxOQAAACDOAmle1kHMtJYbdIXJYF3+Dpcr8779n51L0NyfCGLFhQ\n" + - "AAAED4BTHeR3YD7CFQqusztfL5K+YSD4mRGLBwb7jHiXxIJM4CaV7WQcy0lht0hclgXf4O\n" + - "lyvzvv2fnUvQ3J8IYsWFAAAAG21lZ2Fud29vZHNAdHljaGUtMzI2NS5sb2NhbAEC\n" + - "-----END OPENSSH PRIVATE KEY-----\n")).readPemObject().getContent(); - - - blob[19] = (byte)'C'; - - try - { - CipherParameters privSpec = OpenSSHPrivateKeyUtil.parsePrivateKeyBlob(blob); - fail("Change should trigger failure."); - } - catch (IllegalStateException iles) - { - isEquals("enc keys not supported ", iles.getMessage(), "encrypted keys not supported"); - } - } - - public String getName() - { - return "OpenSSHParsing"; - } - - public void performTest() - throws Exception - { - testDSA(); - testECDSA(); - testRSA(); - testED25519(); - testFailures(); - } - - public void testRSA() - throws Exception - { - CipherParameters pubSpec = OpenSSHPublicKeyUtil.parsePublicKey(Base64.decode("AAAAB3NzaC1yc2EAAAADAQABAAAAgQDvh2BophdIp8ojwGZQR0FQ/awowXnV24nAPm+/na8MOUrdySNhOnlek4LAZl82/+Eu2t21XD6hQUiHKAj6XaNFBthTuss7Cz/tA348DLEMHD9wUtT0FXVmsxqN4BfusunbcULxxVWG2z8FvqeaGgc/Unkp9y7/kyf54pPUCBcClw==")); - - CipherParameters privSpec = OpenSSHPrivateKeyUtil.parsePrivateKeyBlob(new PemReader(new StringReader("-----BEGIN RSA PRIVATE KEY-----\n" + - "MIICXgIBAAKBgQDvh2BophdIp8ojwGZQR0FQ/awowXnV24nAPm+/na8MOUrdySNh\n" + - "Onlek4LAZl82/+Eu2t21XD6hQUiHKAj6XaNFBthTuss7Cz/tA348DLEMHD9wUtT0\n" + - "FXVmsxqN4BfusunbcULxxVWG2z8FvqeaGgc/Unkp9y7/kyf54pPUCBcClwIDAQAB\n" + - "AoGBAOMXYEoXHgAeREE9CkOWKtDUkEJbnF0rNSB0kZIDt5BJSTeYmNh3jdYi2FX9\n" + - "OMx2MFIx4v0tJZvQvyiUxl5IJJ9ZJsYUWF+6VbcTVwYYfdVzZzP2TNyGmF9/ADZW\n" + - "wBehqP04uRlYjt94kqb4HoOKF3gJ3LC4uW9xcEltTBeHWCfhAkEA/2biF5St9/Ya\n" + - "540E4zu/FKPsxLSaT8LWCo9+X7IqIzlBQCB4GjM+nZeTm7eZOkfAFZoxwfiNde/9\n" + - "qleXXf6B2QJBAPAW+jDBC3QF4/g8n9cDxm/A3ICmcOFSychLSrydk9ZyRPbTRyQC\n" + - "YlC2mf/pCrO/yO7h189BXyQ3PXOEhnujce8CQQD7gDy0K90EiH0F94AQpA0OLj5B\n" + - "lfc/BAXycEtpwPBtrzvqAg9C/aNzXIgmly10jqNAoo7NDA2BTcrlq0uLa8xBAkBl\n" + - "7Hs+I1XnZXDIO4Rn1VRysN9rRj15ipnbDAuoUwUl7tDUMBFteg2e0kZCW/6NHIgC\n" + - "0aG6fLgVOdY+qi4lYtfFAkEAqqiBgEgSrDmnJLTm6j/Pv1mBA6b9bJbjOqomrDtr\n" + - "AWTXe+/kSCv/jYYdpNA/tDgAwEmtkWWEie6+SwJB5cXXqg==\n" + - "-----END RSA PRIVATE KEY-----\n")).readPemObject().getContent()); - - - byte[] originalMessage = new byte[10]; - secureRandom.nextBytes(originalMessage); - - originalMessage[0] |= 1; - - RSAEngine rsaEngine = new RSAEngine(); - rsaEngine.init(true, privSpec); - - byte[] ct = rsaEngine.processBlock(originalMessage, 0, originalMessage.length); - - rsaEngine.init(false, pubSpec); - byte[] result = rsaEngine.processBlock(ct, 0, ct.length); - - isTrue("Result did not match original message", Arrays.areEqual(originalMessage, result)); - - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PKCS12Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PKCS12Test.java deleted file mode 100644 index 4bcdab758..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PKCS12Test.java +++ /dev/null @@ -1,206 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.PBEParametersGenerator; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.generators.PKCS12ParametersGenerator; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * test for PKCS12 key generation - vectors from - * - * http://www.drh-consultancy.demon.co.uk/test.txt - */ -public class PKCS12Test - implements Test -{ - char[] password1 = { 's', 'm', 'e', 'g' }; - char[] password2 = { 'q', 'u', 'e', 'e', 'g' }; - - private boolean isEqual( - byte[] a, - byte[] b) - { - if (a.length != b.length) - { - return false; - } - - for (int i = 0; i != a.length; i++) - { - if (a[i] != b[i]) - { - return false; - } - } - - return true; - } - - private TestResult run1( - int id, - char[] password, - byte[] salt, - int iCount, - byte[] result) - { - PBEParametersGenerator generator = new PKCS12ParametersGenerator( - new SHA1Digest()); - - generator.init( - PBEParametersGenerator.PKCS12PasswordToBytes(password), - salt, - iCount); - - CipherParameters key = generator.generateDerivedParameters(24 * 8); - - if (isEqual(result, ((KeyParameter)key).getKey())) - { - return new SimpleTestResult(true, "PKCS12Test: Okay"); - } - else - { - return new SimpleTestResult(false, "PKCS12Test: id " - + id + " Failed"); - } - } - - private TestResult run2( - int id, - char[] password, - byte[] salt, - int iCount, - byte[] result) - { - PBEParametersGenerator generator = new PKCS12ParametersGenerator( - new SHA1Digest()); - - generator.init( - PBEParametersGenerator.PKCS12PasswordToBytes(password), - salt, - iCount); - - ParametersWithIV params = (ParametersWithIV)generator.generateDerivedParameters(64, 64); - - if (isEqual(result, params.getIV())) - { - return new SimpleTestResult(true, "PKCS12Test: Okay"); - } - else - { - return new SimpleTestResult(false, "PKCS12Test: id " - + id + " Failed"); - } - } - - private TestResult run3( - int id, - char[] password, - byte[] salt, - int iCount, - byte[] result) - { - PBEParametersGenerator generator = new PKCS12ParametersGenerator( - new SHA1Digest()); - - generator.init( - PBEParametersGenerator.PKCS12PasswordToBytes(password), - salt, - iCount); - - CipherParameters key = generator.generateDerivedMacParameters(160); - - if (isEqual(result, ((KeyParameter)key).getKey())) - { - return new SimpleTestResult(true, "PKCS12Test: Okay"); - } - else - { - return new SimpleTestResult(false, "PKCS12Test: id " - + id + " Failed"); - } - } - - public String getName() - { - return "PKCS12Test"; - } - - public TestResult perform() - { - TestResult result; - - result = run1(1, password1, Hex.decode("0A58CF64530D823F"), 1, - Hex.decode("8AAAE6297B6CB04642AB5B077851284EB7128F1A2A7FBCA3")); - - if (result.isSuccessful()) - { - result = run2(2, password1, Hex.decode("0A58CF64530D823F"), 1, - Hex.decode("79993DFE048D3B76")); - } - - if (result.isSuccessful()) - { - result = run1(3, password1, Hex.decode("642B99AB44FB4B1F"), 1, - Hex.decode("F3A95FEC48D7711E985CFE67908C5AB79FA3D7C5CAA5D966")); - } - - if (result.isSuccessful()) - { - result = run2(4, password1, Hex.decode("642B99AB44FB4B1F"), 1, - Hex.decode("C0A38D64A79BEA1D")); - } - - if (result.isSuccessful()) - { - result = run3(5, password1, Hex.decode("3D83C0E4546AC140"), 1, - Hex.decode("8D967D88F6CAA9D714800AB3D48051D63F73A312")); - } - - if (result.isSuccessful()) - { - result = run1(6, password2, Hex.decode("05DEC959ACFF72F7"), 1000, - Hex.decode("ED2034E36328830FF09DF1E1A07DD357185DAC0D4F9EB3D4")); - } - - if (result.isSuccessful()) - { - result = run2(7, password2, Hex.decode("05DEC959ACFF72F7"), 1000, - Hex.decode("11DEDAD7758D4860")); - } - - if (result.isSuccessful()) - { - result = run1(8, password2, Hex.decode("1682C0FC5B3F7EC5"), 1000, - Hex.decode("483DD6E919D7DE2E8E648BA8F862F3FBFBDC2BCB2C02957F")); - } - - if (result.isSuccessful()) - { - result = run2(9, password2, Hex.decode("1682C0FC5B3F7EC5"), 1000, - Hex.decode("9D461D1B00355C50")); - } - - if (result.isSuccessful()) - { - result = run3(10, password2, Hex.decode("263216FCC2FAB31C"), 1000, - Hex.decode("5EC4C7A80DF652294C3925B6489A7AB857C83476")); - } - - return result; - } - - public static void main( - String[] args) - { - PKCS12Test test = new PKCS12Test(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PKCS5Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PKCS5Test.java deleted file mode 100644 index 2c2cd87a2..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PKCS5Test.java +++ /dev/null @@ -1,265 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.ByteArrayInputStream; - -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1OctetString; -import com.fr.third.org.bouncycastle.asn1.pkcs.EncryptedPrivateKeyInfo; -import com.fr.third.org.bouncycastle.asn1.pkcs.EncryptionScheme; -import com.fr.third.org.bouncycastle.asn1.pkcs.KeyDerivationFunc; -import com.fr.third.org.bouncycastle.asn1.pkcs.PBES2Parameters; -import com.fr.third.org.bouncycastle.asn1.pkcs.PBKDF2Params; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.pkcs.RC2CBCParameter; -import com.fr.third.org.bouncycastle.crypto.BufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.PBEParametersGenerator; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESedeEngine; -import com.fr.third.org.bouncycastle.crypto.engines.RC2Engine; -import com.fr.third.org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * A test class for PKCS5 PBES2 with PBKDF2 (PKCS5 v2.0) using - * test vectors provider at - * - * RSA's PKCS5 Page - *
- * The vectors are Base 64 encoded and encrypted using the password "password" - * (without quotes). They should all yield the same PrivateKeyInfo object. - */ -public class PKCS5Test - extends SimpleTest -{ - /** - * encrypted using des-cbc. - */ - static byte[] sample1 = Base64.decode( - "MIIBozA9BgkqhkiG9w0BBQ0wMDAbBgkqhkiG9w0BBQwwDgQIfWBDXwLp4K4CAggA" - + "MBEGBSsOAwIHBAiaCF/AvOgQ6QSCAWDWX4BdAzCRNSQSANSuNsT5X8mWYO27mr3Y" - + "9c9LoBVXGNmYWKA77MI4967f7SmjNcgXj3xNE/jmnVz6hhsjS8E5VPT3kfyVkpdZ" - + "0lr5e9Yk2m3JWpPU7++v5zBkZmC4V/MwV/XuIs6U+vykgzMgpxQg0oZKS9zgmiZo" - + "f/4dOCL0UtCDnyOSvqT7mCVIcMDIEKu8QbVlgZYBop08l60EuEU3gARUo8WsYQmO" - + "Dz/ldx0Z+znIT0SXVuOwc+RVItC5T/Qx+aijmmpt+9l14nmaGBrEkmuhmtdvU/4v" - + "aptewGRgmjOfD6cqK+zs0O5NrrJ3P/6ZSxXj91CQgrThGfOv72bUncXEMNtc8pks" - + "2jpHFjGMdKufnadAD7XuMgzkkaklEXZ4f5tU6heIIwr51g0GBEGF96gYPFnjnSQM" - + "75JE02Clo+DfcfXpcybPTwwFg2jd6JTTOfkdf6OdSlA/1XNK43FA"); - - /** - * encrypted using des-ede3-cbc. - */ - static byte[] sample2 = Base64.decode( - "MIIBpjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIeFeOWl1jywYCAggA" - + "MBQGCCqGSIb3DQMHBAjUJ5eGBhQGtQSCAWBrHrRgqO8UUMLcWzZEtpk1l3mjxiF/" - + "koCMkHsFwowgyWhEbgIkTgbSViK54LVK8PskekcGNLph+rB6bGZ7pPbL5pbXASJ8" - + "+MkQcG3FZdlS4Ek9tTJDApj3O1UubZGFG4uvTlJJFbF1BOJ3MkY3XQ9Gl1qwv7j5" - + "6e103Da7Cq9+oIDKmznza78XXQYrUsPo8mJGjUxPskEYlzwvHjKubRnYm/K6RKhi" - + "5f4zX4BQ/Dt3H812ZjRXrsjAJP0KrD/jyD/jCT7zNBVPH1izBds+RwizyQAHwfNJ" - + "BFR78TH4cgzB619X47FDVOnT0LqQNVd0O3cSwnPrXE9XR3tPayE+iOB15llFSmi8" - + "z0ByOXldEpkezCn92Umk++suzIVj1qfsK+bv2phZWJPbLEIWPDRHUbYf76q5ArAr" - + "u4xtxT/hoK3krEs/IN3d70qjlUJ36SEw1UaZ82PWhakQbdtu39ZraMJB"); - - /** - * encrypted using rc2-cbc. - */ - static byte[] sample3 = Base64.decode( - "MIIBrjBIBgkqhkiG9w0BBQ0wOzAeBgkqhkiG9w0BBQwwEQQIrHyQPBZqWLUCAggA" - + "AgEQMBkGCCqGSIb3DQMCMA0CAToECEhbh7YZKiPSBIIBYCT1zp6o5jpFlIkgwPop" - + "7bW1+8ACr4exqzkeb3WflQ8cWJ4cURxzVdvxUnXeW1VJdaQZtjS/QHs5GhPTG/0f" - + "wtvnaPfwrIJ3FeGaZfcg2CrYhalOFmEb4xrE4KyoEQmUN8tb/Cg94uzd16BOPw21" - + "RDnE8bnPdIGY7TyL95kbkqH23mK53pi7h+xWIgduW+atIqDyyt55f7WMZcvDvlj6" - + "VpN/V0h+qxBHL274WA4dj6GYgeyUFpi60HdGCK7By2TBy8h1ZvKGjmB9h8jZvkx1" - + "MkbRumXxyFsowTZawyYvO8Um6lbfEDP9zIEUq0IV8RqH2MRyblsPNSikyYhxX/cz" - + "tdDxRKhilySbSBg5Kr8OfcwKp9bpinN96nmG4xr3Tch1bnVvqJzOQ5+Vva2WwVvH" - + "2JkWvYm5WaANg4Q6bRxu9vz7DuhbJjQdZbxFezIAgrJdSe92B00jO/0Kny1WjiVO" - + "6DA="); - - static byte[] result = Hex.decode( - "30820155020100300d06092a864886f70d01010105000482013f3082013b020100024100" - + "debbfc2c09d61bada2a9462f24224e54cc6b3cc0755f15ce318ef57e79df17026b6a85cc" - + "a12428027245045df2052a329a2f9ad3d17b78a10572ad9b22bf343b020301000102402d" - + "90a96adcec472743527bc023153d8f0d6e96b40c8ed228276d467d843306429f8670559b" - + "f376dd41857f6397c2fc8d95e0e53ed62de420b855430ee4a1b8a1022100ffcaf0838239" - + "31e073ff534f06a5d415b3d414bc614a4544a3dff7ed271817eb022100deea30242117db" - + "2d3b8837f58f1da530ff83cf9283680da33683ec4e583610f1022100e6026381adb0a683" - + "f16a8f4c096b462979b9e4277cc89f3ed8a905b46fa9ff9f02210097c146d4d1d2b3dbaf" - + "53a504ff51674c5c271800de84d003f4f10ac6ab36e38102202bfa141f10bda874e1017d" - + "845e82767c1c38e82745daf421f0c8cd09d7652387"); - - private class PBETest - extends SimpleTest - { - int id; - BufferedBlockCipher cipher; - byte[] sample; - int keySize; - - PBETest( - int id, - BufferedBlockCipher cipher, - byte[] sample, - int keySize) - { - this.id = id; - this.cipher = cipher; - this.sample = sample; - this.keySize = keySize; - } - - public String getName() - { - return cipher.getUnderlyingCipher().getAlgorithmName() + " PKCS5S2 Test " + id; - } - - public void performTest() - { - char[] password = { 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' }; - PBEParametersGenerator generator = new PKCS5S2ParametersGenerator(); - ByteArrayInputStream bIn = new ByteArrayInputStream(sample); - ASN1InputStream dIn = new ASN1InputStream(bIn); - EncryptedPrivateKeyInfo info = null; - - try - { - info = EncryptedPrivateKeyInfo.getInstance(dIn.readObject()); - } - catch (Exception e) - { - fail("failed construction - exception " + e.toString(), e); - } - - PBES2Parameters alg = PBES2Parameters.getInstance(info.getEncryptionAlgorithm().getParameters()); - PBKDF2Params func = PBKDF2Params.getInstance(alg.getKeyDerivationFunc().getParameters()); - EncryptionScheme scheme = alg.getEncryptionScheme(); - - if (func.getKeyLength() != null) - { - keySize = func.getKeyLength().intValue() * 8; - } - - int iterationCount = func.getIterationCount().intValue(); - byte[] salt = func.getSalt(); - - generator.init( - PBEParametersGenerator.PKCS5PasswordToBytes(password), - salt, - iterationCount); - - CipherParameters param; - - if (scheme.getAlgorithm().equals(PKCSObjectIdentifiers.RC2_CBC)) - { - RC2CBCParameter rc2Params = RC2CBCParameter.getInstance(scheme.getParameters()); - byte[] iv = rc2Params.getIV(); - - param = new ParametersWithIV(generator.generateDerivedParameters(keySize), iv); - } - else - { - byte[] iv = ASN1OctetString.getInstance(scheme.getParameters()).getOctets(); - - param = new ParametersWithIV(generator.generateDerivedParameters(keySize), iv); - } - - cipher.init(false, param); - - byte[] data = info.getEncryptedData(); - byte[] out = new byte[cipher.getOutputSize(data.length)]; - int len = cipher.processBytes(data, 0, data.length, out, 0); - - try - { - len += cipher.doFinal(out, len); - } - catch (Exception e) - { - fail("failed doFinal - exception " + e.toString()); - } - - if (result.length != len) - { - fail("failed length"); - } - - for (int i = 0; i != len; i++) - { - if (out[i] != result[i]) - { - fail("failed comparison"); - } - } - } - } - - public String getName() - { - return "PKCS5S2"; - } - - public void performTest() - throws Exception - { - BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new DESEngine())); - SimpleTest test = new PBETest(0, cipher, sample1, 64); - - test.performTest(); - - cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new DESedeEngine())); - test = new PBETest(1, cipher, sample2, 192); - - test.performTest(); - - cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new RC2Engine())); - test = new PBETest(2, cipher, sample3, 0); - test.performTest(); - - // - // RFC 3211 tests - // - char[] password = { 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' }; - PBEParametersGenerator generator = new PKCS5S2ParametersGenerator(); - - byte[] salt = Hex.decode("1234567878563412"); - - generator.init( - PBEParametersGenerator.PKCS5PasswordToBytes(password), - salt, - 5); - - if (!areEqual(((KeyParameter)generator.generateDerivedParameters(64)).getKey(), Hex.decode("d1daa78615f287e6"))) - { - fail("64 test failed"); - } - - password = "All n-entities must communicate with other n-entities via n-1 entiteeheehees".toCharArray(); - - generator.init( - PBEParametersGenerator.PKCS5PasswordToBytes(password), - salt, - 500); - - if (!areEqual(((KeyParameter)generator.generateDerivedParameters(192)).getKey(), Hex.decode("6a8970bf68c92caea84a8df28510858607126380cc47ab2d"))) - { - fail("192 test failed"); - } - - generator.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt, 60000); - if (!areEqual(((KeyParameter)generator.generateDerivedParameters(192)).getKey(), Hex.decode("29aaef810c12ecd2236bbcfb55407f9852b5573dc1c095bb"))) - { - fail("192 (60000) test failed"); - } - } - - public static void main( - String[] args) - { - runTest(new PKCS5Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PSSBlindTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PSSBlindTest.java deleted file mode 100644 index de938182a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PSSBlindTest.java +++ /dev/null @@ -1,398 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.engines.RSABlindingEngine; -import com.fr.third.org.bouncycastle.crypto.engines.RSAEngine; -import com.fr.third.org.bouncycastle.crypto.generators.RSABlindingFactorGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.RSAKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.params.RSABlindingParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters; -import com.fr.third.org.bouncycastle.crypto.signers.PSSSigner; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -import java.math.BigInteger; -import java.security.SecureRandom; - -/* - * RSA PSS test vectors for PKCS#1 V2.1 with blinding - */ -public class PSSBlindTest - extends SimpleTest -{ - private final int DATA_LENGTH = 1000; - private final int NUM_TESTS = 50; - private final int NUM_TESTS_WITH_KEY_GENERATION = 10; - - private class FixedRandom - extends SecureRandom - { - byte[] vals; - - FixedRandom( - byte[] vals) - { - this.vals = vals; - } - - public void nextBytes( - byte[] bytes) - { - System.arraycopy(vals, 0, bytes, 0, vals.length); - } - } - - // - // Example 1: A 1024-bit RSA keypair - // - private RSAKeyParameters pub1 = new RSAKeyParameters(false, - new BigInteger("a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cffb2249bd9a2137",16), - new BigInteger("010001",16)); - - private RSAKeyParameters prv1 = new RSAPrivateCrtKeyParameters( - new BigInteger("a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cffb2249bd9a2137",16), - new BigInteger("010001",16), - new BigInteger("33a5042a90b27d4f5451ca9bbbd0b44771a101af884340aef9885f2a4bbe92e894a724ac3c568c8f97853ad07c0266c8c6a3ca0929f1e8f11231884429fc4d9ae55fee896a10ce707c3ed7e734e44727a39574501a532683109c2abacaba283c31b4bd2f53c3ee37e352cee34f9e503bd80c0622ad79c6dcee883547c6a3b325",16), - new BigInteger("e7e8942720a877517273a356053ea2a1bc0c94aa72d55c6e86296b2dfc967948c0a72cbccca7eacb35706e09a1df55a1535bd9b3cc34160b3b6dcd3eda8e6443",16), - new BigInteger("b69dca1cf7d4d7ec81e75b90fcca874abcde123fd2700180aa90479b6e48de8d67ed24f9f19d85ba275874f542cd20dc723e6963364a1f9425452b269a6799fd",16), - new BigInteger("28fa13938655be1f8a159cbaca5a72ea190c30089e19cd274a556f36c4f6e19f554b34c077790427bbdd8dd3ede2448328f385d81b30e8e43b2fffa027861979",16), - new BigInteger("1a8b38f398fa712049898d7fb79ee0a77668791299cdfa09efc0e507acb21ed74301ef5bfd48be455eaeb6e1678255827580a8e4e8e14151d1510a82a3f2e729",16), - new BigInteger("27156aba4126d24a81f3a528cbfb27f56886f840a9f6e86e17a44b94fe9319584b8e22fdde1e5a2e3bd8aa5ba8d8584194eb2190acf832b847f13a3d24a79f4d",16)); - - // PSSExample1.1 - - private byte[] msg1a = Hex.decode("cdc87da223d786df3b45e0bbbc721326d1ee2af806cc315475cc6f0d9c66e1b62371d45ce2392e1ac92844c310102f156a0d8d52c1f4c40ba3aa65095786cb769757a6563ba958fed0bcc984e8b517a3d5f515b23b8a41e74aa867693f90dfb061a6e86dfaaee64472c00e5f20945729cbebe77f06ce78e08f4098fba41f9d6193c0317e8b60d4b6084acb42d29e3808a3bc372d85e331170fcbf7cc72d0b71c296648b3a4d10f416295d0807aa625cab2744fd9ea8fd223c42537029828bd16be02546f130fd2e33b936d2676e08aed1b73318b750a0167d0"); - - private byte[] slt1a = Hex.decode("dee959c7e06411361420ff80185ed57f3e6776af"); - - private byte[] sig1a = Hex.decode("9074308fb598e9701b2294388e52f971faac2b60a5145af185df5287b5ed2887e57ce7fd44dc8634e407c8e0e4360bc226f3ec227f9d9e54638e8d31f5051215df6ebb9c2f9579aa77598a38f914b5b9c1bd83c4e2f9f382a0d0aa3542ffee65984a601bc69eb28deb27dca12c82c2d4c3f66cd500f1ff2b994d8a4e30cbb33c"); - - // PSSExample1.2 - - private byte[] msg1b = Hex.decode("851384cdfe819c22ed6c4ccb30daeb5cf059bc8e1166b7e3530c4c233e2b5f8f71a1cca582d43ecc72b1bca16dfc7013226b9e"); - - private byte[] slt1b = Hex.decode("ef2869fa40c346cb183dab3d7bffc98fd56df42d"); - - private byte[] sig1b = Hex.decode("3ef7f46e831bf92b32274142a585ffcefbdca7b32ae90d10fb0f0c729984f04ef29a9df0780775ce43739b97838390db0a5505e63de927028d9d29b219ca2c4517832558a55d694a6d25b9dab66003c4cccd907802193be5170d26147d37b93590241be51c25055f47ef62752cfbe21418fafe98c22c4d4d47724fdb5669e843"); - - // - // Example 2: A 1025-bit RSA keypair - // - - private RSAKeyParameters pub2 = new RSAKeyParameters(false, - new BigInteger("01d40c1bcf97a68ae7cdbd8a7bf3e34fa19dcca4ef75a47454375f94514d88fed006fb829f8419ff87d6315da68a1ff3a0938e9abb3464011c303ad99199cf0c7c7a8b477dce829e8844f625b115e5e9c4a59cf8f8113b6834336a2fd2689b472cbb5e5cabe674350c59b6c17e176874fb42f8fc3d176a017edc61fd326c4b33c9", 16), - new BigInteger("010001", 16)); - - private RSAKeyParameters prv2 = new RSAPrivateCrtKeyParameters( - new BigInteger("01d40c1bcf97a68ae7cdbd8a7bf3e34fa19dcca4ef75a47454375f94514d88fed006fb829f8419ff87d6315da68a1ff3a0938e9abb3464011c303ad99199cf0c7c7a8b477dce829e8844f625b115e5e9c4a59cf8f8113b6834336a2fd2689b472cbb5e5cabe674350c59b6c17e176874fb42f8fc3d176a017edc61fd326c4b33c9", 16), - new BigInteger("010001", 16), - new BigInteger("027d147e4673057377fd1ea201565772176a7dc38358d376045685a2e787c23c15576bc16b9f444402d6bfc5d98a3e88ea13ef67c353eca0c0ddba9255bd7b8bb50a644afdfd1dd51695b252d22e7318d1b6687a1c10ff75545f3db0fe602d5f2b7f294e3601eab7b9d1cecd767f64692e3e536ca2846cb0c2dd486a39fa75b1", 16), - new BigInteger("016601e926a0f8c9e26ecab769ea65a5e7c52cc9e080ef519457c644da6891c5a104d3ea7955929a22e7c68a7af9fcad777c3ccc2b9e3d3650bce404399b7e59d1", 16), - new BigInteger("014eafa1d4d0184da7e31f877d1281ddda625664869e8379e67ad3b75eae74a580e9827abd6eb7a002cb5411f5266797768fb8e95ae40e3e8a01f35ff89e56c079", 16), - new BigInteger("e247cce504939b8f0a36090de200938755e2444b29539a7da7a902f6056835c0db7b52559497cfe2c61a8086d0213c472c78851800b171f6401de2e9c2756f31", 16), - new BigInteger("b12fba757855e586e46f64c38a70c68b3f548d93d787b399999d4c8f0bbd2581c21e19ed0018a6d5d3df86424b3abcad40199d31495b61309f27c1bf55d487c1", 16), - new BigInteger("564b1e1fa003bda91e89090425aac05b91da9ee25061e7628d5f51304a84992fdc33762bd378a59f030a334d532bd0dae8f298ea9ed844636ad5fb8cbdc03cad", 16)); - - // PSS Example 2.1 - - private byte[] msg2a = Hex.decode("daba032066263faedb659848115278a52c44faa3a76f37515ed336321072c40a9d9b53bc05014078adf520875146aae70ff060226dcb7b1f1fc27e9360"); - private byte[] slt2a = Hex.decode("57bf160bcb02bb1dc7280cf0458530b7d2832ff7"); - private byte[] sig2a = Hex.decode("014c5ba5338328ccc6e7a90bf1c0ab3fd606ff4796d3c12e4b639ed9136a5fec6c16d8884bdd99cfdc521456b0742b736868cf90de099adb8d5ffd1deff39ba4007ab746cefdb22d7df0e225f54627dc65466131721b90af445363a8358b9f607642f78fab0ab0f43b7168d64bae70d8827848d8ef1e421c5754ddf42c2589b5b3"); - - // PSS Example 2.2 - - private byte[] msg2b = Hex.decode("e4f8601a8a6da1be34447c0959c058570c3668cfd51dd5f9ccd6ad4411fe8213486d78a6c49f93efc2ca2288cebc2b9b60bd04b1e220d86e3d4848d709d032d1e8c6a070c6af9a499fcf95354b14ba6127c739de1bb0fd16431e46938aec0cf8ad9eb72e832a7035de9b7807bdc0ed8b68eb0f5ac2216be40ce920c0db0eddd3860ed788efaccaca502d8f2bd6d1a7c1f41ff46f1681c8f1f818e9c4f6d91a0c7803ccc63d76a6544d843e084e363b8acc55aa531733edb5dee5b5196e9f03e8b731b3776428d9e457fe3fbcb3db7274442d785890e9cb0854b6444dace791d7273de1889719338a77fe"); - private byte[] slt2b = Hex.decode("7f6dd359e604e60870e898e47b19bf2e5a7b2a90"); - private byte[] sig2b = Hex.decode("010991656cca182b7f29d2dbc007e7ae0fec158eb6759cb9c45c5ff87c7635dd46d150882f4de1e9ae65e7f7d9018f6836954a47c0a81a8a6b6f83f2944d6081b1aa7c759b254b2c34b691da67cc0226e20b2f18b42212761dcd4b908a62b371b5918c5742af4b537e296917674fb914194761621cc19a41f6fb953fbcbb649dea"); - - // - // Example 4: A 1027-bit RSA key pair - // - - private RSAKeyParameters pub4 = new RSAKeyParameters(false, - new BigInteger("054adb7886447efe6f57e0368f06cf52b0a3370760d161cef126b91be7f89c421b62a6ec1da3c311d75ed50e0ab5fff3fd338acc3aa8a4e77ee26369acb81ba900fa83f5300cf9bb6c53ad1dc8a178b815db4235a9a9da0c06de4e615ea1277ce559e9c108de58c14a81aa77f5a6f8d1335494498848c8b95940740be7bf7c3705", 16), - new BigInteger("010001", 16)); - - private RSAKeyParameters prv4 = new RSAPrivateCrtKeyParameters( - new BigInteger("054adb7886447efe6f57e0368f06cf52b0a3370760d161cef126b91be7f89c421b62a6ec1da3c311d75ed50e0ab5fff3fd338acc3aa8a4e77ee26369acb81ba900fa83f5300cf9bb6c53ad1dc8a178b815db4235a9a9da0c06de4e615ea1277ce559e9c108de58c14a81aa77f5a6f8d1335494498848c8b95940740be7bf7c3705", 16), - new BigInteger("010001", 16), - new BigInteger("fa041f8cd9697ceed38ec8caa275523b4dd72b09a301d3541d72f5d31c05cbce2d6983b36183af10690bd46c46131e35789431a556771dd0049b57461bf060c1f68472e8a67c25f357e5b6b4738fa541a730346b4a07649a2dfa806a69c975b6aba64678acc7f5913e89c622f2d8abb1e3e32554e39df94ba60c002e387d9011", 16), - new BigInteger("029232336d2838945dba9dd7723f4e624a05f7375b927a87abe6a893a1658fd49f47f6c7b0fa596c65fa68a23f0ab432962d18d4343bd6fd671a5ea8d148413995", 16), - new BigInteger("020ef5efe7c5394aed2272f7e81a74f4c02d145894cb1b3cab23a9a0710a2afc7e3329acbb743d01f680c4d02afb4c8fde7e20930811bb2b995788b5e872c20bb1", 16), - new BigInteger("026e7e28010ecf2412d9523ad704647fb4fe9b66b1a681581b0e15553a89b1542828898f27243ebab45ff5e1acb9d4df1b051fbc62824dbc6f6c93261a78b9a759", 16), - new BigInteger("012ddcc86ef655998c39ddae11718669e5e46cf1495b07e13b1014cd69b3af68304ad2a6b64321e78bf3bbca9bb494e91d451717e2d97564c6549465d0205cf421", 16), - new BigInteger("010600c4c21847459fe576703e2ebecae8a5094ee63f536bf4ac68d3c13e5e4f12ac5cc10ab6a2d05a199214d1824747d551909636b774c22cac0b837599abcc75", 16)); - - // PSS Example 4.1 - - private byte[] msg4a = Hex.decode("9fb03b827c8217d9"); - - private byte[] slt4a = Hex.decode("ed7c98c95f30974fbe4fbddcf0f28d6021c0e91d"); - - private byte[] sig4a = Hex.decode("0323d5b7bf20ba4539289ae452ae4297080feff4518423ff4811a817837e7d82f1836cdfab54514ff0887bddeebf40bf99b047abc3ecfa6a37a3ef00f4a0c4a88aae0904b745c846c4107e8797723e8ac810d9e3d95dfa30ff4966f4d75d13768d20857f2b1406f264cfe75e27d7652f4b5ed3575f28a702f8c4ed9cf9b2d44948"); - - // PSS Example 4.2 - - private byte[] msg4b = Hex.decode("0ca2ad77797ece86de5bf768750ddb5ed6a3116ad99bbd17edf7f782f0db1cd05b0f677468c5ea420dc116b10e80d110de2b0461ea14a38be68620392e7e893cb4ea9393fb886c20ff790642305bf302003892e54df9f667509dc53920df583f50a3dd61abb6fab75d600377e383e6aca6710eeea27156e06752c94ce25ae99fcbf8592dbe2d7e27453cb44de07100ebb1a2a19811a478adbeab270f94e8fe369d90b3ca612f9f"); - - private byte[] slt4b = Hex.decode("22d71d54363a4217aa55113f059b3384e3e57e44"); - - private byte[] sig4b = Hex.decode("049d0185845a264d28feb1e69edaec090609e8e46d93abb38371ce51f4aa65a599bdaaa81d24fba66a08a116cb644f3f1e653d95c89db8bbd5daac2709c8984000178410a7c6aa8667ddc38c741f710ec8665aa9052be929d4e3b16782c1662114c5414bb0353455c392fc28f3db59054b5f365c49e1d156f876ee10cb4fd70598"); - - - // - // Example 8: A 1031-bit RSA key pair - // - - private RSAKeyParameters pub8 = new RSAKeyParameters(false, - new BigInteger("495370a1fb18543c16d3631e3163255df62be6eee890d5f25509e4f778a8ea6fbbbcdf85dff64e0d972003ab3681fbba6dd41fd541829b2e582de9f2a4a4e0a2d0900bef4753db3cee0ee06c7dfae8b1d53b5953218f9cceea695b08668edeaadced9463b1d790d5ebf27e9115b46cad4d9a2b8efab0561b0810344739ada0733f", 16), - new BigInteger("010001", 16)); - - private RSAKeyParameters prv8 = new RSAPrivateCrtKeyParameters( - new BigInteger("495370a1fb18543c16d3631e3163255df62be6eee890d5f25509e4f778a8ea6fbbbcdf85dff64e0d972003ab3681fbba6dd41fd541829b2e582de9f2a4a4e0a2d0900bef4753db3cee0ee06c7dfae8b1d53b5953218f9cceea695b08668edeaadced9463b1d790d5ebf27e9115b46cad4d9a2b8efab0561b0810344739ada0733f", 16), - new BigInteger("010001", 16), - new BigInteger("6c66ffe98980c38fcdeab5159898836165f4b4b817c4f6a8d486ee4ea9130fe9b9092bd136d184f95f504a607eac565846d2fdd6597a8967c7396ef95a6eeebb4578a643966dca4d8ee3de842de63279c618159c1ab54a89437b6a6120e4930afb52a4ba6ced8a4947ac64b30a3497cbe701c2d6266d517219ad0ec6d347dbe9", 16), - new BigInteger("08dad7f11363faa623d5d6d5e8a319328d82190d7127d2846c439b0ab72619b0a43a95320e4ec34fc3a9cea876422305bd76c5ba7be9e2f410c8060645a1d29edb", 16), - new BigInteger("0847e732376fc7900f898ea82eb2b0fc418565fdae62f7d9ec4ce2217b97990dd272db157f99f63c0dcbb9fbacdbd4c4dadb6df67756358ca4174825b48f49706d", 16), - new BigInteger("05c2a83c124b3621a2aa57ea2c3efe035eff4560f33ddebb7adab81fce69a0c8c2edc16520dda83d59a23be867963ac65f2cc710bbcfb96ee103deb771d105fd85", 16), - new BigInteger("04cae8aa0d9faa165c87b682ec140b8ed3b50b24594b7a3b2c220b3669bb819f984f55310a1ae7823651d4a02e99447972595139363434e5e30a7e7d241551e1b9", 16), - new BigInteger("07d3e47bf686600b11ac283ce88dbb3f6051e8efd04680e44c171ef531b80b2b7c39fc766320e2cf15d8d99820e96ff30dc69691839c4b40d7b06e45307dc91f3f", 16)); - - // PSS Example 8.1 - - private byte[] msg8a = Hex.decode("81332f4be62948415ea1d899792eeacf6c6e1db1da8be13b5cea41db2fed467092e1ff398914c714259775f595f8547f735692a575e6923af78f22c6997ddb90fb6f72d7bb0dd5744a31decd3dc3685849836ed34aec596304ad11843c4f88489f209735f5fb7fdaf7cec8addc5818168f880acbf490d51005b7a8e84e43e54287977571dd99eea4b161eb2df1f5108f12a4142a83322edb05a75487a3435c9a78ce53ed93bc550857d7a9fb"); - - private byte[] slt8a = Hex.decode("1d65491d79c864b373009be6f6f2467bac4c78fa"); - - private byte[] sig8a = Hex.decode("0262ac254bfa77f3c1aca22c5179f8f040422b3c5bafd40a8f21cf0fa5a667ccd5993d42dbafb409c520e25fce2b1ee1e716577f1efa17f3da28052f40f0419b23106d7845aaf01125b698e7a4dfe92d3967bb00c4d0d35ba3552ab9a8b3eef07c7fecdbc5424ac4db1e20cb37d0b2744769940ea907e17fbbca673b20522380c5"); - - // PSS Example 8.2 - - private byte[] msg8b = Hex.decode("e2f96eaf0e05e7ba326ecca0ba7fd2f7c02356f3cede9d0faabf4fcc8e60a973e5595fd9ea08"); - - private byte[] slt8b = Hex.decode("435c098aa9909eb2377f1248b091b68987ff1838"); - - private byte[] sig8b = Hex.decode("2707b9ad5115c58c94e932e8ec0a280f56339e44a1b58d4ddcff2f312e5f34dcfe39e89c6a94dcee86dbbdae5b79ba4e0819a9e7bfd9d982e7ee6c86ee68396e8b3a14c9c8f34b178eb741f9d3f121109bf5c8172fada2e768f9ea1433032c004a8aa07eb990000a48dc94c8bac8aabe2b09b1aa46c0a2aa0e12f63fbba775ba7e"); - - // - // Example 9: A 1536-bit RSA key pair - // - - private RSAKeyParameters pub9 = new RSAKeyParameters(false, - new BigInteger("e6bd692ac96645790403fdd0f5beb8b9bf92ed10007fc365046419dd06c05c5b5b2f48ecf989e4ce269109979cbb40b4a0ad24d22483d1ee315ad4ccb1534268352691c524f6dd8e6c29d224cf246973aec86c5bf6b1401a850d1b9ad1bb8cbcec47b06f0f8c7f45d3fc8f319299c5433ddbc2b3053b47ded2ecd4a4caefd614833dc8bb622f317ed076b8057fe8de3f84480ad5e83e4a61904a4f248fb397027357e1d30e463139815c6fd4fd5ac5b8172a45230ecb6318a04f1455d84e5a8b", 16), - new BigInteger("010001", 16)); - - private RSAKeyParameters prv9 = new RSAPrivateCrtKeyParameters( - new BigInteger("e6bd692ac96645790403fdd0f5beb8b9bf92ed10007fc365046419dd06c05c5b5b2f48ecf989e4ce269109979cbb40b4a0ad24d22483d1ee315ad4ccb1534268352691c524f6dd8e6c29d224cf246973aec86c5bf6b1401a850d1b9ad1bb8cbcec47b06f0f8c7f45d3fc8f319299c5433ddbc2b3053b47ded2ecd4a4caefd614833dc8bb622f317ed076b8057fe8de3f84480ad5e83e4a61904a4f248fb397027357e1d30e463139815c6fd4fd5ac5b8172a45230ecb6318a04f1455d84e5a8b", 16), - new BigInteger("010001", 16), - new BigInteger("6a7fd84fb85fad073b34406db74f8d61a6abc12196a961dd79565e9da6e5187bce2d980250f7359575359270d91590bb0e427c71460b55d51410b191bcf309fea131a92c8e702738fa719f1e0041f52e40e91f229f4d96a1e6f172e15596b4510a6daec26105f2bebc53316b87bdf21311666070e8dfee69d52c71a976caae79c72b68d28580dc686d9f5129d225f82b3d615513a882b3db91416b48ce08888213e37eeb9af800d81cab328ce420689903c00c7b5fd31b75503a6d419684d629", 16), - new BigInteger("f8eb97e98df12664eefdb761596a69ddcd0e76daece6ed4bf5a1b50ac086f7928a4d2f8726a77e515b74da41988f220b1cc87aa1fc810ce99a82f2d1ce821edced794c6941f42c7a1a0b8c4d28c75ec60b652279f6154a762aed165d47dee367", 16), - new BigInteger("ed4d71d0a6e24b93c2e5f6b4bbe05f5fb0afa042d204fe3378d365c2f288b6a8dad7efe45d153eef40cacc7b81ff934002d108994b94a5e4728cd9c963375ae49965bda55cbf0efed8d6553b4027f2d86208a6e6b489c176128092d629e49d3d", 16), - new BigInteger("2bb68bddfb0c4f56c8558bffaf892d8043037841e7fa81cfa61a38c5e39b901c8ee71122a5da2227bd6cdeeb481452c12ad3d61d5e4f776a0ab556591befe3e59e5a7fddb8345e1f2f35b9f4cee57c32414c086aec993e9353e480d9eec6289f", 16), - new BigInteger("4ff897709fad079746494578e70fd8546130eeab5627c49b080f05ee4ad9f3e4b7cba9d6a5dff113a41c3409336833f190816d8a6bc42e9bec56b7567d0f3c9c696db619b245d901dd856db7c8092e77e9a1cccd56ee4dba42c5fdb61aec2669", 16), - new BigInteger("77b9d1137b50404a982729316efafc7dfe66d34e5a182600d5f30a0a8512051c560d081d4d0a1835ec3d25a60f4e4d6aa948b2bf3dbb5b124cbbc3489255a3a948372f6978496745f943e1db4f18382ceaa505dfc65757bb3f857a58dce52156", 16)); - - // PSS Example 9.1 - - private byte[] msg9a = Hex.decode("a88e265855e9d7ca36c68795f0b31b591cd6587c71d060a0b3f7f3eaef43795922028bc2b6ad467cfc2d7f659c5385aa70ba3672cdde4cfe4970cc7904601b278872bf51321c4a972f3c95570f3445d4f57980e0f20df54846e6a52c668f1288c03f95006ea32f562d40d52af9feb32f0fa06db65b588a237b34e592d55cf979f903a642ef64d2ed542aa8c77dc1dd762f45a59303ed75e541ca271e2b60ca709e44fa0661131e8d5d4163fd8d398566ce26de8730e72f9cca737641c244159420637028df0a18079d6208ea8b4711a2c750f5"); - - private byte[] slt9a = Hex.decode("c0a425313df8d7564bd2434d311523d5257eed80"); - - private byte[] sig9a = Hex.decode("586107226c3ce013a7c8f04d1a6a2959bb4b8e205ba43a27b50f124111bc35ef589b039f5932187cb696d7d9a32c0c38300a5cdda4834b62d2eb240af33f79d13dfbf095bf599e0d9686948c1964747b67e89c9aba5cd85016236f566cc5802cb13ead51bc7ca6bef3b94dcbdbb1d570469771df0e00b1a8a06777472d2316279edae86474668d4e1efff95f1de61c6020da32ae92bbf16520fef3cf4d88f61121f24bbd9fe91b59caf1235b2a93ff81fc403addf4ebdea84934a9cdaf8e1a9e"); - - // PSS Example 9.2 - - private byte[] msg9b = Hex.decode("c8c9c6af04acda414d227ef23e0820c3732c500dc87275e95b0d095413993c2658bc1d988581ba879c2d201f14cb88ced153a01969a7bf0a7be79c84c1486bc12b3fa6c59871b6827c8ce253ca5fefa8a8c690bf326e8e37cdb96d90a82ebab69f86350e1822e8bd536a2e"); - - private byte[] slt9b = Hex.decode("b307c43b4850a8dac2f15f32e37839ef8c5c0e91"); - - private byte[] sig9b = Hex.decode("80b6d643255209f0a456763897ac9ed259d459b49c2887e5882ecb4434cfd66dd7e1699375381e51cd7f554f2c271704b399d42b4be2540a0eca61951f55267f7c2878c122842dadb28b01bd5f8c025f7e228418a673c03d6bc0c736d0a29546bd67f786d9d692ccea778d71d98c2063b7a71092187a4d35af108111d83e83eae46c46aa34277e06044589903788f1d5e7cee25fb485e92949118814d6f2c3ee361489016f327fb5bc517eb50470bffa1afa5f4ce9aa0ce5b8ee19bf5501b958"); - - - public String getName() - { - return "PSSBlindTest"; - } - - private void testSig( - int id, - RSAKeyParameters pub, - RSAKeyParameters prv, - byte[] slt, - byte[] msg, - byte[] sig) - throws Exception - { - RSABlindingFactorGenerator blindFactorGen = new RSABlindingFactorGenerator(); - RSABlindingEngine blindingEngine = new RSABlindingEngine(); - PSSSigner blindSigner = new PSSSigner(blindingEngine, new SHA1Digest(), 20); - PSSSigner signer = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20); - - blindFactorGen.init(pub); - - BigInteger blindFactor = blindFactorGen.generateBlindingFactor(); - RSABlindingParameters params = new RSABlindingParameters(pub, blindFactor); - - // generate a blind signature - blindSigner.init(true, new ParametersWithRandom(params, new FixedRandom(slt))); - - blindSigner.update(msg, 0, msg.length); - - byte[] blindedData = blindSigner.generateSignature(); - - RSAEngine signerEngine = new RSAEngine(); - - signerEngine.init(true, prv); - - byte[] blindedSig = signerEngine.processBlock(blindedData, 0, blindedData.length); - - // unblind the signature - blindingEngine.init(false, params); - - byte[] s = blindingEngine.processBlock(blindedSig, 0, blindedSig.length); - - //signature verification - if (!areEqual(s, sig)) - { - fail("test " + id + " failed generation"); - } - - //verify signature with PSSSigner - signer.init(false, pub); - signer.update(msg, 0, msg.length); - - if (!signer.verifySignature(s)) - { - fail("test " + id + " failed PSSSigner verification"); - } - } - - private boolean isProcessingOkay( - RSAKeyParameters pub, - RSAKeyParameters prv, - byte[] data, - SecureRandom random) - throws Exception - { - RSABlindingFactorGenerator blindFactorGen = new RSABlindingFactorGenerator(); - RSABlindingEngine blindingEngine = new RSABlindingEngine(); - PSSSigner blindSigner = new PSSSigner(blindingEngine, new SHA1Digest(), 20); - PSSSigner pssEng = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20); - - random.nextBytes(data); - - blindFactorGen.init(pub); - - BigInteger blindFactor = blindFactorGen.generateBlindingFactor(); - RSABlindingParameters params = new RSABlindingParameters(pub, blindFactor); - - // generate a blind signature - blindSigner.init(true, new ParametersWithRandom(params, random)); - - blindSigner.update(data, 0, data.length); - - byte[] blindedData = blindSigner.generateSignature(); - - RSAEngine signerEngine = new RSAEngine(); - - signerEngine.init(true, prv); - - byte[] blindedSig = signerEngine.processBlock(blindedData, 0, blindedData.length); - - // unblind the signature - blindingEngine.init(false, params); - - byte[] s = blindingEngine.processBlock(blindedSig, 0, blindedSig.length); - - //verify signature with PSSSigner - pssEng.init(false, pub); - pssEng.update(data, 0, data.length); - - return pssEng.verifySignature(s); - } - - public void performTest() - throws Exception - { - testSig(1, pub1, prv1, slt1a, msg1a, sig1a); - testSig(2, pub1, prv1, slt1b, msg1b, sig1b); - testSig(3, pub2, prv2, slt2a, msg2a, sig2a); - testSig(4, pub2, prv2, slt2b, msg2b, sig2b); - testSig(5, pub4, prv4, slt4a, msg4a, sig4a); - testSig(6, pub4, prv4, slt4b, msg4b, sig4b); - testSig(7, pub8, prv8, slt8a, msg8a, sig8a); - testSig(8, pub8, prv8, slt8b, msg8b, sig8b); - testSig(9, pub9, prv9, slt9a, msg9a, sig9a); - testSig(10, pub9, prv9, slt9b, msg9b, sig9b); - - // - // loop test - // - int failed = 0; - byte[] data = new byte[DATA_LENGTH]; - - SecureRandom random = new SecureRandom(); - - - RSAKeyParameters[] kprv ={prv1, prv2, prv4, prv8, prv9}; - RSAKeyParameters[] kpub ={pub1, pub2, pub4, pub8, pub9}; - - int i = 0; - for (int j = 0; j < NUM_TESTS; j++, i++) - { - if (i == kprv.length) - { - i = 0; - } - - if (!isProcessingOkay(kpub[i], kprv[i], data, random)) - { - failed++; - } - } - - if (failed != 0) - { - fail("loop test failed - failures: " + failed); - } - - // - // key generation test - // - RSAKeyPairGenerator pGen = new RSAKeyPairGenerator(); - RSAKeyGenerationParameters genParam = new RSAKeyGenerationParameters( - BigInteger.valueOf(0x11), new SecureRandom(), 1024, 25); - - pGen.init(genParam); - failed = 0; - - for (int k = 0; k < NUM_TESTS_WITH_KEY_GENERATION; k++) - { - AsymmetricCipherKeyPair pair = pGen.generateKeyPair(); - - for (int j = 0; j < NUM_TESTS; j++) - { - if (!isProcessingOkay((RSAKeyParameters)pair.getPublic(), (RSAKeyParameters)pair.getPrivate(), data, random)) - { - failed++; - } - } - - } - - if (failed != 0) - { - fail("loop test with key generation failed - failures: " + failed); - } - } - - public static void main( - String[] args) - { - runTest(new PSSBlindTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PSSTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PSSTest.java deleted file mode 100644 index b69f391eb..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PSSTest.java +++ /dev/null @@ -1,369 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.engines.RSAEngine; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters; -import com.fr.third.org.bouncycastle.crypto.signers.PSSSigner; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/* - * RSA PSS test vectors for PKCS#1 V2.1 - */ -public class PSSTest - extends SimpleTest -{ - private final int DATA_LENGTH = 1000; - private final int NUM_TESTS = 500; - - private class FixedRandom - extends SecureRandom - { - byte[] vals; - - FixedRandom( - byte[] vals) - { - this.vals = vals; - } - - public void nextBytes( - byte[] bytes) - { - System.arraycopy(vals, 0, bytes, 0, vals.length); - } - } - - // - // Example 1: A 1024-bit RSA keypair - // - private RSAKeyParameters pub1 = new RSAKeyParameters(false, - new BigInteger("a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cffb2249bd9a2137",16), - new BigInteger("010001",16)); - - private RSAKeyParameters prv1 = new RSAPrivateCrtKeyParameters( - new BigInteger("a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cffb2249bd9a2137",16), - new BigInteger("010001",16), - new BigInteger("33a5042a90b27d4f5451ca9bbbd0b44771a101af884340aef9885f2a4bbe92e894a724ac3c568c8f97853ad07c0266c8c6a3ca0929f1e8f11231884429fc4d9ae55fee896a10ce707c3ed7e734e44727a39574501a532683109c2abacaba283c31b4bd2f53c3ee37e352cee34f9e503bd80c0622ad79c6dcee883547c6a3b325",16), - new BigInteger("e7e8942720a877517273a356053ea2a1bc0c94aa72d55c6e86296b2dfc967948c0a72cbccca7eacb35706e09a1df55a1535bd9b3cc34160b3b6dcd3eda8e6443",16), - new BigInteger("b69dca1cf7d4d7ec81e75b90fcca874abcde123fd2700180aa90479b6e48de8d67ed24f9f19d85ba275874f542cd20dc723e6963364a1f9425452b269a6799fd",16), - new BigInteger("28fa13938655be1f8a159cbaca5a72ea190c30089e19cd274a556f36c4f6e19f554b34c077790427bbdd8dd3ede2448328f385d81b30e8e43b2fffa027861979",16), - new BigInteger("1a8b38f398fa712049898d7fb79ee0a77668791299cdfa09efc0e507acb21ed74301ef5bfd48be455eaeb6e1678255827580a8e4e8e14151d1510a82a3f2e729",16), - new BigInteger("27156aba4126d24a81f3a528cbfb27f56886f840a9f6e86e17a44b94fe9319584b8e22fdde1e5a2e3bd8aa5ba8d8584194eb2190acf832b847f13a3d24a79f4d",16)); - - // PSSExample1.1 - - private byte[] msg1a = Hex.decode("cdc87da223d786df3b45e0bbbc721326d1ee2af806cc315475cc6f0d9c66e1b62371d45ce2392e1ac92844c310102f156a0d8d52c1f4c40ba3aa65095786cb769757a6563ba958fed0bcc984e8b517a3d5f515b23b8a41e74aa867693f90dfb061a6e86dfaaee64472c00e5f20945729cbebe77f06ce78e08f4098fba41f9d6193c0317e8b60d4b6084acb42d29e3808a3bc372d85e331170fcbf7cc72d0b71c296648b3a4d10f416295d0807aa625cab2744fd9ea8fd223c42537029828bd16be02546f130fd2e33b936d2676e08aed1b73318b750a0167d0"); - - private byte[] slt1a = Hex.decode("dee959c7e06411361420ff80185ed57f3e6776af"); - - private byte[] sig1a = Hex.decode("9074308fb598e9701b2294388e52f971faac2b60a5145af185df5287b5ed2887e57ce7fd44dc8634e407c8e0e4360bc226f3ec227f9d9e54638e8d31f5051215df6ebb9c2f9579aa77598a38f914b5b9c1bd83c4e2f9f382a0d0aa3542ffee65984a601bc69eb28deb27dca12c82c2d4c3f66cd500f1ff2b994d8a4e30cbb33c"); - - // PSSExample1.2 - - private byte[] msg1b = Hex.decode("851384cdfe819c22ed6c4ccb30daeb5cf059bc8e1166b7e3530c4c233e2b5f8f71a1cca582d43ecc72b1bca16dfc7013226b9e"); - - private byte[] slt1b = Hex.decode("ef2869fa40c346cb183dab3d7bffc98fd56df42d"); - - private byte[] sig1b = Hex.decode("3ef7f46e831bf92b32274142a585ffcefbdca7b32ae90d10fb0f0c729984f04ef29a9df0780775ce43739b97838390db0a5505e63de927028d9d29b219ca2c4517832558a55d694a6d25b9dab66003c4cccd907802193be5170d26147d37b93590241be51c25055f47ef62752cfbe21418fafe98c22c4d4d47724fdb5669e843"); - - // - // Example 2: A 1025-bit RSA keypair - // - - private RSAKeyParameters pub2 = new RSAKeyParameters(false, - new BigInteger("01d40c1bcf97a68ae7cdbd8a7bf3e34fa19dcca4ef75a47454375f94514d88fed006fb829f8419ff87d6315da68a1ff3a0938e9abb3464011c303ad99199cf0c7c7a8b477dce829e8844f625b115e5e9c4a59cf8f8113b6834336a2fd2689b472cbb5e5cabe674350c59b6c17e176874fb42f8fc3d176a017edc61fd326c4b33c9", 16), - new BigInteger("010001", 16)); - - private RSAKeyParameters prv2 = new RSAPrivateCrtKeyParameters( - new BigInteger("01d40c1bcf97a68ae7cdbd8a7bf3e34fa19dcca4ef75a47454375f94514d88fed006fb829f8419ff87d6315da68a1ff3a0938e9abb3464011c303ad99199cf0c7c7a8b477dce829e8844f625b115e5e9c4a59cf8f8113b6834336a2fd2689b472cbb5e5cabe674350c59b6c17e176874fb42f8fc3d176a017edc61fd326c4b33c9", 16), - new BigInteger("010001", 16), - new BigInteger("027d147e4673057377fd1ea201565772176a7dc38358d376045685a2e787c23c15576bc16b9f444402d6bfc5d98a3e88ea13ef67c353eca0c0ddba9255bd7b8bb50a644afdfd1dd51695b252d22e7318d1b6687a1c10ff75545f3db0fe602d5f2b7f294e3601eab7b9d1cecd767f64692e3e536ca2846cb0c2dd486a39fa75b1", 16), - new BigInteger("016601e926a0f8c9e26ecab769ea65a5e7c52cc9e080ef519457c644da6891c5a104d3ea7955929a22e7c68a7af9fcad777c3ccc2b9e3d3650bce404399b7e59d1", 16), - new BigInteger("014eafa1d4d0184da7e31f877d1281ddda625664869e8379e67ad3b75eae74a580e9827abd6eb7a002cb5411f5266797768fb8e95ae40e3e8a01f35ff89e56c079", 16), - new BigInteger("e247cce504939b8f0a36090de200938755e2444b29539a7da7a902f6056835c0db7b52559497cfe2c61a8086d0213c472c78851800b171f6401de2e9c2756f31", 16), - new BigInteger("b12fba757855e586e46f64c38a70c68b3f548d93d787b399999d4c8f0bbd2581c21e19ed0018a6d5d3df86424b3abcad40199d31495b61309f27c1bf55d487c1", 16), - new BigInteger("564b1e1fa003bda91e89090425aac05b91da9ee25061e7628d5f51304a84992fdc33762bd378a59f030a334d532bd0dae8f298ea9ed844636ad5fb8cbdc03cad", 16)); - - // PSS Example 2.1 - - private byte[] msg2a = Hex.decode("daba032066263faedb659848115278a52c44faa3a76f37515ed336321072c40a9d9b53bc05014078adf520875146aae70ff060226dcb7b1f1fc27e9360"); - private byte[] slt2a = Hex.decode("57bf160bcb02bb1dc7280cf0458530b7d2832ff7"); - private byte[] sig2a = Hex.decode("014c5ba5338328ccc6e7a90bf1c0ab3fd606ff4796d3c12e4b639ed9136a5fec6c16d8884bdd99cfdc521456b0742b736868cf90de099adb8d5ffd1deff39ba4007ab746cefdb22d7df0e225f54627dc65466131721b90af445363a8358b9f607642f78fab0ab0f43b7168d64bae70d8827848d8ef1e421c5754ddf42c2589b5b3"); - - // PSS Example 2.2 - - private byte[] msg2b = Hex.decode("e4f8601a8a6da1be34447c0959c058570c3668cfd51dd5f9ccd6ad4411fe8213486d78a6c49f93efc2ca2288cebc2b9b60bd04b1e220d86e3d4848d709d032d1e8c6a070c6af9a499fcf95354b14ba6127c739de1bb0fd16431e46938aec0cf8ad9eb72e832a7035de9b7807bdc0ed8b68eb0f5ac2216be40ce920c0db0eddd3860ed788efaccaca502d8f2bd6d1a7c1f41ff46f1681c8f1f818e9c4f6d91a0c7803ccc63d76a6544d843e084e363b8acc55aa531733edb5dee5b5196e9f03e8b731b3776428d9e457fe3fbcb3db7274442d785890e9cb0854b6444dace791d7273de1889719338a77fe"); - private byte[] slt2b = Hex.decode("7f6dd359e604e60870e898e47b19bf2e5a7b2a90"); - private byte[] sig2b = Hex.decode("010991656cca182b7f29d2dbc007e7ae0fec158eb6759cb9c45c5ff87c7635dd46d150882f4de1e9ae65e7f7d9018f6836954a47c0a81a8a6b6f83f2944d6081b1aa7c759b254b2c34b691da67cc0226e20b2f18b42212761dcd4b908a62b371b5918c5742af4b537e296917674fb914194761621cc19a41f6fb953fbcbb649dea"); - - // - // Example 4: A 1027-bit RSA key pair - // - - private RSAKeyParameters pub4 = new RSAKeyParameters(false, - new BigInteger("054adb7886447efe6f57e0368f06cf52b0a3370760d161cef126b91be7f89c421b62a6ec1da3c311d75ed50e0ab5fff3fd338acc3aa8a4e77ee26369acb81ba900fa83f5300cf9bb6c53ad1dc8a178b815db4235a9a9da0c06de4e615ea1277ce559e9c108de58c14a81aa77f5a6f8d1335494498848c8b95940740be7bf7c3705", 16), - new BigInteger("010001", 16)); - - private RSAKeyParameters prv4 = new RSAPrivateCrtKeyParameters( - new BigInteger("054adb7886447efe6f57e0368f06cf52b0a3370760d161cef126b91be7f89c421b62a6ec1da3c311d75ed50e0ab5fff3fd338acc3aa8a4e77ee26369acb81ba900fa83f5300cf9bb6c53ad1dc8a178b815db4235a9a9da0c06de4e615ea1277ce559e9c108de58c14a81aa77f5a6f8d1335494498848c8b95940740be7bf7c3705", 16), - new BigInteger("010001", 16), - new BigInteger("fa041f8cd9697ceed38ec8caa275523b4dd72b09a301d3541d72f5d31c05cbce2d6983b36183af10690bd46c46131e35789431a556771dd0049b57461bf060c1f68472e8a67c25f357e5b6b4738fa541a730346b4a07649a2dfa806a69c975b6aba64678acc7f5913e89c622f2d8abb1e3e32554e39df94ba60c002e387d9011", 16), - new BigInteger("029232336d2838945dba9dd7723f4e624a05f7375b927a87abe6a893a1658fd49f47f6c7b0fa596c65fa68a23f0ab432962d18d4343bd6fd671a5ea8d148413995", 16), - new BigInteger("020ef5efe7c5394aed2272f7e81a74f4c02d145894cb1b3cab23a9a0710a2afc7e3329acbb743d01f680c4d02afb4c8fde7e20930811bb2b995788b5e872c20bb1", 16), - new BigInteger("026e7e28010ecf2412d9523ad704647fb4fe9b66b1a681581b0e15553a89b1542828898f27243ebab45ff5e1acb9d4df1b051fbc62824dbc6f6c93261a78b9a759", 16), - new BigInteger("012ddcc86ef655998c39ddae11718669e5e46cf1495b07e13b1014cd69b3af68304ad2a6b64321e78bf3bbca9bb494e91d451717e2d97564c6549465d0205cf421", 16), - new BigInteger("010600c4c21847459fe576703e2ebecae8a5094ee63f536bf4ac68d3c13e5e4f12ac5cc10ab6a2d05a199214d1824747d551909636b774c22cac0b837599abcc75", 16)); - - // PSS Example 4.1 - - private byte[] msg4a = Hex.decode("9fb03b827c8217d9"); - - private byte[] slt4a = Hex.decode("ed7c98c95f30974fbe4fbddcf0f28d6021c0e91d"); - - private byte[] sig4a = Hex.decode("0323d5b7bf20ba4539289ae452ae4297080feff4518423ff4811a817837e7d82f1836cdfab54514ff0887bddeebf40bf99b047abc3ecfa6a37a3ef00f4a0c4a88aae0904b745c846c4107e8797723e8ac810d9e3d95dfa30ff4966f4d75d13768d20857f2b1406f264cfe75e27d7652f4b5ed3575f28a702f8c4ed9cf9b2d44948"); - - // PSS Example 4.2 - - private byte[] msg4b = Hex.decode("0ca2ad77797ece86de5bf768750ddb5ed6a3116ad99bbd17edf7f782f0db1cd05b0f677468c5ea420dc116b10e80d110de2b0461ea14a38be68620392e7e893cb4ea9393fb886c20ff790642305bf302003892e54df9f667509dc53920df583f50a3dd61abb6fab75d600377e383e6aca6710eeea27156e06752c94ce25ae99fcbf8592dbe2d7e27453cb44de07100ebb1a2a19811a478adbeab270f94e8fe369d90b3ca612f9f"); - - private byte[] slt4b = Hex.decode("22d71d54363a4217aa55113f059b3384e3e57e44"); - - private byte[] sig4b = Hex.decode("049d0185845a264d28feb1e69edaec090609e8e46d93abb38371ce51f4aa65a599bdaaa81d24fba66a08a116cb644f3f1e653d95c89db8bbd5daac2709c8984000178410a7c6aa8667ddc38c741f710ec8665aa9052be929d4e3b16782c1662114c5414bb0353455c392fc28f3db59054b5f365c49e1d156f876ee10cb4fd70598"); - - - // - // Example 8: A 1031-bit RSA key pair - // - - private RSAKeyParameters pub8 = new RSAKeyParameters(false, - new BigInteger("495370a1fb18543c16d3631e3163255df62be6eee890d5f25509e4f778a8ea6fbbbcdf85dff64e0d972003ab3681fbba6dd41fd541829b2e582de9f2a4a4e0a2d0900bef4753db3cee0ee06c7dfae8b1d53b5953218f9cceea695b08668edeaadced9463b1d790d5ebf27e9115b46cad4d9a2b8efab0561b0810344739ada0733f", 16), - new BigInteger("010001", 16)); - - private RSAKeyParameters prv8 = new RSAPrivateCrtKeyParameters( - new BigInteger("495370a1fb18543c16d3631e3163255df62be6eee890d5f25509e4f778a8ea6fbbbcdf85dff64e0d972003ab3681fbba6dd41fd541829b2e582de9f2a4a4e0a2d0900bef4753db3cee0ee06c7dfae8b1d53b5953218f9cceea695b08668edeaadced9463b1d790d5ebf27e9115b46cad4d9a2b8efab0561b0810344739ada0733f", 16), - new BigInteger("010001", 16), - new BigInteger("6c66ffe98980c38fcdeab5159898836165f4b4b817c4f6a8d486ee4ea9130fe9b9092bd136d184f95f504a607eac565846d2fdd6597a8967c7396ef95a6eeebb4578a643966dca4d8ee3de842de63279c618159c1ab54a89437b6a6120e4930afb52a4ba6ced8a4947ac64b30a3497cbe701c2d6266d517219ad0ec6d347dbe9", 16), - new BigInteger("08dad7f11363faa623d5d6d5e8a319328d82190d7127d2846c439b0ab72619b0a43a95320e4ec34fc3a9cea876422305bd76c5ba7be9e2f410c8060645a1d29edb", 16), - new BigInteger("0847e732376fc7900f898ea82eb2b0fc418565fdae62f7d9ec4ce2217b97990dd272db157f99f63c0dcbb9fbacdbd4c4dadb6df67756358ca4174825b48f49706d", 16), - new BigInteger("05c2a83c124b3621a2aa57ea2c3efe035eff4560f33ddebb7adab81fce69a0c8c2edc16520dda83d59a23be867963ac65f2cc710bbcfb96ee103deb771d105fd85", 16), - new BigInteger("04cae8aa0d9faa165c87b682ec140b8ed3b50b24594b7a3b2c220b3669bb819f984f55310a1ae7823651d4a02e99447972595139363434e5e30a7e7d241551e1b9", 16), - new BigInteger("07d3e47bf686600b11ac283ce88dbb3f6051e8efd04680e44c171ef531b80b2b7c39fc766320e2cf15d8d99820e96ff30dc69691839c4b40d7b06e45307dc91f3f", 16)); - - // PSS Example 8.1 - - private byte[] msg8a = Hex.decode("81332f4be62948415ea1d899792eeacf6c6e1db1da8be13b5cea41db2fed467092e1ff398914c714259775f595f8547f735692a575e6923af78f22c6997ddb90fb6f72d7bb0dd5744a31decd3dc3685849836ed34aec596304ad11843c4f88489f209735f5fb7fdaf7cec8addc5818168f880acbf490d51005b7a8e84e43e54287977571dd99eea4b161eb2df1f5108f12a4142a83322edb05a75487a3435c9a78ce53ed93bc550857d7a9fb"); - - private byte[] slt8a = Hex.decode("1d65491d79c864b373009be6f6f2467bac4c78fa"); - - private byte[] sig8a = Hex.decode("0262ac254bfa77f3c1aca22c5179f8f040422b3c5bafd40a8f21cf0fa5a667ccd5993d42dbafb409c520e25fce2b1ee1e716577f1efa17f3da28052f40f0419b23106d7845aaf01125b698e7a4dfe92d3967bb00c4d0d35ba3552ab9a8b3eef07c7fecdbc5424ac4db1e20cb37d0b2744769940ea907e17fbbca673b20522380c5"); - - // PSS Example 8.2 - - private byte[] msg8b = Hex.decode("e2f96eaf0e05e7ba326ecca0ba7fd2f7c02356f3cede9d0faabf4fcc8e60a973e5595fd9ea08"); - - private byte[] slt8b = Hex.decode("435c098aa9909eb2377f1248b091b68987ff1838"); - - private byte[] sig8b = Hex.decode("2707b9ad5115c58c94e932e8ec0a280f56339e44a1b58d4ddcff2f312e5f34dcfe39e89c6a94dcee86dbbdae5b79ba4e0819a9e7bfd9d982e7ee6c86ee68396e8b3a14c9c8f34b178eb741f9d3f121109bf5c8172fada2e768f9ea1433032c004a8aa07eb990000a48dc94c8bac8aabe2b09b1aa46c0a2aa0e12f63fbba775ba7e"); - - // - // Example 9: A 1536-bit RSA key pair - // - - private RSAKeyParameters pub9 = new RSAKeyParameters(false, - new BigInteger("e6bd692ac96645790403fdd0f5beb8b9bf92ed10007fc365046419dd06c05c5b5b2f48ecf989e4ce269109979cbb40b4a0ad24d22483d1ee315ad4ccb1534268352691c524f6dd8e6c29d224cf246973aec86c5bf6b1401a850d1b9ad1bb8cbcec47b06f0f8c7f45d3fc8f319299c5433ddbc2b3053b47ded2ecd4a4caefd614833dc8bb622f317ed076b8057fe8de3f84480ad5e83e4a61904a4f248fb397027357e1d30e463139815c6fd4fd5ac5b8172a45230ecb6318a04f1455d84e5a8b", 16), - new BigInteger("010001", 16)); - - private RSAKeyParameters prv9 = new RSAPrivateCrtKeyParameters( - new BigInteger("e6bd692ac96645790403fdd0f5beb8b9bf92ed10007fc365046419dd06c05c5b5b2f48ecf989e4ce269109979cbb40b4a0ad24d22483d1ee315ad4ccb1534268352691c524f6dd8e6c29d224cf246973aec86c5bf6b1401a850d1b9ad1bb8cbcec47b06f0f8c7f45d3fc8f319299c5433ddbc2b3053b47ded2ecd4a4caefd614833dc8bb622f317ed076b8057fe8de3f84480ad5e83e4a61904a4f248fb397027357e1d30e463139815c6fd4fd5ac5b8172a45230ecb6318a04f1455d84e5a8b", 16), - new BigInteger("010001", 16), - new BigInteger("6a7fd84fb85fad073b34406db74f8d61a6abc12196a961dd79565e9da6e5187bce2d980250f7359575359270d91590bb0e427c71460b55d51410b191bcf309fea131a92c8e702738fa719f1e0041f52e40e91f229f4d96a1e6f172e15596b4510a6daec26105f2bebc53316b87bdf21311666070e8dfee69d52c71a976caae79c72b68d28580dc686d9f5129d225f82b3d615513a882b3db91416b48ce08888213e37eeb9af800d81cab328ce420689903c00c7b5fd31b75503a6d419684d629", 16), - new BigInteger("f8eb97e98df12664eefdb761596a69ddcd0e76daece6ed4bf5a1b50ac086f7928a4d2f8726a77e515b74da41988f220b1cc87aa1fc810ce99a82f2d1ce821edced794c6941f42c7a1a0b8c4d28c75ec60b652279f6154a762aed165d47dee367", 16), - new BigInteger("ed4d71d0a6e24b93c2e5f6b4bbe05f5fb0afa042d204fe3378d365c2f288b6a8dad7efe45d153eef40cacc7b81ff934002d108994b94a5e4728cd9c963375ae49965bda55cbf0efed8d6553b4027f2d86208a6e6b489c176128092d629e49d3d", 16), - new BigInteger("2bb68bddfb0c4f56c8558bffaf892d8043037841e7fa81cfa61a38c5e39b901c8ee71122a5da2227bd6cdeeb481452c12ad3d61d5e4f776a0ab556591befe3e59e5a7fddb8345e1f2f35b9f4cee57c32414c086aec993e9353e480d9eec6289f", 16), - new BigInteger("4ff897709fad079746494578e70fd8546130eeab5627c49b080f05ee4ad9f3e4b7cba9d6a5dff113a41c3409336833f190816d8a6bc42e9bec56b7567d0f3c9c696db619b245d901dd856db7c8092e77e9a1cccd56ee4dba42c5fdb61aec2669", 16), - new BigInteger("77b9d1137b50404a982729316efafc7dfe66d34e5a182600d5f30a0a8512051c560d081d4d0a1835ec3d25a60f4e4d6aa948b2bf3dbb5b124cbbc3489255a3a948372f6978496745f943e1db4f18382ceaa505dfc65757bb3f857a58dce52156", 16)); - - // PSS Example 9.1 - - private byte[] msg9a = Hex.decode("a88e265855e9d7ca36c68795f0b31b591cd6587c71d060a0b3f7f3eaef43795922028bc2b6ad467cfc2d7f659c5385aa70ba3672cdde4cfe4970cc7904601b278872bf51321c4a972f3c95570f3445d4f57980e0f20df54846e6a52c668f1288c03f95006ea32f562d40d52af9feb32f0fa06db65b588a237b34e592d55cf979f903a642ef64d2ed542aa8c77dc1dd762f45a59303ed75e541ca271e2b60ca709e44fa0661131e8d5d4163fd8d398566ce26de8730e72f9cca737641c244159420637028df0a18079d6208ea8b4711a2c750f5"); - - private byte[] slt9a = Hex.decode("c0a425313df8d7564bd2434d311523d5257eed80"); - - private byte[] sig9a = Hex.decode("586107226c3ce013a7c8f04d1a6a2959bb4b8e205ba43a27b50f124111bc35ef589b039f5932187cb696d7d9a32c0c38300a5cdda4834b62d2eb240af33f79d13dfbf095bf599e0d9686948c1964747b67e89c9aba5cd85016236f566cc5802cb13ead51bc7ca6bef3b94dcbdbb1d570469771df0e00b1a8a06777472d2316279edae86474668d4e1efff95f1de61c6020da32ae92bbf16520fef3cf4d88f61121f24bbd9fe91b59caf1235b2a93ff81fc403addf4ebdea84934a9cdaf8e1a9e"); - - // PSS Example 9.2 - - private byte[] msg9b = Hex.decode("c8c9c6af04acda414d227ef23e0820c3732c500dc87275e95b0d095413993c2658bc1d988581ba879c2d201f14cb88ced153a01969a7bf0a7be79c84c1486bc12b3fa6c59871b6827c8ce253ca5fefa8a8c690bf326e8e37cdb96d90a82ebab69f86350e1822e8bd536a2e"); - - private byte[] slt9b = Hex.decode("b307c43b4850a8dac2f15f32e37839ef8c5c0e91"); - - private byte[] sig9b = Hex.decode("80b6d643255209f0a456763897ac9ed259d459b49c2887e5882ecb4434cfd66dd7e1699375381e51cd7f554f2c271704b399d42b4be2540a0eca61951f55267f7c2878c122842dadb28b01bd5f8c025f7e228418a673c03d6bc0c736d0a29546bd67f786d9d692ccea778d71d98c2063b7a71092187a4d35af108111d83e83eae46c46aa34277e06044589903788f1d5e7cee25fb485e92949118814d6f2c3ee361489016f327fb5bc517eb50470bffa1afa5f4ce9aa0ce5b8ee19bf5501b958"); - - - public String getName() - { - return "PSSTest"; - } - - private void testSig( - int id, - RSAKeyParameters pub, - RSAKeyParameters prv, - byte[] slt, - byte[] msg, - byte[] sig) - throws Exception - { - PSSSigner eng = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20); - - eng.init(true, new ParametersWithRandom(prv, new FixedRandom(slt))); - - eng.update(msg, 0, msg.length); - - byte[] s = eng.generateSignature(); - - if (!areEqual(s, sig)) - { - fail("test " + id + " failed generation"); - } - - eng.init(false, pub); - - eng.update(msg, 0, msg.length); - - if (!eng.verifySignature(s)) - { - fail("test " + id + " failed verification"); - } - } - - public void performTest() - throws Exception - { - testSig(1, pub1, prv1, slt1a, msg1a, sig1a); - testSig(2, pub1, prv1, slt1b, msg1b, sig1b); - testSig(3, pub2, prv2, slt2a, msg2a, sig2a); - testSig(4, pub2, prv2, slt2b, msg2b, sig2b); - testSig(5, pub4, prv4, slt4a, msg4a, sig4a); - testSig(6, pub4, prv4, slt4b, msg4b, sig4b); - testSig(7, pub8, prv8, slt8a, msg8a, sig8a); - testSig(8, pub8, prv8, slt8b, msg8b, sig8b); - testSig(9, pub9, prv9, slt9a, msg9a, sig9a); - testSig(10, pub9, prv9, slt9b, msg9b, sig9b); - - // - // loop test - sha-1 only - // - PSSSigner eng = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20); - int failed = 0; - byte[] data = new byte[DATA_LENGTH]; - - SecureRandom random = new SecureRandom(); - random.nextBytes(data); - - for (int j = 0; j < NUM_TESTS; j++) - { - eng.init(true, new ParametersWithRandom(prv8, random)); - - eng.update(data, 0, data.length); - - byte[] s = eng.generateSignature(); - - eng.init(false, pub8); - - eng.update(data, 0, data.length); - - if (!eng.verifySignature(s)) - { - failed++; - } - } - - if (failed != 0) - { - fail("loop test failed - failures: " + failed); - } - - // - // loop test - sha-256 and sha-1 - // - eng = new PSSSigner(new RSAEngine(), new SHA256Digest(), new SHA1Digest(), 20); - failed = 0; - data = new byte[DATA_LENGTH]; - - random.nextBytes(data); - - for (int j = 0; j < NUM_TESTS; j++) - { - eng.init(true, new ParametersWithRandom(prv8, random)); - - eng.update(data, 0, data.length); - - byte[] s = eng.generateSignature(); - - eng.init(false, pub8); - - eng.update(data, 0, data.length); - - if (!eng.verifySignature(s)) - { - failed++; - } - } - - if (failed != 0) - { - fail("loop test failed - failures: " + failed); - } - - fixedSaltTest(); - } - - private void fixedSaltTest() - throws Exception - { - byte[] data = Hex.decode("010203040506070809101112131415"); - - PSSSigner eng = new PSSSigner(new RSAEngine(), new SHA256Digest(), new SHA1Digest(), Hex.decode("deadbeef")); - - eng.init(true, prv8); - - eng.update(data, 0, data.length); - - byte[] s = eng.generateSignature(); - - eng.init(false, pub8); - - eng.update(data, 0, data.length); - - if (!eng.verifySignature(s)) - { - fail("fixed salt failed"); - } - - // test failure - eng = new PSSSigner(new RSAEngine(), new SHA256Digest(), new SHA1Digest(), Hex.decode("beefbeef")); - - eng.init(false, pub8); - - eng.update(data, 0, data.length); - - if (eng.verifySignature(s)) - { - fail("fixed salt failure verfied"); - } - } - - public static void main( - String[] args) - { - runTest(new PSSTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PaddingTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PaddingTest.java deleted file mode 100644 index ed25c98c2..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/PaddingTest.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.paddings.BlockCipherPadding; -import com.fr.third.org.bouncycastle.crypto.paddings.ISO10126d2Padding; -import com.fr.third.org.bouncycastle.crypto.paddings.ISO7816d4Padding; -import com.fr.third.org.bouncycastle.crypto.paddings.PKCS7Padding; -import com.fr.third.org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.paddings.TBCPadding; -import com.fr.third.org.bouncycastle.crypto.paddings.X923Padding; -import com.fr.third.org.bouncycastle.crypto.paddings.ZeroBytePadding; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * General Padding tests. - */ -public class PaddingTest - extends SimpleTest -{ - public PaddingTest() - { - } - - private void blockCheck( - PaddedBufferedBlockCipher cipher, - BlockCipherPadding padding, - KeyParameter key, - byte[] data) - { - byte[] out = new byte[data.length + 8]; - byte[] dec = new byte[data.length]; - - try - { - cipher.init(true, key); - - int len = cipher.processBytes(data, 0, data.length, out, 0); - - len += cipher.doFinal(out, len); - - cipher.init(false, key); - - int decLen = cipher.processBytes(out, 0, len, dec, 0); - - decLen += cipher.doFinal(dec, decLen); - - if (!areEqual(data, dec)) - { - fail("failed to decrypt - i = " + data.length + ", padding = " + padding.getPaddingName()); - } - } - catch (Exception e) - { - fail("Exception - " + e.toString(), e); - } - } - - public void testPadding( - BlockCipherPadding padding, - SecureRandom rand, - byte[] ffVector, - byte[] ZeroVector) - { - PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new DESEngine(), padding); - KeyParameter key = new KeyParameter(Hex.decode("0011223344556677")); - - // - // ff test - // - byte[] data = { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0 }; - - if (ffVector != null) - { - padding.addPadding(data, 3); - - if (!areEqual(data, ffVector)) - { - fail("failed ff test for " + padding.getPaddingName()); - } - } - - // - // zero test - // - if (ZeroVector != null) - { - data = new byte[8]; - padding.addPadding(data, 4); - - if (!areEqual(data, ZeroVector)) - { - fail("failed zero test for " + padding.getPaddingName()); - } - } - - for (int i = 1; i != 200; i++) - { - data = new byte[i]; - - rand.nextBytes(data); - - blockCheck(cipher, padding, key, data); - } - } - - private void testOutputSizes() - { - PaddedBufferedBlockCipher bc = new PaddedBufferedBlockCipher(new DESEngine(), new PKCS7Padding()); - KeyParameter key = new KeyParameter(Hex.decode("0011223344556677")); - - for (int i = 0; i < bc.getBlockSize() * 2; i++) - { - bc.init(true, key); - if (bc.getUpdateOutputSize(i) < 0) - { - fail("Padded cipher encrypt negative update output size for input size " + i); - } - if (bc.getOutputSize(i) < 0) - { - fail("Padded cipher encrypt negative output size for input size " + i); - } - - bc.init(false, key); - if (bc.getUpdateOutputSize(i) < 0) - { - fail("Padded cipher decrypt negative update output size for input size " + i); - } - if (bc.getOutputSize(i) < 0) - { - fail("Padded cipher decrypt negative output size for input size " + i); - } - - } - } - - public void performTest() - { - SecureRandom rand = new SecureRandom(new byte[20]); - - rand.setSeed(System.currentTimeMillis()); - - testPadding(new PKCS7Padding(), rand, - Hex.decode("ffffff0505050505"), - Hex.decode("0000000004040404")); - - PKCS7Padding padder = new PKCS7Padding(); - try - { - padder.padCount(new byte[8]); - - fail("invalid padding not detected"); - } - catch (InvalidCipherTextException e) - { - if (!"pad block corrupted".equals(e.getMessage())) - { - fail("wrong exception for corrupt padding: " + e); - } - } - - testPadding(new ISO10126d2Padding(), rand, - null, - null); - - testPadding(new X923Padding(), rand, - null, - null); - - testPadding(new TBCPadding(), rand, - Hex.decode("ffffff0000000000"), - Hex.decode("00000000ffffffff")); - - testPadding(new ZeroBytePadding(), rand, - Hex.decode("ffffff0000000000"), - null); - - testPadding(new ISO7816d4Padding(), rand, - Hex.decode("ffffff8000000000"), - Hex.decode("0000000080000000")); - - testOutputSizes(); - - } - - public String getName() - { - return "PaddingTest"; - } - - public static void main( - String[] args) - { - runTest(new PaddingTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Poly1305Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Poly1305Test.java deleted file mode 100644 index 5e8d75558..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Poly1305Test.java +++ /dev/null @@ -1,512 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.CipherKeyGenerator; -import com.fr.third.org.bouncycastle.crypto.KeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.generators.Poly1305KeyGenerator; -import com.fr.third.org.bouncycastle.crypto.macs.Poly1305; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/* - */ -public class Poly1305Test - extends SimpleTest -{ - private static final int MAXLEN = 1000; - - private static class TestCase - { - private final byte[] key; - private final byte[] nonce; - private final byte[] message; - private final byte[] expectedMac; - - public TestCase(String key, String nonce, String message, String expectedMac) - { - this.key = Hex.decode(key); - // nacl test case keys are not pre-clamped - Poly1305KeyGenerator.clamp(this.key); - this.nonce = (nonce == null) ? null : Hex.decode(nonce); - this.message = Hex.decode(message); - this.expectedMac = Hex.decode(expectedMac); - } - } - - private static TestCase[] CASES = { - // Raw Poly1305 - // onetimeauth.c from nacl-20110221 - new TestCase("eea6a7251c1e72916d11c2cb214d3c25" + "2539121d8e234e652d651fa4c8cff880", null, - "8e993b9f48681273c29650ba32fc76ce48332ea7164d96a4476fb8c531a1186a" - + "c0dfc17c98dce87b4da7f011ec48c97271d2c20f9b928fe2270d6fb863d51738" - + "b48eeee314a7cc8ab932164548e526ae90224368517acfeabd6bb3732bc0e9da" - + "99832b61ca01b6de56244a9e88d5f9b37973f622a43d14a6599b1f654cb45a74e355a5", - "f3ffc7703f9400e52a7dfb4b3d3305d9"), - // Poly1305-AES - // Loop 1 of test-poly1305aes from poly1305aes-20050218 - new TestCase("0000000000000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000", "", "66e94bd4ef8a2c3b884cfa59ca342b2e"), - new TestCase("f795bd0a50e29e0710d3130a20e98d0c" + "f795bd4a52e29ed713d313fa20e98dbc", - "917cf69ebd68b2ec9b9fe9a3eadda692", "66f7", "5ca585c75e8f8f025e710cabc9a1508b"), - new TestCase("3ef49901c8e11c000430d90ad45e7603" + "e69dae0aab9f91c03a325dcc9436fa90", - "166450152e2394835606a9d1dd2cdc8b", "66f75c0e0c7a406586", "2924f51b9c2eff5df09db61dd03a9ca1"), - new TestCase("da4afc035087d90e503f8f0ea08c3e0d" + "85a4ea91a7de0b0d96eed0d4bf6ecf1c", - "0b6ef7a0b8f8c738b0f8d5995415271f", - "66f75c0e0c7a40658629e3392f7f8e3349a02191ffd49f39879a8d9d1d0e23ea", - "3c5a13adb18d31c64cc29972030c917d"), - new TestCase( - "ca3c6a0da0a864024ca3090628c28e0d" + "25eb69bac5cdf7d6bfcee4d9d5507b82", - "046772a4f0a8de92e4f0d628cdb04484", - "66f75c0e0c7a40658629e3392f7f8e3349a02191ffd49f39879a8d9d1d0e23ea3caa4d240bd2ab8a8c4a6bb8d3288d9de4b793f05e97646dd4d98055de", - "fc5fb58dc65daf19b14d1d05da1064e8"), - // Specific test cases generated from test-poly1305aes from poly1305aes-20050218 that - // expose Java unsigned integer problems - new TestCase( - "01bcb20bfc8b6e03609ddd09f44b060f" + "95cc0e44d0b79a8856afcae1bec4fe3c", - null, - "66f75c0e0c7a40658629e3392f7f8e3349a02191ffd49f39879a8d9d1d0e23ea3caa4d240bd2ab8a8c4a6bb8d3288d9de4b793f05e97646dd4d98055de" - + "fc3e0677d956b4c62664bac15962ab15d93ccbbc03aafdbde779162ed93b55361f0f8acaa41d50ef5175927fe79ea316186516eef15001cd04d3524a55" - + "e4fa3c5ca479d3aaa8a897c21807f721b6270ffc68b6889d81a116799f6aaa35d8e04c7a7dd5e6da2519e8759f54e906696f5772fee093283bcef7b930" - + "aed50323bcbc8c820c67422c1e16bdc022a9c0277c9d95fef0ea4ee11e2b27276da811523c5acb80154989f8a67ee9e3fa30b73b0c1c34bf46e3464d97" - + "7cd7fcd0ac3b82721080bb0d9b982ee2c77feee983d7ba35da88ce86955002940652ab63bc56fb16f994da2b01d74356509d7d1b6d7956b0e5a557757b" - + "d1ced2eef8650bc5b6d426108c1518abcbd0befb6a0d5fd57a3e2dbf31458eab63df66613653d4beae73f5c40eb438fbcfdcf4a4ba46320184b9ca0da4" - + "dfae77de7ccc910356caea3243f33a3c81b064b3b7cedc7435c223f664227215715980e6e0bb570d459ba80d7512dbe458c8f0f3f52d659b6e8eef19ee" - + "71aea2ced85c7a42ffca6522a62db49a2a46eff72bd7f7e0883acd087183f0627f3537a4d558754ed63358e8182bee196735b361dc9bd64d5e34e1074a" - + "855655d2974cc6fa1653754cf40f561d8c7dc526aab2908ec2d2b977cde1a1fb1071e32f40e049ea20f30368ba1592b4fe57fb51595d23acbdace324cd" - + "d78060a17187c662368854e915402d9b52fb21e984663e41c26a109437e162cfaf071b53f77e50000a5388ff183b82ce7a1af476c416d7d204157b3633" - + "b2f4ec077b699b032816997e37bceded8d4a04976fd7d0c0b029f290794c3be504c5242287ea2f831f11ed5690d92775cd6e863d7731fd4da687ebfb13" - + "df4c41dc0fb8", "ae345d555eb04d6947bb95c0965237e2"), - new TestCase( - "cd07fd0ef8c0be0afcbdb30af4af0009" + "76fb3635a2dc92a1f768163ab12f2187", - null, - "f05204a74f0f88a7fa1a95b84ec3d8ffb36fcdc7723ea65dfe7cd464e86e0abf6b9d51db3220cfd8496ad6e6d36ebee8d990f9ce0d3bb7f72b7ab5b3ab0a73240d11efe772c857021ae859db4933cdde4387b471d2ce700fef4b81087f8f47c307881fd83017afcd15b8d21edf9b704677f46df97b07e5b83f87c8abd90af9b1d0f9e2710e8ebd0d4d1c6a055abea861f42368bed94d9373e909c1d3715b221c16bc524c55c31ec3eab204850bb2474a84f9917038eff9d921130951391b5c54f09b5e1de833ea2cd7d3b306740abb7096d1e173da83427da2adddd3631eda30b54dbf487f2b082e8646f07d6e0a87e97522ca38d4ace4954bf3db6dd3a93b06fa18eb56856627ed6cffcd7ae26374554ca18ab8905f26331d323fe10e6e70624c7bc07a70f06ecd804b48f8f7e75e910165e1beb554f1f0ec7949c9c8d429a206b4d5c0653102249b6098e6b45fac2a07ff0220b0b8ae8f4c6bcc0c813a7cd141fa8b398b42575fc395747c5a0257ac41d6c1f434cfbf5dfe8349f5347ef6b60e611f5d6c3cbc20ca2555274d1934325824cef4809da293ea13f181929e2af025bbd1c9abdc3af93afd4c50a2854ade3887f4d2c8c225168052c16e74d76d2dd3e9467a2c5b8e15c06ffbffa42b8536384139f07e195a8c9f70f514f31dca4eb2cf262c0dcbde53654b6250a29efe21d54e83c80e005a1cad36d5934ff01c32e4bc5fe06d03064ff4a268517df4a94c759289f323734318cfa5d859d4ce9c16e63d02dff0896976f521607638535d2ee8dd3312e1ddc80a55d34fe829ab954c1ebd54d929954770f1be9d32b4c05003c5c9e97943b6431e2afe820b1e967b19843e5985a131b1100517cdc363799104af91e2cf3f53cb8fd003653a6dd8a31a3f9d566a7124b0ffe9695bcb87c482eb60106f88198f766a40bc0f4873c23653c5f9e7a8e446f770beb8034cf01d21028ba15ccee21a8db918c4829d61c88bfa927bc5def831501796c5b401a60a6b1b433c9fb905c8cd40412fffee81ab", - "045be28cc52009f506bdbfabedacf0b4"), - // Test case from JIRA issue BJA-620 - new TestCase( - "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff", - null, - "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff" - + "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff" - + "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff" - + "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffff", - "c80cb43844f387946e5aa6085bdf67da") - - - }; - - public String getName() - { - return "Poly1305"; - } - - public void performTest() - throws Exception - { - testKeyGenerator(); - testInit(); - for (int i = 0; i < CASES.length; i++) - { - testCase(i); - } - testSequential(); - testReset(); - rfc7539Test(); - } - - private void testCase(int i) - { - byte[] out = new byte[16]; - TestCase tc = CASES[i]; - - final Mac mac; - if (tc.nonce == null) - { - // Raw Poly1305 test - don't do any transform on AES key part - mac = new Poly1305(); - mac.init(new KeyParameter(tc.key)); - } - else - { - mac = new Poly1305(new AESEngine()); - mac.init(new ParametersWithIV(new KeyParameter(tc.key), tc.nonce)); - } - mac.update(tc.message, 0, tc.message.length); - mac.doFinal(out, 0); - - if (!Arrays.areEqual(out, tc.expectedMac)) - { - fail("Mismatched output " + i, new String(Hex.encode(tc.expectedMac)), new String(Hex.encode(out))); - } - } - - private void testSequential() - { - // Sequential test, adapted from test-poly1305aes - int len; - byte[] kr = new byte[32]; - byte[] m = new byte[MAXLEN]; - byte[] n = new byte[16]; - byte[] out = new byte[16]; - - int c = 0; - final Mac mac = new Poly1305(new AESEngine()); - for (int loop = 0; loop < 13; loop++) - { - len = 0; - for (; ; ) - { - c++; - mac.init(new ParametersWithIV(new KeyParameter(kr), n)); - mac.update(m, 0, len); - mac.doFinal(out, 0); - - // if (c == 678) - // { - // TestCase tc = CASES[0]; - // - // if (!Arrays.areEqual(tc.key, kr)) - // { - // System.err.println("Key bad"); - // System.err.println(new String(Hex.encode(tc.key))); - // System.err.println(new String(Hex.encode(kr))); - // System.exit(1); - // } - // if (!Arrays.areEqual(tc.nonce, n)) - // { - // System.err.println("Nonce bad"); - // System.exit(1); - // } - // System.out.printf("[%d] m: %s\n", c, new String(Hex.encode(m, 0, len))); - // System.out.printf("[%d] K: %s\n", c, new String(Hex.encodje(kr))); - // System.out.printf("[%d] N: %s\n", c, new String(Hex.encode(n))); - // System.out.printf("[%d] M: ", c); - // } - // System.out.printf("%d/%s\n", c, new String(Hex.encode(out))); - - if (len >= MAXLEN) - { - break; - } - n[0] ^= loop; - for (int i = 0; i < 16; ++i) - { - n[i] ^= out[i]; - } - if (len % 2 != 0) - { - for (int i = 0; i < 16; ++i) - { - kr[i] ^= out[i]; - } - } - if (len % 3 != 0) - { - for (int i = 0; i < 16; ++i) - { - kr[i + 16] ^= out[i]; - } - } - Poly1305KeyGenerator.clamp(kr); - m[len++] ^= out[0]; - } - } - // Output after 13 loops as generated by poly1305 ref - if (c != 13013 || !Arrays.areEqual(out, Hex.decode("89824ddf0816481051f4a82731cd56d5"))) - { - fail("Sequential Poly1305 " + c, "89824ddf0816481051f4a82731cd56d5", new String(Hex.encode(out))); - } - } - - private void testReset() - { - CipherKeyGenerator gen = new Poly1305KeyGenerator(); - gen.init(new KeyGenerationParameters(new SecureRandom(), 256)); - byte[] k = gen.generateKey(); - - byte[] m = new byte[10000]; - byte[] check = new byte[16]; - byte[] out = new byte[16]; - - // Generate baseline - Mac poly = new Poly1305(new AESEngine()); - poly.init(new ParametersWithIV(new KeyParameter(k), new byte[16])); - - poly.update(m, 0, m.length); - poly.doFinal(check, 0); - - // Check reset after doFinal - poly.update(m, 0, m.length); - poly.doFinal(out, 0); - - if (!Arrays.areEqual(check, out)) - { - fail("Mac not reset after doFinal"); - } - - // Check reset - poly.update((byte)1); - poly.update((byte)2); - poly.reset(); - poly.update(m, 0, m.length); - poly.doFinal(out, 0); - - if (!Arrays.areEqual(check, out)) - { - fail("Mac not reset after doFinal"); - } - - // Check init resets - poly.update((byte)1); - poly.update((byte)2); - poly.init(new ParametersWithIV(new KeyParameter(k), new byte[16])); - poly.update(m, 0, m.length); - poly.doFinal(out, 0); - - if (!Arrays.areEqual(check, out)) - { - fail("Mac not reset after doFinal"); - } - } - - private void testInit() - { - CipherKeyGenerator gen = new Poly1305KeyGenerator(); - gen.init(new KeyGenerationParameters(new SecureRandom(), 256)); - byte[] k = gen.generateKey(); - - Mac poly = new Poly1305(new AESEngine()); - poly.init(new ParametersWithIV(new KeyParameter(k), new byte[16])); - - try - { - poly.init(new ParametersWithIV(new KeyParameter(k), new byte[15])); - fail("16 byte nonce required"); - } - catch (IllegalArgumentException e) - { - // Expected - } - - try - { - byte[] k2 = new byte[k.length - 1]; - System.arraycopy(k, 0, k2, 0, k2.length); - poly.init(new ParametersWithIV(new KeyParameter(k2), new byte[16])); - fail("32 byte key required"); - } - catch (IllegalArgumentException e) - { - // Expected - } - /* - try - { - k[19] = (byte)0xFF; - poly.init(new ParametersWithIV(new KeyParameter(k), new byte[16])); - fail("Unclamped key should not be accepted."); - } catch (IllegalArgumentException e) - { - // Expected - } - */ - } - - private void testKeyGenerator() - { - CipherKeyGenerator gen = new Poly1305KeyGenerator(); - gen.init(new KeyGenerationParameters(new SecureRandom(), 256)); - byte[] k = gen.generateKey(); - - if (k.length != 32) - { - fail("Poly1305 key should be 256 bits."); - } - - try - { - Poly1305KeyGenerator.checkKey(k); - } - catch (IllegalArgumentException e) - { - fail("Poly1305 key should be clamped on generation."); - } - - byte[] k2 = new byte[k.length]; - System.arraycopy(k, 0, k2, 0, k2.length); - Poly1305KeyGenerator.clamp(k); - if (!Arrays.areEqual(k, k2)) - { - fail("Poly1305 key should be clamped on generation."); - } - /* - try - { - k2[19] = (byte)0xff; - Poly1305KeyGenerator.checkKey(k2); - fail("Unclamped key should fail check."); - } catch (IllegalArgumentException e) - { - // Expected - } - */ - } - - public void rfc7539Test() - { - // From RFC 7539 - byte[] keyMaterial = Hex.decode("85d6be7857556d337f4452fe42d506a80103808afb0db2fd4abff6af4149f51b"); - byte[] data = Hex.decode("43727970746f677261706869 63 20 46 6f 72 75 6d 20 52 65 73 65 61 72 63 68 20 47 72 6f7570"); - byte[] expected = Hex.decode("a8061dc1305136c6c22b8baf0c0127a9"); - - checkVector(keyMaterial, data, expected); - - data = Hex.decode("48656c6c6f20776f726c6421"); - keyMaterial = Hex.decode( - "746869732069732033322d6279746520" + - "6b657920666f7220506f6c7931333035"); - - checkVector(keyMaterial, data, Hex.decode("a6f745008f81c916a20dcc74eef2b2f0")); - - // A.3 #1 - keyMaterial = Hex.decode("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - - data = Hex.decode( - "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" - + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" - + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" - + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - - checkVector(keyMaterial, data, Hex.decode("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")); - - // A.3 #2 - keyMaterial = Hex.decode("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0036 e5 f6 b5 c5 e0 60 70 f0 ef ca 96 22 7a 86 3e"); - - data = Hex.decode( - "41 6e 79 20 73 75 62 6d 69 73 73 69 6f 6e 20 74" - + "6f 20 74 68 65 20 49 45 54 46 20 69 6e 74 65 6e" - + "64 65 64 20 62 79 20 74 68 65 20 43 6f 6e 74 72" - + "69 62 75 74 6f 72 20 66 6f 72 20 70 75 62 6c 69" - + "63 61 74 69 6f 6e 20 61 73 20 61 6c 6c 20 6f 72" - + "20 70 61 72 74 20 6f 66 20 61 6e 20 49 45 54 46" - + "20 49 6e 74 65 72 6e 65 74 2d 44 72 61 66 74 20" - + "6f 72 20 52 46 43 20 61 6e 64 20 61 6e 79 20 73" - + "74 61 74 65 6d 65 6e 74 20 6d 61 64 65 20 77 69" - + "74 68 69 6e 20 74 68 65 20 63 6f 6e 74 65 78 74" - + "20 6f 66 20 61 6e 20 49 45 54 46 20 61 63 74 69" - + "76 69 74 79 20 69 73 20 63 6f 6e 73 69 64 65 72" - + "65 64 20 61 6e 20 22 49 45 54 46 20 43 6f 6e 74" - + "72 69 62 75 74 69 6f 6e 22 2e 20 53 75 63 68 20" - + "73 74 61 74 65 6d 65 6e 74 73 20 69 6e 63 6c 75" - + "64 65 20 6f 72 61 6c 20 73 74 61 74 65 6d 65 6e" - + "74 73 20 69 6e 20 49 45 54 46 20 73 65 73 73 69" - + "6f 6e 73 2c 20 61 73 20 77 65 6c 6c 20 61 73 20" - + "77 72 69 74 74 65 6e 20 61 6e 64 20 65 6c 65 63" - + "74 72 6f 6e 69 63 20 63 6f 6d 6d 75 6e 69 63 61" - + "74 69 6f 6e 73 20 6d 61 64 65 20 61 74 20 61 6e" - + "79 20 74 69 6d 65 20 6f 72 20 70 6c 61 63 65 2c" - + "20 77 68 69 63 68 20 61 72 65 20 61 64 64 72 65" - + "73 73 65 64 20 74 6f"); - - checkVector(keyMaterial, data, Hex.decode("36 e5 f6 b5 c5 e0 60 70 f0 ef ca 96 22 7a 86 3e")); - - // A.3 #3 - keyMaterial = Hex.decode("36 e5 f6 b5 c5 e0 60 70 f0 ef ca 96 22 7a 86 3e00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - - checkVector(keyMaterial, data, Hex.decode("f3 47 7e 7c d9 54 17 af 89 a6 b8 79 4c 31 0c f0")); - - // A.3 #4 - - keyMaterial = Hex.decode("1c 92 40 a5 eb 55 d3 8a f3 33 88 86 04 f6 b5 f0 47 39 17 c1 40 2b 80 09 9d ca 5c bc 20 70 75 c0"); - - data = Hex.decode( - "27 54 77 61 73 20 62 72 69 6c 6c 69 67 2c 20 61" - + "6e 64 20 74 68 65 20 73 6c 69 74 68 79 20 74 6f" - + "76 65 73 0a 44 69 64 20 67 79 72 65 20 61 6e 64" - + "20 67 69 6d 62 6c 65 20 69 6e 20 74 68 65 20 77" - + "61 62 65 3a 0a 41 6c 6c 20 6d 69 6d 73 79 20 77" - + "65 72 65 20 74 68 65 20 62 6f 72 6f 67 6f 76 65" - + "73 2c 0a 41 6e 64 20 74 68 65 20 6d 6f 6d 65 20" - + "72 61 74 68 73 20 6f 75 74 67 72 61 62 65 2e"); - - checkVector(keyMaterial, data, Hex.decode("45 41 66 9a 7e aa ee 61 e7 08 dc 7c bc c5 eb 62")); - - // A.3 #5 - keyMaterial = Hex.decode("02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - data = Hex.decode("FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF"); - - checkVector(keyMaterial, data, Hex.decode("03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")); - - // A.3 #6 - keyMaterial = Hex.decode("02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF"); - data = Hex.decode("02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - - checkVector(keyMaterial, data, Hex.decode("03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")); - - // A.3 #7 - keyMaterial = Hex.decode("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - data = Hex.decode("FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FFF0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - - checkVector(keyMaterial, data, Hex.decode("05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")); - - // A.3 #8 - keyMaterial = Hex.decode("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - data = Hex.decode("FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FFFB FE FE FE FE FE FE FE FE FE FE FE FE FE FE FE01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01"); - - checkVector(keyMaterial, data, Hex.decode("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")); - - // A.3 #9 - keyMaterial = Hex.decode("02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - data = Hex.decode("FD FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF"); - - checkVector(keyMaterial, data, Hex.decode("FA FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF")); - - // A.3 #10 - keyMaterial = Hex.decode("01 00 00 00 00 00 00 00 04 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - data = Hex.decode( - "E3 35 94 D7 50 5E 43 B9 00 00 00 00 00 00 00 00" - + "33 94 D7 50 5E 43 79 CD 01 00 00 00 00 00 00 00" - + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" - + "01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - - checkVector(keyMaterial, data, Hex.decode("14 00 00 00 00 00 00 00 55 00 00 00 00 00 00 00")); - - // A.3 #11 - keyMaterial = Hex.decode("01 00 00 00 00 00 00 00 04 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - data = Hex.decode( - "E3 35 94 D7 50 5E 43 B9 00 00 00 00 00 00 00 00" - + "33 94 D7 50 5E 43 79 CD 01 00 00 00 00 00 00 00" - + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - - checkVector(keyMaterial, data, Hex.decode("13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")); - } - - private void checkVector(byte[] keyMaterial, byte[] input, byte[] tag) - { - Poly1305 poly1305 = new Poly1305(); - - poly1305.init(new KeyParameter(keyMaterial)); - - poly1305.update(input, 0, input.length); - - byte[] mac = new byte[poly1305.getMacSize()]; - - poly1305.doFinal(mac, 0); - - if (!Arrays.areEqual(tag, mac)) - { - fail("rfc7539", Hex.toHexString(tag), Hex.toHexString(mac)); - } - } - - public static void main(String[] args) - throws Exception - { - runTest(new Poly1305Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC2Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC2Test.java deleted file mode 100644 index d99946e0f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC2Test.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.RC2Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.RC2Parameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - -/** - * RC2 tester - vectors from ftp://ftp.isi.edu/in-notes/rfc2268.txt - * - * RFC 2268 "A Description of the RC2(r) Encryption Algorithm" - */ -public class RC2Test - extends CipherTest -{ - static BlockCipherVectorTest[] tests = - { - new BlockCipherVectorTest(0, new RC2Engine(), - new RC2Parameters(Hex.decode("0000000000000000"), 63), - "0000000000000000", "ebb773f993278eff"), - - new BlockCipherVectorTest(1, new RC2Engine(), - new RC2Parameters(Hex.decode("ffffffffffffffff"), 64), - "ffffffffffffffff", "278b27e42e2f0d49"), - - new BlockCipherVectorTest(2, new RC2Engine(), - new RC2Parameters(Hex.decode("3000000000000000"), 64), - "1000000000000001", "30649edf9be7d2c2"), - - new BlockCipherVectorTest(3, new RC2Engine(), - new RC2Parameters(Hex.decode("88"), 64), - "0000000000000000", "61a8a244adacccf0"), - - new BlockCipherVectorTest(4, new RC2Engine(), - new RC2Parameters(Hex.decode("88bca90e90875a"), 64), - "0000000000000000", "6ccf4308974c267f"), - - new BlockCipherVectorTest(5, new RC2Engine(), - new RC2Parameters(Hex.decode("88bca90e90875a7f0f79c384627bafb2"), 64), - "0000000000000000", "1a807d272bbe5db1"), - - new BlockCipherVectorTest(6, new RC2Engine(), - new RC2Parameters(Hex.decode("88bca90e90875a7f0f79c384627bafb2"), 128), - "0000000000000000", "2269552ab0f85ca6"), - - new BlockCipherVectorTest(7, new RC2Engine(), - new RC2Parameters(Hex.decode("88bca90e90875a7f0f79c384627bafb216f80a6f85920584c42fceb0be255daf1e"), 129), - "0000000000000000", "5b78d3a43dfff1f1") - }; - - RC2Test() - { - super(tests, new RC2Engine(), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "RC2"; - } - - public static void main( - String[] args) - { - runTest(new RC2Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC2WrapTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC2WrapTest.java deleted file mode 100644 index 86fcbfc4a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC2WrapTest.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.Wrapper; -import com.fr.third.org.bouncycastle.crypto.engines.RC2WrapEngine; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.params.RC2Parameters; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * RC2 wrap tester - */ -public class RC2WrapTest - implements Test -{ - private class RFCRandom - extends SecureRandom - { - public void nextBytes( - byte[] nextBytes) - { - System.arraycopy(Hex.decode("4845cce7fd1250"), 0, nextBytes, 0, nextBytes.length); - } - } - - private TestResult wrapTest( - int id, - CipherParameters paramsWrap, - CipherParameters paramsUnwrap, - byte[] in, - byte[] out) - { - Wrapper wrapper = new RC2WrapEngine(); - - wrapper.init(true, paramsWrap); - - try - { - byte[] cText = wrapper.wrap(in, 0, in.length); - if (!Arrays.areEqual(cText, out)) - { - return new SimpleTestResult(false, getName() + ": failed wrap test " + id + " expected " + new String(Hex.encode(out)) + " got " + new String(Hex.encode(cText))); - } - } - catch (Exception e) - { - return new SimpleTestResult(false, getName() + ": failed wrap test exception " + e.toString(), e); - } - - wrapper.init(false, paramsUnwrap); - - try - { - byte[] pText = wrapper.unwrap(out, 0, out.length); - if (!Arrays.areEqual(pText, in)) - { - return new SimpleTestResult(false, getName() + ": failed unwrap test " + id + " expected " + new String(Hex.encode(in)) + " got " + new String(Hex.encode(pText))); - } - } - catch (Exception e) - { - return new SimpleTestResult(false, getName() + ": failed unwrap test exception " + e.toString(), e); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public TestResult perform() - { - byte[] kek1 = Hex.decode("fd04fd08060707fb0003fefffd02fe05"); - byte[] iv1 = Hex.decode("c7d90059b29e97f7"); - byte[] in1 = Hex.decode("b70a25fbc9d86a86050ce0d711ead4d9"); - byte[] out1 = Hex.decode("70e699fb5701f7833330fb71e87c85a420bdc99af05d22af5a0e48d35f3138986cbaafb4b28d4f35"); - // - // note the RFC 3217 test specifies a key to be used with an effective key size of - // 40 bits which is why it is done here - in practice nothing less than 128 bits should be used. - // - CipherParameters paramWrap = new ParametersWithRandom(new ParametersWithIV(new RC2Parameters(kek1, 40), iv1), new RFCRandom()); - CipherParameters paramUnwrap = new RC2Parameters(kek1, 40); - - TestResult result = wrapTest(1, paramWrap, paramUnwrap, in1, out1); - - if (!result.isSuccessful()) - { - return result; - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public String getName() - { - return "RC2Wrap"; - } - - public static void main( - String[] args) - { - RC2WrapTest test = new RC2WrapTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC4Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC4Test.java deleted file mode 100644 index b874a0b81..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC4Test.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.RC4Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * RC4 Test - */ -public class RC4Test - extends SimpleTest -{ - StreamCipherVectorTest[] tests = - { - new StreamCipherVectorTest(0, new RC4Engine(), - new KeyParameter(Hex.decode("0123456789ABCDEF")), - "4e6f772069732074", "3afbb5c77938280d"), - new StreamCipherVectorTest(0, new RC4Engine(), - new KeyParameter(Hex.decode("0123456789ABCDEF")), - "68652074696d6520", "1cf1e29379266d59"), - new StreamCipherVectorTest(0, new RC4Engine(), - new KeyParameter(Hex.decode("0123456789ABCDEF")), - "666f7220616c6c20", "12fbb0c771276459") - }; - - public String getName() - { - return "RC4"; - } - - public void performTest() - { - for (int i = 0; i != tests.length; i++) - { - tests[i].performTest(); - } - } - - public static void main( - String[] args) - { - runTest(new RC4Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC5Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC5Test.java deleted file mode 100644 index f530d48fe..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC5Test.java +++ /dev/null @@ -1,188 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.RC532Engine; -import com.fr.third.org.bouncycastle.crypto.engines.RC564Engine; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.crypto.params.RC5Parameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * RC5 tester - vectors from ftp://ftp.nordu.net/rfc/rfc2040.txt - * - * RFC 2040 "The RC5, RC5-CBC, RC5-CBC-Pad, and RC5-CTS Algorithms" - */ -public class RC5Test - implements Test -{ - BlockCipherVectorTest[] tests = - { - new BlockCipherVectorTest(0, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00"), 0), - Hex.decode("0000000000000000")), - "0000000000000000", "7a7bba4d79111d1e"), - new BlockCipherVectorTest(1, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00"), 0), - Hex.decode("0000000000000000")), - "ffffffffffffffff", "797bba4d78111d1e"), - new BlockCipherVectorTest(2, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00"), 0), - Hex.decode("0000000000000001")), - "0000000000000000", "7a7bba4d79111d1f"), - new BlockCipherVectorTest(3, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00"), 0), - Hex.decode("0000000000000000")), - "0000000000000001", "7a7bba4d79111d1f"), - new BlockCipherVectorTest(4, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00"), 0), - Hex.decode("0102030405060708")), - "1020304050607080", "8b9ded91ce7794a6"), - new BlockCipherVectorTest(5, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("11"), 1), - Hex.decode("0000000000000000")), - "0000000000000000", "2f759fe7ad86a378"), - new BlockCipherVectorTest(6, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00"), 2), - Hex.decode("0000000000000000")), - "0000000000000000", "dca2694bf40e0788"), - new BlockCipherVectorTest(7, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00000000"), 2), - Hex.decode("0000000000000000")), - "0000000000000000", "dca2694bf40e0788"), - new BlockCipherVectorTest(8, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00000000"), 8), - Hex.decode("0000000000000000")), - "0000000000000000", "dcfe098577eca5ff"), - new BlockCipherVectorTest(9, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00"), 8), - Hex.decode("0102030405060708")), - "1020304050607080", "9646fb77638f9ca8"), - new BlockCipherVectorTest(10, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00"), 12), - Hex.decode("0102030405060708")), - "1020304050607080", "b2b3209db6594da4"), - new BlockCipherVectorTest(11, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00"), 16), - Hex.decode("0102030405060708")), - "1020304050607080", "545f7f32a5fc3836"), - new BlockCipherVectorTest(12, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("01020304"), 8), - Hex.decode("0000000000000000")), - "ffffffffffffffff", "8285e7c1b5bc7402"), - new BlockCipherVectorTest(13, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("01020304"), 12), - Hex.decode("0000000000000000")), - "ffffffffffffffff", "fc586f92f7080934"), - new BlockCipherVectorTest(14, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("01020304"), 16), - Hex.decode("0000000000000000")), - "ffffffffffffffff", "cf270ef9717ff7c4"), - new BlockCipherVectorTest(15, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("0102030405060708"), 12), - Hex.decode("0000000000000000")), - "ffffffffffffffff", "e493f1c1bb4d6e8c"), - new BlockCipherVectorTest(16, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("0102030405060708"), 8), - Hex.decode("0102030405060708")), - "1020304050607080", "5c4c041e0f217ac3"), - new BlockCipherVectorTest(17, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("0102030405060708"), 12), - Hex.decode("0102030405060708")), - "1020304050607080", "921f12485373b4f7"), - new BlockCipherVectorTest(18, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("0102030405060708"), 16), - Hex.decode("0102030405060708")), - "1020304050607080", "5ba0ca6bbe7f5fad"), - new BlockCipherVectorTest(19, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("01020304050607081020304050607080"), 8), - Hex.decode("0102030405060708")), - "1020304050607080", "c533771cd0110e63"), - new BlockCipherVectorTest(20, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("01020304050607081020304050607080"), 12), - Hex.decode("0102030405060708")), - "1020304050607080", "294ddb46b3278d60"), - new BlockCipherVectorTest(21, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("01020304050607081020304050607080"), 16), - Hex.decode("0102030405060708")), - "1020304050607080", "dad6bda9dfe8f7e8"), - new BlockCipherVectorTest(22, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("0102030405"), 12), - Hex.decode("0000000000000000")), - "ffffffffffffffff", "97e0787837ed317f"), - new BlockCipherVectorTest(23, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("0102030405"), 8), - Hex.decode("0000000000000000")), - "ffffffffffffffff", "7875dbf6738c6478"), - new BlockCipherVectorTest(23, new CBCBlockCipher(new RC532Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("0102030405"), 8), - Hex.decode("7875dbf6738c6478")), - "0808080808080808", "8f34c3c681c99695"), - new BlockCipherVectorTest(640, new CBCBlockCipher(new RC564Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00"), 0), - Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", "9f09b98d3f6062d9d4d59973d00e0e63"), - new BlockCipherVectorTest(641, new CBCBlockCipher(new RC564Engine()), - new ParametersWithIV( - new RC5Parameters(Hex.decode("00"), 0), - Hex.decode("00000000000000000000000000000000")), - "ffffffffffffffffffffffffffffffff", "9e09b98d3f6062d9d3d59973d00e0e63") - }; - - public String getName() - { - return "RC5"; - } - - public TestResult perform() - { - for (int i = 0; i != tests.length; i++) - { - TestResult res = tests[i].perform(); - - if (!res.isSuccessful()) - { - return res; - } - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public static void main( - String[] args) - { - RC5Test test = new RC5Test(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC6Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC6Test.java deleted file mode 100644 index d2df503c8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RC6Test.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.RC6Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * RC6 Test - test vectors from AES Submitted RSA Reference implementation. - * ftp://ftp.funet.fi/pub/crypt/cryptography/symmetric/aes/rc6-unix-refc.tar - */ -public class RC6Test - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new RC6Engine(), - new KeyParameter( - Hex.decode("00000000000000000000000000000000")), - "80000000000000000000000000000000", - "f71f65e7b80c0c6966fee607984b5cdf"), - new BlockCipherVectorTest(1, new RC6Engine(), - new KeyParameter( - Hex.decode("000000000000000000000000000000008000000000000000")), - "00000000000000000000000000000000", - "dd04c176440bbc6686c90aee775bd368"), - new BlockCipherVectorTest(2, new RC6Engine(), - new KeyParameter( - Hex.decode("000000000000000000000000000000000000001000000000")), - "00000000000000000000000000000000", - "937fe02d20fcb72f0f57201012b88ba4"), - new BlockCipherVectorTest(3, new RC6Engine(), - new KeyParameter( - Hex.decode("00000001000000000000000000000000")), - "00000000000000000000000000000000", - "8a380594d7396453771a1dfbe2914c8e"), - new BlockCipherVectorTest(4, new RC6Engine(), - new KeyParameter( - Hex.decode("1000000000000000000000000000000000000000000000000000000000000000")), - "00000000000000000000000000000000", - "11395d4bfe4c8258979ee2bf2d24dff4"), - new BlockCipherVectorTest(5, new RC6Engine(), - new KeyParameter( - Hex.decode("0000000000000000000000000000000000080000000000000000000000000000")), - "00000000000000000000000000000000", - "3d6f7e99f6512553bb983e8f75672b97") - }; - - RC6Test() - { - super(tests, new RC6Engine(), new KeyParameter(new byte[32])); - } - - public String getName() - { - return "RC6"; - } - - public static void main( - String[] args) - { - runTest(new RC6Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RFC3211WrapTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RFC3211WrapTest.java deleted file mode 100644 index 42397d19f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RFC3211WrapTest.java +++ /dev/null @@ -1,203 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.Wrapper; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESedeEngine; -import com.fr.third.org.bouncycastle.crypto.engines.RFC3211WrapEngine; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.prng.FixedSecureRandom; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Wrap Test based on RFC3211 test vectors - */ -public class RFC3211WrapTest - extends SimpleTest -{ - SecureRandom r1 = new FixedSecureRandom(Hex.decode("C436F541")); - - SecureRandom r2 = new FixedSecureRandom(Hex.decode("FA060A45")); - - public String getName() - { - return "RFC3211Wrap"; - } - - private void wrapTest( - int id, - BlockCipher engine, - byte[] kek, - byte[] iv, - SecureRandom rand, - byte[] in, - byte[] out) - throws Exception - { - Wrapper wrapper = new RFC3211WrapEngine(engine); - - wrapper.init(true, new ParametersWithRandom(new ParametersWithIV(new KeyParameter(kek), iv), rand)); - - byte[] cText = wrapper.wrap(in, 0, in.length); - if (!Arrays.areEqual(cText, out)) - { - fail("failed wrap test " + id + " expected " + new String(Hex.encode(out)) + " got " + new String(Hex.encode(cText))); - } - - wrapper.init(false, new ParametersWithIV(new KeyParameter(kek), iv)); - - byte[] pText = wrapper.unwrap(out, 0, out.length); - if (!Arrays.areEqual(pText, in)) - { - fail("rfailed unwrap test " + id + " expected " + new String(Hex.encode(in)) + " got " + new String(Hex.encode(pText))); - } - } - - private void testCorruption() - throws InvalidCipherTextException - { - byte[] kek = Hex.decode("D1DAA78615F287E6"); - byte[] iv = Hex.decode("EFE598EF21B33D6D"); - - Wrapper wrapper = new RFC3211WrapEngine(new DESEngine()); - - wrapper.init(false, new ParametersWithIV(new KeyParameter(kek), iv)); - - byte[] block = Hex.decode("ff739D838C627C897323A2F8C436F541"); - encryptBlock(kek, iv, block); - - try - { - wrapper.unwrap(block, 0, block.length); - - fail("bad length not detected"); - } - catch (InvalidCipherTextException e) - { - if (!e.getMessage().equals("wrapped key corrupted")) - { - fail("wrong exception on length"); - } - } - - block = Hex.decode("08639D838C627C897323A2F8C436F541"); - testChecksum(kek, iv, block, wrapper); - - block = Hex.decode("08736D838C627C897323A2F8C436F541"); - testChecksum(kek, iv, block, wrapper); - - block = Hex.decode("08739D638C627C897323A2F8C436F541"); - testChecksum(kek, iv, block, wrapper); - } - - private void testChecksum(byte[] kek, byte[] iv, byte[] block, Wrapper wrapper) - { - encryptBlock(kek, iv, block); - - try - { - wrapper.unwrap(block, 0, block.length); - - fail("bad checksum not detected"); - } - catch (InvalidCipherTextException e) - { - if (!e.getMessage().equals("wrapped key corrupted")) - { - fail("wrong exception"); - } - } - } - - private void encryptBlock(byte[] key, byte[] iv, byte[] cekBlock) - { - BlockCipher engine = new CBCBlockCipher(new DESEngine()); - - engine.init(true, new ParametersWithIV(new KeyParameter(key), iv)); - - for (int i = 0; i < cekBlock.length; i += 8) - { - engine.processBlock(cekBlock, i, cekBlock, i); - } - - for (int i = 0; i < cekBlock.length; i += 8) - { - engine.processBlock(cekBlock, i, cekBlock, i); - } - } - - public void performTest() - throws Exception - { - wrapTest(1, new DESEngine(), Hex.decode("D1DAA78615F287E6"), Hex.decode("EFE598EF21B33D6D"), r1, Hex.decode("8C627C897323A2F8"), Hex.decode("B81B2565EE373CA6DEDCA26A178B0C10")); - wrapTest(2, new DESedeEngine(), Hex.decode("6A8970BF68C92CAEA84A8DF28510858607126380CC47AB2D"), Hex.decode("BAF1CA7931213C4E"), r2, - Hex.decode("8C637D887223A2F965B566EB014B0FA5D52300A3F7EA40FFFC577203C71BAF3B"), - Hex.decode("C03C514ABDB9E2C5AAC038572B5E24553876B377AAFB82ECA5A9D73F8AB143D9EC74E6CAD7DB260C")); - - testCorruption(); - - Wrapper wrapper = new RFC3211WrapEngine(new DESEngine()); - ParametersWithIV params = new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16]); - byte[] buf = new byte[16]; - - try - { - wrapper.init(true, params); - - wrapper.unwrap(buf, 0, buf.length); - - fail("failed unwrap state test."); - } - catch (IllegalStateException e) - { - // expected - } - catch (InvalidCipherTextException e) - { - fail("unexpected exception: " + e, e); - } - - try - { - wrapper.init(false, params); - - wrapper.wrap(buf, 0, buf.length); - - fail("failed unwrap state test."); - } - catch (IllegalStateException e) - { - // expected - } - - // - // short test - // - try - { - wrapper.init(false, params); - - wrapper.unwrap(buf, 0, buf.length / 2); - - fail("failed unwrap short test."); - } - catch (InvalidCipherTextException e) - { - // expected - } - } - - public static void main( - String[] args) - { - runTest(new RFC3211WrapTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD128DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD128DigestTest.java deleted file mode 100644 index d9a0c0861..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD128DigestTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.RIPEMD128Digest; - -/** - * RIPEMD128 Digest Test - */ -public class RIPEMD128DigestTest - extends DigestTest -{ - final static String[] messages = { - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890" - }; - - final static String[] digests = { - "cdf26213a150dc3ecb610f18f6b38b46", - "86be7afa339d0fc7cfc785e72f578d33", - "c14a12199c66e4ba84636b0f69144c77", - "9e327b3d6e523062afc1132d7df9d1b8", - "fd2aa607f71dc8f510714922b371834e", - "a1aa0689d0fafa2ddc22e88b49133a06", - "d1e959eb179c911faea4624c60c5c702", - "3f45ef194732c2dbb2c4a2c769795fa3" - }; - - final static String million_a_digest = "4a7f5723f954eba1216c9d8f6320431f"; - - RIPEMD128DigestTest() - { - super(new RIPEMD128Digest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - millionATest(million_a_digest); - } - - protected Digest cloneDigest(Digest digest) - { - return new RIPEMD128Digest((RIPEMD128Digest)digest); - } - - public static void main( - String[] args) - { - runTest(new RIPEMD128DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD128HMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD128HMacTest.java deleted file mode 100644 index d6cc0d9c9..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD128HMacTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.RIPEMD128Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * RIPEMD128 HMac Test, test vectors from RFC 2286 - */ -public class RIPEMD128HMacTest - implements Test -{ - final static String[] keys = { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4a656665", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "0102030405060708090a0b0c0d0e0f10111213141516171819", - "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - }; - - final static String[] digests = { - "fbf61f9492aa4bbf81c172e84e0734db", - "875f828862b6b334b427c55f9f7ff09b", - "09f0b2846d2f543da363cbec8d62a38d", - "bdbbd7cf03e44b5aa60af815be4d2294", - "e79808f24b25fd031c155f0d551d9a3a", - "dc732928de98104a1f59d373c150acbb", - "5c6bec96793e16d40690c237635f30c5" - }; - - final static String[] messages = { - "Hi There", - "what do ya want for nothing?", - "0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", - "0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd", - "Test With Truncation", - "Test Using Larger Than Block-Size Key - Hash Key First", - "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data" - }; - - public String getName() - { - return "RIPEMD128HMac"; - } - - public TestResult perform() - { - HMac hmac = new HMac(new RIPEMD128Digest()); - byte[] resBuf = new byte[hmac.getMacSize()]; - - for (int i = 0; i < messages.length; i++) - { - byte[] m = messages[i].getBytes(); - if (messages[i].startsWith("0x")) - { - m = Hex.decode(messages[i].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[i]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[i]))) - { - return new SimpleTestResult(false, getName() + ": Vector " + i + " failed"); - } - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public static void main( - String[] args) - { - RIPEMD128HMacTest test = new RIPEMD128HMacTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD160DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD160DigestTest.java deleted file mode 100644 index 881057e98..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD160DigestTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.RIPEMD160Digest; - -/** - * RIPEMD160 Digest Test - */ -public class RIPEMD160DigestTest - extends DigestTest -{ - final static String[] messages = { - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890" - }; - - final static String[] digests = { - "9c1185a5c5e9fc54612808977ee8f548b2258d31", - "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", - "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", - "5d0689ef49d2fae572b881b123a85ffa21595f36", - "f71c27109c692c1b56bbdceb5b9d2865b3708dbc", - "12a053384a9c0c88e405a06c27dcf49ada62eb2b", - "b0e20b6e3116640286ed3a87a5713079b21f5189", - "9b752e45573d4b39f4dbd3323cab82bf63326bfb" - }; - - final static String million_a_digest = "52783243c1697bdbe16d37f97f68f08325dc1528"; - - RIPEMD160DigestTest() - { - super(new RIPEMD160Digest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - millionATest(million_a_digest); - } - - protected Digest cloneDigest(Digest digest) - { - return new RIPEMD160Digest((RIPEMD160Digest)digest); - } - - public static void main( - String[] args) - { - runTest(new RIPEMD160DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD160HMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD160HMacTest.java deleted file mode 100644 index 3863a0342..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD160HMacTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.RIPEMD160Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * RIPEMD160 HMac Test, test vectors from RFC 2286 - */ -public class RIPEMD160HMacTest - implements Test -{ - final static String[] keys = { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4a656665", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "0102030405060708090a0b0c0d0e0f10111213141516171819", - "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - }; - - final static String[] digests = { - "24cb4bd67d20fc1a5d2ed7732dcc39377f0a5668", - "dda6c0213a485a9e24f4742064a7f033b43c4069", - "b0b105360de759960ab4f35298e116e295d8e7c1", - "d5ca862f4d21d5e610e18b4cf1beb97a4365ecf4", - "7619693978f91d90539ae786500ff3d8e0518e39", - "6466ca07ac5eac29e1bd523e5ada7605b791fd8b", - "69ea60798d71616cce5fd0871e23754cd75d5a0a" - }; - - final static String[] messages = { - "Hi There", - "what do ya want for nothing?", - "0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", - "0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd", - "Test With Truncation", - "Test Using Larger Than Block-Size Key - Hash Key First", - "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data" - }; - - public String getName() - { - return "RIPEMD160HMac"; - } - - public TestResult perform() - { - HMac hmac = new HMac(new RIPEMD160Digest()); - byte[] resBuf = new byte[hmac.getMacSize()]; - - for (int i = 0; i < messages.length; i++) - { - byte[] m = messages[i].getBytes(); - if (messages[i].startsWith("0x")) - { - m = Hex.decode(messages[i].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[i]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[i]))) - { - return new SimpleTestResult(false, getName() + ": Vector " + i + " failed"); - } - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public static void main( - String[] args) - { - RIPEMD160HMacTest test = new RIPEMD160HMacTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD256DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD256DigestTest.java deleted file mode 100644 index 303e7220c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD256DigestTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.RIPEMD256Digest; - -/** - * RIPEMD128 Digest Test - */ -public class RIPEMD256DigestTest - extends DigestTest -{ - final static String[] messages = { - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890" - }; - - final static String[] digests = { - "02ba4c4e5f8ecd1877fc52d64d30e37a2d9774fb1e5d026380ae0168e3c5522d", - "f9333e45d857f5d90a91bab70a1eba0cfb1be4b0783c9acfcd883a9134692925", - "afbd6e228b9d8cbbcef5ca2d03e6dba10ac0bc7dcbe4680e1e42d2e975459b65", - "87e971759a1ce47a514d5c914c392c9018c7c46bc14465554afcdf54a5070c0e", - "649d3034751ea216776bf9a18acc81bc7896118a5197968782dd1fd97d8d5133", - "3843045583aac6c8c8d9128573e7a9809afb2a0f34ccc36ea9e72f16f6368e3f", - "5740a408ac16b720b84424ae931cbb1fe363d1d0bf4017f1a89f7ea6de77a0b8", - "06fdcc7a409548aaf91368c06a6275b553e3f099bf0ea4edfd6778df89a890dd" - }; - - final static String million_a_digest = "ac953744e10e31514c150d4d8d7b677342e33399788296e43ae4850ce4f97978"; - - RIPEMD256DigestTest() - { - super(new RIPEMD256Digest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - millionATest(million_a_digest); - } - - protected Digest cloneDigest(Digest digest) - { - return new RIPEMD256Digest((RIPEMD256Digest)digest); - } - - public static void main( - String[] args) - { - runTest(new RIPEMD256DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD320DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD320DigestTest.java deleted file mode 100644 index 232140b52..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RIPEMD320DigestTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.RIPEMD320Digest; - -/** - * RIPEMD320 Digest Test - */ -public class RIPEMD320DigestTest - extends DigestTest -{ - final static String[] messages = { - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890" - }; - - final static String[] digests = { - "22d65d5661536cdc75c1fdf5c6de7b41b9f27325ebc61e8557177d705a0ec880151c3a32a00899b8", - "ce78850638f92658a5a585097579926dda667a5716562cfcf6fbe77f63542f99b04705d6970dff5d", - "de4c01b3054f8930a79d09ae738e92301e5a17085beffdc1b8d116713e74f82fa942d64cdbc4682d", - "3a8e28502ed45d422f68844f9dd316e7b98533fa3f2a91d29f84d425c88d6b4eff727df66a7c0197", - "cabdb1810b92470a2093aa6bce05952c28348cf43ff60841975166bb40ed234004b8824463e6b009", - "d034a7950cf722021ba4b84df769a5de2060e259df4c9bb4a4268c0e935bbc7470a969c9d072a1ac", - "ed544940c86d67f250d232c30b7b3e5770e0c60c8cb9a4cafe3b11388af9920e1b99230b843c86a4", - "557888af5f6d8ed62ab66945c6d2a0a47ecd5341e915eb8fea1d0524955f825dc717e4a008ab2d42" - }; - - final static String million_a_digest = "bdee37f4371e20646b8b0d862dda16292ae36f40965e8c8509e63d1dbddecc503e2b63eb9245bb66"; - - RIPEMD320DigestTest() - { - super(new RIPEMD320Digest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - millionATest(million_a_digest); - } - - protected Digest cloneDigest(Digest digest) - { - return new RIPEMD320Digest((RIPEMD320Digest)digest); - } - - public static void main( - String[] args) - { - runTest(new RIPEMD320DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RNGUtils.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RNGUtils.java deleted file mode 100644 index e664c025d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RNGUtils.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.util.Random; - -class RNGUtils -{ - public static int nextInt(Random rng, int n) - { - return rng.nextInt(n); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RSABlindedTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RSABlindedTest.java deleted file mode 100644 index bbb56ee0a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RSABlindedTest.java +++ /dev/null @@ -1,437 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricBlockCipher; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.encodings.OAEPEncoding; -import com.fr.third.org.bouncycastle.crypto.encodings.PKCS1Encoding; -import com.fr.third.org.bouncycastle.crypto.engines.RSABlindedEngine; -import com.fr.third.org.bouncycastle.crypto.generators.RSAKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -import java.math.BigInteger; -import java.security.SecureRandom; - -public class RSABlindedTest - extends SimpleTest -{ - static BigInteger mod = new BigInteger("b259d2d6e627a768c94be36164c2d9fc79d97aab9253140e5bf17751197731d6f7540d2509e7b9ffee0a70a6e26d56e92d2edd7f85aba85600b69089f35f6bdbf3c298e05842535d9f064e6b0391cb7d306e0a2d20c4dfb4e7b49a9640bdea26c10ad69c3f05007ce2513cee44cfe01998e62b6c3637d3fc0391079b26ee36d5", 16); - static BigInteger pubExp = new BigInteger("11", 16); - static BigInteger privExp = new BigInteger("92e08f83cc9920746989ca5034dcb384a094fb9c5a6288fcc4304424ab8f56388f72652d8fafc65a4b9020896f2cde297080f2a540e7b7ce5af0b3446e1258d1dd7f245cf54124b4c6e17da21b90a0ebd22605e6f45c9f136d7a13eaac1c0f7487de8bd6d924972408ebb58af71e76fd7b012a8d0e165f3ae2e5077a8648e619", 16); - static BigInteger p = new BigInteger("f75e80839b9b9379f1cf1128f321639757dba514642c206bbbd99f9a4846208b3e93fbbe5e0527cc59b1d4b929d9555853004c7c8b30ee6a213c3d1bb7415d03", 16); - static BigInteger q = new BigInteger("b892d9ebdbfc37e397256dd8a5d3123534d1f03726284743ddc6be3a709edb696fc40c7d902ed804c6eee730eee3d5b20bf6bd8d87a296813c87d3b3cc9d7947", 16); - static BigInteger pExp = new BigInteger("1d1a2d3ca8e52068b3094d501c9a842fec37f54db16e9a67070a8b3f53cc03d4257ad252a1a640eadd603724d7bf3737914b544ae332eedf4f34436cac25ceb5", 16); - static BigInteger qExp = new BigInteger("6c929e4e81672fef49d9c825163fec97c4b7ba7acb26c0824638ac22605d7201c94625770984f78a56e6e25904fe7db407099cad9b14588841b94f5ab498dded", 16); - static BigInteger crtCoef = new BigInteger("dae7651ee69ad1d081ec5e7188ae126f6004ff39556bde90e0b870962fa7b926d070686d8244fe5a9aa709a95686a104614834b0ada4b10f53197a5cb4c97339", 16); - - static String input = "4e6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"; - - // - // to check that we handling byte extension by big number correctly. - // - static String edgeInput = "ff6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"; - - static byte[] oversizedSig = Hex.decode("01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff004e6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"); - static byte[] dudBlock = Hex.decode("000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff004e6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"); - static byte[] truncatedDataBlock = Hex.decode("0001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff004e6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"); - static byte[] incorrectPadding = Hex.decode("0001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff4e6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"); - static byte[] missingDataBlock = Hex.decode("0001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - - public String getName() - { - return "RSABlinded"; - } - - private void testStrictPKCS1Length(RSAKeyParameters pubParameters, RSAKeyParameters privParameters) - { - AsymmetricBlockCipher eng = new RSABlindedEngine(); - - eng.init(true, privParameters); - - byte[] data = null; - - try - { - data = eng.processBlock(oversizedSig, 0, oversizedSig.length); - } - catch (Exception e) - { - fail("RSA: failed - exception " + e.toString(), e); - } - - eng = new PKCS1Encoding(eng); - - eng.init(false, pubParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - - fail("oversized signature block not recognised"); - } - catch (InvalidCipherTextException e) - { - if (!e.getMessage().equals("block incorrect size")) - { - fail("RSA: failed - exception " + e.toString(), e); - } - } - - //System.setProperty(PKCS1Encoding.STRICT_LENGTH_ENABLED_PROPERTY, "false"); - - System.getProperties().put(PKCS1Encoding.STRICT_LENGTH_ENABLED_PROPERTY, "false"); - eng = new PKCS1Encoding(new RSABlindedEngine()); - - eng.init(false, pubParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (InvalidCipherTextException e) - { - fail("RSA: failed - exception " + e.toString(), e); - } - - System.getProperties().remove(PKCS1Encoding.STRICT_LENGTH_ENABLED_PROPERTY); - } - - private void testTruncatedPKCS1Block(RSAKeyParameters pubParameters, RSAKeyParameters privParameters) - { - checkForPKCS1Exception(pubParameters, privParameters, truncatedDataBlock, "block incorrect"); - } - - private void testDudPKCS1Block(RSAKeyParameters pubParameters, RSAKeyParameters privParameters) - { - checkForPKCS1Exception(pubParameters, privParameters, dudBlock, "block incorrect"); - } - - private void testWrongPaddingPKCS1Block(RSAKeyParameters pubParameters, RSAKeyParameters privParameters) - { - checkForPKCS1Exception(pubParameters, privParameters, incorrectPadding, "block incorrect"); - } - - private void testMissingDataPKCS1Block(RSAKeyParameters pubParameters, RSAKeyParameters privParameters) - { - checkForPKCS1Exception(pubParameters, privParameters, missingDataBlock, "block incorrect"); - } - - private void checkForPKCS1Exception(RSAKeyParameters pubParameters, RSAKeyParameters privParameters, byte[] inputData, String expectedMessage) - { - AsymmetricBlockCipher eng = new RSABlindedEngine(); - - eng.init(true, privParameters); - - byte[] data = null; - - try - { - data = eng.processBlock(inputData, 0, inputData.length); - } - catch (Exception e) - { - fail("RSA: failed - exception " + e.toString(), e); - } - - eng = new PKCS1Encoding(eng); - - eng.init(false, pubParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - - fail("missing data block not recognised"); - } - catch (InvalidCipherTextException e) - { - if (!e.getMessage().equals(expectedMessage)) - { - fail("RSA: failed - exception " + e.toString(), e); - } - } - } - - private void testOAEP(RSAKeyParameters pubParameters, RSAKeyParameters privParameters) - { - // - // OAEP - public encrypt, private decrypt - // - AsymmetricBlockCipher eng = new OAEPEncoding(new RSABlindedEngine()); - byte[] data = Hex.decode(input); - - eng.init(true, pubParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, privParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(new String(Hex.encode(data)))) - { - fail("failed OAEP Test"); - } - } - - public void performTest() - { - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod, pubExp); - RSAKeyParameters privParameters = new RSAPrivateCrtKeyParameters(mod, pubExp, privExp, p, q, pExp, qExp, crtCoef); - byte[] data = Hex.decode(edgeInput); - - // - // RAW - // - AsymmetricBlockCipher eng = new RSABlindedEngine(); - - eng.init(true, pubParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("RSA: failed - exception " + e.toString(), e); - } - - eng.init(false, privParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!edgeInput.equals(new String(Hex.encode(data)))) - { - fail("failed RAW edge Test"); - } - - data = Hex.decode(input); - - eng.init(true, pubParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, privParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(new String(Hex.encode(data)))) - { - fail("failed RAW Test"); - } - - // - // PKCS1 - public encrypt, private decrypt - // - eng = new PKCS1Encoding(eng); - - eng.init(true, pubParameters); - - if (eng.getOutputBlockSize() != ((PKCS1Encoding)eng).getUnderlyingCipher().getOutputBlockSize()) - { - fail("PKCS1 output block size incorrect"); - } - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, privParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(new String(Hex.encode(data)))) - { - fail("failed PKCS1 public/private Test"); - } - - // - // PKCS1 - private encrypt, public decrypt - // - eng = new PKCS1Encoding(((PKCS1Encoding)eng).getUnderlyingCipher()); - - eng.init(true, privParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, pubParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(new String(Hex.encode(data)))) - { - fail("failed PKCS1 private/public Test"); - } - - // - // key generation test - // - RSAKeyPairGenerator pGen = new RSAKeyPairGenerator(); - RSAKeyGenerationParameters genParam = new RSAKeyGenerationParameters( - BigInteger.valueOf(0x11), new SecureRandom(), 768, 25); - - pGen.init(genParam); - - AsymmetricCipherKeyPair pair = pGen.generateKeyPair(); - - eng = new RSABlindedEngine(); - - if (((RSAKeyParameters)pair.getPublic()).getModulus().bitLength() < 768) - { - fail("failed key generation (768) length test"); - } - - eng.init(true, pair.getPublic()); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, pair.getPrivate()); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(new String(Hex.encode(data)))) - { - fail("failed key generation (768) Test"); - } - - genParam = new RSAKeyGenerationParameters(BigInteger.valueOf(0x11), new SecureRandom(), 1024, 25); - - pGen.init(genParam); - pair = pGen.generateKeyPair(); - - eng.init(true, pair.getPublic()); - - if (((RSAKeyParameters)pair.getPublic()).getModulus().bitLength() < 1024) - { - fail("failed key generation (1024) length test"); - } - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, pair.getPrivate()); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(new String(Hex.encode(data)))) - { - fail("failed key generation (1024) test"); - } - - testOAEP(pubParameters, privParameters); - testStrictPKCS1Length(pubParameters, privParameters); - testDudPKCS1Block(pubParameters, privParameters); - testMissingDataPKCS1Block(pubParameters, privParameters); - testTruncatedPKCS1Block(pubParameters, privParameters); - testWrongPaddingPKCS1Block(pubParameters, privParameters); - - try - { - new RSABlindedEngine().processBlock(new byte[]{ 1 }, 0, 1); - fail("failed initialisation check"); - } - catch (IllegalStateException e) - { - // expected - } - } - - - public static void main( - String[] args) - { - runTest(new RSABlindedTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RSADigestSignerTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RSADigestSignerTest.java deleted file mode 100644 index 644612c50..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RSADigestSignerTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.DERNull; -import com.fr.third.org.bouncycastle.asn1.nist.NISTObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import com.fr.third.org.bouncycastle.asn1.x509.DigestInfo; -import com.fr.third.org.bouncycastle.asn1.x509.X509ObjectIdentifiers; -import com.fr.third.org.bouncycastle.crypto.CryptoException; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.NullDigest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA224Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA384Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA3Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512tDigest; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters; -import com.fr.third.org.bouncycastle.crypto.signers.RSADigestSigner; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class RSADigestSignerTest - extends SimpleTest -{ - public String getName() - { - return "RSADigestSigner"; - } - - public void performTest() throws Exception - { - BigInteger rsaPubMod = new BigInteger(Base64.decode("AIASoe2PQb1IP7bTyC9usjHP7FvnUMVpKW49iuFtrw/dMpYlsMMoIU2jupfifDpdFxIktSB4P+6Ymg5WjvHKTIrvQ7SR4zV4jaPTu56Ys0pZ9EDA6gb3HLjtU+8Bb1mfWM+yjKxcPDuFjwEtjGlPHg1Vq+CA9HNcMSKNn2+tW6qt")); - BigInteger rsaPubExp = new BigInteger(Base64.decode("EQ==")); - BigInteger rsaPrivMod = new BigInteger(Base64.decode("AIASoe2PQb1IP7bTyC9usjHP7FvnUMVpKW49iuFtrw/dMpYlsMMoIU2jupfifDpdFxIktSB4P+6Ymg5WjvHKTIrvQ7SR4zV4jaPTu56Ys0pZ9EDA6gb3HLjtU+8Bb1mfWM+yjKxcPDuFjwEtjGlPHg1Vq+CA9HNcMSKNn2+tW6qt")); - BigInteger rsaPrivDP = new BigInteger(Base64.decode("JXzfzG5v+HtLJIZqYMUefJfFLu8DPuJGaLD6lI3cZ0babWZ/oPGoJa5iHpX4Ul/7l3s1PFsuy1GhzCdOdlfRcQ==")); - BigInteger rsaPrivDQ = new BigInteger(Base64.decode("YNdJhw3cn0gBoVmMIFRZzflPDNthBiWy/dUMSRfJCxoZjSnr1gysZHK01HteV1YYNGcwPdr3j4FbOfri5c6DUQ==")); - BigInteger rsaPrivExp = new BigInteger(Base64.decode("DxFAOhDajr00rBjqX+7nyZ/9sHWRCCp9WEN5wCsFiWVRPtdB+NeLcou7mWXwf1Y+8xNgmmh//fPV45G2dsyBeZbXeJwB7bzx9NMEAfedchyOwjR8PYdjK3NpTLKtZlEJ6Jkh4QihrXpZMO4fKZWUm9bid3+lmiq43FwW+Hof8/E=")); - BigInteger rsaPrivP = new BigInteger(Base64.decode("AJ9StyTVW+AL/1s7RBtFwZGFBgd3zctBqzzwKPda6LbtIFDznmwDCqAlIQH9X14X7UPLokCDhuAa76OnDXb1OiE=")); - BigInteger rsaPrivQ = new BigInteger(Base64.decode("AM3JfD79dNJ5A3beScSzPtWxx/tSLi0QHFtkuhtSizeXdkv5FSba7lVzwEOGKHmW829bRoNxThDy4ds1IihW1w0=")); - BigInteger rsaPrivQinv = new BigInteger(Base64.decode("Lt0g7wrsNsQxuDdB8q/rH8fSFeBXMGLtCIqfOec1j7FEIuYA/ACiRDgXkHa0WgN7nLXSjHoy630wC5Toq8vvUg==")); - RSAKeyParameters rsaPublic = new RSAKeyParameters(false, rsaPubMod, rsaPubExp); - RSAPrivateCrtKeyParameters rsaPrivate = new RSAPrivateCrtKeyParameters(rsaPrivMod, rsaPubExp, rsaPrivExp, rsaPrivP, rsaPrivQ, rsaPrivDP, rsaPrivDQ, rsaPrivQinv); - - checkDigest(rsaPublic, rsaPrivate, new SHA1Digest(), X509ObjectIdentifiers.id_SHA1); - checkNullDigest(rsaPublic, rsaPrivate, new SHA1Digest(), X509ObjectIdentifiers.id_SHA1); - - checkDigest(rsaPublic, rsaPrivate, new SHA224Digest(), NISTObjectIdentifiers.id_sha224); - checkDigest(rsaPublic, rsaPrivate, new SHA256Digest(), NISTObjectIdentifiers.id_sha256); - checkNullDigest(rsaPublic, rsaPrivate, new SHA256Digest(), NISTObjectIdentifiers.id_sha256); - checkDigest(rsaPublic, rsaPrivate, new SHA384Digest(), NISTObjectIdentifiers.id_sha384); - checkDigest(rsaPublic, rsaPrivate, new SHA512Digest(), NISTObjectIdentifiers.id_sha512); - checkDigest(rsaPublic, rsaPrivate, new SHA512tDigest(224), NISTObjectIdentifiers.id_sha512_224); - checkDigest(rsaPublic, rsaPrivate, new SHA512tDigest(256), NISTObjectIdentifiers.id_sha512_256); - - checkDigest(rsaPublic, rsaPrivate, new SHA3Digest(224), NISTObjectIdentifiers.id_sha3_224); - checkDigest(rsaPublic, rsaPrivate, new SHA3Digest(256), NISTObjectIdentifiers.id_sha3_256); - checkDigest(rsaPublic, rsaPrivate, new SHA3Digest(384), NISTObjectIdentifiers.id_sha3_384); - checkDigest(rsaPublic, rsaPrivate, new SHA3Digest(512), NISTObjectIdentifiers.id_sha3_512); - - // Null format test - RSADigestSigner signer = new RSADigestSigner(new NullDigest()); - - signer.init(true, rsaPrivate); - - signer.update(new byte[16], 0, 16); - - try - { - signer.generateSignature(); - fail("no exception"); - } - catch (CryptoException e) - { - isTrue(e.getMessage().startsWith("unable to encode signature: malformed DigestInfo")); - } - } - - private void checkDigest(RSAKeyParameters rsaPublic, RSAPrivateCrtKeyParameters rsaPrivate, Digest digest, ASN1ObjectIdentifier digOid) - throws Exception - { - byte[] msg = new byte[] { 1, 6, 3, 32, 7, 43, 2, 5, 7, 78, 4, 23 }; - - RSADigestSigner signer = new RSADigestSigner(digest); - signer.init(true, rsaPrivate); - signer.update(msg, 0, msg.length); - byte[] sig = signer.generateSignature(); - - signer = new RSADigestSigner(digest, digOid); - signer.init(false, rsaPublic); - signer.update(msg, 0, msg.length); - if (!signer.verifySignature(sig)) - { - fail("RSA Digest Signer failed."); - } - } - - private void checkNullDigest(RSAKeyParameters rsaPublic, RSAPrivateCrtKeyParameters rsaPrivate, Digest digest, ASN1ObjectIdentifier digOid) - throws Exception - { - byte[] msg = new byte[] { 1, 6, 3, 32, 7, 43, 2, 5, 7, 78, 4, 23 }; - - RSADigestSigner signer = new RSADigestSigner(new NullDigest()); - - byte[] hash = new byte[digest.getDigestSize()]; - digest.update(msg, 0, msg.length); - digest.doFinal(hash, 0); - - DigestInfo digInfo = new DigestInfo(new AlgorithmIdentifier(digOid, DERNull.INSTANCE), hash); - byte[] infoEnc = digInfo.getEncoded(); - - signer.init(true, rsaPrivate); - - signer.update(infoEnc, 0, infoEnc.length); - - byte[] sig = signer.generateSignature(); - - signer = new RSADigestSigner(digest, digOid); - signer.init(false, rsaPublic); - signer.update(msg, 0, msg.length); - if (!signer.verifySignature(sig)) - { - fail("NONE - RSA Digest Signer failed."); - } - - signer = new RSADigestSigner(new NullDigest()); - signer.init(false, rsaPublic); - signer.update(infoEnc, 0, infoEnc.length); - if (!signer.verifySignature(sig)) - { - fail("NONE - RSA Digest Signer failed."); - } - } - - public static void main(String[] args) - { - runTest(new RSADigestSignerTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RSAKeyEncapsulationTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RSAKeyEncapsulationTest.java deleted file mode 100644 index ec72dbd06..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RSAKeyEncapsulationTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.generators.KDF2BytesGenerator; -import com.fr.third.org.bouncycastle.crypto.generators.RSAKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.kems.RSAKeyEncapsulation; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyGenerationParameters; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Tests for the RSA Key Encapsulation Mechanism - */ -public class RSAKeyEncapsulationTest - extends SimpleTest -{ - public String getName() - { - return "RSAKeyEncapsulation"; - } - - public void performTest() - throws Exception - { - // Generate RSA key pair - RSAKeyPairGenerator rsaGen = new RSAKeyPairGenerator(); - rsaGen.init(new RSAKeyGenerationParameters(BigInteger.valueOf(65537), new SecureRandom(), 1024, 5)); - AsymmetricCipherKeyPair keys = rsaGen.generateKeyPair(); - - // Set RSA-KEM parameters - RSAKeyEncapsulation kem; - KDF2BytesGenerator kdf = new KDF2BytesGenerator(new SHA1Digest()); - SecureRandom rnd = new SecureRandom(); - byte[] out = new byte[128]; - KeyParameter key1, key2; - - // Test RSA-KEM - kem = new RSAKeyEncapsulation(kdf, rnd); - - kem.init(keys.getPublic()); - key1 = (KeyParameter)kem.encrypt(out, 128); - - kem.init(keys.getPrivate()); - key2 = (KeyParameter)kem.decrypt(out, 128); - - if (!areEqual(key1.getKey(), key2.getKey())) - { - fail("failed test"); - } - } - - public static void main( - String[] args) - { - runTest(new RSAKeyEncapsulationTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RSATest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RSATest.java deleted file mode 100644 index 501002114..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RSATest.java +++ /dev/null @@ -1,719 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricBlockCipher; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.encodings.OAEPEncoding; -import com.fr.third.org.bouncycastle.crypto.encodings.PKCS1Encoding; -import com.fr.third.org.bouncycastle.crypto.engines.RSAEngine; -import com.fr.third.org.bouncycastle.crypto.generators.RSAKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class RSATest - extends SimpleTest -{ - /* - * Based on https://github.com/crocs-muni/roca/blob/master/java/BrokenKey.java - * Credits: ported to Java by Martin Paljak - */ - static class BrokenKey_CVE_2017_15361 - { - private static final int[] prims = new int[]{ 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, - 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167 }; - private static final BigInteger[] primes = new BigInteger[prims.length]; - - static - { - for (int i = 0; i < prims.length; i++) - { - primes[i] = BigInteger.valueOf(prims[i]); - } - } - - private static final BigInteger[] markers = new BigInteger[] - { - new BigInteger("6"), - new BigInteger("30"), - new BigInteger("126"), - new BigInteger("1026"), - new BigInteger("5658"), - new BigInteger("107286"), - new BigInteger("199410"), - new BigInteger("8388606"), - new BigInteger("536870910"), - new BigInteger("2147483646"), - new BigInteger("67109890"), - new BigInteger("2199023255550"), - new BigInteger("8796093022206"), - new BigInteger("140737488355326"), - new BigInteger("5310023542746834"), - new BigInteger("576460752303423486"), - new BigInteger("1455791217086302986"), - new BigInteger("147573952589676412926"), - new BigInteger("20052041432995567486"), - new BigInteger("6041388139249378920330"), - new BigInteger("207530445072488465666"), - new BigInteger("9671406556917033397649406"), - new BigInteger("618970019642690137449562110"), - new BigInteger("79228162521181866724264247298"), - new BigInteger("2535301200456458802993406410750"), - new BigInteger("1760368345969468176824550810518"), - new BigInteger("50079290986288516948354744811034"), - new BigInteger("473022961816146413042658758988474"), - new BigInteger("10384593717069655257060992658440190"), - new BigInteger("144390480366845522447407333004847678774"), - new BigInteger("2722258935367507707706996859454145691646"), - new BigInteger("174224571863520493293247799005065324265470"), - new BigInteger("696898287454081973172991196020261297061886"), - new BigInteger("713623846352979940529142984724747568191373310"), - new BigInteger("1800793591454480341970779146165214289059119882"), - new BigInteger("126304807362733370595828809000324029340048915994"), - new BigInteger("11692013098647223345629478661730264157247460343806"), - new BigInteger("187072209578355573530071658587684226515959365500926") - }; - - public static boolean isAffected(RSAKeyParameters publicKey) - { - BigInteger modulus = publicKey.getModulus(); - - for (int i = 0; i < primes.length; i++) - { - int remainder = modulus.remainder(primes[i]).intValue(); - if (!markers[i].testBit(remainder)) - { - return false; - } - } - - return true; - } - } - - static BigInteger mod = new BigInteger("b259d2d6e627a768c94be36164c2d9fc79d97aab9253140e5bf17751197731d6f7540d2509e7b9ffee0a70a6e26d56e92d2edd7f85aba85600b69089f35f6bdbf3c298e05842535d9f064e6b0391cb7d306e0a2d20c4dfb4e7b49a9640bdea26c10ad69c3f05007ce2513cee44cfe01998e62b6c3637d3fc0391079b26ee36d5", 16); - static BigInteger pubExp = new BigInteger("11", 16); - static BigInteger privExp = new BigInteger("92e08f83cc9920746989ca5034dcb384a094fb9c5a6288fcc4304424ab8f56388f72652d8fafc65a4b9020896f2cde297080f2a540e7b7ce5af0b3446e1258d1dd7f245cf54124b4c6e17da21b90a0ebd22605e6f45c9f136d7a13eaac1c0f7487de8bd6d924972408ebb58af71e76fd7b012a8d0e165f3ae2e5077a8648e619", 16); - static BigInteger p = new BigInteger("f75e80839b9b9379f1cf1128f321639757dba514642c206bbbd99f9a4846208b3e93fbbe5e0527cc59b1d4b929d9555853004c7c8b30ee6a213c3d1bb7415d03", 16); - static BigInteger q = new BigInteger("b892d9ebdbfc37e397256dd8a5d3123534d1f03726284743ddc6be3a709edb696fc40c7d902ed804c6eee730eee3d5b20bf6bd8d87a296813c87d3b3cc9d7947", 16); - static BigInteger pExp = new BigInteger("1d1a2d3ca8e52068b3094d501c9a842fec37f54db16e9a67070a8b3f53cc03d4257ad252a1a640eadd603724d7bf3737914b544ae332eedf4f34436cac25ceb5", 16); - static BigInteger qExp = new BigInteger("6c929e4e81672fef49d9c825163fec97c4b7ba7acb26c0824638ac22605d7201c94625770984f78a56e6e25904fe7db407099cad9b14588841b94f5ab498dded", 16); - static BigInteger crtCoef = new BigInteger("dae7651ee69ad1d081ec5e7188ae126f6004ff39556bde90e0b870962fa7b926d070686d8244fe5a9aa709a95686a104614834b0ada4b10f53197a5cb4c97339", 16); - - static String input = "4e6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"; - - // - // to check that we handling byte extension by big number correctly. - // - static String edgeInput = "ff6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"; - - static byte[] oversizedSig = Hex.decode("01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff004e6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"); - static byte[] dudBlock = Hex.decode("000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff004e6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"); - static byte[] truncatedDataBlock = Hex.decode("0001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff004e6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"); - static byte[] incorrectPadding = Hex.decode("0001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff4e6f77206973207468652074696d6520666f7220616c6c20676f6f64206d656e"); - static byte[] missingDataBlock = Hex.decode("0001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - - public String getName() - { - return "RSA"; - } - - private void testStrictPKCS1Length(RSAKeyParameters pubParameters, RSAKeyParameters privParameters) - { - AsymmetricBlockCipher eng = new RSAEngine(); - - eng.init(true, privParameters); - - byte[] data = null; - byte[] overSized = null; - - try - { - overSized = data = eng.processBlock(oversizedSig, 0, oversizedSig.length); - } - catch (Exception e) - { - fail("RSA: failed - exception " + e.toString(), e); - } - - eng = new PKCS1Encoding(eng); - - eng.init(false, pubParameters); - - try - { - data = eng.processBlock(overSized, 0, overSized.length); - - fail("oversized signature block not recognised"); - } - catch (InvalidCipherTextException e) - { - if (!e.getMessage().equals("block incorrect size")) - { - fail("RSA: failed - exception " + e.toString(), e); - } - } - - eng = new PKCS1Encoding(new RSAEngine(), Hex.decode("feedbeeffeedbeeffeedbeef")); - eng.init(false, new ParametersWithRandom(privParameters, new SecureRandom())); - - try - { - data = eng.processBlock(overSized, 0, overSized.length); - isTrue("not fallback", Arrays.areEqual(Hex.decode("feedbeeffeedbeeffeedbeef"), data)); - } - catch (InvalidCipherTextException e) - { - fail("RSA: failed - exception " + e.toString(), e); - } - - //System.setProperty(PKCS1Encoding.STRICT_LENGTH_ENABLED_PROPERTY, "false"); - - System.getProperties().put(PKCS1Encoding.NOT_STRICT_LENGTH_ENABLED_PROPERTY, "true"); - eng = new PKCS1Encoding(new RSAEngine()); - - eng.init(false, pubParameters); - - try - { - data = eng.processBlock(overSized, 0, overSized.length); - } - catch (InvalidCipherTextException e) - { - fail("RSA: failed - exception " + e.toString(), e); - } - - System.getProperties().remove(PKCS1Encoding.NOT_STRICT_LENGTH_ENABLED_PROPERTY); - } - - private void testUnsafeModulusAndWrongExp() - { - try - { - try - { - new RSAKeyParameters(false, mod, pubExp.multiply(BigInteger.valueOf(2))); - - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isTrue("RSA publicExponent is even".equals(e.getMessage())); - } - - try - { - new RSAKeyParameters(false, mod.multiply(BigInteger.valueOf(2)), pubExp); - - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isTrue("RSA modulus is even".equals(e.getMessage())); - } - - try - { - new RSAKeyParameters(false, mod.multiply(BigInteger.valueOf(3)), pubExp); - - fail("no exception"); - } - catch (IllegalArgumentException e) - { - isTrue("RSA modulus has a small prime factor".equals(e.getMessage())); - } - - System.getProperties().put("com.fr.third.org.bouncycastle.rsa.allow_unsafe_mod", "true"); - - // this should now work (sigh...) - new RSAKeyParameters(false, mod.multiply(BigInteger.valueOf(3)), pubExp); - } - finally - { - System.getProperties().remove("com.fr.third.org.bouncycastle.rsa.allow_unsafe_mod"); - } - } - - private void testTruncatedPKCS1Block(RSAKeyParameters pubParameters, RSAKeyParameters privParameters) - { - checkForPKCS1Exception(pubParameters, privParameters, truncatedDataBlock, "block incorrect"); - } - - private void testDudPKCS1Block(RSAKeyParameters pubParameters, RSAKeyParameters privParameters) - { - checkForPKCS1Exception(pubParameters, privParameters, dudBlock, "block incorrect"); - } - - private void testWrongPaddingPKCS1Block(RSAKeyParameters pubParameters, RSAKeyParameters privParameters) - { - checkForPKCS1Exception(pubParameters, privParameters, incorrectPadding, "block incorrect"); - } - - private void testMissingDataPKCS1Block(RSAKeyParameters pubParameters, RSAKeyParameters privParameters) - { - checkForPKCS1Exception(pubParameters, privParameters, missingDataBlock, "block incorrect"); - } - - private void checkForPKCS1Exception(RSAKeyParameters pubParameters, RSAKeyParameters privParameters, byte[] inputData, String expectedMessage) - { - AsymmetricBlockCipher eng = new RSAEngine(); - - eng.init(true, privParameters); - - byte[] data = null; - - try - { - data = eng.processBlock(inputData, 0, inputData.length); - } - catch (Exception e) - { - fail("RSA: failed - exception " + e.toString(), e); - } - - eng = new PKCS1Encoding(eng); - - eng.init(false, pubParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - - fail("missing data block not recognised"); - } - catch (InvalidCipherTextException e) - { - if (!e.getMessage().equals(expectedMessage)) - { - fail("RSA: failed - exception " + e.toString(), e); - } - } - } - - private void testOAEP(RSAKeyParameters pubParameters, RSAKeyParameters privParameters) - { - // - // OAEP - public encrypt, private decrypt - // - AsymmetricBlockCipher eng = new OAEPEncoding(new RSAEngine()); - byte[] data = Hex.decode(input); - - eng.init(true, pubParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, privParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(new String(Hex.encode(data)))) - { - fail("failed OAEP Test"); - } - - // check for oversized input - byte[] message = new byte[87]; - RSAEngine rsaEngine = new RSAEngine(); - AsymmetricBlockCipher cipher = new OAEPEncoding(rsaEngine, new SHA1Digest(), new SHA1Digest(), message); - cipher.init(true, new ParametersWithRandom(pubParameters, new SecureRandom())); - - try - { - cipher.processBlock(message, 0, message.length); - - fail("no exception thrown"); - } - catch (DataLengthException e) - { - isTrue("message mismatch", "input data too long".equals(e.getMessage())); - } - catch (InvalidCipherTextException e) - { - fail("failed - exception " + e.toString(), e); - } - - } - - private void zeroBlockTest(CipherParameters encParameters, CipherParameters decParameters) - { - AsymmetricBlockCipher eng = new PKCS1Encoding(new RSAEngine()); - - eng.init(true, encParameters); - - if (eng.getOutputBlockSize() != ((PKCS1Encoding)eng).getUnderlyingCipher().getOutputBlockSize()) - { - fail("PKCS1 output block size incorrect"); - } - - byte[] zero = new byte[0]; - byte[] data = null; - - try - { - data = eng.processBlock(zero, 0, zero.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, decParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!Arrays.areEqual(zero, data)) - { - fail("failed PKCS1 zero Test"); - } - } - - private void test_CVE_2017_15361() - { - SecureRandom random = new SecureRandom(); - RSAKeyPairGenerator pGen = new RSAKeyPairGenerator(); - BigInteger e = BigInteger.valueOf(0x11); - - for (int strength = 512; strength <= 2048; strength += 32) - { - pGen.init(new RSAKeyGenerationParameters( - e, random, strength, 100)); - - RSAKeyParameters pubKey = (RSAKeyParameters)pGen.generateKeyPair().getPublic(); - - if (BrokenKey_CVE_2017_15361.isAffected(pubKey)) - { - fail("failed CVE-2017-15361 vulnerability test for generated RSA key"); - } - } - } - - public void performTest() - { - RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod, pubExp); - RSAKeyParameters privParameters = new RSAPrivateCrtKeyParameters(mod, pubExp, privExp, p, q, pExp, qExp, crtCoef); - byte[] data = Hex.decode(edgeInput); - - // - // RAW - // - AsymmetricBlockCipher eng = new RSAEngine(); - - eng.init(true, pubParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("RSA: failed - exception " + e.toString(), e); - } - - eng.init(false, privParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!edgeInput.equals(new String(Hex.encode(data)))) - { - fail("failed RAW edge Test"); - } - - data = Hex.decode(input); - - eng.init(true, pubParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, privParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(new String(Hex.encode(data)))) - { - fail("failed RAW Test"); - } - - // - // PKCS1 - public encrypt, private decrypt - // - eng = new PKCS1Encoding(eng); - - eng.init(true, pubParameters); - - if (eng.getOutputBlockSize() != ((PKCS1Encoding)eng).getUnderlyingCipher().getOutputBlockSize()) - { - fail("PKCS1 output block size incorrect"); - } - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, privParameters); - - byte[] plainData = null; - try - { - plainData = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(Hex.toHexString(plainData))) - { - fail("failed PKCS1 public/private Test"); - } - - PKCS1Encoding fEng = new PKCS1Encoding(new RSAEngine(), input.length() / 2); - fEng.init(false, new ParametersWithRandom(privParameters, new SecureRandom())); - try - { - plainData = fEng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(Hex.toHexString(plainData))) - { - fail("failed PKCS1 public/private fixed Test"); - } - - fEng = new PKCS1Encoding(new RSAEngine(), input.length()); - fEng.init(false, new ParametersWithRandom(privParameters, new SecureRandom())); - try - { - data = fEng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (input.equals(Hex.toHexString(data))) - { - fail("failed to recognise incorrect plaint text length"); - } - - data = plainData; - - // - // PKCS1 - private encrypt, public decrypt - // - eng = new PKCS1Encoding(((PKCS1Encoding)eng).getUnderlyingCipher()); - - eng.init(true, privParameters); - - try - { - data = eng.processBlock(plainData, 0, plainData.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, pubParameters); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(Hex.toHexString(data))) - { - fail("failed PKCS1 private/public Test"); - } - - zeroBlockTest(pubParameters, privParameters); - zeroBlockTest(privParameters, pubParameters); - - // - // key generation test - // - RSAKeyPairGenerator pGen = new RSAKeyPairGenerator(); - RSAKeyGenerationParameters genParam = new RSAKeyGenerationParameters( - BigInteger.valueOf(0x11), new SecureRandom(), 768, 25); - - pGen.init(genParam); - - AsymmetricCipherKeyPair pair = pGen.generateKeyPair(); - - eng = new RSAEngine(); - - if (((RSAKeyParameters)pair.getPublic()).getModulus().bitLength() < 768) - { - fail("failed key generation (768) length test"); - } - - eng.init(true, pair.getPublic()); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, pair.getPrivate()); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(new String(Hex.encode(data)))) - { - fail("failed key generation (768) Test"); - } - - genParam = new RSAKeyGenerationParameters(BigInteger.valueOf(0x11), new SecureRandom(), 1024, 25); - - pGen.init(genParam); - pair = pGen.generateKeyPair(); - - eng.init(true, pair.getPublic()); - - if (((RSAKeyParameters)pair.getPublic()).getModulus().bitLength() < 1024) - { - fail("failed key generation (1024) length test"); - } - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - eng.init(false, pair.getPrivate()); - - try - { - data = eng.processBlock(data, 0, data.length); - } - catch (Exception e) - { - fail("failed - exception " + e.toString(), e); - } - - if (!input.equals(new String(Hex.encode(data)))) - { - fail("failed key generation (1024) test"); - } - - genParam = new RSAKeyGenerationParameters( - BigInteger.valueOf(0x11), new SecureRandom(), 128, 25); - pGen.init(genParam); - - for (int i = 0; i < 100; ++i) - { - pair = pGen.generateKeyPair(); - RSAPrivateCrtKeyParameters privKey = (RSAPrivateCrtKeyParameters)pair.getPrivate(); - BigInteger pqDiff = privKey.getP().subtract(privKey.getQ()).abs(); - - if (pqDiff.bitLength() < 42) - { - fail("P and Q too close in RSA key pair"); - } - } - - testOAEP(pubParameters, privParameters); - testStrictPKCS1Length(pubParameters, privParameters); - testDudPKCS1Block(pubParameters, privParameters); - testMissingDataPKCS1Block(pubParameters, privParameters); - testTruncatedPKCS1Block(pubParameters, privParameters); - testWrongPaddingPKCS1Block(pubParameters, privParameters); - test_CVE_2017_15361(); - testUnsafeModulusAndWrongExp(); - - try - { - new RSAEngine().processBlock(new byte[]{1}, 0, 1); - fail("failed initialisation check"); - } - catch (IllegalStateException e) - { - // expected - } - } - - - public static void main( - String[] args) - { - runTest(new RSATest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RegressionTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RegressionTest.java deleted file mode 100644 index 6ee5a4b5d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RegressionTest.java +++ /dev/null @@ -1,182 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.Test; - -public class RegressionTest -{ - public static Test[] tests = - { - new AESTest(), - new AESLightTest(), - new AESFastTest(), - new AESWrapTest(), - new AESWrapPadTest(), - new ARIATest(), - new DESTest(), - new DESedeTest(), - new ModeTest(), - new PaddingTest(), - new DHTest(), - new ElGamalTest(), - new DSATest(), - new ECTest(), - new DeterministicDSATest(), - new GOST3410Test(), - new ECGOST3410Test(), - new ECIESTest(), - new ECNRTest(), - new MacTest(), - new GOST28147MacTest(), - new RC2Test(), - new RC2WrapTest(), - new RC4Test(), - new RC5Test(), - new RC6Test(), - new RijndaelTest(), - new SerpentTest(), - new TnepresTest(), - new CamelliaTest(), - new CamelliaLightTest(), - new DigestRandomNumberTest(), - new SkipjackTest(), - new BlowfishTest(), - new TwofishTest(), - new Threefish256Test(), - new Threefish512Test(), - new Threefish1024Test(), - new SkeinDigestTest(), - new SkeinMacTest(), - new CAST5Test(), - new CAST6Test(), - new GOST28147Test(), - new IDEATest(), - new RSATest(), - new RSABlindedTest(), - new RSADigestSignerTest(), - new PSSBlindTest(), - new ISO9796Test(), - new ISO9797Alg3MacTest(), - new MD2DigestTest(), - new MD4DigestTest(), - new MD5DigestTest(), - new SHA1DigestTest(), - new SHA224DigestTest(), - new SHA256DigestTest(), - new SHA384DigestTest(), - new SHA512DigestTest(), - new SHA512t224DigestTest(), - new SHA512t256DigestTest(), - new SHA3DigestTest(), - new RIPEMD128DigestTest(), - new RIPEMD160DigestTest(), - new RIPEMD256DigestTest(), - new RIPEMD320DigestTest(), - new TigerDigestTest(), - new GOST3411DigestTest(), - new GOST3411_2012_256DigestTest(), - new GOST3411_2012_512DigestTest(), - new WhirlpoolDigestTest(), - new MD5HMacTest(), - new SHA1HMacTest(), - new SHA224HMacTest(), - new SHA256HMacTest(), - new SHA384HMacTest(), - new SHA512HMacTest(), - new RIPEMD128HMacTest(), - new RIPEMD160HMacTest(), - new OAEPTest(), - new PSSTest(), - new CTSTest(), - new NISTCTSTest(), - new CCMTest(), - new PKCS5Test(), - new PKCS12Test(), - new KDF1GeneratorTest(), - new KDF2GeneratorTest(), - new MGF1GeneratorTest(), - new HKDFGeneratorTest(), - new DHKEKGeneratorTest(), - new ECDHKEKGeneratorTest(), - new ShortenedDigestTest(), - new EqualsHashCodeTest(), - new TEATest(), - new XTEATest(), - new RFC3211WrapTest(), - new SEEDTest(), - new Salsa20Test(), - new XSalsa20Test(), - new ChaChaTest(), - new ChaCha20Poly1305Test(), - new CMacTest(), - new EAXTest(), - new GCMTest(), - new GMacTest(), - new HCFamilyTest(), - new HCFamilyVecTest(), - new ISAACTest(), - new NoekeonTest(), - new VMPCKSA3Test(), - new VMPCMacTest(), - new VMPCTest(), - new Grainv1Test(), - new Grain128Test(), - //new NaccacheSternTest(), - new SRP6Test(), - new SCryptTest(), - new ResetTest(), - new NullTest(), - new DSTU4145Test(), - new SipHashTest(), - new Poly1305Test(), - new OCBTest(), - new NonMemoableDigestTest(), - new RSAKeyEncapsulationTest(), - new ECIESKeyEncapsulationTest(), - new HashCommitmentTest(), - new CipherStreamTest(), - new BlockCipherResetTest(), - new StreamCipherResetTest(), - new SM3DigestTest(), - new Shacal2Test(), - new KDFCounterGeneratorTest(), - new KDFDoublePipelineIteratorGeneratorTest(), - new KDFFeedbackGeneratorTest(), - new CramerShoupTest(), - new BCryptTest(), - new OpenBSDBCryptTest(), - new X931SignerTest(), - new Blake2bDigestTest(), - new Blake2sDigestTest(), - new Blake2xsDigestTest(), - new KeccakDigestTest(), - new SHAKEDigestTest(), - new SM2EngineTest(), - new SM2KeyExchangeTest(), - new SM2SignerTest(), - new SM4Test(), - new DSTU7624Test(), - new DSTU7564Test(), - new IsoTrailerTest(), - new GOST3412Test(), - new GOST3412MacTest(), - new GSKKDFTest(), - new X25519Test(), - new X448Test(), - new Ed25519Test(), - new Ed448Test(), - new CSHAKETest(), - new Argon2Test(), - new OpenSSHKeyParsingTests(), - new EthereumIESTest(), - new BigIntegersTest(), - new ZucTest(), - new Haraka256DigestTest(), - new Haraka512DigestTest() - }; - - public static void main(String[] args) - { - SimpleTest.runTests(tests); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ResetTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ResetTest.java deleted file mode 100644 index 8efbfcf2f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ResetTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.DataLengthException; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.engines.DESEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class ResetTest - extends SimpleTest -{ - private static final byte[] input = Hex.decode("4e6f77206973207468652074696d6520666f7220616c6c20"); - private static final byte[] output = Hex.decode("3fa40e8a984d48156a271787ab8883f9893d51ec4b563b53"); - public String getName() - { - return "Reset"; - } - - public void performTest() - throws Exception - { - BufferedBlockCipher cipher = new BufferedBlockCipher(new DESEngine()); - - KeyParameter param = new KeyParameter(Hex.decode("0123456789abcdef")); - - basicTrial(cipher, param); - - cipher.init(false, param); - - byte[] out = new byte[input.length]; - - int len2 = cipher.processBytes(output, 0, output.length - 1, out, 0); - - try - { - cipher.doFinal(out, len2); - fail("no DataLengthException - short input"); - } - catch (DataLengthException e) - { - // ignore - } - - len2 = cipher.processBytes(output, 0, output.length, out, 0); - - cipher.doFinal(out, len2); - - if (!areEqual(input, out)) - { - fail("failed reversal one got " + new String(Hex.encode(out))); - } - - len2 = cipher.processBytes(output, 0, output.length - 1, out, 0); - - try - { - cipher.doFinal(out, len2); - fail("no DataLengthException - short output"); - } - catch (DataLengthException e) - { - // ignore - } - - len2 = cipher.processBytes(output, 0, output.length, out, 0); - - cipher.doFinal(out, len2); - - if (!areEqual(input, out)) - { - fail("failed reversal two got " + new String(Hex.encode(out))); - } - } - - private void basicTrial(BufferedBlockCipher cipher, KeyParameter param) - throws InvalidCipherTextException - { - cipher.init(true, param); - - byte[] out = new byte[input.length]; - - int len1 = cipher.processBytes(input, 0, input.length, out, 0); - - cipher.doFinal(out, len1); - - if (!areEqual(out, output)) - { - fail("failed - " + "expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); - } - } - - public static void main( - String[] args) - { - runTest(new ResetTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RijndaelTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RijndaelTest.java deleted file mode 100644 index af2225aae..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/RijndaelTest.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.RijndaelEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test vectors from the NIST standard tests and Brian Gladman's vector set - * - * http://fp.gladman.plus.com/cryptography_technology/rijndael/ - */ -public class RijndaelTest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new RijndaelEngine(128), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "0EDD33D3C621E546455BD8BA1418BEC8"), - new BlockCipherVectorTest(1, new RijndaelEngine(128), - new KeyParameter(Hex.decode("00000000000000000000000000000080")), - "00000000000000000000000000000000", "172AEAB3D507678ECAF455C12587ADB7"), - new BlockCipherMonteCarloTest(2, 10000, new RijndaelEngine(128), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", "C34C052CC0DA8D73451AFE5F03BE297F"), - new BlockCipherMonteCarloTest(3, 10000, new RijndaelEngine(128), - new KeyParameter(Hex.decode("5F060D3716B345C253F6749ABAC10917")), - "355F697E8B868B65B25A04E18D782AFA", "ACC863637868E3E068D2FD6E3508454A"), - new BlockCipherVectorTest(4, new RijndaelEngine(128), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "6CD02513E8D4DC986B4AFE087A60BD0C"), - new BlockCipherMonteCarloTest(5, 10000, new RijndaelEngine(128), - new KeyParameter(Hex.decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")), - "F3F6752AE8D7831138F041560631B114", "77BA00ED5412DFF27C8ED91F3C376172"), - new BlockCipherVectorTest(6, new RijndaelEngine(128), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "80000000000000000000000000000000", "DDC6BF790C15760D8D9AEB6F9A75FD4E"), - new BlockCipherMonteCarloTest(7, 10000, new RijndaelEngine(128), - new KeyParameter(Hex.decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")), - "C737317FE0846F132B23C8C2A672CE22", "E58B82BFBA53C0040DC610C642121168"), - new BlockCipherVectorTest(8, new RijndaelEngine(160), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c")), - "3243f6a8885a308d313198a2e03707344a409382", "16e73aec921314c29df905432bc8968ab64b1f51"), - new BlockCipherVectorTest(8, new RijndaelEngine(160), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160")), - "3243f6a8885a308d313198a2e03707344a409382", "0553eb691670dd8a5a5b5addf1aa7450f7a0e587"), - new BlockCipherVectorTest(8, new RijndaelEngine(160), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da5")), - "3243f6a8885a308d313198a2e03707344a409382", "73cd6f3423036790463aa9e19cfcde894ea16623"), - new BlockCipherVectorTest(8, new RijndaelEngine(160), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da56a784d90")), - "3243f6a8885a308d313198a2e03707344a409382", "601b5dcd1cf4ece954c740445340bf0afdc048df"), - new BlockCipherVectorTest(8, new RijndaelEngine(160), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da56a784d9045190cfe")), - "3243f6a8885a308d313198a2e03707344a409382", "579e930b36c1529aa3e86628bacfe146942882cf"), - new BlockCipherVectorTest(8, new RijndaelEngine(192), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d", "b24d275489e82bb8f7375e0d5fcdb1f481757c538b65148a"), - new BlockCipherVectorTest(9, new RijndaelEngine(192), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da5")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d", "725ae43b5f3161de806a7c93e0bca93c967ec1ae1b71e1cf"), - new BlockCipherVectorTest(10, new RijndaelEngine(192), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da56a784d90")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d", "bbfc14180afbf6a36382a061843f0b63e769acdc98769130"), - new BlockCipherVectorTest(11, new RijndaelEngine(192), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da56a784d9045190cfe")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d", "0ebacf199e3315c2e34b24fcc7c46ef4388aa475d66c194c"), - new BlockCipherVectorTest(12, new RijndaelEngine(224), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d0082efa9", "b0a8f78f6b3c66213f792ffd2a61631f79331407a5e5c8d3793aceb1"), - new BlockCipherVectorTest(13, new RijndaelEngine(224), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d0082efa9", "08b99944edfce33a2acb131183ab0168446b2d15e958480010f545e3"), - new BlockCipherVectorTest(14, new RijndaelEngine(224), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da5")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d0082efa9", "be4c597d8f7efe22a2f7e5b1938e2564d452a5bfe72399c7af1101e2"), - new BlockCipherVectorTest(15, new RijndaelEngine(224), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da56a784d90")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d0082efa9", "ef529598ecbce297811b49bbed2c33bbe1241d6e1a833dbe119569e8"), - new BlockCipherVectorTest(16, new RijndaelEngine(224), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da56a784d9045190cfe")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d0082efa9", "02fafc200176ed05deb8edb82a3555b0b10d47a388dfd59cab2f6c11"), - new BlockCipherVectorTest(17, new RijndaelEngine(256), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d0082efa98ec4e6c8", "7d15479076b69a46ffb3b3beae97ad8313f622f67fedb487de9f06b9ed9c8f19"), - new BlockCipherVectorTest(18, new RijndaelEngine(256), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d0082efa98ec4e6c8", "514f93fb296b5ad16aa7df8b577abcbd484decacccc7fb1f18dc567309ceeffd"), - new BlockCipherVectorTest(19, new RijndaelEngine(256), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da5")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d0082efa98ec4e6c8", "5d7101727bb25781bf6715b0e6955282b9610e23a43c2eb062699f0ebf5887b2"), - new BlockCipherVectorTest(20, new RijndaelEngine(256), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da56a784d90")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d0082efa98ec4e6c8", "d56c5a63627432579e1dd308b2c8f157b40a4bfb56fea1377b25d3ed3d6dbf80"), - new BlockCipherVectorTest(21, new RijndaelEngine(256), - new KeyParameter(Hex.decode("2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da56a784d9045190cfe")), - "3243f6a8885a308d313198a2e03707344a4093822299f31d0082efa98ec4e6c8", "a49406115dfb30a40418aafa4869b7c6a886ff31602a7dd19c889dc64f7e4e7a") - }; - - RijndaelTest() - { - super(tests, new RijndaelEngine(128), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "Rijndael"; - } - - public static void main( - String[] args) - { - runTest(new RijndaelTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SCryptTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SCryptTest.java deleted file mode 100644 index b940d5f8e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SCryptTest.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.BufferedReader; -import java.io.InputStreamReader; - -import com.fr.third.org.bouncycastle.crypto.generators.SCrypt; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/* - * scrypt test vectors from "Stronger Key Derivation Via Sequential Memory-hard Functions" Appendix B. - * (http://www.tarsnap.com/scrypt/scrypt.pdf) - */ -public class SCryptTest - extends SimpleTest -{ - public String getName() - { - return "SCrypt"; - } - - public void performTest() - throws Exception - { - testParameters(); - testVectors(); - } - - public void testParameters() - { - checkOK("Minimal values", new byte[0], new byte[0], 2, 1, 1, 1); - checkIllegal("Cost parameter must be > 1", new byte[0], new byte[0], 1, 1, 1, 1); - checkOK("Cost parameter 32768 OK for r == 1", new byte[0], new byte[0], 32768, 1, 1, 1); - checkIllegal("Cost parameter must < 65536 for r == 1", new byte[0], new byte[0], 65536, 1, 1, 1); - checkIllegal("Block size must be >= 1", new byte[0], new byte[0], 2, 0, 2, 1); - checkIllegal("Parallelisation parameter must be >= 1", new byte[0], new byte[0], 2, 1, 0, 1); - // checkOK("Parallelisation parameter 65535 OK for r = 4", new byte[0], new byte[0], 2, 32, - // 65535, 1); - checkIllegal("Parallelisation parameter must be < 65535 for r = 4", new byte[0], new byte[0], 2, 32, 65536, 1); - - checkIllegal("Len parameter must be > 1", new byte[0], new byte[0], 2, 1, 1, 0); - } - - private void checkOK(String msg, byte[] pass, byte[] salt, int N, int r, int p, int len) - { - try - { - SCrypt.generate(pass, salt, N, r, p, len); - } - catch (IllegalArgumentException e) - { - e.printStackTrace(); - fail(msg); - } - } - - private void checkIllegal(String msg, byte[] pass, byte[] salt, int N, int r, int p, int len) - { - try - { - SCrypt.generate(pass, salt, N, r, p, len); - fail(msg); - } - catch (IllegalArgumentException e) - { - // e.printStackTrace(); - } - } - - public void testVectors() - throws Exception - { - BufferedReader br = new BufferedReader(new InputStreamReader( - getClass().getResourceAsStream("SCryptTestVectors.txt"))); - - int count = 0; - String line = br.readLine(); - - while (line != null) - { - ++count; - String header = line; - StringBuffer data = new StringBuffer(); - - while (!isEndData(line = br.readLine())) - { - for (int i = 0; i != line.length(); i++) - { - if (line.charAt(i) != ' ') - { - data.append(line.charAt(i)); - } - } - } - - int start = header.indexOf('(') + 1; - int limit = header.lastIndexOf(')'); - String argStr = header.substring(start, limit); - String[] args = Strings.split(argStr, ','); - - byte[] P = extractQuotedString(args[0]); - byte[] S = extractQuotedString(args[1]); - int N = extractInteger(args[2]); - int r = extractInteger(args[3]); - int p = extractInteger(args[4]); - int dkLen = extractInteger(args[5]); - byte[] expected = Hex.decode(data.toString()); - - // This skips very expensive test case(s), remove check to re-enable - if (N <= 16384) - { - byte[] result = SCrypt.generate(P, S, N, r, p, dkLen); - - if (!areEqual(expected, result)) - { - fail("Result does not match expected value in test case " + count); - } - } - } - - br.close(); - } - - private static boolean isEndData(String line) - { - return line == null || line.startsWith("scrypt"); - } - - private static byte[] extractQuotedString(String arg) - { - arg = arg.trim(); - arg = arg.substring(1, arg.length() - 1); - return Strings.toByteArray(arg); - } - - private static int extractInteger(String arg) - { - return Integer.parseInt(arg.trim()); - } - - public static void main(String[] args) - { - runTest(new SCryptTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SEEDTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SEEDTest.java deleted file mode 100644 index bab0325ef..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SEEDTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.SEEDEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * SEED tester - vectors http://www.ietf.org/rfc/rfc4009.txt - */ -public class SEEDTest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new SEEDEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "000102030405060708090a0b0c0d0e0f", - "5EBAC6E0054E166819AFF1CC6D346CDB"), - new BlockCipherVectorTest(0, new SEEDEngine(), - new KeyParameter(Hex.decode("000102030405060708090a0b0c0d0e0f")), - "00000000000000000000000000000000", - "c11f22f20140505084483597e4370f43"), - new BlockCipherVectorTest(0, new SEEDEngine(), - new KeyParameter(Hex.decode("4706480851E61BE85D74BFB3FD956185")), - "83A2F8A288641FB9A4E9A5CC2F131C7D", - "EE54D13EBCAE706D226BC3142CD40D4A"), - new BlockCipherVectorTest(0, new SEEDEngine(), - new KeyParameter(Hex.decode("28DBC3BC49FFD87DCFA509B11D422BE7")), - "B41E6BE2EBA84A148E2EED84593C5EC7", - "9B9B7BFCD1813CB95D0B3618F40F5122"), - new BlockCipherVectorTest(0, new SEEDEngine(), - new KeyParameter(Hex.decode("0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E")), - "0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E", - "8296F2F1B007AB9D533FDEE35A9AD850"), - }; - - SEEDTest() - { - super(tests, new SEEDEngine(), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "SEED"; - } - - public static void main( - String[] args) - { - runTest(new SEEDTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA1DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA1DigestTest.java deleted file mode 100644 index 1c1da2a53..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA1DigestTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; - -/** - * standard vector test for SHA-1 from "Handbook of Applied Cryptography", page 345. - */ -public class SHA1DigestTest - extends DigestTest -{ - private static String[] messages = - { - "", - "a", - "abc", - "abcdefghijklmnopqrstuvwxyz" - }; - - private static String[] digests = - { - "da39a3ee5e6b4b0d3255bfef95601890afd80709", - "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8", - "a9993e364706816aba3e25717850c26c9cd0d89d", - "32d10c7b8cf96570ca04ce37f2a19d84240d3a89" - }; - - SHA1DigestTest() - { - super(new SHA1Digest(), messages, digests); - } - - protected Digest cloneDigest(Digest digest) - { - return new SHA1Digest((SHA1Digest)digest); - } - - protected Digest cloneDigest(byte[] encodedState) - { - return new SHA1Digest(encodedState); - } - - public static void main( - String[] args) - { - runTest(new SHA1DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA1HMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA1HMacTest.java deleted file mode 100644 index 59a79da84..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA1HMacTest.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * SHA1 HMac Test, test vectors from RFC 2202 - */ -public class SHA1HMacTest - implements Test -{ - final static String[] keys = { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4a656665", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "0102030405060708090a0b0c0d0e0f10111213141516171819", - "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F" - }; - - final static String[] digests = { - "b617318655057264e28bc0b6fb378c8ef146be00", - "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79", - "125d7342b9ac11cd91a39af48aa17b4f63f175d3", - "4c9007f4026250c6bc8414f9bf50c86c2d7235da", - "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04", - "aa4ae5e15272d00e95705637ce8a3b55ed402112", - "e8e99d0f45237d786d6bbaa7965c7808bbff1a91", - "5FD596EE78D5553C8FF4E72D266DFD192366DA29" - }; - - final static String[] messages = { - "Hi There", - "what do ya want for nothing?", - "0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", - "0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd", - "Test With Truncation", - "Test Using Larger Than Block-Size Key - Hash Key First", - "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", - "Sample message for keylen=blocklen" - }; - - public String getName() - { - return "SHA1HMac"; - } - - public TestResult perform() - { - HMac hmac = new HMac(new SHA1Digest()); - byte[] resBuf = new byte[hmac.getMacSize()]; - - for (int i = 0; i < messages.length; i++) - { - byte[] m = messages[i].getBytes(); - if (messages[i].startsWith("0x")) - { - m = Hex.decode(messages[i].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[i]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[i]))) - { - return new SimpleTestResult(false, getName() + ": Vector " + i + " failed"); - } - } - - // - // test reset - // - int vector = 0; // vector used for test - byte[] m = messages[vector].getBytes(); - if (messages[vector].startsWith("0x")) - { - m = Hex.decode(messages[vector].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[vector]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - hmac.reset(); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[vector]))) - { - return new SimpleTestResult(false, getName() + - "Reset with vector " + vector + " failed"); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public static void main( - String[] args) - { - SHA1HMacTest test = new SHA1HMacTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA224DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA224DigestTest.java deleted file mode 100644 index 141b701fc..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA224DigestTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA224Digest; - -/** - * standard vector test for SHA-224 from RFC 3874 - only the last three are in - * the RFC. - */ -public class SHA224DigestTest - extends DigestTest -{ - private static String[] messages = - { - "", - "a", - "abc", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" - }; - - private static String[] digests = - { - "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", - "abd37534c7d9a2efb9465de931cd7055ffdb8879563ae98078d6d6d5", - "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", - "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" - }; - - // 1 million 'a' - static private String million_a_digest = "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67"; - - SHA224DigestTest() - { - super(new SHA224Digest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - millionATest(million_a_digest); - } - - protected Digest cloneDigest(Digest digest) - { - return new SHA224Digest((SHA224Digest)digest); - } - - protected Digest cloneDigest(byte[] encodedState) - { - return new SHA224Digest(encodedState); - } - - public static void main( - String[] args) - { - runTest(new SHA224DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA224HMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA224HMacTest.java deleted file mode 100644 index 75eb9f06e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA224HMacTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA224Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * SHA224 HMac Test - */ -public class SHA224HMacTest - implements Test -{ - final static String[] keys = { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4a656665", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "0102030405060708090a0b0c0d0e0f10111213141516171819", - "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - }; - - final static String[] digests = { - "896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22", - "a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44", - "7fb3cb3588c6c1f6ffa9694d7d6ad2649365b0c1f65d69d1ec8333ea", - "6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a", - "0e2aea68a90c8d37c988bcdb9fca6fa8099cd857c7ec4a1815cac54c", - "95e9a0db962095adaebe9b2d6f0dbce2d499f112f2d2b7273fa6870e", - "3a854166ac5d9f023f54d517d0b39dbd946770db9c2b95c9f6f565d1" - }; - - final static String[] messages = { - "Hi There", - "what do ya want for nothing?", - "0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", - "0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd", - "Test With Truncation", - "Test Using Larger Than Block-Size Key - Hash Key First", - "This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm." - }; - - public String getName() - { - return "SHA224HMac"; - } - - public TestResult perform() - { - HMac hmac = new HMac(new SHA224Digest()); - byte[] resBuf = new byte[hmac.getMacSize()]; - - for (int i = 0; i < messages.length; i++) - { - byte[] m = messages[i].getBytes(); - if (messages[i].startsWith("0x")) - { - m = Hex.decode(messages[i].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[i]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[i]))) - { - return new SimpleTestResult(false, getName() + ": Vector " + i + " failed got -" + new String(Hex.encode(resBuf))); - } - } - - // - // test reset - // - int vector = 0; // vector used for test - byte[] m = messages[vector].getBytes(); - if (messages[vector].startsWith("0x")) - { - m = Hex.decode(messages[vector].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[vector]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - hmac.reset(); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[vector]))) - { - return new SimpleTestResult(false, getName() + - "Reset with vector " + vector + " failed"); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public static void main( - String[] args) - { - SHA224HMacTest test = new SHA224HMacTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA256DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA256DigestTest.java deleted file mode 100644 index eb4d97c7b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA256DigestTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; - -/** - * standard vector test for SHA-256 from FIPS Draft 180-2. - * - * Note, the first two vectors are _not_ from the draft, the last three are. - */ -public class SHA256DigestTest - extends DigestTest -{ - private static String[] messages = - { - "", - "a", - "abc", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" - }; - - private static String[] digests = - { - "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", - "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", - "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" - }; - - // 1 million 'a' - static private String million_a_digest = "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0"; - - SHA256DigestTest() - { - super(new SHA256Digest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - millionATest(million_a_digest); - } - - protected Digest cloneDigest(Digest digest) - { - return new SHA256Digest((SHA256Digest)digest); - } - - protected Digest cloneDigest(byte[] encodedState) - { - return new SHA256Digest(encodedState); - } - - public static void main( - String[] args) - { - runTest(new SHA256DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA256HMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA256HMacTest.java deleted file mode 100644 index 3618450af..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA256HMacTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * SHA256 HMac Test - */ -public class SHA256HMacTest - implements Test -{ - final static String[] keys = { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4a656665", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "0102030405060708090a0b0c0d0e0f10111213141516171819", - "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - }; - - final static String[] digests = { - "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7", - "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843", - "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe", - "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b", - "a3b6167473100ee06e0c796c2955552bfa6f7c0a6a8aef8b93f860aab0cd20c5", - "60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54", - "9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2" - }; - - final static String[] messages = { - "Hi There", - "what do ya want for nothing?", - "0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", - "0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd", - "Test With Truncation", - "Test Using Larger Than Block-Size Key - Hash Key First", - "This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm." - }; - - public String getName() - { - return "SHA256HMac"; - } - - public TestResult perform() - { - HMac hmac = new HMac(new SHA256Digest()); - byte[] resBuf = new byte[hmac.getMacSize()]; - - for (int i = 0; i < messages.length; i++) - { - byte[] m = messages[i].getBytes(); - if (messages[i].startsWith("0x")) - { - m = Hex.decode(messages[i].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[i]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[i]))) - { - return new SimpleTestResult(false, getName() + ": Vector " + i + " failed got -" + new String(Hex.encode(resBuf))); - } - } - - // - // test reset - // - int vector = 0; // vector used for test - byte[] m = messages[vector].getBytes(); - if (messages[vector].startsWith("0x")) - { - m = Hex.decode(messages[vector].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[vector]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - hmac.reset(); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[vector]))) - { - return new SimpleTestResult(false, getName() + - "Reset with vector " + vector + " failed"); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public static void main( - String[] args) - { - SHA256HMacTest test = new SHA256HMacTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA384DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA384DigestTest.java deleted file mode 100644 index d61bf3c03..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA384DigestTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA384Digest; - -/** - * standard vector test for SHA-384 from FIPS Draft 180-2. - * - * Note, the first two vectors are _not_ from the draft, the last three are. - */ -public class SHA384DigestTest - extends DigestTest -{ - private static String[] messages = - { - "", - "a", - "abc", - "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" - }; - - private static String[] digests = - { - "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b", - "54a59b9f22b0b80880d8427e548b7c23abd873486e1f035dce9cd697e85175033caa88e6d57bc35efae0b5afd3145f31", - "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7", - "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039" - }; - - static private String million_a_digest = "9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985"; - - SHA384DigestTest() - { - super(new SHA384Digest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - millionATest(million_a_digest); - } - - protected Digest cloneDigest(Digest digest) - { - return new SHA384Digest((SHA384Digest)digest); - } - - protected Digest cloneDigest(byte[] encodedState) - { - return new SHA384Digest(encodedState); - } - - public static void main( - String[] args) - { - runTest(new SHA384DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA384HMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA384HMacTest.java deleted file mode 100644 index 976efd3b6..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA384HMacTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA384Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * SHA384 HMac Test - */ -public class SHA384HMacTest - implements Test -{ - final static String[] keys = { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4a656665", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "0102030405060708090a0b0c0d0e0f10111213141516171819", - "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - }; - - final static String[] digests = { - "afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6", - "af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e8e2240ca5e69e2c78b3239ecfab21649", - "88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e55966144b2a5ab39dc13814b94e3ab6e101a34f27", - "3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e1f573b4e6801dd23c4a7d679ccf8a386c674cffb", - "3abf34c3503b2a23a46efc619baef897f4c8e42c934ce55ccbae9740fcbc1af4ca62269e2a37cd88ba926341efe4aeea", - "4ece084485813e9088d2c63a041bc5b44f9ef1012a2b588f3cd11f05033ac4c60c2ef6ab4030fe8296248df163f44952", - "6617178e941f020d351e2f254e8fd32c602420feb0b8fb9adccebb82461e99c5a678cc31e799176d3860e6110c46523e" - }; - - final static String[] messages = { - "Hi There", - "what do ya want for nothing?", - "0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", - "0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd", - "Test With Truncation", - "Test Using Larger Than Block-Size Key - Hash Key First", - "This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm." - }; - - public String getName() - { - return "SHA384HMac"; - } - - public TestResult perform() - { - HMac hmac = new HMac(new SHA384Digest()); - byte[] resBuf = new byte[hmac.getMacSize()]; - - for (int i = 0; i < messages.length; i++) - { - byte[] m = messages[i].getBytes(); - if (messages[i].startsWith("0x")) - { - m = Hex.decode(messages[i].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[i]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[i]))) - { - return new SimpleTestResult(false, getName() + ": Vector " + i + " failed got -" + new String(Hex.encode(resBuf))); - } - } - - // - // test reset - // - int vector = 0; // vector used for test - byte[] m = messages[vector].getBytes(); - if (messages[vector].startsWith("0x")) - { - m = Hex.decode(messages[vector].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[vector]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - hmac.reset(); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[vector]))) - { - return new SimpleTestResult(false, getName() + - "Reset with vector " + vector + " failed"); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public static void main( - String[] args) - { - SHA384HMacTest test = new SHA384HMacTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA3DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA3DigestTest.java deleted file mode 100644 index 219add444..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA3DigestTest.java +++ /dev/null @@ -1,301 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.BufferedReader; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA3Digest; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * SHA3 Digest Test - */ -public class SHA3DigestTest - extends SimpleTest -{ - static class MySHA3Digest extends SHA3Digest - { - MySHA3Digest(int bitLength) - { - super(bitLength); - } - - int myDoFinal(byte[] out, int outOff, byte partialByte, int partialBits) - { - return doFinal(out, outOff, partialByte, partialBits); - } - } - - SHA3DigestTest() - { - } - - public String getName() - { - return "SHA-3"; - } - - public void performTest() throws Exception - { - testVectors(); - } - - public void testVectors() throws Exception - { - BufferedReader r = new BufferedReader(new InputStreamReader( - getClass().getResourceAsStream("SHA3TestVectors.txt"))); - - String line; - while (null != (line = readLine(r))) - { - if (line.length() != 0) - { - TestVector v = readTestVector(r, line); - runTestVector(v); - } - } - - r.close(); - } - - private MySHA3Digest createDigest(String algorithm) throws Exception - { - if (algorithm.startsWith("SHA3-")) - { - int bits = parseDecimal(algorithm.substring("SHA3-".length())); - return new MySHA3Digest(bits); - } - throw new IllegalArgumentException("Unknown algorithm: " + algorithm); - } - - private byte[] decodeBinary(String block) - { - int bits = block.length(); - int fullBytes = bits / 8; - int totalBytes = (bits + 7) / 8; - byte[] result = new byte[totalBytes]; - - for (int i = 0; i < fullBytes; ++i) - { - String byteStr = reverse(block.substring(i * 8, (i + 1) * 8)); - result[i] = (byte)parseBinary(byteStr); - } - - if (totalBytes > fullBytes) - { - String byteStr = reverse(block.substring(fullBytes * 8)); - result[fullBytes] = (byte)parseBinary(byteStr); - } - - return result; - } - - private int parseBinary(String s) - { - return Integer.parseInt(s, 2); - } - - private int parseDecimal(String s) - { - return Integer.parseInt(s); - } - - private String readBlock(BufferedReader r) throws IOException - { - StringBuffer b = new StringBuffer(); - String line; - while ((line = readBlockLine(r)) != null) - { - b.append(line); - } - return b.toString(); - } - - private String readBlockLine(BufferedReader r) throws IOException - { - String line = readLine(r); - if (line == null || line.length() == 0) - { - return null; - } - - char[] chars = line.toCharArray(); - - int pos = 0; - for (int i = 0; i != chars.length; i++) - { - if (chars[i] != ' ') - { - chars[pos++] = chars[i]; - } - } - - return new String(chars, 0, pos); - } - - private TestVector readTestVector(BufferedReader r, String header) throws IOException - { - String[] parts = splitAround(header, TestVector.SAMPLE_OF); - - String algorithm = parts[0]; - int bits = parseDecimal(stripFromChar(parts[1], '-')); - - skipUntil(r, TestVector.MSG_HEADER); - String messageBlock = readBlock(r); - if (messageBlock.length() != bits) - { - throw new IllegalStateException("Test vector length mismatch"); - } - byte[] message = decodeBinary(messageBlock); - - skipUntil(r, TestVector.HASH_HEADER); - byte[] hash = Hex.decode(readBlock(r)); - - return new TestVector(algorithm, bits, message, hash); - } - - private String readLine(BufferedReader r) throws IOException - { - String line = r.readLine(); - return line == null ? null : stripFromChar(line, '#').trim(); - } - - private String requireLine(BufferedReader r) throws IOException - { - String line = readLine(r); - if (line == null) - { - throw new EOFException(); - } - return line; - } - - private String reverse(String s) - { - return new StringBuffer(s).reverse().toString(); - } - - private void runTestVector(TestVector v) throws Exception - { - int bits = v.getBits(); - int partialBits = bits % 8; - -// System.out.println(v.getAlgorithm() + " " + bits + "-bit"); -// System.out.println(Hex.toHexString(v.getMessage()).toUpperCase()); -// System.out.println(Hex.toHexString(v.getHash()).toUpperCase()); - - MySHA3Digest d = createDigest(v.getAlgorithm()); - byte[] output = new byte[d.getDigestSize()]; - - byte[] m = v.getMessage(); - if (partialBits == 0) - { - d.update(m, 0, m.length); - d.doFinal(output, 0); - } - else - { - d.update(m, 0, m.length - 1); - d.myDoFinal(output, 0, m[m.length - 1], partialBits); - } - - if (!Arrays.areEqual(v.getHash(), output)) - { - fail(v.getAlgorithm() + " " + v.getBits() + "-bit test vector hash mismatch"); -// System.err.println(v.getAlgorithm() + " " + v.getBits() + "-bit test vector hash mismatch"); -// System.err.println(Hex.toHexString(output).toUpperCase()); - } - } - - private void skipUntil(BufferedReader r, String header) throws IOException - { - String line; - do - { - line = requireLine(r); - } - while (line.length() == 0); - if (!line.equals(header)) - { - throw new IOException("Expected: " + header); - } - } - - private String[] splitAround(String s, String separator) - { - List strings = new ArrayList(); - - String remaining = s; - int index; - - while ((index = remaining.indexOf(separator)) > 0) - { - strings.add(remaining.substring(0, index)); - remaining = remaining.substring(index + separator.length()); - } - strings.add(remaining); - - return (String[])strings.toArray(new String[strings.size()]); - } - - private String stripFromChar(String s, char c) - { - int i = s.indexOf(c); - if (i >= 0) - { - s = s.substring(0, i); - } - return s; - } - - public static void main( - String[] args) - { - runTest(new SHA3DigestTest()); - } - - private static class TestVector - { - private static String SAMPLE_OF = " sample of "; - private static String MSG_HEADER = "Msg as bit string"; - private static String HASH_HEADER = "Hash val is"; - - private String algorithm; - private int bits; - private byte[] message; - private byte[] hash; - - private TestVector(String algorithm, int bits, byte[] message, byte[] hash) - { - this.algorithm = algorithm; - this.bits = bits; - this.message = message; - this.hash = hash; - } - - public String getAlgorithm() - { - return algorithm; - } - - public int getBits() - { - return bits; - } - - public byte[] getMessage() - { - return message; - } - - public byte[] getHash() - { - return hash; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA3HMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA3HMacTest.java deleted file mode 100644 index a8f09aaa5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA3HMacTest.java +++ /dev/null @@ -1,335 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA3Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * SHA224 HMac Test - */ -public class SHA3HMacTest - extends SimpleTest -{ - final static String[][] sha3_224 = - { - { - "000102030405060708090a0b0c0d0e0f101112131415161718191a1b", - "53616d706c65206d65737361676520666f72206b65796c656e3c626c6f636b6c656e", - "332cfd59347fdb8e576e77260be4aba2d6dc53117b3bfb52c6d18c04" - }, - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f" + - "20212223 24252627 28292a2b 2c2d2e2f" + - "30313233 34353637 38393a3b 3c3d3e3f" + - "40414243 44454647 48494a4b 4c4d4e4f" + - "50515253 54555657 58595a5b 5c5d5e5f" + - "60616263 64656667 68696a6b 6c6d6e6f" + - "70717273 74757677 78797a7b 7c7d7e7f" + - "80818283 84858687 88898a8b 8c8d8e8f", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3d626c 6f636b6c" + - "656e", - "d8b733bc f66c644a 12323d56 4e24dcf3" + - "fc75f231 f3b67968 359100c7" - - }, - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f" + - "20212223 24252627 28292a2b 2c2d2e2f" + - "30313233 34353637 38393a3b 3c3d3e3f" + - "40414243 44454647 48494a4b 4c4d4e4f" + - "50515253 54555657 58595a5b 5c5d5e5f" + - "60616263 64656667 68696a6b 6c6d6e6f" + - "70717273 74757677 78797a7b 7c7d7e7f" + - "80818283 84858687 88898a8b 8c8d8e8f" + - "90919293 94959697 98999a9b 9c9d9e9f" + - "a0a1a2a3 a4a5a6a7 a8a9aaab", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3e626c 6f636b6c" + - "656e", - "078695ee cc227c63 6ad31d06 3a15dd05" + - "a7e819a6 6ec6d8de 1e193e59" - }, - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3c626c 6f636b6c" + - "656e2c20 77697468 20747275 6e636174" + - "65642074 6167", - "8569c54c bb00a9b7 8ff1b391 b0e5" - }, - { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4869205468657265", - "3b16546bbc7be2706a031dcafd56373d9884367641d8c59af3c860f7" - } - }; - - final static String[][] sha3_256 = - { - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3c626c 6f636b6c" + - "656e", - "4fe8e202 c4f058e8 dddc23d8 c34e4673" + - "43e23555 e24fc2f0 25d598f5 58f67205" - }, - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f" + - "20212223 24252627 28292a2b 2c2d2e2f" + - "30313233 34353637 38393a3b 3c3d3e3f" + - "40414243 44454647 48494a4b 4c4d4e4f" + - "50515253 54555657 58595a5b 5c5d5e5f" + - "60616263 64656667 68696a6b 6c6d6e6f" + - "70717273 74757677 78797a7b 7c7d7e7f" + - "80818283 84858687", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3d626c 6f636b6c" + - "656e", - "68b94e2e 538a9be4 103bebb5 aa016d47" + - "961d4d1a a9060613 13b557f8 af2c3faa" - }, - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f" + - "20212223 24252627 28292a2b 2c2d2e2f" + - "30313233 34353637 38393a3b 3c3d3e3f" + - "40414243 44454647 48494a4b 4c4d4e4f" + - "50515253 54555657 58595a5b 5c5d5e5f" + - "60616263 64656667 68696a6b 6c6d6e6f" + - "70717273 74757677 78797a7b 7c7d7e7f" + - "80818283 84858687 88898a8b 8c8d8e8f" + - "90919293 94959697 98999a9b 9c9d9e9f" + - "a0a1a2a3 a4a5a6a7", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3e626c 6f636b6c" + - "656e", - "9bcf2c23 8e235c3c e88404e8 13bd2f3a" + - "97185ac6 f238c63d 6229a00b 07974258" - }, - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3c626c 6f636b6c" + - "656e2c20 77697468 20747275 6e636174" + - "65642074 6167", - "c8dc7148 d8c1423a a549105d afdf9cad" - }, - { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4869205468657265", - "ba85192310dffa96e2a3a40e69774351140bb7185e1202cdcc917589f95e16bb" - } - }; - - final static String[][] sha3_384 = { - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f" + - "20212223 24252627 28292a2b 2c2d2e2f", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3c626c 6f636b6c" + - "656e", - "d588a3c5 1f3f2d90 6e8298c1 199aa8ff" + - "62962181 27f6b38a 90b6afe2 c5617725" + - "bc99987f 79b22a55 7b6520db 710b7f42" - }, - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f" + - "20212223 24252627 28292a2b 2c2d2e2f" + - "30313233 34353637 38393a3b 3c3d3e3f" + - "40414243 44454647 48494a4b 4c4d4e4f" + - "50515253 54555657 58595a5b 5c5d5e5f" + - "60616263 64656667", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3d626c 6f636b6c" + - "656e", - "a27d24b5 92e8c8cb f6d4ce6f c5bf62d8" + - "fc98bf2d 486640d9 eb8099e2 4047837f" + - "5f3bffbe 92dcce90 b4ed5b1e 7e44fa90" - }, - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f" + - "20212223 24252627 28292a2b 2c2d2e2f" + - "30313233 34353637 38393a3b 3c3d3e3f" + - "40414243 44454647 48494a4b 4c4d4e4f" + - "50515253 54555657 58595a5b 5c5d5e5f" + - "60616263 64656667 68696a6b 6c6d6e6f" + - "70717273 74757677 78797a7b 7c7d7e7f" + - "80818283 84858687 88898a8b 8c8d8e8f" + - "90919293 94959697", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3e626c 6f636b6c" + - "656e", - "e5ae4c73 9f455279 368ebf36 d4f5354c" + - "95aa184c 899d3870 e460ebc2 88ef1f94" + - "70053f73 f7c6da2a 71bcaec3 8ce7d6ac" - }, - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f" + - "20212223 24252627 28292a2b 2c2d2e2f", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3c626c 6f636b6c" + - "656e2c20 77697468 20747275 6e636174" + - "65642074 6167", - "25f4bf53 606e91af 79d24a4b b1fd6aec" + - "d44414a3 0c8ebb0a" - }, - { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4869205468657265", - "68d2dcf7fd4ddd0a2240c8a437305f61fb7334cfb5d0226e1bc27dc10a2e723a20d370b47743130e26ac7e3d532886bd" - } - }; - - final static String[][] sha3_512 = { - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f" + - "20212223 24252627 28292a2b 2c2d2e2f" + - "30313233 34353637 38393a3b 3c3d3e3f", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3c626c 6f636b6c" + - "656e", - "4efd629d 6c71bf86 162658f2 9943b1c3" + - "08ce27cd fa6db0d9 c3ce8176 3f9cbce5" + - "f7ebe986 8031db1a 8f8eb7b6 b95e5c5e" + - "3f657a89 96c86a2f 6527e307 f0213196" - }, - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f" + - "20212223 24252627 28292a2b 2c2d2e2f" + - "30313233 34353637 38393a3b 3c3d3e3f" + - "40414243 44454647", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3d626c 6f636b6c" + - "656e", - "544e257e a2a3e5ea 19a590e6 a24b724c" + - "e6327757 723fe275 1b75bf00 7d80f6b3" + - "60744bf1 b7a88ea5 85f9765b 47911976" + - "d3191cf8 3c039f5f fab0d29c c9d9b6da" - }, - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f" + - "20212223 24252627 28292a2b 2c2d2e2f" + - "30313233 34353637 38393a3b 3c3d3e3f" + - "40414243 44454647 48494a4b 4c4d4e4f" + - "50515253 54555657 58595a5b 5c5d5e5f" + - "60616263 64656667 68696a6b 6c6d6e6f" + - "70717273 74757677 78797a7b 7c7d7e7f" + - "80818283 84858687", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3e626c 6f636b6c" + - "656e", - "5f464f5e 5b7848e3 885e49b2 c385f069" + - "4985d0e3 8966242d c4a5fe3f ea4b37d4" + - "6b65cece d5dcf594 38dd840b ab22269f" + - "0ba7febd b9fcf746 02a35666 b2a32915" - }, - { - "00010203 04050607 08090a0b 0c0d0e0f" + - "10111213 14151617 18191a1b 1c1d1e1f" + - "20212223 24252627 28292a2b 2c2d2e2f" + - "30313233 34353637 38393a3b 3c3d3e3f", - "53616d70 6c65206d 65737361 67652066" + - "6f72206b 65796c65 6e3c626c 6f636b6c" + - "656e2c20 77697468 20747275 6e636174" + - "65642074 6167", - "7bb06d85 9257b25c e73ca700 df34c5cb" + - "ef5c898b ac91029e 0b27975d 4e526a08" - }, - { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4869205468657265", - "eb3fbd4b2eaab8f5c504bd3a41465aacec15770a7cabac531e482f860b5ec7ba47ccb2c6f2afce8f88d22b6dc61380f23a668fd3888bb80537c0a0b86407689e" - } - }; - - public String getName() - { - return "SHA3HMac"; - } - - public void performTest() - throws Exception - { - doTest(new HMac(new SHA3Digest(224)), sha3_224); - doTest(new HMac(new SHA3Digest(256)), sha3_256); - doTest(new HMac(new SHA3Digest(384)), sha3_384); - doTest(new HMac(new SHA3Digest(512)), sha3_512); - } - - public void doTest(HMac hmac, String[][] data) - { - byte[] resBuf = new byte[hmac.getMacSize()]; - - for (int i = 0; i < data.length; i++) - { - byte[] m = Hex.decode(data[i][1]); - - hmac.init(new KeyParameter(Hex.decode(data[i][0]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - isTrue(hmac.getAlgorithmName() + " vector " + i + " failed got " + new String(Hex.encode(resBuf)), startsWith(resBuf, Hex.decode(data[i][2]))); - } - - // - // test reset - // - int vector = 0; // vector used for test - byte[] m = Hex.decode(data[vector][1]); - - hmac.init(new KeyParameter(Hex.decode(data[vector][0]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - hmac.reset(); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - isTrue(hmac.getAlgorithmName() + " reset with vector " + vector + " failed", Arrays.areEqual(resBuf, Hex.decode(data[vector][2]))); - } - - private static boolean startsWith(byte[] a, byte[] b) - { - if (a.length == b.length) - { - return Arrays.areEqual(a, b); - } - - for (int i = 0; i != b.length; i++) - { - if (a[i] != b[i]) - { - return false; - } - } - - return true; - } - - public static void main( - String[] args) - { - SHA3HMacTest test = new SHA3HMacTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA512DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA512DigestTest.java deleted file mode 100644 index 7f2a4de6d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA512DigestTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512Digest; - -/** - * standard vector test for SHA-512 from FIPS Draft 180-2. - * - * Note, the first two vectors are _not_ from the draft, the last three are. - */ -public class SHA512DigestTest - extends DigestTest -{ - private static String[] messages = - { - "", - "a", - "abc", - "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" - }; - - private static String[] digests = - { - "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", - "1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75", - "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f", - "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909" - }; - - // 1 million 'a' - static private String million_a_digest = "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b"; - - SHA512DigestTest() - { - super(new SHA512Digest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - millionATest(million_a_digest); - } - - protected Digest cloneDigest(Digest digest) - { - return new SHA512Digest((SHA512Digest)digest); - } - - protected Digest cloneDigest(byte[] encodedState) - { - return new SHA512Digest(encodedState); - } - - public static void main( - String[] args) - { - runTest(new SHA512DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA512HMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA512HMacTest.java deleted file mode 100644 index 16cf70ffd..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA512HMacTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA512Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.Test; -import com.fr.third.org.bouncycastle.util.test.TestResult; - -/** - * SHA512 HMac Test - */ -public class SHA512HMacTest - implements Test -{ - final static String[] keys = { - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", - "4a656665", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "0102030405060708090a0b0c0d0e0f10111213141516171819", - "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - }; - - final static String[] digests = { - "87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854", - "164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737", - "fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb", - "b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd", - "415fad6271580a531d4179bc891d87a650188707922a4fbb36663a1eb16da008711c5b50ddd0fc235084eb9d3364a1454fb2ef67cd1d29fe6773068ea266e96b", - "80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598", - "e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58" - }; - - final static String[] messages = { - "Hi There", - "what do ya want for nothing?", - "0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", - "0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd", - "Test With Truncation", - "Test Using Larger Than Block-Size Key - Hash Key First", - "This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm." - }; - - public String getName() - { - return "SHA512HMac"; - } - - public TestResult perform() - { - HMac hmac = new HMac(new SHA512Digest()); - byte[] resBuf = new byte[hmac.getMacSize()]; - - for (int i = 0; i < messages.length; i++) - { - byte[] m = messages[i].getBytes(); - if (messages[i].startsWith("0x")) - { - m = Hex.decode(messages[i].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[i]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[i]))) - { - return new SimpleTestResult(false, getName() + ": Vector " + i + " failed got -" + new String(Hex.encode(resBuf))); - } - } - - // - // test reset - // - int vector = 0; // vector used for test - byte[] m = messages[vector].getBytes(); - if (messages[vector].startsWith("0x")) - { - m = Hex.decode(messages[vector].substring(2)); - } - hmac.init(new KeyParameter(Hex.decode(keys[vector]))); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - hmac.reset(); - hmac.update(m, 0, m.length); - hmac.doFinal(resBuf, 0); - - if (!Arrays.areEqual(resBuf, Hex.decode(digests[vector]))) - { - return new SimpleTestResult(false, getName() + - "Reset with vector " + vector + " failed"); - } - - return new SimpleTestResult(true, getName() + ": Okay"); - } - - public static void main( - String[] args) - { - SHA512HMacTest test = new SHA512HMacTest(); - TestResult result = test.perform(); - - System.out.println(result); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA512t224DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA512t224DigestTest.java deleted file mode 100644 index fa5376950..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA512t224DigestTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512tDigest; - -/** - * standard vector test for SHA-512/224 from FIPS 180-4. - * - * Note, only the last 2 message entries are FIPS originated.. - */ -public class SHA512t224DigestTest - extends DigestTest -{ - private static String[] messages = - { - "", - "a", - "abc", - "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" - }; - - private static String[] digests = - { - "6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4", - "d5cdb9ccc769a5121d4175f2bfdd13d6310e0d3d361ea75d82108327", - "4634270F707B6A54DAAE7530460842E20E37ED265CEEE9A43E8924AA", - "23FEC5BB94D60B23308192640B0C453335D664734FE40E7268674AF9" - }; - - // 1 million 'a' - static private String million_a_digest = "37ab331d76f0d36de422bd0edeb22a28accd487b7a8453ae965dd287"; - - SHA512t224DigestTest() - { - super(new SHA512tDigest(224), messages, digests); - } - - public void performTest() - { - super.performTest(); - - millionATest(million_a_digest); - } - - protected Digest cloneDigest(Digest digest) - { - return new SHA512tDigest((SHA512tDigest)digest); - } - - protected Digest cloneDigest(byte[] encodedState) - { - return new SHA512tDigest(encodedState); - } - - public static void main( - String[] args) - { - runTest(new SHA512t224DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA512t256DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA512t256DigestTest.java deleted file mode 100644 index abc2a8d33..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHA512t256DigestTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512tDigest; - -/** - * standard vector test for SHA-512/256 from FIPS 180-4. - * - * Note, only the last 2 message entries are FIPS originated.. - */ -public class SHA512t256DigestTest - extends DigestTest -{ - private static String[] messages = - { - "", - "a", - "abc", - "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" - }; - - private static String[] digests = - { - "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a", - "455e518824bc0601f9fb858ff5c37d417d67c2f8e0df2babe4808858aea830f8", - "53048E2681941EF99B2E29B76B4C7DABE4C2D0C634FC6D46E0E2F13107E7AF23", - "3928E184FB8690F840DA3988121D31BE65CB9D3EF83EE6146FEAC861E19B563A" - }; - - // 1 million 'a' - static private String million_a_digest = "9a59a052930187a97038cae692f30708aa6491923ef5194394dc68d56c74fb21"; - - SHA512t256DigestTest() - { - super(new SHA512tDigest(256), messages, digests); - } - - public void performTest() - { - super.performTest(); - - millionATest(million_a_digest); - } - - protected Digest cloneDigest(Digest digest) - { - return new SHA512tDigest((SHA512tDigest)digest); - } - - protected Digest cloneDigest(byte[] encodedState) - { - return new SHA512tDigest(encodedState); - } - - public static void main( - String[] args) - { - runTest(new SHA512t256DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHAKEDigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHAKEDigestTest.java deleted file mode 100644 index da167612b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SHAKEDigestTest.java +++ /dev/null @@ -1,346 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.BufferedReader; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; - -import com.fr.third.org.bouncycastle.crypto.digests.SHAKEDigest; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * SHAKE Digest Test - */ -public class SHAKEDigestTest - extends SimpleTest -{ - static class MySHAKEDigest extends SHAKEDigest - { - MySHAKEDigest(int bitLength) - { - super(bitLength); - } - - int myDoFinal(byte[] out, int outOff, int outLen, byte partialByte, int partialBits) - { - return doFinal(out, outOff, outLen, partialByte, partialBits); - } - } - - SHAKEDigestTest() - { - } - - public String getName() - { - return "SHAKE"; - } - - public void performTest() throws Exception - { - testVectors(); - } - - public void testVectors() throws Exception - { - BufferedReader r = new BufferedReader(new InputStreamReader( - getClass().getResourceAsStream("SHAKETestVectors.txt"))); - - String line; - while (null != (line = readLine(r))) - { - if (line.length() != 0) - { - TestVector v = readTestVector(r, line); - runTestVector(v); - } - } - - r.close(); - } - - private MySHAKEDigest createDigest(String algorithm) throws Exception - { - if (algorithm.startsWith("SHAKE-")) - { - int bits = parseDecimal(algorithm.substring("SHAKE-".length())); - return new MySHAKEDigest(bits); - } - throw new IllegalArgumentException("Unknown algorithm: " + algorithm); - } - - private byte[] decodeBinary(String block) - { - int bits = block.length(); - int fullBytes = bits / 8; - int totalBytes = (bits + 7) / 8; - byte[] result = new byte[totalBytes]; - - for (int i = 0; i < fullBytes; ++i) - { - String byteStr = reverse(block.substring(i * 8, (i + 1) * 8)); - result[i] = (byte)parseBinary(byteStr); - } - - if (totalBytes > fullBytes) - { - String byteStr = reverse(block.substring(fullBytes * 8)); - result[fullBytes] = (byte)parseBinary(byteStr); - } - - return result; - } - - private int parseBinary(String s) - { - return Integer.parseInt(s, 2); - } - - private int parseDecimal(String s) - { - return Integer.parseInt(s); - } - - private String readBlock(BufferedReader r) throws IOException - { - StringBuffer b = new StringBuffer(); - String line; - while ((line = readBlockLine(r)) != null) - { - b.append(line); - } - return b.toString(); - } - - private String readBlockLine(BufferedReader r) throws IOException - { - String line = readLine(r); - if (line == null || line.length() == 0) - { - return null; - } - - char[] chars = line.toCharArray(); - - int pos = 0; - for (int i = 0; i != chars.length; i++) - { - if (chars[i] != ' ') - { - chars[pos++] = chars[i]; - } - } - - return new String(chars, 0, pos); - } - - private TestVector readTestVector(BufferedReader r, String header) throws IOException - { - String[] parts = splitAround(header, TestVector.SAMPLE_OF); - - String algorithm = parts[0]; - int bits = parseDecimal(stripFromChar(parts[1], '-')); - - skipUntil(r, TestVector.MSG_HEADER); - String messageBlock = readBlock(r); - if (messageBlock.length() != bits) - { - throw new IllegalStateException("Test vector length mismatch"); - } - byte[] message = decodeBinary(messageBlock); - - skipUntil(r, TestVector.OUTPUT_HEADER); - byte[] output = Hex.decode(readBlock(r)); - - return new TestVector(algorithm, bits, message, output); - } - - private String readLine(BufferedReader r) throws IOException - { - String line = r.readLine(); - return line == null ? null : stripFromChar(line, '#').trim(); - } - - private String requireLine(BufferedReader r) throws IOException - { - String line = readLine(r); - if (line == null) - { - throw new EOFException(); - } - return line; - } - - private String reverse(String s) - { - return new StringBuffer(s).reverse().toString(); - } - - private void runTestVector(TestVector v) throws Exception - { - int bits = v.getBits(); - int partialBits = bits % 8; - - byte[] expected = v.getOutput(); - -// System.out.println(v.getAlgorithm() + " " + bits + "-bit"); -// System.out.println(Hex.toHexString(v.getMessage()).toUpperCase()); -// System.out.println(Hex.toHexString(expected).toUpperCase()); - - int outLen = expected.length; - - MySHAKEDigest d = createDigest(v.getAlgorithm()); - byte[] output = new byte[outLen]; - - byte[] m = v.getMessage(); - if (partialBits == 0) - { - d.update(m, 0, m.length); - d.doFinal(output, 0, outLen); - } - else - { - d.update(m, 0, m.length - 1); - d.myDoFinal(output, 0, outLen, m[m.length - 1], partialBits); - } - - if (!Arrays.areEqual(expected, output)) - { - fail(v.getAlgorithm() + " " + v.getBits() + "-bit test vector hash mismatch"); -// System.err.println(v.getAlgorithm() + " " + v.getBits() + "-bit test vector hash mismatch"); -// System.err.println(Hex.toHexString(output).toUpperCase()); - } - - if (partialBits == 0) - { - d = createDigest(v.getAlgorithm()); - - m = v.getMessage(); - - d.update(m, 0, m.length); - d.doOutput(output, 0, outLen / 2); - d.doOutput(output, outLen / 2, output.length - outLen / 2); - - if (!Arrays.areEqual(expected, output)) - { - fail(v.getAlgorithm() + " " + v.getBits() + "-bit test vector extended hash mismatch"); - } - - try - { - d.update((byte)0x01); - fail("no exception"); - } - catch (IllegalStateException e) - { - isTrue("wrong exception", "attempt to absorb while squeezing".equals(e.getMessage())); - } - - d = createDigest(v.getAlgorithm()); - - m = v.getMessage(); - - d.update(m, 0, m.length); - d.doOutput(output, 0, outLen / 2); - d.doFinal(output, outLen / 2, output.length - outLen / 2); - - if (!Arrays.areEqual(expected, output)) - { - fail(v.getAlgorithm() + " " + v.getBits() + "-bit test vector extended doFinal hash mismatch"); - } - - d.update((byte)0x01); // this should be okay as we've reset on doFinal() - } - } - - private void skipUntil(BufferedReader r, String header) throws IOException - { - String line; - do - { - line = requireLine(r); - } - while (line.length() == 0); - if (!line.equals(header)) - { - throw new IOException("Expected: " + header); - } - } - - private String[] splitAround(String s, String separator) - { - List strings = new ArrayList(); - - String remaining = s; - int index; - - while ((index = remaining.indexOf(separator)) > 0) - { - strings.add(remaining.substring(0, index)); - remaining = remaining.substring(index + separator.length()); - } - strings.add(remaining); - - return (String[])strings.toArray(new String[strings.size()]); - } - - private String stripFromChar(String s, char c) - { - int i = s.indexOf(c); - if (i >= 0) - { - s = s.substring(0, i); - } - return s; - } - - public static void main( - String[] args) - { - runTest(new SHAKEDigestTest()); - } - - private static class TestVector - { - private static String SAMPLE_OF = " sample of "; - private static String MSG_HEADER = "Msg as bit string"; - private static String OUTPUT_HEADER = "Output val is"; - - private String algorithm; - private int bits; - private byte[] message; - private byte[] output; - - private TestVector(String algorithm, int bits, byte[] message, byte[] output) - { - this.algorithm = algorithm; - this.bits = bits; - this.message = message; - this.output = output; - } - - public String getAlgorithm() - { - return algorithm; - } - - public int getBits() - { - return bits; - } - - public byte[] getMessage() - { - return message; - } - - public byte[] getOutput() - { - return output; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM2EngineTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM2EngineTest.java deleted file mode 100644 index 880f861ca..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM2EngineTest.java +++ /dev/null @@ -1,248 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.engines.SM2Engine; -import com.fr.third.org.bouncycastle.crypto.generators.ECKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.math.ec.ECConstants; -import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.math.ec.ECPoint; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestRandomBigInteger; - -public class SM2EngineTest - extends SimpleTest -{ - public String getName() - { - return "SM2Engine"; - } - - private void doEngineTestFp() - throws Exception - { - BigInteger SM2_ECC_P = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3", 16); - BigInteger SM2_ECC_A = new BigInteger("787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", 16); - BigInteger SM2_ECC_B = new BigInteger("63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", 16); - BigInteger SM2_ECC_N = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", 16); - BigInteger SM2_ECC_H = ECConstants.ONE; - BigInteger SM2_ECC_GX = new BigInteger("421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", 16); - BigInteger SM2_ECC_GY = new BigInteger("0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", 16); - - ECCurve curve = new ECCurve.Fp(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); - - ECPoint g = curve.createPoint(SM2_ECC_GX, SM2_ECC_GY); - ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N); - - ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator(); - - ECKeyGenerationParameters aKeyGenParams = new ECKeyGenerationParameters(domainParams, new TestRandomBigInteger("1649AB77A00637BD5E2EFE283FBF353534AA7F7CB89463F208DDBC2920BB0DA0", 16)); - - keyPairGenerator.init(aKeyGenParams); - - AsymmetricCipherKeyPair aKp = keyPairGenerator.generateKeyPair(); - - ECPublicKeyParameters aPub = (ECPublicKeyParameters)aKp.getPublic(); - ECPrivateKeyParameters aPriv = (ECPrivateKeyParameters)aKp.getPrivate(); - - SM2Engine sm2Engine = new SM2Engine(); - - byte[] m = Strings.toByteArray("encryption standard"); - - sm2Engine.init(true, new ParametersWithRandom(aPub, new TestRandomBigInteger("4C62EEFD6ECFC2B95B92FD6C3D9575148AFA17425546D49018E5388D49DD7B4F", 16))); - - byte[] enc = sm2Engine.processBlock(m, 0, m.length); - - isTrue("enc wrong", Arrays.areEqual(Hex.decode( - "04245C26 FB68B1DD DDB12C4B 6BF9F2B6 D5FE60A3 83B0D18D 1C4144AB F17F6252" + - "E776CB92 64C2A7E8 8E52B199 03FDC473 78F605E3 6811F5C0 7423A24B 84400F01" + - "B8650053 A89B41C4 18B0C3AA D00D886C 00286467 9C3D7360 C30156FA B7C80A02" + - "76712DA9 D8094A63 4B766D3A 285E0748 0653426D"), enc)); - - sm2Engine.init(false, aPriv); - - byte[] dec = sm2Engine.processBlock(enc, 0, enc.length); - - isTrue("dec wrong", Arrays.areEqual(m, dec)); - - enc[80] = (byte)(enc[80] + 1); - - try - { - sm2Engine.processBlock(enc, 0, enc.length); - fail("no exception"); - } - catch (InvalidCipherTextException e) - { - isTrue("wrong exception", "invalid cipher text".equals(e.getMessage())); - } - - // long message - sm2Engine = new SM2Engine(); - - m = new byte[4097]; - for (int i = 0; i != m.length; i++) - { - m[i] = (byte)i; - } - - sm2Engine.init(true, new ParametersWithRandom(aPub, new TestRandomBigInteger("4C62EEFD6ECFC2B95B92FD6C3D9575148AFA17425546D49018E5388D49DD7B4F", 16))); - - enc = sm2Engine.processBlock(m, 0, m.length); - - sm2Engine.init(false, aPriv); - - dec = sm2Engine.processBlock(enc, 0, enc.length); - - isTrue("dec wrong", Arrays.areEqual(m, dec)); - } - - private void doEngineTestFpC1C3C2() - throws Exception - { - BigInteger SM2_ECC_P = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3", 16); - BigInteger SM2_ECC_A = new BigInteger("787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", 16); - BigInteger SM2_ECC_B = new BigInteger("63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", 16); - BigInteger SM2_ECC_N = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", 16); - BigInteger SM2_ECC_H = ECConstants.ONE; - BigInteger SM2_ECC_GX = new BigInteger("421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", 16); - BigInteger SM2_ECC_GY = new BigInteger("0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", 16); - - ECCurve curve = new ECCurve.Fp(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); - - ECPoint g = curve.createPoint(SM2_ECC_GX, SM2_ECC_GY); - ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N); - - ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator(); - - ECKeyGenerationParameters aKeyGenParams = new ECKeyGenerationParameters(domainParams, new TestRandomBigInteger("1649AB77A00637BD5E2EFE283FBF353534AA7F7CB89463F208DDBC2920BB0DA0", 16)); - - keyPairGenerator.init(aKeyGenParams); - - AsymmetricCipherKeyPair aKp = keyPairGenerator.generateKeyPair(); - - ECPublicKeyParameters aPub = (ECPublicKeyParameters)aKp.getPublic(); - ECPrivateKeyParameters aPriv = (ECPrivateKeyParameters)aKp.getPrivate(); - - SM2Engine sm2Engine = new SM2Engine(SM2Engine.Mode.C1C3C2); - - byte[] m = Strings.toByteArray("encryption standard"); - - sm2Engine.init(true, new ParametersWithRandom(aPub, new TestRandomBigInteger("4C62EEFD6ECFC2B95B92FD6C3D9575148AFA17425546D49018E5388D49DD7B4F", 16))); - - byte[] enc = sm2Engine.processBlock(m, 0, m.length); - - isTrue("enc wrong", Arrays.areEqual(Hex.decode( - "04245C26 FB68B1DD DDB12C4B 6BF9F2B6 D5FE60A3 83B0D18D 1C4144AB F17F6252" + - "E776CB92 64C2A7E8 8E52B199 03FDC473 78F605E3 6811F5C0 7423A24B 84400F01" + - "B8 9C3D7360 C30156FA B7C80A02" + - "76712DA9 D8094A63 4B766D3A 285E0748 0653426D 650053 A89B41C4 18B0C3AA D00D886C 00286467"), enc)); - - sm2Engine.init(false, aPriv); - - byte[] dec = sm2Engine.processBlock(enc, 0, enc.length); - - isTrue("dec wrong", Arrays.areEqual(m, dec)); - - enc[80] = (byte)(enc[80] + 1); - - try - { - sm2Engine.processBlock(enc, 0, enc.length); - fail("no exception"); - } - catch (InvalidCipherTextException e) - { - isTrue("wrong exception", "invalid cipher text".equals(e.getMessage())); - } - - // long message - sm2Engine = new SM2Engine(SM2Engine.Mode.C1C3C2); - - m = new byte[4097]; - for (int i = 0; i != m.length; i++) - { - m[i] = (byte)i; - } - - sm2Engine.init(true, new ParametersWithRandom(aPub, new TestRandomBigInteger("4C62EEFD6ECFC2B95B92FD6C3D9575148AFA17425546D49018E5388D49DD7B4F", 16))); - - enc = sm2Engine.processBlock(m, 0, m.length); - - sm2Engine.init(false, aPriv); - - dec = sm2Engine.processBlock(enc, 0, enc.length); - - isTrue("dec wrong", Arrays.areEqual(m, dec)); - } - - private void doEngineTestF2m() - throws Exception - { - BigInteger SM2_ECC_A = new BigInteger("00", 16); - BigInteger SM2_ECC_B = new BigInteger("E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B", 16); - BigInteger SM2_ECC_N = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC972CF7E6B6F900945B3C6A0CF6161D", 16); - BigInteger SM2_ECC_H = BigInteger.valueOf(4); - BigInteger SM2_ECC_GX = new BigInteger("00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD", 16); - BigInteger SM2_ECC_GY = new BigInteger("013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E", 16); - - ECCurve curve = new ECCurve.F2m(257, 12, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); - - ECPoint g = curve.createPoint(SM2_ECC_GX, SM2_ECC_GY); - ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N, SM2_ECC_H); - - ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator(); - - ECKeyGenerationParameters aKeyGenParams = new ECKeyGenerationParameters(domainParams, new TestRandomBigInteger("56A270D17377AA9A367CFA82E46FA5267713A9B91101D0777B07FCE018C757EB", 16)); - - keyPairGenerator.init(aKeyGenParams); - - AsymmetricCipherKeyPair aKp = keyPairGenerator.generateKeyPair(); - - ECPublicKeyParameters aPub = (ECPublicKeyParameters)aKp.getPublic(); - ECPrivateKeyParameters aPriv = (ECPrivateKeyParameters)aKp.getPrivate(); - - SM2Engine sm2Engine = new SM2Engine(); - - byte[] m = Strings.toByteArray("encryption standard"); - - sm2Engine.init(true, new ParametersWithRandom(aPub, new TestRandomBigInteger("6D3B497153E3E92524E5C122682DBDC8705062E20B917A5F8FCDB8EE4C66663D", 16))); - - byte[] enc = sm2Engine.processBlock(m, 0, m.length); - - isTrue("f2m enc wrong", Arrays.areEqual(Hex.decode( - "04019D23 6DDB3050 09AD52C5 1BB93270 9BD534D4 76FBB7B0 DF9542A8 A4D890A3" + - "F2E100B2 3B938DC0 A94D1DF8 F42CF45D 2D6601BF 638C3D7D E75A29F0 2AFB7E45" + - "E91771FD 55AC6213 C2A8A040 E4CAB5B2 6A9CFCDA 737373A4 8625D375 8FA37B3E" + - "AB80E9CF CABA665E 3199EA15 A1FA8189 D96F5791 25E4"), enc)); - - sm2Engine.init(false, aPriv); - - byte[] dec = sm2Engine.processBlock(enc, 0, enc.length); - - isTrue("f2m dec wrong", Arrays.areEqual(m, dec)); - } - - public void performTest() - throws Exception - { - doEngineTestFp(); - doEngineTestF2m(); - doEngineTestFpC1C3C2(); - } - - public static void main(String[] args) - { - runTest(new SM2EngineTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM2KeyExchangeTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM2KeyExchangeTest.java deleted file mode 100644 index 34b54f173..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM2KeyExchangeTest.java +++ /dev/null @@ -1,229 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.agreement.SM2KeyExchange; -import com.fr.third.org.bouncycastle.crypto.generators.ECKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithID; -import com.fr.third.org.bouncycastle.crypto.params.SM2KeyExchangePrivateParameters; -import com.fr.third.org.bouncycastle.crypto.params.SM2KeyExchangePublicParameters; -import com.fr.third.org.bouncycastle.math.ec.ECConstants; -import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.math.ec.ECPoint; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestRandomBigInteger; - -public class SM2KeyExchangeTest - extends SimpleTest -{ - public String getName() - { - return "SM2KeyExchange"; - } - - private void doKeyExchangeTestFp() - throws Exception - { - BigInteger SM2_ECC_P = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3", 16); - BigInteger SM2_ECC_A = new BigInteger("787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", 16); - BigInteger SM2_ECC_B = new BigInteger("63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", 16); - BigInteger SM2_ECC_N = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", 16); - BigInteger SM2_ECC_H = ECConstants.ONE; - BigInteger SM2_ECC_GX = new BigInteger("421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", 16); - BigInteger SM2_ECC_GY = new BigInteger("0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", 16); - - ECCurve curve = new ECCurve.Fp(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); - - ECPoint g = curve.createPoint(SM2_ECC_GX, SM2_ECC_GY); - ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N); - - ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator(); - - ECKeyGenerationParameters aKeyGenParams = new ECKeyGenerationParameters(domainParams, new TestRandomBigInteger("6FCBA2EF9AE0AB902BC3BDE3FF915D44BA4CC78F88E2F8E7F8996D3B8CCEEDEE", 16)); - - keyPairGenerator.init(aKeyGenParams); - - AsymmetricCipherKeyPair aKp = keyPairGenerator.generateKeyPair(); - - ECPublicKeyParameters aPub = (ECPublicKeyParameters)aKp.getPublic(); - ECPrivateKeyParameters aPriv = (ECPrivateKeyParameters)aKp.getPrivate(); - - ECKeyGenerationParameters aeKeyGenParams = new ECKeyGenerationParameters(domainParams, new TestRandomBigInteger("83A2C9C8B96E5AF70BD480B472409A9A327257F1EBB73F5B073354B248668563", 16)); - - keyPairGenerator.init(aeKeyGenParams); - - AsymmetricCipherKeyPair aeKp = keyPairGenerator.generateKeyPair(); - - ECPublicKeyParameters aePub = (ECPublicKeyParameters)aeKp.getPublic(); - ECPrivateKeyParameters aePriv = (ECPrivateKeyParameters)aeKp.getPrivate(); - - ECKeyGenerationParameters bKeyGenParams = new ECKeyGenerationParameters(domainParams, new TestRandomBigInteger("5E35D7D3F3C54DBAC72E61819E730B019A84208CA3A35E4C2E353DFCCB2A3B53", 16)); - - keyPairGenerator.init(bKeyGenParams); - - AsymmetricCipherKeyPair bKp = keyPairGenerator.generateKeyPair(); - - ECPublicKeyParameters bPub = (ECPublicKeyParameters)bKp.getPublic(); - ECPrivateKeyParameters bPriv = (ECPrivateKeyParameters)bKp.getPrivate(); - - ECKeyGenerationParameters beKeyGenParams = new ECKeyGenerationParameters(domainParams, new TestRandomBigInteger("33FE21940342161C55619C4A0C060293D543C80AF19748CE176D83477DE71C80", 16)); - - keyPairGenerator.init(beKeyGenParams); - - AsymmetricCipherKeyPair beKp = keyPairGenerator.generateKeyPair(); - - ECPublicKeyParameters bePub = (ECPublicKeyParameters)beKp.getPublic(); - ECPrivateKeyParameters bePriv = (ECPrivateKeyParameters)beKp.getPrivate(); - - SM2KeyExchange exch = new SM2KeyExchange(); - - exch.init(new ParametersWithID(new SM2KeyExchangePrivateParameters(true, aPriv, aePriv), Strings.toByteArray("ALICE123@YAHOO.COM"))); - - byte[] k1 = exch.calculateKey(128, new ParametersWithID(new SM2KeyExchangePublicParameters(bPub, bePub), Strings.toByteArray("BILL456@YAHOO.COM"))); - - isTrue("key 1 wrong", Arrays.areEqual(Hex.decode("55b0ac62a6b927ba23703832c853ded4"), k1)); - - exch = new SM2KeyExchange(); - - exch.init(new ParametersWithID(new SM2KeyExchangePrivateParameters(false, bPriv, bePriv), Strings.toByteArray("BILL456@YAHOO.COM"))); - - byte[] k2 = exch.calculateKey(128, new ParametersWithID(new SM2KeyExchangePublicParameters(aPub, aePub), Strings.toByteArray("ALICE123@YAHOO.COM"))); - - isTrue("key 2 wrong", Arrays.areEqual(Hex.decode("55b0ac62a6b927ba23703832c853ded4"), k2)); - - // with key confirmation - exch = new SM2KeyExchange(); - - exch.init(new ParametersWithID(new SM2KeyExchangePrivateParameters(false, bPriv, bePriv), Strings.toByteArray("BILL456@YAHOO.COM"))); - - byte[][] vals2 = exch.calculateKeyWithConfirmation(128, null, new ParametersWithID(new SM2KeyExchangePublicParameters(aPub, aePub), Strings.toByteArray("ALICE123@YAHOO.COM"))); - - isTrue("key 2 wrong", Arrays.areEqual(Hex.decode("55b0ac62a6b927ba23703832c853ded4"), k2)); - - isTrue("conf a tag 2 wrong", Arrays.areEqual(Hex.decode("284C8F198F141B502E81250F1581C7E9EEB4CA6990F9E02DF388B45471F5BC5C"), vals2[1])); - isTrue("conf b tag 2 wrong", Arrays.areEqual(Hex.decode("23444DAF8ED7534366CB901C84B3BDBB63504F4065C1116C91A4C00697E6CF7A"), vals2[2])); - - exch = new SM2KeyExchange(); - - exch.init(new ParametersWithID(new SM2KeyExchangePrivateParameters(true, aPriv, aePriv), Strings.toByteArray("ALICE123@YAHOO.COM"))); - - byte[][] vals1 = exch.calculateKeyWithConfirmation(128, vals2[1], new ParametersWithID(new SM2KeyExchangePublicParameters(bPub, bePub), Strings.toByteArray("BILL456@YAHOO.COM"))); - - isTrue("conf key 1 wrong", Arrays.areEqual(Hex.decode("55b0ac62a6b927ba23703832c853ded4"), vals1[0])); - isTrue("conf tag 1 wrong", Arrays.areEqual(Hex.decode("23444DAF8ED7534366CB901C84B3BDBB63504F4065C1116C91A4C00697E6CF7A"), vals1[1])); - } - - private void doKeyExchangeTestF2m() - throws Exception - { - BigInteger SM2_ECC_A = new BigInteger("00", 16); - BigInteger SM2_ECC_B = new BigInteger("E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B", 16); - BigInteger SM2_ECC_N = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC972CF7E6B6F900945B3C6A0CF6161D", 16); - BigInteger SM2_ECC_H = BigInteger.valueOf(4); - BigInteger SM2_ECC_GX = new BigInteger("00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD", 16); - BigInteger SM2_ECC_GY = new BigInteger("013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E", 16); - - ECCurve curve = new ECCurve.F2m(257, 12, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); - - ECPoint g = curve.createPoint(SM2_ECC_GX, SM2_ECC_GY); - ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N, SM2_ECC_H); - - ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator(); - - ECKeyGenerationParameters aKeyGenParams = new ECKeyGenerationParameters(domainParams, new TestRandomBigInteger("4813903D254F2C20A94BC5704238496954BB5279F861952EF2C5298E84D2CEAA", 16)); - - keyPairGenerator.init(aKeyGenParams); - - AsymmetricCipherKeyPair aKp = keyPairGenerator.generateKeyPair(); - - ECPublicKeyParameters aPub = (ECPublicKeyParameters)aKp.getPublic(); - ECPrivateKeyParameters aPriv = (ECPrivateKeyParameters)aKp.getPrivate(); - - ECKeyGenerationParameters aeKeyGenParams = new ECKeyGenerationParameters(domainParams, new TestRandomBigInteger("54A3D6673FF3A6BD6B02EBB164C2A3AF6D4A4906229D9BFCE68CC366A2E64BA4", 16)); - - keyPairGenerator.init(aeKeyGenParams); - - AsymmetricCipherKeyPair aeKp = keyPairGenerator.generateKeyPair(); - - ECPublicKeyParameters aePub = (ECPublicKeyParameters)aeKp.getPublic(); - ECPrivateKeyParameters aePriv = (ECPrivateKeyParameters)aeKp.getPrivate(); - - ECKeyGenerationParameters bKeyGenParams = new ECKeyGenerationParameters(domainParams, new TestRandomBigInteger("08F41BAE0922F47C212803FE681AD52B9BF28A35E1CD0EC273A2CF813E8FD1DC", 16)); - - keyPairGenerator.init(bKeyGenParams); - - AsymmetricCipherKeyPair bKp = keyPairGenerator.generateKeyPair(); - - ECPublicKeyParameters bPub = (ECPublicKeyParameters)bKp.getPublic(); - ECPrivateKeyParameters bPriv = (ECPrivateKeyParameters)bKp.getPrivate(); - - ECKeyGenerationParameters beKeyGenParams = new ECKeyGenerationParameters(domainParams, new TestRandomBigInteger("1F21933387BEF781D0A8F7FD708C5AE0A56EE3F423DBC2FE5BDF6F068C53F7AD", 16)); - - keyPairGenerator.init(beKeyGenParams); - - AsymmetricCipherKeyPair beKp = keyPairGenerator.generateKeyPair(); - - ECPublicKeyParameters bePub = (ECPublicKeyParameters)beKp.getPublic(); - ECPrivateKeyParameters bePriv = (ECPrivateKeyParameters)beKp.getPrivate(); - - SM2KeyExchange exch = new SM2KeyExchange(); - - exch.init(new ParametersWithID(new SM2KeyExchangePrivateParameters(true, aPriv, aePriv), Strings.toByteArray("ALICE123@YAHOO.COM"))); - - byte[] k1 = exch.calculateKey(128, new ParametersWithID(new SM2KeyExchangePublicParameters(bPub, bePub), Strings.toByteArray("BILL456@YAHOO.COM"))); - - // there appears to be typo for ZA in the draft - //isTrue("F2m key 1 wrong", Arrays.areEqual(Hex.decode("4E587E5C66634F22D973A7D98BF8BE23"), k1)); - isTrue("F2m key 1 wrong", Arrays.areEqual(Hex.decode("8c2b03289aa7126555dc660cfc29fd74"), k1)); - - exch = new SM2KeyExchange(); - - exch.init(new ParametersWithID(new SM2KeyExchangePrivateParameters(false, bPriv, bePriv), Strings.toByteArray("BILL456@YAHOO.COM"))); - - byte[] k2 = exch.calculateKey(128, new ParametersWithID(new SM2KeyExchangePublicParameters(aPub, aePub), Strings.toByteArray("ALICE123@YAHOO.COM"))); - - //isTrue("F2m key 2 wrong", Arrays.areEqual(Hex.decode("4E587E5C66634F22D973A7D98BF8BE23"), k2)); - isTrue("F2m key 2 wrong", Arrays.areEqual(Hex.decode("8c2b03289aa7126555dc660cfc29fd74"), k2)); - - // with key confirmation - exch = new SM2KeyExchange(); - - exch.init(new ParametersWithID(new SM2KeyExchangePrivateParameters(false, bPriv, bePriv), Strings.toByteArray("BILL456@YAHOO.COM"))); - - byte[][] vals2 = exch.calculateKeyWithConfirmation(128, null, new ParametersWithID(new SM2KeyExchangePublicParameters(aPub, aePub), Strings.toByteArray("ALICE123@YAHOO.COM"))); - - isTrue("key 2 wrong", Arrays.areEqual(Hex.decode("8c2b03289aa7126555dc660cfc29fd74"), k2)); - - isTrue("conf a tag 2 wrong", Arrays.areEqual(Hex.decode("d8294c4c0f0ac180feac95e8a0d786638c9e915b9a684b2348809af03a0de2a5"), vals2[1])); - isTrue("conf b tag 2 wrong", Arrays.areEqual(Hex.decode("52089e706911b58fd5e7c7b2ab5cf32bb61e481ef1e114a1e33d99eec84b5a4f"), vals2[2])); - - exch = new SM2KeyExchange(); - - exch.init(new ParametersWithID(new SM2KeyExchangePrivateParameters(true, aPriv, aePriv), Strings.toByteArray("ALICE123@YAHOO.COM"))); - - byte[][] vals1 = exch.calculateKeyWithConfirmation(128, vals2[1], new ParametersWithID(new SM2KeyExchangePublicParameters(bPub, bePub), Strings.toByteArray("BILL456@YAHOO.COM"))); - - isTrue("conf key 1 wrong", Arrays.areEqual(Hex.decode("8c2b03289aa7126555dc660cfc29fd74"), vals1[0])); - isTrue("conf tag 1 wrong", Arrays.areEqual(Hex.decode("52089e706911b58fd5e7c7b2ab5cf32bb61e481ef1e114a1e33d99eec84b5a4f"), vals1[1])); - } - - public void performTest() - throws Exception - { - doKeyExchangeTestFp(); - doKeyExchangeTestF2m(); - } - - public static void main(String[] args) - { - runTest(new SM2KeyExchangeTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM2SignerTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM2SignerTest.java deleted file mode 100644 index 89db8596a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM2SignerTest.java +++ /dev/null @@ -1,280 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.IOException; -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encodable; -import com.fr.third.org.bouncycastle.asn1.ASN1Integer; -import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.x9.ECNamedCurveTable; -import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SM3Digest; -import com.fr.third.org.bouncycastle.crypto.generators.ECKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithID; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.signers.SM2Signer; -import com.fr.third.org.bouncycastle.math.ec.ECConstants; -import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.math.ec.ECPoint; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; -import com.fr.third.org.bouncycastle.util.test.TestRandomBigInteger; - -public class SM2SignerTest - extends SimpleTest -{ - private static final ECDomainParameters PARAMS_FP_DRAFT = createParamsFpDraft(); - private static final ECDomainParameters PARAMS_F2M = createParamsF2m(); - - public String getName() - { - return "SM2Signer"; - } - - private void doSignerTestFpDraftSM3() - throws Exception - { - doSignerTest( - PARAMS_FP_DRAFT, - new SM3Digest(), - "ALICE123@YAHOO.COM", - "message digest", - "128B2FA8BD433C6C068C8D803DFF79792A519A55171B1B650C23661D15897263", - "6CB28D99385C175C94F94E934817663FC176D925DD72B727260DBAAE1FB2F96F", - "40F1EC59F793D9F49E09DCEF49130D4194F79FB1EED2CAA55BACDB49C4E755D1", - "6FC6DAC32C5D5CF10C77DFB20F7C2EB667A457872FB09EC56327A67EC7DEEBE7" - ); - } - - private void doSignerTestFpDraftSha256() - throws Exception - { - doSignerTest( - PARAMS_FP_DRAFT, - new SHA256Digest(), - "ALICE123@YAHOO.COM", - "message digest", - "128B2FA8BD433C6C068C8D803DFF79792A519A55171B1B650C23661D15897263", - "6CB28D99385C175C94F94E934817663FC176D925DD72B727260DBAAE1FB2F96F", - "7D62A5EDBDDC8AF4D69C9E37A60D31F5CEFE8727709117E0869648D0A9AE4F57", - "1E5E89718B716AAFC6253443168E4F7CF7E1B7B3934307686CE5947C1BD55EDA" - ); - } - - private void doSignerTestFpStandardSM3() - throws Exception - { - doSignerTest( - "sm2p256v1", - new SM3Digest(), - "sm2test@example.com", - "hi chappy", - "110E7973206F68C19EE5F7328C036F26911C8C73B4E4F36AE3291097F8984FFC", - "3174C6FFC3C279D2422F3FC0A9F3E574674A4490FE45A5325CAF7D3EC4C8F96C", - "05890B9077B92E47B17A1FF42A814280E556AFD92B4A98B9670BF8B1A274C2FA", - "E3ABBB8DB2B6ECD9B24ECCEA7F679FB9A4B1DB52F4AA985E443AD73237FA1993" - ); - } - - private void doSignerTestFpStandardSha256() - throws Exception - { - doSignerTest( - "sm2p256v1", - new SHA256Digest(), - "sm2test@example.com", - "hi chappy", - "110E7973206F68C19EE5F7328C036F26911C8C73B4E4F36AE3291097F8984FFC", - "3174C6FFC3C279D2422F3FC0A9F3E574674A4490FE45A5325CAF7D3EC4C8F96C", - "94DA20EA69E4FC70692158BF3D30F87682A4B2F84DF4A4829A1EFC5D9C979D3F", - "EE15AF8D455B728AB80E592FCB654BF5B05620B2F4D25749D263D5C01FAD365F" - ); - } - - private void doSignerTestFpP256SM3() - throws Exception - { - doSignerTest( - "P-256", - new SM3Digest(), - "sm2_p256_test@example.com", - "no backdoors here", - "110E7973206F68C19EE5F7328C036F26911C8C73B4E4F36AE3291097F8984FFC", - "3174C6FFC3C279D2422F3FC0A9F3E574674A4490FE45A5325CAF7D3EC4C8F96C", - "96AA39A0C4A5C454653F394E86386F2E38BE14C57D0E555F3A27A5CEF30E51BD", - "62372BE4AC97DBE725AC0B279BB8FD15883858D814FD792DDB0A401DCC988E70" - ); - } - - private void doSignerTestFpP256Sha256() - throws Exception - { - doSignerTest( - "P-256", - new SHA256Digest(), - "sm2_p256_test@example.com", - "no backdoors here", - "110E7973206F68C19EE5F7328C036F26911C8C73B4E4F36AE3291097F8984FFC", - "3174C6FFC3C279D2422F3FC0A9F3E574674A4490FE45A5325CAF7D3EC4C8F96C", - "503D234A22123D7029271EB9E0D763619A69868DE8296C13EDD4CA32D280CFDE", - "0BDE97699B77268584DDD238DA120095F01130AD2DB37184270F37C02FB2E86B" - ); - } - - private void doSignerTestF2m() - throws Exception - { - doSignerTest( - PARAMS_F2M, - new SM3Digest(), - "ALICE123@YAHOO.COM", - "message digest", - "771EF3DBFF5F1CDC32B9C572930476191998B2BF7CB981D7F5B39202645F0931", - "36CD79FC8E24B7357A8A7B4A46D454C397703D6498158C605399B341ADA186D6", - "6D3FBA26EAB2A1054F5D198332E335817C8AC453ED26D3391CD4439D825BF25B", - "3124C5688D95F0A10252A9BED033BEC84439DA384621B6D6FAD77F94B74A9556" - ); - } - - private void doSignerTest(String curveName, Digest d, String ident, String msg, String x, String nonce, String r, String s) - throws Exception - { - X9ECParameters x9 = ECNamedCurveTable.getByName(curveName); - ECDomainParameters domainParams = new ECDomainParameters(x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed()); - - doSignerTest(domainParams, d, ident, msg, x, nonce, r, s); - } - - private void doSignerTest(ECDomainParameters domainParams, Digest d, String ident, String msg, String x, String nonce, String r, String s) - throws Exception - { - byte[] idBytes = Strings.toByteArray(ident); - byte[] msgBytes = Strings.toByteArray(msg); - AsymmetricCipherKeyPair kp = generateKeyPair(domainParams, x); - - SM2Signer signer = new SM2Signer(d); - - signer.init(true, new ParametersWithID( - new ParametersWithRandom(kp.getPrivate(), new TestRandomBigInteger(nonce, 16)), - idBytes)); - - signer.update(msgBytes, 0, msgBytes.length); - - byte[] sig = signer.generateSignature(); - - BigInteger[] rs = decode(sig); - - isTrue("r wrong", rs[0].equals(new BigInteger(r, 16))); - isTrue("s wrong", rs[1].equals(new BigInteger(s, 16))); - - signer.init(false, new ParametersWithID(kp.getPublic(), idBytes)); - - signer.update(msgBytes, 0, msgBytes.length); - - isTrue("verification failed", signer.verifySignature(sig)); - } - - private void doVerifyBoundsCheck() - throws IOException - { - ECDomainParameters domainParams = PARAMS_F2M; - - AsymmetricCipherKeyPair kp = generateKeyPair(domainParams, "771EF3DBFF5F1CDC32B9C572930476191998B2BF7CB981D7F5B39202645F0931"); - - SM2Signer signer = new SM2Signer(); - - signer.init(false, kp.getPublic()); - - signer.update(new byte[20], 0, 20); - isTrue(!signer.verifySignature(encode(ECConstants.ZERO, ECConstants.EIGHT))); - - signer.update(new byte[20], 0, 20); - isTrue(!signer.verifySignature(encode(ECConstants.EIGHT, ECConstants.ZERO))); - - signer.update(new byte[20], 0, 20); - isTrue(!signer.verifySignature(encode(domainParams.getN(), ECConstants.EIGHT))); - - signer.update(new byte[20], 0, 20); - isTrue(!signer.verifySignature(encode(ECConstants.EIGHT, domainParams.getN()))); - } - - public void performTest() - throws Exception - { - doSignerTestFpDraftSM3(); - doSignerTestFpDraftSha256(); - doSignerTestFpStandardSM3(); - doSignerTestFpStandardSha256(); - doSignerTestFpP256SM3(); - doSignerTestFpP256Sha256(); - doSignerTestF2m(); - doVerifyBoundsCheck(); - } - - private static ECDomainParameters createParamsFpDraft() - { - BigInteger SM2_ECC_P = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3", 16); - BigInteger SM2_ECC_A = new BigInteger("787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", 16); - BigInteger SM2_ECC_B = new BigInteger("63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", 16); - BigInteger SM2_ECC_N = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", 16); - BigInteger SM2_ECC_H = ECConstants.ONE; - BigInteger SM2_ECC_GX = new BigInteger("421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", 16); - BigInteger SM2_ECC_GY = new BigInteger("0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", 16); - - ECCurve curve = new ECCurve.Fp(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); - ECPoint g = curve.createPoint(SM2_ECC_GX, SM2_ECC_GY); - return new ECDomainParameters(curve, g, SM2_ECC_N, SM2_ECC_H); - } - - private static ECDomainParameters createParamsF2m() - { - BigInteger SM2_ECC_A = new BigInteger("00", 16); - BigInteger SM2_ECC_B = new BigInteger("E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B", 16); - BigInteger SM2_ECC_N = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC972CF7E6B6F900945B3C6A0CF6161D", 16); - BigInteger SM2_ECC_H = BigInteger.valueOf(4); - BigInteger SM2_ECC_GX = new BigInteger("00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD", 16); - BigInteger SM2_ECC_GY = new BigInteger("013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E", 16); - - ECCurve curve = new ECCurve.F2m(257, 12, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); - ECPoint g = curve.createPoint(SM2_ECC_GX, SM2_ECC_GY); - return new ECDomainParameters(curve, g, SM2_ECC_N, SM2_ECC_H); - } - - private static BigInteger[] decode(byte[] sig) - { - ASN1Sequence s = ASN1Sequence.getInstance(sig); - - return new BigInteger[] { - decodeValue(s.getObjectAt(0)), - decodeValue(s.getObjectAt(1)) }; - } - - private static BigInteger decodeValue(ASN1Encodable e) - { - return ASN1Integer.getInstance(e).getValue(); - } - - private static byte[] encode(BigInteger r, BigInteger s) - throws IOException - { - return new DERSequence(new ASN1Encodable[] { new ASN1Integer(r), new ASN1Integer(s)}).getEncoded(); - } - - private static AsymmetricCipherKeyPair generateKeyPair(ECDomainParameters domainParams, String x) - { - ECKeyPairGenerator kpg = new ECKeyPairGenerator(); - kpg.init(new ECKeyGenerationParameters(domainParams, new TestRandomBigInteger(x, 16))); - return kpg.generateKeyPair(); - } - - public static void main(String[] args) - { - runTest(new SM2SignerTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM3DigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM3DigestTest.java deleted file mode 100644 index df788378b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM3DigestTest.java +++ /dev/null @@ -1,197 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SM3Digest; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - -/** - * standard vector test for SM3 digest from chinese specification - */ -public class SM3DigestTest - extends DigestTest -{ - private static String[] messages = { - // Standard test vectors - "abc", - "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd", - // Non-standard test vectors - "", - "a", - "abcdefghijklmnopqrstuvwxyz", - }; - - private static String[] hexMessages = { - /* 2 p.57 ZA */ - "0090" + - "414C494345313233405941484F4F2E434F4D" + - "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498" + - "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A" + - "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D" + - "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2" + - "0AE4C7798AA0F119471BEE11825BE46202BB79E2A5844495E97C04FF4DF2548A" + - "7C0240F88F1CD4E16352A73C17B7F16F07353E53A176D684A9FE0C6BB798E857", - /* 3 p.59 ZA */ - "0090" + - "414C494345313233405941484F4F2E434F4D" + - "000000000000000000000000000000000000000000000000000000000000000000" + - "00E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B" + - "00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD" + - "013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E" + - "0165961645281A8626607B917F657D7E9382F1EA5CD931F40F6627F357542653B2" + - "01686522130D590FB8DE635D8FCA715CC6BF3D05BEF3F75DA5D543454448166612", - /* 4 p.72 ZA */ - "0090" + - "414C494345313233405941484F4F2E434F4D" + - "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498" + - "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A" + - "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D" + - "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2" + - "3099093BF3C137D8FCBBCDF4A2AE50F3B0F216C3122D79425FE03A45DBFE1655" + - "3DF79E8DAC1CF0ECBAA2F2B49D51A4B387F2EFAF482339086A27A8E05BAED98B", - /* 5 p.72 ZB */ - "0088" + - "42494C4C343536405941484F4F2E434F4D" + - "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498" + - "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A" + - "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D" + - "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2" + - "245493D446C38D8CC0F118374690E7DF633A8A4BFB3329B5ECE604B2B4F37F43" + - "53C0869F4B9E17773DE68FEC45E14904E0DEA45BF6CECF9918C85EA047C60A4C", - /* 6 p.75 ZA */ - "0090" + - "414C494345313233405941484F4F2E434F4D" + - "000000000000000000000000000000000000000000000000000000000000000000" + - "00E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B" + - "00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD" + - "013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E" + - "008E3BDB2E11F9193388F1F901CCC857BF49CFC065FB38B9069CAAE6D5AFC3592F" + - "004555122AAC0075F42E0A8BBD2C0665C789120DF19D77B4E3EE4712F598040415", - /* 7 p.76 ZB */ - "0088" + - "42494C4C343536405941484F4F2E434F4D" + - "000000000000000000000000000000000000000000000000000000000000000000" + - "00E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B" + - "00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD" + - "013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E" + - "0034297DD83AB14D5B393B6712F32B2F2E938D4690B095424B89DA880C52D4A7D9" + - "0199BBF11AC95A0EA34BBD00CA50B93EC24ACB68335D20BA5DCFE3B33BDBD2B62D", - /* 8 TopsecCA cert ZA */ - "0080" + - "31323334353637383132333435363738" + - "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC" + - "28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93" + - "32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7" + - "BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0" + - "D69C2F1EEC3BFB6B95B30C28085C77B125D77A9C39525D8190768F37D6B205B5" + - "89DCD316BBE7D89A9DC21917F17799E698531F5E6E3E10BD31370B259C3F81C3", - /* 9 */ - "4D38D2958CA7FD2CFAE3AF04486959CF92C8EF48E8B83A05C112E739D5F181D0" + - "3082020CA003020102020900" + - "AF28725D98D33143300C06082A811CCF" + - "550183750500307D310B300906035504" + - "060C02636E310B300906035504080C02" + - "626A310B300906035504070C02626A31" + - "0F300D060355040A0C06746F70736563" + - "310F300D060355040B0C06746F707365" + - "633111300F06035504030C08546F7073" + - "65634341311F301D06092A864886F70D" + - "0109010C10626A40746F707365632E63" + - "6F6D2E636E301E170D31323036323430" + - "37353433395A170D3332303632303037" + - "353433395A307D310B30090603550406" + - "0C02636E310B300906035504080C0262" + - "6A310B300906035504070C02626A310F" + - "300D060355040A0C06746F7073656331" + - "0F300D060355040B0C06746F70736563" + - "3111300F06035504030C08546F707365" + - "634341311F301D06092A864886F70D01" + - "09010C10626A40746F707365632E636F" + - "6D2E636E3059301306072A8648CE3D02" + - "0106082A811CCF5501822D03420004D6" + - "9C2F1EEC3BFB6B95B30C28085C77B125" + - "D77A9C39525D8190768F37D6B205B589" + - "DCD316BBE7D89A9DC21917F17799E698" + - "531F5E6E3E10BD31370B259C3F81C3A3" + - "733071300F0603551D130101FF040530" + - "030101FF301D0603551D0E041604148E" + - "5D90347858BAAAD870D8BDFBA6A85E7B" + - "563B64301F0603551D23041830168014" + - "8E5D90347858BAAAD870D8BDFBA6A85E" + - "7B563B64300B0603551D0F0404030201" + - "06301106096086480186F84201010404" + - "03020057", - }; - - private static String[] digests = { - // Standard test vectors - "66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0", - "debe9ff92275b8a138604889c18e5a4d6fdb70e5387e5765293dcba39c0c5732", - // Non-standard test vectors - "1ab21d8355cfa17f8e61194831e81a8f22bec8c728fefb747ed035eb5082aa2b", - "623476ac18f65a2909e43c7fec61b49c7e764a91a18ccb82f1917a29c86c5e88", - "b80fe97a4da24afc277564f66a359ef440462ad28dcc6d63adb24d5c20a61595", - // Additional vectors for GMSSL - "F4A38489E32B45B6F876E3AC2168CA392362DC8F23459C1D1146FC3DBFB7BC9A", - "26352AF82EC19F207BBC6F9474E11E90CE0F7DDACE03B27F801817E897A81FD5", - "E4D1D0C3CA4C7F11BC8FF8CB3F4C02A78F108FA098E51A668487240F75E20F31", - "6B4B6D0E276691BD4A11BF72F4FB501AE309FDACB72FA6CC336E6656119ABD67", - "329c2f6030cc7e0ca3af6c97b76243ca250338ad3d3dc3a8b322d1cfdf98c2b7", // original appears wrong -> "ECF0080215977B2E5D6D61B98A99442F03E8803DC39E349F8DCA5621A9ACDF2B", - "557BAD30E183559AEEC3B2256E1C7C11F870D22B165D015ACF9465B09B87B527", - "4D38D2958CA7FD2CFAE3AF04486959CF92C8EF48E8B83A05C112E739D5F181D0", - "C3B02E500A8B60B77DEDCF6F4C11BEF8D56E5CDE708C72065654FD7B2167915A", - }; - - final static String sixtyFourKdigest = "97049bdc8f0736bc7300eafa9980aeb9cf00f24f7ec3a8f1f8884954d7655c1d"; - final static String million_a_digest = "c8aaf89429554029e231941a2acc0ad61ff2a5acd8fadd25847a3a732b3b02c3"; - - SM3DigestTest() - { - super(new SM3Digest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - SM3Digest dig = new SM3Digest(); - byte[] resBuf = new byte[dig.getDigestSize()]; - - vectorTest(dig, 10, resBuf, Hex.decode(hexMessages[0]), Hex.decode(digests[messages.length])); - vectorTest(dig, 11, resBuf, Hex.decode(hexMessages[1]), Hex.decode(digests[messages.length + 1])); - vectorTest(dig, 12, resBuf, Hex.decode(hexMessages[2]), Hex.decode(digests[messages.length + 2])); - vectorTest(dig, 13, resBuf, Hex.decode(hexMessages[3]), Hex.decode(digests[messages.length + 3])); - vectorTest(dig, 14, resBuf, Hex.decode(hexMessages[4]), Hex.decode(digests[messages.length + 4])); - vectorTest(dig, 15, resBuf, Hex.decode(hexMessages[5]), Hex.decode(digests[messages.length + 5])); - vectorTest(dig, 16, resBuf, Hex.decode(hexMessages[6]), Hex.decode(digests[messages.length + 6])); - vectorTest(dig, 17, resBuf, Hex.decode(hexMessages[7]), Hex.decode(digests[messages.length + 7])); - - sixtyFourKTest(sixtyFourKdigest); - millionATest(million_a_digest); - } - - private void vectorTest( - Digest digest, - int count, - byte[] resBuf, - byte[] input, - byte[] expected) - { - digest.update(input, 0, input.length); - digest.doFinal(resBuf, 0); - - if (!areEqual(resBuf, expected)) - { - fail("Vector " + count + " failed got " + new String(Hex.encode(resBuf))); - } - } - - protected Digest cloneDigest(Digest digest) - { - return new SM3Digest((SM3Digest)digest); - } - - public static void main(String[] args) - { - runTest(new SM3DigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM4Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM4Test.java deleted file mode 100644 index 2661c56fc..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SM4Test.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.engines.SM4Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * SM4 tester, vectors from http://eprint.iacr.org/2008/329.pdf - */ -public class SM4Test - extends CipherTest -{ - static SimpleTest[] tests = { - new BlockCipherVectorTest(0, new SM4Engine(), - new KeyParameter(Hex.decode("0123456789abcdeffedcba9876543210")), - "0123456789abcdeffedcba9876543210", - "681edf34d206965e86b3e94f536e4246") - }; - - SM4Test() - { - super(tests, new SM4Engine(), new KeyParameter(new byte[16])); - } - - public void performTest() - throws Exception - { - super.performTest(); - - test1000000(); - } - - private void test1000000() - { - byte[] plain = Hex.decode("0123456789abcdeffedcba9876543210"); - byte[] key = Hex.decode("0123456789abcdeffedcba9876543210"); - byte[] cipher = Hex.decode("595298c7c6fd271f0402f804c33d3f66"); - byte[] buf = new byte[16]; - - BlockCipher engine = new SM4Engine(); - - engine.init(true, new KeyParameter(key)); - - System.arraycopy(plain, 0, buf, 0, buf.length); - - for (int i = 0; i != 1000000; i++) - { - engine.processBlock(buf, 0, buf, 0); - } - - if (!areEqual(cipher, buf)) - { - fail("1000000 encryption test failed"); - } - - engine.init(false, new KeyParameter(key)); - - for (int i = 0; i != 1000000; i++) - { - engine.processBlock(buf, 0, buf, 0); - } - - if (!areEqual(plain, buf)) - { - fail("1000000 decryption test failed"); - } - } - - public String getName() - { - return "SM4"; - } - - public static void main( - String[] args) - { - runTest(new SM4Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SRP6Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SRP6Test.java deleted file mode 100644 index 20274fc47..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SRP6Test.java +++ /dev/null @@ -1,267 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.CryptoException; -import com.fr.third.org.bouncycastle.crypto.agreement.srp.SRP6Client; -import com.fr.third.org.bouncycastle.crypto.agreement.srp.SRP6Server; -import com.fr.third.org.bouncycastle.crypto.agreement.srp.SRP6StandardGroups; -import com.fr.third.org.bouncycastle.crypto.agreement.srp.SRP6Util; -import com.fr.third.org.bouncycastle.crypto.agreement.srp.SRP6VerifierGenerator; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.generators.DHParametersGenerator; -import com.fr.third.org.bouncycastle.crypto.params.DHParameters; -import com.fr.third.org.bouncycastle.crypto.params.SRP6GroupParameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class SRP6Test extends SimpleTest -{ - private static final BigInteger ZERO = BigInteger.valueOf(0); - - private static BigInteger fromHex(String hex) - { - return new BigInteger(1, Hex.decode(hex)); - } - - private final SecureRandom random = new SecureRandom(); - - public String getName() - { - return "SRP6"; - } - - public void performTest() throws Exception - { - rfc5054AppendixBTestVectors(); - - testMutualVerification(SRP6StandardGroups.rfc5054_1024); - testClientCatchesBadB(SRP6StandardGroups.rfc5054_1024); - testServerCatchesBadA(SRP6StandardGroups.rfc5054_1024); - - testWithRandomParams(256); - testWithRandomParams(384); - testWithRandomParams(512); - } - - private void rfc5054AppendixBTestVectors() throws Exception - { - byte[] I = "alice".getBytes("UTF8"); - byte[] P = "password123".getBytes("UTF8"); - byte[] s = Hex.decode("BEB25379D1A8581EB5A727673A2441EE"); - BigInteger N = SRP6StandardGroups.rfc5054_1024.getN(); - BigInteger g = SRP6StandardGroups.rfc5054_1024.getG(); - BigInteger a = fromHex("60975527035CF2AD1989806F0407210BC81EDC04E2762A56AFD529DDDA2D4393"); - BigInteger b = fromHex("E487CB59D31AC550471E81F00F6928E01DDA08E974A004F49E61F5D105284D20"); - - BigInteger expect_k = fromHex("7556AA045AEF2CDD07ABAF0F665C3E818913186F"); - BigInteger expect_x = fromHex("94B7555AABE9127CC58CCF4993DB6CF84D16C124"); - BigInteger expect_v = fromHex("7E273DE8696FFC4F4E337D05B4B375BEB0DDE1569E8FA00A9886D812" - + "9BADA1F1822223CA1A605B530E379BA4729FDC59F105B4787E5186F5" - + "C671085A1447B52A48CF1970B4FB6F8400BBF4CEBFBB168152E08AB5" - + "EA53D15C1AFF87B2B9DA6E04E058AD51CC72BFC9033B564E26480D78" - + "E955A5E29E7AB245DB2BE315E2099AFB"); - BigInteger expect_A = fromHex("61D5E490F6F1B79547B0704C436F523DD0E560F0C64115BB72557EC4" - + "4352E8903211C04692272D8B2D1A5358A2CF1B6E0BFCF99F921530EC" - + "8E39356179EAE45E42BA92AEACED825171E1E8B9AF6D9C03E1327F44" - + "BE087EF06530E69F66615261EEF54073CA11CF5858F0EDFDFE15EFEA" - + "B349EF5D76988A3672FAC47B0769447B"); - BigInteger expect_B = fromHex("BD0C61512C692C0CB6D041FA01BB152D4916A1E77AF46AE105393011" - + "BAF38964DC46A0670DD125B95A981652236F99D9B681CBF87837EC99" - + "6C6DA04453728610D0C6DDB58B318885D7D82C7F8DEB75CE7BD4FBAA" - + "37089E6F9C6059F388838E7A00030B331EB76840910440B1B27AAEAE" - + "EB4012B7D7665238A8E3FB004B117B58"); - BigInteger expect_u = fromHex("CE38B9593487DA98554ED47D70A7AE5F462EF019"); - BigInteger expect_S = fromHex("B0DC82BABCF30674AE450C0287745E7990A3381F63B387AAF271A10D" - + "233861E359B48220F7C4693C9AE12B0A6F67809F0876E2D013800D6C" - + "41BB59B6D5979B5C00A172B4A2A5903A0BDCAF8A709585EB2AFAFA8F" - + "3499B200210DCC1F10EB33943CD67FC88A2F39A4BE5BEC4EC0A3212D" - + "C346D7E474B29EDE8A469FFECA686E5A"); - - BigInteger k = SRP6Util.calculateK(new SHA1Digest(), N, g); - if (!k.equals(expect_k)) - { - fail("wrong value of 'k'"); - } - - BigInteger x = SRP6Util.calculateX(new SHA1Digest(), N, s, I, P); - if (!x.equals(expect_x)) - { - fail("wrong value of 'x'"); - } - - SRP6VerifierGenerator gen = new SRP6VerifierGenerator(); - gen.init(N, g, new SHA1Digest()); - BigInteger v = gen.generateVerifier(s, I, P); - if (!v.equals(expect_v)) - { - fail("wrong value of 'v'"); - } - - final BigInteger aVal = a; - SRP6Client client = new SRP6Client() - { - protected BigInteger selectPrivateValue() - { - return aVal; - } - }; - client.init(N, g, new SHA1Digest(), random); - - BigInteger A = client.generateClientCredentials(s, I, P); - if (!A.equals(expect_A)) - { - fail("wrong value of 'A'"); - } - - final BigInteger bVal = b; - SRP6Server server = new SRP6Server() - { - protected BigInteger selectPrivateValue() - { - return bVal; - } - }; - server.init(N, g, v, new SHA1Digest(), random); - - BigInteger B = server.generateServerCredentials(); - if (!B.equals(expect_B)) - { - fail("wrong value of 'B'"); - } - - BigInteger u = SRP6Util.calculateU(new SHA1Digest(), N, A, B); - if (!u.equals(expect_u)) - { - fail("wrong value of 'u'"); - } - - BigInteger clientS = client.calculateSecret(B); - if (!clientS.equals(expect_S)) - { - fail("wrong value of 'S' (client)"); - } - - BigInteger serverS = server.calculateSecret(A); - if (!serverS.equals(expect_S)) - { - fail("wrong value of 'S' (server)"); - } - } - - private void testWithRandomParams(int bits) throws CryptoException - { - DHParametersGenerator paramGen = new DHParametersGenerator(); - paramGen.init(bits, 25, random); - DHParameters parameters = paramGen.generateParameters(); - - testMutualVerification(new SRP6GroupParameters(parameters.getP(), parameters.getG())); - } - - private void testMutualVerification(SRP6GroupParameters group) throws CryptoException - { - byte[] I = "username".getBytes(); - byte[] P = "password".getBytes(); - byte[] s = new byte[16]; - random.nextBytes(s); - - SRP6VerifierGenerator gen = new SRP6VerifierGenerator(); - gen.init(group, new SHA256Digest()); - BigInteger v = gen.generateVerifier(s, I, P); - - SRP6Client client = new SRP6Client(); - client.init(group, new SHA256Digest(), random); - - SRP6Server server = new SRP6Server(); - server.init(group, v, new SHA256Digest(), random); - - BigInteger A = client.generateClientCredentials(s, I, P); - BigInteger B = server.generateServerCredentials(); - - BigInteger clientS = client.calculateSecret(B); - BigInteger serverS = server.calculateSecret(A); - - if (!clientS.equals(serverS)) - { - fail("SRP agreement failed - client/server calculated different secrets"); - } - } - - private void testClientCatchesBadB(SRP6GroupParameters group) - { - byte[] I = "username".getBytes(); - byte[] P = "password".getBytes(); - byte[] s = new byte[16]; - random.nextBytes(s); - - SRP6Client client = new SRP6Client(); - client.init(group, new SHA256Digest(), random); - - client.generateClientCredentials(s, I, P); - - try - { - client.calculateSecret(ZERO); - fail("Client failed to detect invalid value for 'B'"); - } - catch (CryptoException e) - { - // Expected - } - - try - { - client.calculateSecret(group.getN()); - fail("Client failed to detect invalid value for 'B'"); - } - catch (CryptoException e) - { - // Expected - } - } - - private void testServerCatchesBadA(SRP6GroupParameters group) - { - byte[] I = "username".getBytes(); - byte[] P = "password".getBytes(); - byte[] s = new byte[16]; - random.nextBytes(s); - - SRP6VerifierGenerator gen = new SRP6VerifierGenerator(); - gen.init(group, new SHA256Digest()); - BigInteger v = gen.generateVerifier(s, I, P); - - SRP6Server server = new SRP6Server(); - server.init(group, v, new SHA256Digest(), random); - - server.generateServerCredentials(); - - try - { - server.calculateSecret(ZERO); - fail("Client failed to detect invalid value for 'A'"); - } - catch (CryptoException e) - { - // Expected - } - - try - { - server.calculateSecret(group.getN()); - fail("Client failed to detect invalid value for 'A'"); - } - catch (CryptoException e) - { - // Expected - } - } - - public static void main(String[] args) - { - runTest(new SRP6Test()); - } -} - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Salsa20Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Salsa20Test.java deleted file mode 100644 index 13caa146b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Salsa20Test.java +++ /dev/null @@ -1,400 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.crypto.engines.Salsa20Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Salsa20 Test - */ -public class Salsa20Test - extends SimpleTest -{ - byte[] zeroes = Hex.decode( - "00000000000000000000000000000000" - + "00000000000000000000000000000000" - + "00000000000000000000000000000000" - + "00000000000000000000000000000000"); - - String set1v0_0 = "4DFA5E481DA23EA09A31022050859936" - + "DA52FCEE218005164F267CB65F5CFD7F" - + "2B4F97E0FF16924A52DF269515110A07" - + "F9E460BC65EF95DA58F740B7D1DBB0AA"; - - String set1v0_192 = "DA9C1581F429E0A00F7D67E23B730676" - + "783B262E8EB43A25F55FB90B3E753AEF" - + "8C6713EC66C51881111593CCB3E8CB8F" - + "8DE124080501EEEB389C4BCB6977CF95"; - - String set1v0_256 = "7D5789631EB4554400E1E025935DFA7B" - + "3E9039D61BDC58A8697D36815BF1985C" - + "EFDF7AE112E5BB81E37ECF0616CE7147" - + "FC08A93A367E08631F23C03B00A8DA2F"; - - String set1v0_448 = "B375703739DACED4DD4059FD71C3C47F" - + "C2F9939670FAD4A46066ADCC6A564578" - + "3308B90FFB72BE04A6B147CBE38CC0C3" - + "B9267C296A92A7C69873F9F263BE9703"; - - String set1v9_0 = "0471076057830FB99202291177FBFE5D" - + "38C888944DF8917CAB82788B91B53D1C" - + "FB06D07A304B18BB763F888A61BB6B75" - + "5CD58BEC9C4CFB7569CB91862E79C459"; - - String set1v9_192 = "D1D7E97556426E6CFC21312AE3811425" - + "9E5A6FB10DACBD88E4354B0472556935" - + "2B6DA5ACAFACD5E266F9575C2ED8E6F2" - + "EFE4B4D36114C3A623DD49F4794F865B"; - - String set1v9_256 = "AF06FAA82C73291231E1BD916A773DE1" - + "52FD2126C40A10C3A6EB40F22834B8CC" - + "68BD5C6DBD7FC1EC8F34165C517C0B63" - + "9DB0C60506D3606906B8463AA0D0EC2F"; - - String set1v9_448 = "AB3216F1216379EFD5EC589510B8FD35" - + "014D0AA0B613040BAE63ECAB90A9AF79" - + "661F8DA2F853A5204B0F8E72E9D9EB4D" - + "BA5A4690E73A4D25F61EE7295215140C"; - - String set6v0_0 = "F5FAD53F79F9DF58C4AEA0D0ED9A9601" - + "F278112CA7180D565B420A48019670EA" - + "F24CE493A86263F677B46ACE1924773D" - + "2BB25571E1AA8593758FC382B1280B71"; - - String set6v0_65472 = "B70C50139C63332EF6E77AC54338A407" - + "9B82BEC9F9A403DFEA821B83F7860791" - + "650EF1B2489D0590B1DE772EEDA4E3BC" - + "D60FA7CE9CD623D9D2FD5758B8653E70"; - - String set6v0_65536 = "81582C65D7562B80AEC2F1A673A9D01C" - + "9F892A23D4919F6AB47B9154E08E699B" - + "4117D7C666477B60F8391481682F5D95" - + "D96623DBC489D88DAA6956B9F0646B6E"; - - String set6v1_0 = "3944F6DC9F85B128083879FDF190F7DE" - + "E4053A07BC09896D51D0690BD4DA4AC1" - + "062F1E47D3D0716F80A9B4D85E6D6085" - + "EE06947601C85F1A27A2F76E45A6AA87"; - - String set6v1_65472 = "36E03B4B54B0B2E04D069E690082C8C5" - + "92DF56E633F5D8C7682A02A65ECD1371" - + "8CA4352AACCB0DA20ED6BBBA62E177F2" - + "10E3560E63BB822C4158CAA806A88C82"; - - String set6v1_65536 = "1B779E7A917C8C26039FFB23CF0EF8E0" - + "8A1A13B43ACDD9402CF5DF38501098DF" - + "C945A6CC69A6A17367BC03431A86B3ED" - + "04B0245B56379BF997E25800AD837D7D"; - - // Salsa20/12 - String salsa12_set1v0_0 = "FC207DBFC76C5E1774961E7A5AAD0906" - + "9B2225AC1CE0FE7A0CE77003E7E5BDF8" - + "B31AF821000813E6C56B8C1771D6EE70" - + "39B2FBD0A68E8AD70A3944B677937897"; - - String salsa12_set1v0_192 = "4B62A4881FA1AF9560586510D5527ED4" - + "8A51ECAFA4DECEEBBDDC10E9918D44AB" - + "26B10C0A31ED242F146C72940C6E9C37" - + "53F641DA84E9F68B4F9E76B6C48CA5AC"; - - String salsa12_set1v0_256 = "F52383D9DEFB20810325F7AEC9EADE34" - + "D9D883FEE37E05F74BF40875B2D0BE79" - + "ED8886E5BFF556CEA8D1D9E86B1F68A9" - + "64598C34F177F8163E271B8D2FEB5996"; - - String salsa12_set1v0_448 = "A52ED8C37014B10EC0AA8E05B5CEEE12" - + "3A1017557FB3B15C53E6C5EA8300BF74" - + "264A73B5315DC821AD2CAB0F3BB2F152" - + "BDAEA3AEE97BA04B8E72A7B40DCC6BA4"; - - // Salsa20/8 - String salsa8_set1v0_0 = "A9C9F888AB552A2D1BBFF9F36BEBEB33" - + "7A8B4B107C75B63BAE26CB9A235BBA9D" - + "784F38BEFC3ADF4CD3E266687EA7B9F0" - + "9BA650AE81EAC6063AE31FF12218DDC5"; - - String salsa8_set1v0_192 = "BB5B6BB2CC8B8A0222DCCC1753ED4AEB" - + "23377ACCBD5D4C0B69A8A03BB115EF71" - + "871BC10559080ACA7C68F0DEF32A80DD" - + "BAF497259BB76A3853A7183B51CC4B9F"; - - String salsa8_set1v0_256 = "4436CDC0BE39559F5E5A6B79FBDB2CAE" - + "4782910F27FFC2391E05CFC78D601AD8" - + "CD7D87B074169361D997D1BED9729C0D" - + "EB23418E0646B7997C06AA84E7640CE3"; - - String salsa8_set1v0_448 = "BEE85903BEA506B05FC04795836FAAAC" - + "7F93F785D473EB762576D96B4A65FFE4" - + "63B34AAE696777FC6351B67C3753B89B" - + "A6B197BD655D1D9CA86E067F4D770220"; - - - public String getName() - { - return "Salsa20"; - } - - public void performTest() - { - salsa20Test1(20, new ParametersWithIV(new KeyParameter(Hex.decode("80000000000000000000000000000000")), Hex.decode("0000000000000000")), - set1v0_0, set1v0_192, set1v0_256, set1v0_448); - salsa20Test1(20, new ParametersWithIV(new KeyParameter(Hex.decode("00400000000000000000000000000000")), Hex.decode("0000000000000000")), - set1v9_0, set1v9_192, set1v9_256, set1v9_448); - salsa20Test1(12, new ParametersWithIV(new KeyParameter(Hex.decode("80000000000000000000000000000000")), Hex.decode("0000000000000000")), - salsa12_set1v0_0, salsa12_set1v0_192, salsa12_set1v0_256, salsa12_set1v0_448); - salsa20Test1(8, new ParametersWithIV(new KeyParameter(Hex.decode("80000000000000000000000000000000")), Hex.decode("0000000000000000")), - salsa8_set1v0_0, salsa8_set1v0_192, salsa8_set1v0_256, salsa8_set1v0_448); - salsa20Test2(new ParametersWithIV(new KeyParameter(Hex.decode("0053A6F94C9FF24598EB3E91E4378ADD3083D6297CCF2275C81B6EC11467BA0D")), Hex.decode("0D74DB42A91077DE")), - set6v0_0, set6v0_65472, set6v0_65536); - salsa20Test2(new ParametersWithIV(new KeyParameter(Hex.decode("0558ABFE51A4F74A9DF04396E93C8FE23588DB2E81D4277ACD2073C6196CBF12")), Hex.decode("167DE44BB21980E7")), - set6v1_0, set6v1_65472, set6v1_65536); - reinitBug(); - skipTest(); - } - - private void salsa20Test1(int rounds, CipherParameters params, String v0, String v192, String v256, String v448) - { - StreamCipher salsa = new Salsa20Engine(rounds); - byte[] buf = new byte[64]; - - salsa.init(true, params); - - for (int i = 0; i != 7; i++) - { - salsa.processBytes(zeroes, 0, 64, buf, 0); - switch (i) - { - case 0: - if (!areEqual(buf, Hex.decode(v0))) - { - mismatch("v0/" + rounds, v0, buf); - } - break; - case 3: - if (!areEqual(buf, Hex.decode(v192))) - { - mismatch("v192/" + rounds, v192, buf); - } - break; - case 4: - if (!areEqual(buf, Hex.decode(v256))) - { - mismatch("v256/" + rounds, v256, buf); - } - break; - default: - // ignore - } - } - - for (int i = 0; i != 64; i++) - { - buf[i] = salsa.returnByte(zeroes[i]); - } - - if (!areEqual(buf, Hex.decode(v448))) - { - mismatch("v448", v448, buf); - } - } - - private void salsa20Test2(CipherParameters params, String v0, String v65472, String v65536) - { - StreamCipher salsa = new Salsa20Engine(); - byte[] buf = new byte[64]; - - salsa.init(true, params); - - for (int i = 0; i != 1025; i++) - { - salsa.processBytes(zeroes, 0, 64, buf, 0); - switch (i) - { - case 0: - if (!areEqual(buf, Hex.decode(v0))) - { - mismatch("v0", v0, buf); - } - break; - case 1023: - if (!areEqual(buf, Hex.decode(v65472))) - { - mismatch("v65472", v65472, buf); - } - break; - case 1024: - if (!areEqual(buf, Hex.decode(v65536))) - { - mismatch("v65536", v65536, buf); - } - break; - default: - // ignore - } - } - } - - private void mismatch(String name, String expected, byte[] found) - { - fail("mismatch on " + name, expected, new String(Hex.encode(found))); - } - - - private void reinitBug() - { - KeyParameter key = new KeyParameter(Hex.decode("80000000000000000000000000000000")); - ParametersWithIV parameters = new ParametersWithIV(key, Hex.decode("0000000000000000")); - - StreamCipher salsa = new Salsa20Engine(); - - salsa.init(true, parameters); - - try - { - salsa.init(true, key); - fail("Salsa20 should throw exception if no IV in Init"); - } - catch (IllegalArgumentException e) - { - } - } - - private boolean areEqual(byte[] a, int aOff, byte[] b, int bOff) - { - for (int i = bOff; i != b.length; i++) - { - if (a[aOff + i - bOff] != b[i]) - { - return false; - } - } - - return true; - } - - private void skipTest() - { - SecureRandom rand = new SecureRandom(); - byte[] plain = new byte[50000]; - byte[] cipher = new byte[50000]; - - rand.nextBytes(plain); - - CipherParameters params = new ParametersWithIV(new KeyParameter(Hex.decode("0053A6F94C9FF24598EB3E91E4378ADD3083D6297CCF2275C81B6EC11467BA0D")), Hex.decode("0D74DB42A91077DE")); - Salsa20Engine engine = new Salsa20Engine(); - - engine.init(true, params); - - engine.processBytes(plain, 0, plain.length, cipher, 0); - - byte[] fragment = new byte[20]; - - engine.init(true, params); - - engine.skip(10); - - engine.processBytes(plain, 10, fragment.length, fragment, 0); - - if (!areEqual(cipher, 10, fragment, 0)) - { - fail("skip forward 10 failed"); - } - - engine.skip(1000); - - engine.processBytes(plain, 1010 + fragment.length, fragment.length, fragment, 0); - - if (!areEqual(cipher, 1010 + fragment.length, fragment, 0)) - { - fail("skip forward 1000 failed"); - } - - engine.skip(-10); - - engine.processBytes(plain, 1010 + 2 * fragment.length - 10, fragment.length, fragment, 0); - - if (!areEqual(cipher, 1010 + 2 * fragment.length - 10, fragment, 0)) - { - fail("skip back 10 failed"); - } - - engine.skip(-1000); - - if (engine.getPosition() != 60) - { - fail("skip position incorrect - " + 60 + " got " + engine.getPosition()); - } - - engine.processBytes(plain, 60, fragment.length, fragment, 0); - - if (!areEqual(cipher, 60, fragment, 0)) - { - fail("skip back 1000 failed"); - } - - long pos = engine.seekTo(1010); - if (pos != 1010) - { - fail("position wrong"); - } - - engine.processBytes(plain, 1010, fragment.length, fragment, 0); - - if (!areEqual(cipher, 1010, fragment, 0)) - { - fail("seek to 1010 failed"); - } - - engine.reset(); - - for (int i = 0; i != 5000; i++) - { - engine.skip(i); - - if (engine.getPosition() != i) - { - fail("skip forward at wrong position"); - } - - engine.processBytes(plain, i, fragment.length, fragment, 0); - - if (!areEqual(cipher, i, fragment, 0)) - { - fail("skip forward i failed: " + i); - } - - if (engine.getPosition() != i + fragment.length) - { - fail("cipher at wrong position: " + engine.getPosition() + " [" + i + "]"); - } - - engine.skip(-fragment.length); - - if (engine.getPosition() != i) - { - fail("skip back at wrong position"); - } - - engine.processBytes(plain, i, fragment.length, fragment, 0); - - if (!areEqual(cipher, i, fragment, 0)) - { - fail("skip back i failed: " + i); - } - - engine.reset(); - } - } - - public static void main( - String[] args) - { - runTest(new Salsa20Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SerpentTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SerpentTest.java deleted file mode 100644 index e1cd92f50..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SerpentTest.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.engines.SerpentEngine; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.EAXBlockCipher; -import com.fr.third.org.bouncycastle.crypto.paddings.PKCS7Padding; -import com.fr.third.org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.AEADParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test vectors based on the NESSIE submission - */ -public class SerpentTest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new SerpentEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000000000000000", "3620b17ae6a993d09618b8768266bae9"), - new BlockCipherVectorTest(1, new SerpentEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "264E5481EFF42A4606ABDA06C0BFDA3D"), - new BlockCipherVectorTest(2, new SerpentEngine(), - new KeyParameter(Hex.decode("D9D9D9D9D9D9D9D9D9D9D9D9D9D9D9D9")), - "D9D9D9D9D9D9D9D9D9D9D9D9D9D9D9D9", "20EA07F19C8E93FDA30F6B822AD5D486"), - new BlockCipherVectorTest(3, new SerpentEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000008000")), - "00000000000000000000000000000000", "40520018C4AC2BBA285AEEB9BCB58755"), - new BlockCipherVectorTest(4, new SerpentEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "00000000000000000000000000000001", "AD86DE83231C3203A86AE33B721EAA9F"), - new BlockCipherVectorTest(5, new SerpentEngine(), - new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F")), - "3DA46FFA6F4D6F30CD258333E5A61369", "00112233445566778899AABBCCDDEEFF"), - new BlockCipherVectorTest(6, new SerpentEngine(), - new KeyParameter(Hex.decode("2BD6459F82C5B300952C49104881FF482BD6459F82C5B300952C49104881FF48")), - "677C8DFAA08071743FD2B415D1B28AF2", "EA024714AD5C4D84EA024714AD5C4D84"), - new BlockCipherVectorTest(7, new SerpentEngine(), - new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F1011121314151617")), - "4528CACCB954D450655E8CFD71CBFAC7", "00112233445566778899AABBCCDDEEFF"), - new BlockCipherVectorTest(8, new SerpentEngine(), - new KeyParameter(Hex.decode("2BD6459F82C5B300952C49104881FF482BD6459F82C5B300")), - "E0208BE278E21420C4B1B9747788A954", "EA024714AD5C4D84EA024714AD5C4D84"), - new BlockCipherVectorTest(9, new SerpentEngine(), - new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F")), - "33B3DC87EDDD9B0F6A1F407D14919365", "00112233445566778899AABBCCDDEEFF"), - new BlockCipherVectorTest(10, new SerpentEngine(), - new KeyParameter(Hex.decode("2BD6459F82C5B300952C49104881FF48")), - "BEB6C069393822D3BE73FF30525EC43E", "EA024714AD5C4D84EA024714AD5C4D84"), - new BlockCipherMonteCarloTest(20, 100, new SerpentEngine(), - new KeyParameter(Hex.decode("F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3")), - "F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3", "8FD0E58DB7A54B929FCA6A12F96F20AF"), - new BlockCipherMonteCarloTest(21, 100, new SerpentEngine(), - new KeyParameter(Hex.decode("0004000000000000000000000000000000000000000000000000000000000000")), - "00000000000000000000000000000000", "E7B681E8871FD05FEAE5FB64DA891EA2"), - new BlockCipherMonteCarloTest(22, 100, new SerpentEngine(), - new KeyParameter(Hex.decode("0000000020000000000000000000000000000000000000000000000000000000")), - "00000000000000000000000000000000", "C5545D516EEC73BFA3622A8194F95620"), - new BlockCipherMonteCarloTest(23, 100, new SerpentEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000002000000")), - "00000000000000000000000000000000", "11FF5C9BE006F82C98BD4FAC1A19920E"), - new BlockCipherMonteCarloTest(24, 100, new SerpentEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "00000000000000000000000000010000", "47CA1CA404B6481CAD4C21C8A0415A0E"), - new BlockCipherMonteCarloTest(25, 100, new SerpentEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "00000000000000008000000000000000", "A0A2D5B07E27D539CA5BEE9DE1EAB3E6") - }; - - SerpentTest() - { - super(tests, new SerpentEngine(), new KeyParameter(new byte[32])); - } - - public void performTest() - throws Exception - { - super.performTest(); - - doCbc(Hex.decode("BE4295539F6BD1752FD0A80229EF8847"), Hex.decode("00963F59224794D5AD4252094358FBC3"), Strings.toByteArray("CBC Mode Test"), Hex.decode("CF2CF2547E02F6D34D97246E8042ED89")); - doEax(Hex.decode("7494A57648FB420043BFBFC5639EB82D"), Hex.decode("6DF94638B83E01458F3E30C9A1D6AF1C"), Strings.toByteArray("EAX Mode Test"), new byte[0], 128, Hex.decode("96C521F32DC5E9BBC369DDE4914CB13B710EEBBAB7D706D3ABE06A99DC")); - } - - private void doEax(byte[] key, byte[] iv, byte[] pt, byte[] aad, int tagLength, byte[] expected) - throws InvalidCipherTextException - { - EAXBlockCipher c = new EAXBlockCipher(new SerpentEngine()); - - c.init(true, new AEADParameters(new KeyParameter(key), tagLength, iv, aad)); - - byte[] out = new byte[expected.length]; - - int len = c.processBytes(pt, 0, pt.length, out, 0); - - c.doFinal(out, len); - - if (!Arrays.areEqual(expected, out)) - { - fail("EAX test failed"); - } - } - - private void doCbc(byte[] key, byte[] iv, byte[] pt, byte[] expected) - throws Exception - { - PaddedBufferedBlockCipher c = new PaddedBufferedBlockCipher(new CBCBlockCipher(new SerpentEngine()), new PKCS7Padding()); - - byte[] ct = new byte[expected.length]; - - c.init(true, new ParametersWithIV(new KeyParameter(key), iv)); - - int l = c.processBytes(pt, 0, pt.length, ct, 0); - - c.doFinal(ct, l); - - if (!Arrays.areEqual(expected, ct)) - { - fail("CBC test failed"); - } - } - - public String getName() - { - return "Serpent"; - } - - public static void main( - String[] args) - { - runTest(new SerpentTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Shacal2Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Shacal2Test.java deleted file mode 100644 index 45f4a5bc4..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Shacal2Test.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.engines.Shacal2Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Shacal2 tester - vectors from https://www.cosic.esat.kuleuven.be/nessie/testvectors/ - */ -public class Shacal2Test - extends CipherTest -{ - static SimpleTest[] tests = - { - // set 8.0 - new BlockCipherVectorTest(0, new Shacal2Engine(), - new KeyParameter(Hex.decode("000102030405060708090A0B0C0D0E0F" + - "101112131415161718191A1B1C1D1E1F" + - "202122232425262728292A2B2C2D2E2F" + - "303132333435363738393A3B3C3D3E3F")), - "98BCC10405AB0BFC686BECECAAD01AC1" + - "9B452511BCEB9CB094F905C51CA45430", - "00112233445566778899AABBCCDDEEFF" + - "102132435465768798A9BACBDCEDFE0F"), - // set 8.1 - new BlockCipherVectorTest(1, new Shacal2Engine(), - new KeyParameter(Hex.decode("2BD6459F82C5B300952C49104881FF48" + - "2BD6459F82C5B300952C49104881FF48" + - "2BD6459F82C5B300952C49104881FF48" + - "2BD6459F82C5B300952C49104881FF48")), - "481F122A75F2C4C3395140B5A951EBBA" + - "06D96BDFD9D8FF4FB59CBD1287808D5A", - "EA024714AD5C4D84EA024714AD5C4D84" + - "EA024714AD5C4D84EA024714AD5C4D84"), - // 7.255 - new BlockCipherVectorTest(2, new Shacal2Engine(), - new KeyParameter(Hex.decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")), - "94FEDFF2A0CFE3C983D340C88D73F8CF" + - "4B79FC581797EC10B27D4DA1B51E1BC7", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), - // 7.100 - new BlockCipherVectorTest(3, new Shacal2Engine(), - new KeyParameter(Hex.decode("64646464646464646464646464646464" + - "64646464646464646464646464646464" + - "64646464646464646464646464646464" + - "64646464646464646464646464646464")), - "6643CB84B3B3F126F5E50959EF4CE73D" + - "B8500918ABE1056368DB06CA8C1C0D45", - "64646464646464646464646464646464" + - "64646464646464646464646464646464"), - // 7.50 - new BlockCipherVectorTest(4, new Shacal2Engine(), - new KeyParameter(Hex.decode("32323232323232323232323232323232" + - "32323232323232323232323232323232" + - "32323232323232323232323232323232" + - "32323232323232323232323232323232")), - "92E937285AB11FE3561542C43C918966" + - "971DE722E9B9D38BD69EAC77899DCF81", - "32323232323232323232323232323232" + - "32323232323232323232323232323232"), - // 7.0 - new BlockCipherVectorTest(5, new Shacal2Engine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000" + - "00000000000000000000000000000000" + - "00000000000000000000000000000000" + - "00000000000000000000000000000000")), - "F8C9259FA4F5D787B570AFA9219166A6" + - "3636FC5C30AC289155D0CC4FFCB4B03D", - "00000000000000000000000000000000" + - "00000000000000000000000000000000"), - // 6.255 - new BlockCipherVectorTest(6, new Shacal2Engine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000" + - "00000000000000000000000000000000" + - "00000000000000000000000000000000" + - "00000000000000000000000000000000")), - "F4E976DF0172CD961D4C8D466A12F676" + - "5B9089046E747CD2A41BF43C18A8328E", - "00000000000000000000000000000000" + - "00000000000000000000000000000001"), - // 6.100 - new BlockCipherVectorTest(7, new Shacal2Engine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000" + - "00000000000000000000000000000000" + - "00000000000000000000000000000000" + - "00000000000000000000000000000000")), - "3B929F0597E21D0076EC399D21B67713" + - "B40E3AD559704219A26A3380212D5AD6", - "00000000000000000000000008000000" + - "00000000000000000000000000000000"), - - // 6.0 - new BlockCipherVectorTest(8, new Shacal2Engine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000" + - "00000000000000000000000000000000" + - "00000000000000000000000000000000" + - "00000000000000000000000000000000")), - "43A0DAD8307F19FBBCF166FE20BAC075" + - "C56FF14042550E472094B042BE5963EE", - "80000000000000000000000000000000" + - "00000000000000000000000000000000"), - }; - - Shacal2Test() - { - super(tests, new Shacal2Engine(), new KeyParameter(new byte[16])); - } - - public void performTest() - throws Exception - { - super.performTest(); - - // 1.0 - iteratedTest(0, - Hex.decode("80000000000000000000000000000000" + - "00000000000000000000000000000000" + - "00000000000000000000000000000000" + - "00000000000000000000000000000000"), - Hex.decode("00000000000000000000000000000000" + - "00000000000000000000000000000000"), - Hex.decode("361AB6322FA9E7A7BB23818D839E01BD" + - "DAFDF47305426EDD297AEDB9F6202BAE"), - Hex.decode("226A582DE04383D0F3E7DE655DD848AC" + - "3E14CCFB4E76F7B7069879F67C4D5420"), - Hex.decode("B05D5A18C0712082CFF5BA9DBBCD7269" + - "114FC3DF83B42DAC306D95BBC473D839")); - - // 1.100 - iteratedTest(1, - Hex.decode("00000000000000000000000008000000" + - "00000000000000000000000000000000" + - "00000000000000000000000000000000" + - "00000000000000000000000000000000"), - Hex.decode("00000000000000000000000000000000" + - "00000000000000000000000000000000"), - Hex.decode("F703282E54592A5617E10618027BB67F" + - "639E43A90767150D8B7F5E83054B3CBD"), - Hex.decode("3B442692B579485B8BA2F92CE3B90DE7" + - "D2EA03D8B3C8E7BE7BF6415F798EED90"), - Hex.decode("331B9B65F06230380BBEECFBFBA94BCF" + - "92AF6341F815D7651F996144A5377263")); - } - - private void iteratedTest(int index, byte[] key, byte[] plain, byte[] cipher, byte[] cipher100, byte[] cipher1000) - { - BlockCipher engine = new Shacal2Engine(); - - engine.init(true, new KeyParameter(key)); - - byte[] buf = new byte[plain.length]; - - System.arraycopy(plain, 0, buf, 0, plain.length); - - engine.processBlock(buf, 0, buf, 0); - - if (!Arrays.areEqual(cipher, buf)) - { - fail(index + " single count failed"); - } - - for (int i = 1; i != 100; i++) - { - engine.processBlock(buf, 0, buf, 0); - } - - if (!Arrays.areEqual(cipher100, buf)) - { - fail(index + " 100 count failed"); - } - - for (int i = 100; i != 1000; i++) - { - engine.processBlock(buf, 0, buf, 0); - } - - if (!Arrays.areEqual(cipher1000, buf)) - { - fail(index + " 1000 count failed"); - } - } - - public String getName() - { - return "Shacal2"; - } - - public static void main( - String[] args) - { - runTest(new Shacal2Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ShortenedDigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ShortenedDigestTest.java deleted file mode 100644 index 0cca27603..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ShortenedDigestTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Created on 6/05/2006 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.ExtendedDigest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512Digest; -import com.fr.third.org.bouncycastle.crypto.digests.ShortenedDigest; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class ShortenedDigestTest - extends SimpleTest -{ - public void performTest() - { - ExtendedDigest d = new SHA1Digest(); - ShortenedDigest sd = new ShortenedDigest(new SHA1Digest(), 10); - - if (sd.getDigestSize() != 10) - { - fail("size check wrong for SHA-1"); - } - - if (sd.getByteLength() != d.getByteLength()) - { - fail("byte length check wrong for SHA-1"); - } - - // - // check output fits - // - sd.doFinal(new byte[10], 0); - - d = new SHA512Digest(); - sd = new ShortenedDigest(new SHA512Digest(), 20); - - if (sd.getDigestSize() != 20) - { - fail("size check wrong for SHA-512"); - } - - if (sd.getByteLength() != d.getByteLength()) - { - fail("byte length check wrong for SHA-512"); - } - - // - // check output fits - // - sd.doFinal(new byte[20], 0); - - try - { - new ShortenedDigest(null, 20); - - fail("null parameter not caught"); - } - catch (IllegalArgumentException e) - { - // expected - } - - try - { - new ShortenedDigest(new SHA1Digest(), 50); - - fail("short digest not caught"); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - public String getName() - { - return "ShortenedDigest"; - } - - public static void main( - String[] args) - { - runTest(new ShortenedDigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SipHashTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SipHashTest.java deleted file mode 100644 index a7e0524da..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SipHashTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.macs.SipHash; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Pack; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/* - * SipHash test values from "SipHash: a fast short-input PRF", by Jean-Philippe - * Aumasson and Daniel J. Bernstein (https://131002.net/siphash/siphash.pdf), Appendix A. - */ -public class SipHashTest - extends SimpleTest -{ - private static final int UPDATE_BYTES = 0; - private static final int UPDATE_FULL = 1; - private static final int UPDATE_MIX = 2; - - public String getName() - { - return "SipHash"; - } - - public void performTest() - throws Exception - { - byte[] key = Hex.decode("000102030405060708090a0b0c0d0e0f"); - byte[] input = Hex.decode("000102030405060708090a0b0c0d0e"); - - runMAC(key, input, UPDATE_BYTES); - runMAC(key, input, UPDATE_FULL); - runMAC(key, input, UPDATE_MIX); - - SecureRandom random = new SecureRandom(); - for (int i = 0; i < 100; ++i) - { - randomTest(random); - } - } - - private void runMAC(byte[] key, byte[] input, int updateType) - throws Exception - { - long expected = 0xa129ca6149be45e5L; - - SipHash mac = new SipHash(); - mac.init(new KeyParameter(key)); - - updateMAC(mac, input, updateType); - - long result = mac.doFinal(); - if (expected != result) - { - fail("Result does not match expected value for doFinal()"); - } - - byte[] expectedBytes = new byte[8]; - Pack.longToLittleEndian(expected, expectedBytes, 0); - - updateMAC(mac, input, updateType); - - byte[] output = new byte[mac.getMacSize()]; - int len = mac.doFinal(output, 0); - if (len != output.length) - { - fail("Result length does not equal getMacSize() for doFinal(byte[],int)"); - } - if (!areEqual(expectedBytes, output)) - { - fail("Result does not match expected value for doFinal(byte[],int)"); - } - } - - private void randomTest(SecureRandom random) - { - byte[] key = new byte[16]; - random.nextBytes(key); - - int length = 1 + RNGUtils.nextInt(random, 1024); - byte[] input = new byte[length]; - random.nextBytes(input); - - SipHash mac = new SipHash(); - mac.init(new KeyParameter(key)); - - updateMAC(mac, input, UPDATE_BYTES); - long result1 = mac.doFinal(); - - updateMAC(mac, input, UPDATE_FULL); - long result2 = mac.doFinal(); - - updateMAC(mac, input, UPDATE_MIX); - long result3 = mac.doFinal(); - - if (result1 != result2 || result1 != result3) - { - fail("Inconsistent results in random test"); - } - } - - private void updateMAC(SipHash mac, byte[] input, int updateType) - { - switch (updateType) - { - case UPDATE_BYTES: - { - for (int i = 0; i < input.length; ++i) - { - mac.update(input[i]); - } - break; - } - case UPDATE_FULL: - { - mac.update(input, 0, input.length); - break; - } - case UPDATE_MIX: - { - int step = Math.max(1, input.length / 3); - int pos = 0; - while (pos < input.length) - { - mac.update(input[pos++]); - int len = Math.min(input.length - pos, step); - mac.update(input, pos, len); - pos += len; - } - break; - } - default: - throw new IllegalStateException(); - } - } - - public static void main(String[] args) - { - runTest(new SipHashTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SkeinDigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SkeinDigestTest.java deleted file mode 100644 index 3836ef7b6..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SkeinDigestTest.java +++ /dev/null @@ -1,294 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SkeinDigest; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Memoable; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class SkeinDigestTest - extends SimpleTest -{ - private static class Case - { - private byte[] message; - private byte[] digest; - private int blockSize; - private int outputSize; - - public Case(int blockSize, int outputSize, String message, String digest) - { - this.blockSize = blockSize; - this.outputSize = outputSize; - this.message = Hex.decode(message); - this.digest = Hex.decode(digest); - } - - public int getOutputSize() - { - return outputSize; - } - - public int getBlockSize() - { - return blockSize; - } - - public byte[] getMessage() - { - return message; - } - - public byte[] getDigest() - { - return digest; - } - - } - - // Test cases from skein_golden_kat.txt and skein_golden_kat_short.txt in Skein 1.3 NIST CD - private static final Case[] TEST_CASES = { - new Case(256, 256, "", "c8877087da56e072870daa843f176e9453115929094c3a40c463a196c29bf7ba"), - new Case(256, 256, "fb", "088eb23cc2bccfb8171aa64e966d4af937325167dfcd170700ffd21f8a4cbdac"), - new Case(256, 256, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8", - "5c3002ff57a627089ea2f97a5000d5678416389019e80e45a3bbcab118315d26"), - new Case(256, 256, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a129233", - "640c894a4bba6574c83e920ddf7dd2982fc634881bbbcb9d774eae0a285e89ce"), - new Case(256, 160, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "0cd491b7715704c3a15a45a1ca8d93f8f646d3a1"), - new Case(256, 224, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "afd1e2d0f5b6cd4e1f8b3935fa2497d27ee97e72060adac099543487"), - new Case(256, 256, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "4de6fe2bfdaa3717a4261030ef0e044ced9225d066354610842a24a3eafd1dcf"), - new Case(256, 384, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "954620fb31e8b782a2794c6542827026fe069d715df04261629fcbe81d7d529b" - + "95ba021fa4239fb00afaa75f5fd8e78b"), - new Case(256, 512, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "51347e27c7eabba514959f899a6715ef6ad5cf01c23170590e6a8af399470bf9" - + "0ea7409960a708c1dbaa90e86389df254abc763639bb8cdf7fb663b29d9557c3"), - new Case(256, 1024, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "6c9b6facbaf116b538aa655e0be0168084aa9f1be445f7e06714585e5999a6c9" - + "84fffa9d41a316028692d4aad18f573fbf27cf78e84de26da1928382b023987d" - + "cfe002b6201ea33713c54a8a5d9eb346f0365e04330d2faaf7bc8aba92a5d7fb" - + "6345c6fb26750bce65ab2045c233627679ac6e9acb33602e26fe3526063ecc8b"), - - new Case(512, 512, "", "bc5b4c50925519c290cc634277ae3d6257212395cba733bbad37a4af0fa06af4" - + "1fca7903d06564fea7a2d3730dbdb80c1f85562dfcc070334ea4d1d9e72cba7a"), - new Case(512, 512, "fb", "c49e03d50b4b2cc46bd3b7ef7014c8a45b016399fd1714467b7596c86de98240" - + "e35bf7f9772b7d65465cd4cffab14e6bc154c54fc67b8bc340abf08eff572b9e"), - new Case(512, 512, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8", - "abefb179d52f68f86941acbbe014cc67ec66ad78b7ba9508eb1400ee2cbdb06f" - + "9fe7c2a260a0272d0d80e8ef5e8737c0c6a5f1c02ceb00fb2746f664b85fcef5"), - new Case(512, 512, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a129233", - "5c5b7956f9d973c0989aa40a71aa9c48a65af2757590e9a758343c7e23ea2df4" - + "057ce0b49f9514987feff97f648e1dd065926e2c371a0211ca977c213f14149f"), - new Case(512, 160, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "ef03079d61b57c6047e15fa2b35b46fa24279539"), - new Case(512, 224, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "d9e3219b214e15246a2038f76a573e018ef69b385b3bd0576b558231"), - new Case(512, 256, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "809dd3f763a11af90912bbb92bc0d94361cbadab10142992000c88b4ceb88648"), - new Case(512, 384, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "825f5cbd5da8807a7b4d3e7bd9cd089ca3a256bcc064cd73a9355bf3ae67f2bf" - + "93ac7074b3b19907a0665ba3a878b262"), - new Case(512, 512, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "1a0d5abf4432e7c612d658f8dcfa35b0d1ab68b8d6bd4dd115c23cc57b5c5bcd" - + "de9bff0ece4208596e499f211bc07594d0cb6f3c12b0e110174b2a9b4b2cb6a9"), - - new Case(1024, 1024, "", "0fff9563bb3279289227ac77d319b6fff8d7e9f09da1247b72a0a265cd6d2a62" - + "645ad547ed8193db48cff847c06494a03f55666d3b47eb4c20456c9373c86297" - + "d630d5578ebd34cb40991578f9f52b18003efa35d3da6553ff35db91b81ab890" - + "bec1b189b7f52cb2a783ebb7d823d725b0b4a71f6824e88f68f982eefc6d19c6"), - new Case(1024, 1024, "fb", "6426bdc57b2771a6ef1b0dd39f8096a9a07554565743ac3de851d28258fcff22" - + "9993e11c4e6bebc8b6ecb0ad1b140276081aa390ec3875960336119427827473" - + "4770671b79f076771e2cfdaaf5adc9b10cbae43d8e6cd2b1c1f5d6c82dc96618" - + "00ddc476f25865b8748253173187d81da971c027d91d32fb390301c2110d2db2"), - new Case(1024, 1024, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8", - "140e93726ab0b0467c0b8a834ad8cda4d1769d273661902b70db0dcb5ee692ac" - + "b3f852d03b11f857850f2428432811309c1dcbe5724f00267ea3667e89fadb4e" - + "4911da6b0ba8a7eddf87c1c67152ef0f07b7fead3557318478bdef5ad1e5926d" - + "7071fdd4bfa5076d4b3253f8de479ebdf5357676f1641b2f097e9b785e9e528e"), - new Case(1024, 1024, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a129233", - "31105e1ef042c30b95b16e0f6e6a1a19172bb7d54a0597dd0c711194888efe1d" - + "bce82d47416df9577ca387219f06e45cd10964ff36f6711edbbea0e9595b0f66" - + "f72b755d70a46857e0aec98561a743d49370d8e572e212811273125f66cc30bf" - + "117d3221894c48012bf6e2219de91e064b01523517420a1e00f71c4cc04bab62"), - new Case(1024, 160, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "2e6a4cbf2ef05ea9c24b93e8d1de732ddf2739eb"), - new Case(1024, 224, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "1d6de19f37f7a3c265440eecb4b9fbd3300bb5ac60895cfc0d4d3c72"), - new Case(1024, 256, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "986a4d472b123e8148731a8eac9db23325f0058c4ccbc44a5bb6fe3a8db672d7"), - new Case(1024, 384, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "9c3d0648c11f31c18395d5e6c8ebd73f43d189843fc45235e2c35e345e12d62b" - + "c21a41f65896ddc6a04969654c2e2ce9"), - new Case(1024, 512, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "5d0416f49c2d08dfd40a1446169dc6a1d516e23b8b853be4933513051de8d5c2" - + "6baccffb08d3b16516ba3c6ccf3e9a6c78fff6ef955f2dbc56e1459a7cdba9a5"), - new Case(1024, 1024, "fbd17c26b61a82e12e125f0d459b96c91ab4837dff22b39b78439430cdfc5dc8" - + "78bb393a1a5f79bef30995a85a12923339ba8ab7d8fc6dc5fec6f4ed22c122bb" - + "e7eb61981892966de5cef576f71fc7a80d14dab2d0c03940b95b9fb3a727c66a" - + "6e1ff0dc311b9aa21a3054484802154c1826c2a27a0914152aeb76f1168d4410", - "96ca81f586c825d0360aef5acaec49ad55289e1797072eee198b64f349ce65b6" - + "e6ed804fe38f05135fe769cc56240ddda5098f620865ce4a4278c77fa2ec6bc3" - + "1c0f354ca78c7ca81665bfcc5dc54258c3b8310ed421d9157f36c093814d9b25" - + "103d83e0ddd89c52d0050e13a64c6140e6388431961685734b1f138fe2243086"), - - }; - - public String getName() - { - return "SkeinDigest"; - } - - public void performTest() - throws Exception - { - runTest(TEST_CASES[7]); - for (int i = 0; i < TEST_CASES.length; i++) - { - Case test = TEST_CASES[i]; - runTest(test); - } - } - - private void runTest(Case dc) - { - SkeinDigest digest = new SkeinDigest(dc.getBlockSize(), dc.getOutputSize()); - - byte[] message = dc.getMessage(); - digest.update(message, 0, message.length); - - byte[] output = new byte[digest.getDigestSize()]; - digest.doFinal(output, 0); - - if (!Arrays.areEqual(output, dc.getDigest())) - { - fail(digest.getAlgorithmName() + " message mismatch.\n Message " + new String(Hex.encode(dc.getMessage())), - new String(Hex.encode(dc.getDigest())), new String(Hex.encode(output))); - } - - // Clone test - digest.update(message, 0, message.length / 2); - - // clone the Digest - Digest d = new SkeinDigest(digest); - - digest.update(message, message.length / 2, message.length - message.length / 2); - digest.doFinal(output, 0); - - if (!areEqual(dc.getDigest(), output)) - { - fail("failing clone vector test", new String(Hex.encode(dc.getDigest())), new String(Hex.encode(output))); - } - - d.update(message, message.length / 2, message.length - message.length / 2); - d.doFinal(output, 0); - - if (!areEqual(dc.getDigest(), output)) - { - fail("failing second clone vector test", new String(Hex.encode(dc.getDigest())), new String(Hex.encode(output))); - } - - // - // memo test - // - Memoable m = (Memoable)digest; - - digest.update(message, 0, message.length / 2); - - // copy the Digest - Memoable copy1 = m.copy(); - Memoable copy2 = copy1.copy(); - - digest.update(message, message.length / 2, message.length - message.length / 2); - digest.doFinal(output, 0); - - if (!areEqual(dc.getDigest(), output)) - { - fail("failing memo vector test", new String(Hex.encode(dc.getDigest())), new String(Hex.encode(output))); - } - - m.reset(copy1); - - digest.update(message, message.length / 2, message.length - message.length / 2); - digest.doFinal(output, 0); - - if (!areEqual(dc.getDigest(), output)) - { - fail("failing memo reset vector test", new String(Hex.encode(dc.getDigest())), new String(Hex.encode(output))); - } - - Digest md = (Digest)copy2; - - md.update(message, message.length / 2, message.length - message.length / 2); - md.doFinal(output, 0); - - if (!areEqual(dc.getDigest(), output)) - { - fail("failing memo copy vector test", new String(Hex.encode(dc.getDigest())), new String(Hex.encode(output))); - } - } - - public static void main(String[] args) - throws IOException - { - // generateTests(); - runTest(new SkeinDigestTest()); - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SkeinMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SkeinMacTest.java deleted file mode 100644 index 7d7443914..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SkeinMacTest.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.macs.SkeinMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class SkeinMacTest - extends SimpleTest -{ - private static class Case - { - private byte[] message; - private byte[] digest; - private byte[] key; - private int blockSize; - private int outputSize; - - public Case(int blockSize, int outputSize, String message, String key, String digest) - { - this.blockSize = blockSize; - this.outputSize = outputSize; - this.message = Hex.decode(message); - this.key = Hex.decode(key); - this.digest = Hex.decode(digest); - } - - public int getOutputSize() - { - return outputSize; - } - - public int getBlockSize() - { - return blockSize; - } - - public byte[] getMessage() - { - return message; - } - - public byte[] getKey() - { - return key; - } - - public byte[] getDigest() - { - return digest; - } - - public String toString() - { - return "new Case(" + blockSize + ", " + outputSize + ", \"" + new String(Hex.encode(message)) + "\", \"" - + new String(Hex.encode(key)) + "\", \"" + new String(Hex.encode(digest)) + "\""; - } - - } - - // Test cases from skein_golden_kat.txt in Skein 1.3 NIST CD - // Excludes empty '(none)' key 'random+MAC' tests, which are in effect digest - private static final Case[] TEST_CASES = { - new Case(256, 256, "", "cb41f1706cde09651203c2d0efbaddf8", "886e4efefc15f06aa298963971d7a25398fffe5681c84db39bd00851f64ae29d"), - new Case(256, 256, "d3", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c193", "979422a94e3afaa46664124d4e5e8b9422b1d8baf11c6ae6725992ac72a112ca"), - new Case(256, 256, "d3090c72", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e", "1d658372cbea2f9928493cc47599d6f4ad8ce33536bedfa20b739f07516519d5"), - new Case(256, 256, "d3090c72167517f7", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e92", "41ef6b0f0fad81c040284f3b1a91e9c44e4c26a6d7207f3aac4362856ef12aca"), - new Case(256, 256, "d3090c72167517f7c7ad82a70c2fd3f6", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c193", "ca8208119b9e4e4057631ab31015cfd256f6763a0a34381633d97f640899b84f"), - new Case(256, 256, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e", "9e9980fcc16ee082cf164a5147d0e0692aeffe3dcb8d620e2bb542091162e2e9"), - new Case(256, 256, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc235", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c193", "c353a316558ec34f8245dd2f9c2c4961fbc7decc3b69053c103e4b8aaaf20394"), - new Case(256, 256, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdf", "cb41f1706cde09651203c2d0efbaddf8", "b1b8c18188e69a6ecae0b6018e6b638c6a91e6de6881e32a60858468c17b520d"), - new Case(256, 256, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e92", "1dfd2515a412e78852cd81a7f2167711b4ca19b2891c2ea36ba94f8451944793"), - new Case(256, 224, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf8", "a097340709b443ed2c0a921f5dcefef3ead65c4f0bcd5f13da54d7ed"), - new Case(256, 256, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e", "ac1b4fab6561c92d0c487e082daec53e0db4f505e08bf51cae4fd5375e37fc04"), - new Case(256, 384, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e92", "96e6cebb23573d0a70ce36a67aa05d2403148093f25c695e1254887cc97f9771d2518413af4286bf2a06b61a53f7fcec"), - new Case(256, 512, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c193", "0e95e597e71d6350f20b99c4179f54f43a4722705c06ba765a82cb0a314fe2fe87ef8090063b757e53182706ed18737dadc0da1e1c66518f08334052702c5ed7"), - new Case(256, 264, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf8", "064abd4896f460b1953f5a357e7f7c5256e29cdb62b8740d0b52295cfa2ef4c7a2"), - new Case(256, 520, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e", "edf220e43e048603bd16197d59b673b9974de5b8bcf7cb1558a4799f6fd3743eb5fb400cd6129afc0c60e7b741b7e5806f0e0b93eb8429fbc7efa222175a9c80fd"), - new Case(256, 1032, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e92", "f3f59fb07399c7b73aae02a8590883cb2fdfde75c55654e71846522301bde48d267169adcc559e038e8c2f28faa552b550d51874055384adea93c036c71a1f0af0c7bcc3bc923738d5307b9da7cb423d4e615c629c4aba71f70d4c9d1fa008176825e51bfa0203445a4083947ec19f6a0fbd082b5b970f2396fb67420639410447"), - new Case(256, 2056, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c193", "80eb80d9b8836b32fa576fc84ba08edfbdfd6979123d61914e610a70a372b37f560a10909484f9f4a377c93e29ba681dfe522c41dc83b5ee0567e5370007c7bbe4df0b2b4a25e088f80d72fc30734cdcd76d817b42fbd44dca881019afb25306f19d4e91848778af306517d2072cef72caa327e877c5b6554f83cec3d00877131b47c4d3b557f5a13541c4d5080ee3ce7a658993d083efd0db3496a8752060c3c8552f44b290cabdcc867f691ad605836c08dbd59c9528d885b600b85fdfc8a9d0e636ac3ad8b4295bcb0169e78dc358e77eacc8c4b61bddfa9e5f32d2268a006cfe05c57150fe8e68cabd21cf6cf6035aa1fe4db36c922b765aad0b64e82a2c37"), - new Case(256, 256, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed696e6c9db1e6abea026288954a9c2d5758d7c5db7c9e48aa3d21cae3d977a7c3926066aa393dbd538dd0c30da8916c8757f24c18488014668a2627163a37b261833dc2f8c3c56b1b2e0be21fd3fbdb507b2950b77a6cc02efb393e57419383a920767bca2c972107aa61384542d47cbfb82cfe5c415389d1b0a2d74e2c5da851", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e", "8f88de68f03cd2f396ccdd49c3a0f4ff15bcda7eb357da9753f6116b124de91d"), - new Case(512, 512, "", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c", "9bd43d2a2fcfa92becb9f69faab3936978f1b865b7e44338fc9c8f16aba949ba340291082834a1fc5aa81649e13d50cd98641a1d0883062bfe2c16d1faa7e3aa"), - new Case(512, 512, "d3", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1", "f0c0a10f031c8fc69cfabcd54154c318b5d6cd95d06b12cf20264402492211ee010d5cecc2dc37fd772afac0596b2bf71e6020ef2dee7c860628b6e643ed9ff6"), - new Case(512, 512, "d3090c72167517f7", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e", "0c1f1921253dd8e5c2d4c5f4099f851042d91147892705829161f5fc64d89785226eb6e187068493ee4c78a4b7c0f55a8cbbb1a5982c2daf638fc6a74b16b0d7"), - new Case(512, 512, "d3090c72167517f7c7ad82a70c2fd3f6", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1", "478d7b6c0cc6e35d9ebbdedf39128e5a36585db6222891692d1747d401de34ce3db6fcbab6c968b7f2620f4a844a2903b547775579993736d2493a75ff6752a1"), - new Case(512, 512, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e59", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c193", "13c170bac1de35e5fb843f65fabecf214a54a6e0458a4ff6ea5df91915468f4efcd371effa8965a9e82c5388d84730490dcf3976af157b8baf550655a5a6ab78"), - new Case(512, 512, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc235", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1", "a947812529a72fd3b8967ec391b298bee891babc8487a1ec4ea3d88f6b2b5be09ac6a780f30f8e8c3bbb4f18bc302a28f3e87d170ba0f858a8fefe3487478cca"), - new Case(512, 512, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdf", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c", "7690ba61f10e0bba312980b0212e6a9a51b0e9aadfde7ca535754a706e042335b29172aae29d8bad18efaf92d43e6406f3098e253f41f2931eda5911dc740352"), - new Case(512, 512, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e", "d10e3ba81855ac087fbf5a3bc1f99b27d05f98ba22441138026225d34a418b93fd9e8dfaf5120757451adabe050d0eb59d271b0fe1bbf04badbcf9ba25a8791b"), - new Case(512, 160, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c193", "5670b226156570dff3efe16661ab86eb24982cdf"), - new Case(512, 224, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c", "c41b9ff9753e6c0f8ed88866e320535e927fe4da552c289841a920db"), - new Case(512, 384, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e", "dfbf5c1319a1d9d70efb2f1600fbcf694f935907f31d24a16d6cd2fb2d7855a769681766c0a29da778eed346cd1d740f"), - new Case(512, 512, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1", "04d8cddb0ad931d54d195899a094684344e902286037272890bce98a41813edc37a3cee190a693fcca613ee30049ce7ec2bdff9613f56778a13f8c28a21d167a"), - new Case(512, 1024, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c193", "08fca368b3b14ac406676adf37ac9be2dbb8704e694055a0c6331184d4f0070098f23f0963ee29002495771bf56fb4d3d9ff3506abcd80be927379f7880d5d7703919fbf92184f498ac44f47f015ce676eded9165d47d53733f5a27abbc05f45acd98b97cc15ffdced641defd1a5119ef841b452a1b8f94ee69004466ccdc143"), - new Case(512, 264, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c", "669e770ebe7eacc2b64caaf049923ad297a5b37cfa61c283392d81ccfcb9bbbc09"), - new Case(512, 1032, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e", "acc2e03f07f33e9820a6038421089429adcd6a7a83f733beec048c05bf37531a170a5537fcb565c348a70a83217f8be768ff6f95fd2b3d89cb7d8a3dc849505e3710eb4e65a8e7134bbf580d92fe18c9aa987563669b1f014aa5e092519089355534eaa9f0bdc99f6839f54080ffe74623254c906ecb8896b4346c3178a0bc2898"), - new Case(512, 2056, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1", "9f3e082223c43090a4a3ffbdcd469cbabfe0c1399d1edf45a5dfc18f4db5428928a76e979b8d0d5dffec0e6a59ada448c1ffbc06cc80a2006f002adc0c6dbf458563762228dce4381944e460ebebfe06f1237093634625107469a22a189a47f8b025899265d8890a1b39df64552394377e88ba2ad44a8c8d174f884ac8c3ae24ddb0affca5fceb6aa76e09706881e8371774b9b050a69b96ef5e97e81043f8b7e9479e287ab441bacd62caf768a82c8c3e3107be70eb8799a39856fe29842a04e25de0ef9de1b7e65bd0f1f7306835287fc957388e2035b7d22d3aa9c06a9fefbca16f3f60e1c4def89038d918942152a069aa2e0be8ae7475d859031adec84583"), - new Case(1024, 1024, "", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc81463134", "bcf37b3459c88959d6b6b58b2bfe142cef60c6f4ec56b0702480d7893a2b0595aa354e87102a788b61996b9cbc1eade7dafbf6581135572c09666d844c90f066b800fc4f5fd1737644894ef7d588afc5c38f5d920bdbd3b738aea3a3267d161ed65284d1f57da73b68817e17e381ca169115152b869c66b812bb9a84275303f0"), - new Case(1024, 1024, "d3090c72", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c", "df0596e5808835a3e304aa27923db05f61dac57c0696a1d19abf188e70aa9dbcc659e9510f7c9a37fbc025bd4e5ea293e78ed7838dd0b08864e8ad40ddb3a88031ebefc21572a89960d1916107a7da7ac0c067e34ec46a86a29ca63fa250bd398eb32ec1ed0f8ac8329f26da018b029e41e2e58d1dfc44de81615e6c987ed9c9"), - new Case(1024, 1024, "d3090c72167517f7", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c042eb4187aa1c015a4767032c0bb28f076b66485f51531c12e948f47dbc2cb904a4b75d1e8a6d931dab4a07e0a54d1bb5b55e602141746bd09fb15e8f01a8d74e9e63959cb37336bc1b896ec78da734c15e362db04368fbba280f20a043e0d0941e9f5193e1b360a33c43b266524880125222e648f05f28be34ba3cabfc9c544", "3cfbb79cd88af8ee09c7670bcbab6907a31f80fa31d9d7c9d50826c9568f307a78bd254961398c76b6e338fd9ca5f351059350d30963c3320659b223b991fc46d1307686fe2b4763d9f593c57ad5adbc45caf2ea3dc6090f5a74fa5fa6d9e9838964ea0a2aa216831ab069b00629a1a9b037083403bdb25d3d06a21c430c87dd"), - new Case(1024, 1024, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e59", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1", "0a1b960099fc9d653b0fd1f5b6b972fb366907b772cbce5a59b6171d7935506f70c212bd169d68c5cfd8618343611b7eb2e686ff1dc7c03a57e1a55ed10726848161eea903d53b58459be42d95df989c66c2eea4e51cde272c2d8be67bf3bca2aee633777eb8486781eaa060d0f538abd6c93dbd2d1bf66e6f50bfdcac3725a4"), - new Case(1024, 1024, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c", "3e0cd7938d71c39ffbb08a6ba7995ade3ad140e2c0c45cdbafb099247e08e4c20b61c1f885ced5ed2f816680925034918236e5807f0eecf3f27e9cfca36675eb75873efa1fb41f17541dc2f7c2469eaecb35cc7ca58e489804caf56f09fb97c9f689c64ad49c6888f86c483e901bd3d25798b394ef93faf9154900f92f31f433"), - new Case(1024, 1024, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdf", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc81463134", "7266752f7e9aa04bd7d8a1b16030677de6021301f6a62473c76bae2b98bbf8aad73bd00a4b5035f741caf2317ab80e4e97f5c5bbe8acc0e8b424bcb13c7c6740a985801fba54addde8d4f13f69d2bfc98ae104d46a211145217e51d510ea846cec9581d14fda079f775c8b18d66cb31bf7060996ee8a69eee7f107909ce59a97"), - new Case(1024, 1024, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c042eb4187aa1c015a4767032c0bb28f076b66485f51531c12e948f47dbc2cb904a4b75d1e8a6d931dab4a07e0a54d1bb5b55e602141746bd09fb15e8f01a8d74e9e63959cb37336bc1b896ec78da734c15e362db04368fbba280f20a043e0d0941e9f5193e1b360a33c43b266524880125222e648f05f28be34ba3cabfc9c544", "71f40bf2aa635125ef83c8df0d4e9ea18b73b56be4f45e89b910a7c68d396b65b09d18abc7d1b6de3f53fd5de583e6f22e612dd17b292068af6027daaf8b4cd60acf5bc85044741e9f7a1f423f5827f5e360930a2e71912239af9fc6343604fdcf3f3569854f2bb8d25a81e3b3f5261a02fe8292aaaa50c324101ab2c7a2f349"), - new Case(1024, 160, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1", "17c3c533b27d666da556ae586e641b7a3a0bcc45"), - new Case(1024, 224, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc81463134", "6625df9801581009125ea4e5c94ad6f1a2d692c278822ccb6eb67235"), - new Case(1024, 256, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c", "6c5b671c1766f6eecea6d24b641d4a6bf84bba13a1976f8f80b3f30ee2f93de6"), - new Case(1024, 384, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c042eb4187aa1c015a4767032c0bb28f076b66485f51531c12e948f47dbc2cb904a4b75d1e8a6d931dab4a07e0a54d1bb5b55e602141746bd09fb15e8f01a8d74e9e63959cb37336bc1b896ec78da734c15e362db04368fbba280f20a043e0d0941e9f5193e1b360a33c43b266524880125222e648f05f28be34ba3cabfc9c544", "98af454d7fa3706dfaafbf58c3f9944868b57f68f493987347a69fce19865febba0407a16b4e82065035651f0b1e0327"), - new Case(1024, 1024, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1", "211ac479e9961141da3aac19d320a1dbbbfad55d2dce87e6a345fcd58e36827597378432b482d89bad44dddb13e6ad86e0ee1e0882b4eb0cd6a181e9685e18dd302ebb3aa74502c06254dcadfb2bd45d288f82366b7afc3bc0f6b1a3c2e8f84d37fbedd07a3f8fcff84faf24c53c11da600aaa118e76cfdcb366d0b3f7729dce"), - new Case(1024, 264, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc81463134", "dc1d253b7cadbdaef18503b1809a7f1d4f8c323b7f6f8ca50b76d3864649ce1c7d"), - new Case(1024, 520, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c", "decd79578d12bf6806530c382230a2c7836429c70cac941179e1dd982938bab91fb6f3638df1cc1ef615ecfc4249e5aca8a73c4c1eebef662a836d0be903b00146"), - new Case(1024, 1032, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c042eb4187aa1c015a4767032c0bb28f076b66485f51531c12e948f47dbc2cb904a4b75d1e8a6d931dab4a07e0a54d1bb5b55e602141746bd09fb15e8f01a8d74e9e63959cb37336bc1b896ec78da734c15e362db04368fbba280f20a043e0d0941e9f5193e1b360a33c43b266524880125222e648f05f28be34ba3cabfc9c544", "440fe691e04f1fed8c253d6c4670646156f33fffaea702de9445df5739eb960cecf85d56e2e6860a610211a5c909932ab774b978aa0b0d5bbce82775172ab12dceddd51d1eb030057ce61bea6c18f6bb368d26ae76a9e44a962eb132e6c42c25d9fecc4f13348300ca55c78e0990de96c1ae24eb3ee3324782c93dd628260a2c8d"), - new Case(1024, 1024, "d3090c72167517f7c7ad82a70c2fd3f6443f608301591e598eadb195e8357135ba26fede2ee187417f816048d00fc23512737a2113709a77e4170c49a94b7fdff45ff579a72287743102e7766c35ca5abc5dfe2f63a1e726ce5fbd2926db03a2dd18b03fc1508a9aac45eb362440203a323e09edee6324ee2e37b4432c1867ed696e6c9db1e6abea026288954a9c2d5758d7c5db7c9e48aa3d21cae3d977a7c3926066aa393dbd538dd0c30da8916c8757f24c18488014668a2627163a37b261833dc2f8c3c56b1b2e0be21fd3fbdb507b2950b77a6cc02efb393e57419383a920767bca2c972107aa61384542d47cbfb82cfe5c415389d1b0a2d74e2c5da851", "cb41f1706cde09651203c2d0efbaddf847a0d315cb2e53ff8bac41da0002672e920244c66e02d5f0dad3e94c42bb65f0d14157decf4105ef5609d5b0984457c1935df3061ff06e9f204192ba11e5bb2cac0430c1c370cb3d113fea5ec1021eb875e5946d7a96ac69a1626c6206b7252736f24253c9ee9b85eb852dfc814631346c", "46a42b0d7b8679f8fcea156c072cf9833c468a7d59ac5e5d326957d60dfe1cdfb27eb54c760b9e049fda47f0b847ac68d6b340c02c39d4a18c1bdfece3f405fae8aa848bdbefe3a4c277a095e921228618d3be8bd1999a071682810de748440ad416a97742cc9e8a9b85455b1d76472cf562f525116698d5cd0a35ddf86e7f8a"), - - }; - - public String getName() - { - return "SkeinMac"; - } - - public void performTest() - throws Exception - { - for (int i = 0; i < TEST_CASES.length; i++) - { - Case test = TEST_CASES[i]; - runTest(test); - } - } - - private void runTest(Case dc) - { - Mac digest = new SkeinMac(dc.getBlockSize(), dc.getOutputSize()); - digest.init(new KeyParameter(dc.getKey())); - - byte[] message = dc.getMessage(); - digest.update(message, 0, message.length); - - byte[] output = new byte[digest.getMacSize()]; - digest.doFinal(output, 0); - - if (!Arrays.areEqual(output, dc.getDigest())) - { - fail(digest.getAlgorithmName() + " message " + (dc.getMessage().length * 8) + " mismatch.\n Message " + new String(Hex.encode(dc.getMessage())) - + "\n Key " + new String(Hex.encode(dc.getKey())) + "\n Expected " - + new String(Hex.encode(dc.getDigest())) + "\n Actual " + new String(Hex.encode(output))); - } - - } - - public static void main(String[] args) - throws IOException - { - runTest(new SkeinMacTest()); - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SkipjackTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SkipjackTest.java deleted file mode 100644 index ff0b64def..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/SkipjackTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.SkipjackEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - */ -public class SkipjackTest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new SkipjackEngine(), - new KeyParameter(Hex.decode("00998877665544332211")), - "33221100ddccbbaa", "2587cae27a12d300") - }; - - SkipjackTest() - { - super(tests, new SkipjackEngine(), new KeyParameter(Hex.decode("00998877665544332211"))); - } - - public String getName() - { - return "SKIPJACK"; - } - - public static void main( - String[] args) - { - runTest(new SkipjackTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/StreamCipherResetTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/StreamCipherResetTest.java deleted file mode 100644 index c2f88904e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/StreamCipherResetTest.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.crypto.engines.ChaChaEngine; -import com.fr.third.org.bouncycastle.crypto.engines.Grain128Engine; -import com.fr.third.org.bouncycastle.crypto.engines.Grainv1Engine; -import com.fr.third.org.bouncycastle.crypto.engines.HC128Engine; -import com.fr.third.org.bouncycastle.crypto.engines.HC256Engine; -import com.fr.third.org.bouncycastle.crypto.engines.ISAACEngine; -import com.fr.third.org.bouncycastle.crypto.engines.RC4Engine; -import com.fr.third.org.bouncycastle.crypto.engines.Salsa20Engine; -import com.fr.third.org.bouncycastle.crypto.engines.XSalsa20Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test whether block ciphers implement reset contract on init, encrypt/decrypt and reset. - */ -public class StreamCipherResetTest - extends SimpleTest -{ - public String getName() - { - return "Stream Cipher Reset"; - } - - public void performTest() - throws Exception - { - testReset(new Salsa20Engine(), new Salsa20Engine(), new ParametersWithIV(new KeyParameter(random(32)), - random(8))); - testReset(new Salsa20Engine(), new Salsa20Engine(), new ParametersWithIV(new KeyParameter(random(16)), - random(8))); - testReset(new XSalsa20Engine(), new XSalsa20Engine(), new ParametersWithIV(new KeyParameter(random(32)), - random(24))); - testReset(new ChaChaEngine(), new ChaChaEngine(), new ParametersWithIV(new KeyParameter(random(32)), random(8))); - testReset(new ChaChaEngine(), new ChaChaEngine(), new ParametersWithIV(new KeyParameter(random(16)), random(8))); - testReset(new RC4Engine(), new RC4Engine(), new KeyParameter(random(16))); - testReset(new ISAACEngine(), new ISAACEngine(), new KeyParameter(random(16))); - testReset(new HC128Engine(), new HC128Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(16))); - testReset(new HC256Engine(), new HC256Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(16))); - testReset(new Grainv1Engine(), new Grainv1Engine(), new ParametersWithIV(new KeyParameter(random(16)), - random(8))); - testReset(new Grain128Engine(), new Grain128Engine(), new ParametersWithIV(new KeyParameter(random(16)), - random(12))); - } - - private static final SecureRandom RAND = new SecureRandom(); - - private byte[] random(int size) - { - final byte[] data = new byte[size]; - RAND.nextBytes(data); - return data; - } - - private void testReset(StreamCipher cipher1, StreamCipher cipher2, CipherParameters params) - throws InvalidCipherTextException - { - cipher1.init(true, params); - - byte[] plaintext = new byte[1023]; - byte[] ciphertext = new byte[plaintext.length]; - - // Establish baseline answer - cipher1.processBytes(plaintext, 0, plaintext.length, ciphertext, 0); - - // Test encryption resets - checkReset(cipher1, params, true, plaintext, ciphertext); - - // Test decryption resets with fresh instance - cipher2.init(false, params); - checkReset(cipher2, params, false, ciphertext, plaintext); - } - - private void checkReset(StreamCipher cipher, - CipherParameters params, - boolean encrypt, - byte[] pretext, - byte[] posttext) - throws InvalidCipherTextException - { - // Do initial run - byte[] output = new byte[posttext.length]; - cipher.processBytes(pretext, 0, pretext.length, output, 0); - - // Check encrypt resets cipher - cipher.init(encrypt, params); - - try - { - cipher.processBytes(pretext, 0, pretext.length, output, 0); - } - catch (Exception e) - { - fail(cipher.getAlgorithmName() + " init did not reset: " + e.getMessage()); - } - if (!Arrays.areEqual(output, posttext)) - { - fail(cipher.getAlgorithmName() + " init did not reset.", new String(Hex.encode(posttext)), - new String(Hex.encode(output))); - } - - // Check reset resets data - cipher.reset(); - - try - { - cipher.processBytes(pretext, 0, pretext.length, output, 0); - } - catch (Exception e) - { - fail(cipher.getAlgorithmName() + " reset did not reset: " + e.getMessage()); - } - if (!Arrays.areEqual(output, posttext)) - { - fail(cipher.getAlgorithmName() + " reset did not reset."); - } - } - - public static void main(String[] args) - { - runTest(new StreamCipherResetTest()); - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/StreamCipherVectorTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/StreamCipherVectorTest.java deleted file mode 100644 index bfe2c9817..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/StreamCipherVectorTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * a basic test that takes a stream cipher, key parameter, and an input - * and output string. - */ -public class StreamCipherVectorTest - extends SimpleTest -{ - int id; - StreamCipher cipher; - CipherParameters param; - byte[] input; - byte[] output; - - public StreamCipherVectorTest( - int id, - StreamCipher cipher, - CipherParameters param, - String input, - String output) - { - this.id = id; - this.cipher = cipher; - this.param = param; - this.input = Hex.decode(input); - this.output = Hex.decode(output); - } - - public String getName() - { - return cipher.getAlgorithmName() + " Vector Test " + id; - } - - public void performTest() - { - cipher.init(true, param); - - byte[] out = new byte[input.length]; - - cipher.processBytes(input, 0, input.length, out, 0); - - if (!areEqual(out, output)) - { - fail("failed.", new String(Hex.encode(output)) , new String(Hex.encode(out))); - } - - cipher.init(false, param); - - cipher.processBytes(output, 0, output.length, out, 0); - - if (!areEqual(input, out)) - { - fail("failed reversal"); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/TEATest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/TEATest.java deleted file mode 100644 index a80fa7509..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/TEATest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.TEAEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * TEA tester - based on C implementation results from http://www.simonshepherd.supanet.com/tea.htm - */ -public class TEATest - extends CipherTest -{ - static SimpleTest[] tests = { - new BlockCipherVectorTest(0, new TEAEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "0000000000000000", - "41ea3a0a94baa940"), - new BlockCipherVectorTest(1, new TEAEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "0102030405060708", - "6a2f9cf3fccf3c55"), - new BlockCipherVectorTest(2, new TEAEngine(), - new KeyParameter(Hex.decode("0123456712345678234567893456789A")), - "0000000000000000", - "34e943b0900f5dcb"), - new BlockCipherVectorTest(3, new TEAEngine(), - new KeyParameter(Hex.decode("0123456712345678234567893456789A")), - "0102030405060708", - "773dc179878a81c0"), - }; - - TEATest() - { - super(tests, new TEAEngine(), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "TEA"; - } - - public static void main( - String[] args) - { - runTest(new TEATest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Threefish1024Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Threefish1024Test.java deleted file mode 100644 index ffed05962..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Threefish1024Test.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.ThreefishEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.TweakableBlockCipherParameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class Threefish1024Test - extends CipherTest -{ - // Test cases from skein_golden_kat_internals.txt in Skein 1.3 NIST CD - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_1024), - new TweakableBlockCipherParameters( - new KeyParameter(new byte[128]), - new byte[16]), - "0000000000000000000000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000000", - "f05c3d0a3d05b304f785ddc7d1e036015c8aa76e2f217b06c6e1544c0bc1a90d" + - "f0accb9473c24e0fd54fea68057f43329cb454761d6df5cf7b2e9b3614fbd5a2" + - "0b2e4760b40603540d82eabc5482c171c832afbe68406bc39500367a592943fa" + - "9a5b4a43286ca3c4cf46104b443143d560a4b230488311df4feef7e1dfe8391e"), - new BlockCipherVectorTest(1, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_1024), - new TweakableBlockCipherParameters( - new KeyParameter(Hex.decode( - "101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f" + - "303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f" + - "505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f" + - "707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f")), - Hex.decode("000102030405060708090a0b0c0d0e0f")), - "fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0efeeedecebeae9e8e7e6e5e4e3e2e1e0" + - "dfdedddcdbdad9d8d7d6d5d4d3d2d1d0cfcecdcccbcac9c8c7c6c5c4c3c2c1c0" + - "bfbebdbcbbbab9b8b7b6b5b4b3b2b1b0afaeadacabaaa9a8a7a6a5a4a3a2a1a0" + - "9f9e9d9c9b9a999897969594939291908f8e8d8c8b8a89888786858483828180", - "a6654ddbd73cc3b05dd777105aa849bce49372eaaffc5568d254771bab85531c" + - "94f780e7ffaae430d5d8af8c70eebbe1760f3b42b737a89cb363490d670314bd" + - "8aa41ee63c2e1f45fbd477922f8360b388d6125ea6c7af0ad7056d01796e90c8" + - "3313f4150a5716b30ed5f569288ae974ce2b4347926fce57de44512177dd7cde") - }; - - Threefish1024Test() - { - super(tests, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_1024), new KeyParameter(new byte[128])); - } - - public String getName() - { - return "Threefish-1024"; - } - - public static void main( - String[] args) - { - runTest(new Threefish1024Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Threefish256Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Threefish256Test.java deleted file mode 100644 index 929919d1d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Threefish256Test.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.ThreefishEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.TweakableBlockCipherParameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class Threefish256Test - extends CipherTest -{ - // Test cases from skein_golden_kat_internals.txt in Skein 1.3 NIST CD - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_256), - new TweakableBlockCipherParameters( - new KeyParameter(new byte[32]), - new byte[16]), - "0000000000000000000000000000000000000000000000000000000000000000", - "84da2a1f8beaee947066ae3e3103f1ad536db1f4a1192495116b9f3ce6133fd8"), - new BlockCipherVectorTest(1, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_256), - new TweakableBlockCipherParameters( - new KeyParameter(Hex.decode( - "101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f")), - Hex.decode("000102030405060708090a0b0c0d0e0f")), - "FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0EFEEEDECEBEAE9E8E7E6E5E4E3E2E1E0", - "e0d091ff0eea8fdfc98192e62ed80ad59d865d08588df476657056b5955e97df") - }; - - Threefish256Test() - { - super(tests, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_256), new KeyParameter(new byte[32])); - } - - public String getName() - { - return "Threefish-256"; - } - - public static void main( - String[] args) - { - runTest(new Threefish256Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Threefish512Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Threefish512Test.java deleted file mode 100644 index 0656b8a3c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/Threefish512Test.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.ThreefishEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.TweakableBlockCipherParameters; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class Threefish512Test - extends CipherTest -{ - // Test cases from skein_golden_kat_internals.txt in Skein 1.3 NIST CD - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), - new TweakableBlockCipherParameters( - new KeyParameter(new byte[64]), - new byte[16]), - "0000000000000000000000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000000", - "b1a2bbc6ef6025bc40eb3822161f36e375d1bb0aee3186fbd19e47c5d479947b" + - "7bc2f8586e35f0cff7e7f03084b0b7b1f1ab3961a580a3e97eb41ea14a6d7bbe"), - new BlockCipherVectorTest(1, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), - new TweakableBlockCipherParameters( - new KeyParameter(Hex.decode( - "101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f" + - "303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f")), - Hex.decode("000102030405060708090a0b0c0d0e0f")), - "fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0efeeedecebeae9e8e7e6e5e4e3e2e1e0" + - "dfdedddcdbdad9d8d7d6d5d4d3d2d1d0cfcecdcccbcac9c8c7c6c5c4c3c2c1c0", - "e304439626d45a2cb401cad8d636249a6338330eb06d45dd8b36b90e97254779" + - "272a0a8d99463504784420ea18c9a725af11dffea10162348927673d5c1caf3d") - }; - - Threefish512Test() - { - super(tests, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), new KeyParameter(new byte[64])); - } - - public String getName() - { - return "Threefish-512"; - } - - public static void main( - String[] args) - { - runTest(new Threefish512Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/TigerDigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/TigerDigestTest.java deleted file mode 100644 index 61afe6516..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/TigerDigestTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.TigerDigest; - -/** - * Tiger Digest Test - */ -public class TigerDigestTest - extends DigestTest -{ - final static String[] messages = { - "", - "abc", - "Tiger", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw", - "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789", - "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996.", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-" - }; - - final static String[] digests = { - "3293AC630C13F0245F92BBB1766E16167A4E58492DDE73F3", - "2AAB1484E8C158F2BFB8C5FF41B57A525129131C957B5F93", - "DD00230799F5009FEC6DEBC838BB6A27DF2B9D6F110C7937", - "F71C8583902AFB879EDFE610F82C0D4786A3A534504486B5", - "38F41D9D9A710A10C3727AC0DEEAA270727D9F926EC10139", - "48CEEB6308B87D46E95D656112CDF18D97915F9765658957", - "631ABDD103EB9A3D245B6DFD4D77B257FC7439501D1568DD", - "C54034E5B43EB8005848A7E0AE6AAC76E4FF590AE715FD25", - "C54034E5B43EB8005848A7E0AE6AAC76E4FF590AE715FD25" - }; - - final static String hash64k = "FDF4F5B35139F48E710E421BE5AF411DE1A8AAC333F26204"; - - TigerDigestTest() - { - super(new TigerDigest(), messages, digests); - } - - public void performTest() - { - super.performTest(); - - sixtyFourKTest(hash64k); - } - - protected Digest cloneDigest(Digest digest) - { - return new TigerDigest((TigerDigest)digest); - } - - public static void main( - String[] args) - { - runTest(new TigerDigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/TnepresTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/TnepresTest.java deleted file mode 100644 index 357502ee5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/TnepresTest.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.engines.TnepresEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test vectors based on Floppy 4 of the Serpent AES submission. - */ -public class TnepresTest - extends CipherTest -{ - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new TnepresEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "00000000000000000000000000000000", "8910494504181950f98dd998a82b6749"), - new BlockCipherVectorTest(1, new TnepresEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "80000000000000000000000000000000", "10b5ffb720b8cb9002a1142b0ba2e94a"), - new BlockCipherVectorTest(2, new TnepresEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000008000000000000000000000", "4f057a42d8d5bd9746e434680ddcd5e5"), - new BlockCipherVectorTest(3, new TnepresEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "00000000000000000000400000000000", "99407bf8582ef12550886ef5b6f169b9"), - new BlockCipherVectorTest(4, new TnepresEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "40000000000000000000000000000000", "d522a3b8d6d89d4d2a124fdd88f36896"), - new BlockCipherVectorTest(5, new TnepresEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "00000000000200000000000000000000", "189b8ec3470085b3da97e82ca8964e32"), - new BlockCipherVectorTest(6, new TnepresEngine(), - new KeyParameter(Hex.decode("000000000000000000000000000000000000000000000000")), - "00000000000000000000008000000000", "f77d868cf760b9143a89809510ccb099"), - new BlockCipherVectorTest(7, new TnepresEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "08000000000000000000000000000000", "d43b7b981b829342fce0e3ec6f5f4c82"), - new BlockCipherVectorTest(8, new TnepresEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "00000000000000000100000000000000", "0bf30e1a0c33ccf6d5293177886912a7"), - new BlockCipherVectorTest(9, new TnepresEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")), - "00000000000000000000000000000001", "6a7f3b805d2ddcba49b89770ade5e507"), - new BlockCipherVectorTest(10, new TnepresEngine(), - new KeyParameter(Hex.decode("80000000000000000000000000000000")), - "00000000000000000000000000000000", "49afbfad9d5a34052cd8ffa5986bd2dd"), - new BlockCipherVectorTest(11, new TnepresEngine(), - new KeyParameter(Hex.decode("000000000000000000000000004000000000000000000000")), - "00000000000000000000000000000000", "ba8829b1de058c4b48615d851fc74f17"), - new BlockCipherVectorTest(12, new TnepresEngine(), - new KeyParameter(Hex.decode("0000000000000000000000000000000000000000000000000000000100000000")), - "00000000000000000000000000000000", "89f64377bf1e8a46c8247044e8056a98"), -/* - new BlockCipherMonteCarloTest(13, 10000, new TnepresEngine(), - new KeyParameter(Hex.decode("47f5f881daab9b67b43bd1342e339c19")), - "7a4f7db38c52a8b711b778a38d203b6b", "003380e19f10065740394f48e2fe80b7"), -*/ - new BlockCipherMonteCarloTest(13, 100, new TnepresEngine(), - new KeyParameter(Hex.decode("47f5f881daab9b67b43bd1342e339c19")), - "7a4f7db38c52a8b711b778a38d203b6b", "4db75303d815c2f7cc6ca935d1c5a046"), -/* - new BlockCipherMonteCarloTest(14, 10000, new TnepresEngine(), - new KeyParameter(Hex.decode("31fba879ebc5e80df35e6fa33eaf92d6")), - "70a05e12f74589009692a337f53ff614", "afb5425426906db26b70bdf842ac5400"), -*/ - new BlockCipherMonteCarloTest(14, 100, new TnepresEngine(), - new KeyParameter(Hex.decode("31fba879ebc5e80df35e6fa33eaf92d6")), - "70a05e12f74589009692a337f53ff614", "fc53a50f4d3bc9836001893d2f41742d"), -/* - new BlockCipherMonteCarloTest(15, 10000, new TnepresEngine(), - new KeyParameter(Hex.decode("bde6dd392307984695aee80e574f9977caae9aa78eda53e8")), - "9cc523d034a93740a0aa4e2054bb34d8", "1949d506ada7de1f1344986e8ea049b2"), -*/ - new BlockCipherMonteCarloTest(15, 100, new TnepresEngine(), - new KeyParameter(Hex.decode("bde6dd392307984695aee80e574f9977caae9aa78eda53e8")), - "9cc523d034a93740a0aa4e2054bb34d8", "77117e6a9e80f40b2a36b7d755573c2d"), -/* - new BlockCipherMonteCarloTest(16, 10000, new TnepresEngine(), - new KeyParameter(Hex.decode("60f6f8ad4290699dc50921a1bbcca92da914e7d9cf01a9317c79c0af8f2487a1")), - "ee1a61106fae2d381d686cbf854bab65", "e57f45559027cb1f2ed9603d814e1c34"), -*/ - new BlockCipherMonteCarloTest(16, 100, new TnepresEngine(), - new KeyParameter(Hex.decode("60f6f8ad4290699dc50921a1bbcca92da914e7d9cf01a9317c79c0af8f2487a1")), - "ee1a61106fae2d381d686cbf854bab65", "dcd7f13ea0dcdfd0139d1a42e2ffb84b") - }; - - TnepresTest() - { - super(tests, new TnepresEngine(), new KeyParameter(new byte[32])); - } - - public void performTest() - throws Exception - { - super.performTest(); - - doCbcMonte(new byte[16], new byte[16], new byte[16], Hex.decode("9ea101ecebaa41c712bcb0d9bab3e2e4")); - doCbcMonte(Hex.decode("9ea101ecebaa41c712bcb0d9bab3e2e4"), Hex.decode("9ea101ecebaa41c712bcb0d9bab3e2e4"), Hex.decode("b4813d8a66244188b9e92c75913fa2f4"), Hex.decode("f86b2c265b9c75869f31e2c684c13e9f")); - } - - private void doCbcMonte(byte[] key, byte[] iv, byte[] pt, byte[] expected) - { - BlockCipher c = new TnepresEngine(); - - byte[] ct = new byte[16]; - - System.arraycopy(iv, 0, ct, 0, 16); - - for (int i = 0; i < 10000; i++) - { - for (int k = 0; k != iv.length; k++) - { - iv[k] ^= pt[k]; - } - System.arraycopy(ct, 0, pt, 0, 16); - - c.init(true, new KeyParameter(key)); - - c.processBlock(iv, 0, ct, 0); - - System.arraycopy(ct, 0, iv, 0, 16); - } - - if (!Arrays.areEqual(expected, ct)) - { - fail("CBC monte test failed"); - } - } - - public String getName() - { - return "Tnepres"; - } - - public static void main( - String[] args) - { - runTest(new TnepresTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/TwofishTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/TwofishTest.java deleted file mode 100644 index f2a4e3ddb..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/TwofishTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.TwofishEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class TwofishTest - extends CipherTest -{ - static String key1 = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"; - static String key2 = "000102030405060708090a0b0c0d0e0f1011121314151617"; - static String key3 = "000102030405060708090a0b0c0d0e0f"; - - static String input = "000102030405060708090A0B0C0D0E0F"; - - static SimpleTest[] tests = - { - new BlockCipherVectorTest(0, new TwofishEngine(), - new KeyParameter(Hex.decode(key1)), - input, "8ef0272c42db838bcf7b07af0ec30f38"), - new BlockCipherVectorTest(1, new TwofishEngine(), - new KeyParameter(Hex.decode(key2)), - input, "95accc625366547617f8be4373d10cd7"), - new BlockCipherVectorTest(2, new TwofishEngine(), - new KeyParameter(Hex.decode(key3)), - input, "9fb63337151be9c71306d159ea7afaa4") - }; - - TwofishTest() - { - super(tests, new TwofishEngine(), new KeyParameter(new byte[32])); - } - - public String getName() - { - return "Twofish"; - } - - public static void main( - String[] args) - { - runTest(new TwofishTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/VMPCKSA3Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/VMPCKSA3Test.java deleted file mode 100644 index 27b05e298..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/VMPCKSA3Test.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.engines.VMPCKSA3Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * VMPC Test - */ -public class VMPCKSA3Test extends SimpleTest -{ - private static final byte[] input = new byte[1000000]; - - public String getName() - { - return "VMPC-KSA3"; - } - - private void checkByte(byte[] array, int position, byte b) - { - if (array[position] != b) - { - fail("Fail on position " + position, - new String(Hex.encode(new byte[] { b })), - new String(Hex.encode(new byte[] { array[position] }))); - } - } - - public void performTest() - { - byte[] key = Hex.decode("9661410AB797D8A9EB767C21172DF6C7"); - byte[] iv = Hex.decode("4B5C2F003E67F39557A8D26F3DA2B155"); - CipherParameters kp = new KeyParameter(key); - CipherParameters kpwiv = new ParametersWithIV(kp, iv); - - VMPCKSA3Engine engine = new VMPCKSA3Engine(); - - try - { - engine.init(true, kp); - fail("init failed to throw expected exception"); - } - catch (IllegalArgumentException e) - { - // Expected - } - - engine.init(true, kpwiv); - checkEngine(engine); - - engine.reset(); - byte[] output = checkEngine(engine); - - engine.init(false, kpwiv); - byte[] recovered = new byte[output.length]; - engine.processBytes(output, 0, output.length, recovered, 0); - - if (!Arrays.areEqual(input, recovered)) - { - fail("decrypted bytes differ from original bytes"); - } - } - - private byte[] checkEngine(VMPCKSA3Engine engine) - { - byte[] output = new byte[input.length]; - engine.processBytes(input, 0, output.length, output, 0); - - checkByte(output, 0, (byte) 0xB6); - checkByte(output, 1, (byte) 0xEB); - checkByte(output, 2, (byte) 0xAE); - checkByte(output, 3, (byte) 0xFE); - checkByte(output, 252, (byte) 0x48); - checkByte(output, 253, (byte) 0x17); - checkByte(output, 254, (byte) 0x24); - checkByte(output, 255, (byte) 0x73); - checkByte(output, 1020, (byte) 0x1D); - checkByte(output, 1021, (byte) 0xAE); - checkByte(output, 1022, (byte) 0xC3); - checkByte(output, 1023, (byte) 0x5A); - checkByte(output, 102396, (byte) 0x1D); - checkByte(output, 102397, (byte) 0xA7); - checkByte(output, 102398, (byte) 0xE1); - checkByte(output, 102399, (byte) 0xDC); - - return output; - } - - public static void main(String[] args) - { - runTest(new VMPCKSA3Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/VMPCMacTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/VMPCMacTest.java deleted file mode 100644 index 368f535db..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/VMPCMacTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.macs.VMPCMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class VMPCMacTest extends SimpleTest -{ - public String getName() - { - return "VMPC-MAC"; - } - - public static void main(String[] args) - { - runTest(new VMPCMacTest()); - } - - static byte[] output1 = Hex.decode("9BDA16E2AD0E284774A3ACBC8835A8326C11FAAD"); - - public void performTest() throws Exception - { - CipherParameters kp = new KeyParameter( - Hex.decode("9661410AB797D8A9EB767C21172DF6C7")); - CipherParameters kpwiv = new ParametersWithIV(kp, - Hex.decode("4B5C2F003E67F39557A8D26F3DA2B155")); - - byte[] m = new byte[512]; - - int offset = 117; - for (int i = 0; i < 256; i++) - { - m[offset + i] = (byte) i; - } - - VMPCMac mac = new VMPCMac(); - mac.init(kpwiv); - - mac.update(m, offset, 256); - - byte[] out = new byte[20]; - mac.doFinal(out, 0); - - if (!Arrays.areEqual(out, output1)) - { - fail("Fail", new String(Hex.encode(output1)), new String(Hex.encode(out))); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/VMPCTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/VMPCTest.java deleted file mode 100644 index a9344920b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/VMPCTest.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.engines.VMPCEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * VMPC Test - */ -public class VMPCTest extends SimpleTest -{ - private static final byte[] input = new byte[1000000]; - - public String getName() - { - return "VMPC"; - } - - private void checkByte(byte[] array, int position, byte b) - { - if (array[position] != b) - { - fail("Fail on position " + position, - new String(Hex.encode(new byte[] { b })), - new String(Hex.encode(new byte[] { array[position] }))); - } - } - - public void performTest() - { - byte[] key = Hex.decode("9661410AB797D8A9EB767C21172DF6C7"); - byte[] iv = Hex.decode("4B5C2F003E67F39557A8D26F3DA2B155"); - CipherParameters kp = new KeyParameter(key); - CipherParameters kpwiv = new ParametersWithIV(kp, iv); - - VMPCEngine engine = new VMPCEngine(); - - try - { - engine.init(true, kp); - fail("init failed to throw expected exception"); - } - catch (IllegalArgumentException e) - { - // Expected - } - - engine.init(true, kpwiv); - checkEngine(engine); - - engine.reset(); - byte[] output = checkEngine(engine); - - engine.init(false, kpwiv); - byte[] recovered = new byte[output.length]; - engine.processBytes(output, 0, output.length, recovered, 0); - - if (!Arrays.areEqual(input, recovered)) - { - fail("decrypted bytes differ from original bytes"); - } - } - - private byte[] checkEngine(VMPCEngine engine) - { - byte[] output = new byte[input.length]; - engine.processBytes(input, 0, output.length, output, 0); - - checkByte(output, 0, (byte) 0xA8); - checkByte(output, 1, (byte) 0x24); - checkByte(output, 2, (byte) 0x79); - checkByte(output, 3, (byte) 0xF5); - checkByte(output, 252, (byte) 0xB8); - checkByte(output, 253, (byte) 0xFC); - checkByte(output, 254, (byte) 0x66); - checkByte(output, 255, (byte) 0xA4); - checkByte(output, 1020, (byte) 0xE0); - checkByte(output, 1021, (byte) 0x56); - checkByte(output, 1022, (byte) 0x40); - checkByte(output, 1023, (byte) 0xA5); - checkByte(output, 102396, (byte) 0x81); - checkByte(output, 102397, (byte) 0xCA); - checkByte(output, 102398, (byte) 0x49); - checkByte(output, 102399, (byte) 0x9A); - - return output; - } - - public static void main(String[] args) - { - runTest(new VMPCTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/WhirlpoolDigestTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/WhirlpoolDigestTest.java deleted file mode 100644 index d1b7d59d6..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/WhirlpoolDigestTest.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.WhirlpoolDigest; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * ISO vector test for Whirlpool - * - */ -public class WhirlpoolDigestTest - extends DigestTest -{ - private static String[] messages = - { - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890", - "abcdbcdecdefdefgefghfghighijhijk" - }; - - private static String[] digests = - { - "19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A73E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3", - "8ACA2602792AEC6F11A67206531FB7D7F0DFF59413145E6973C45001D0087B42D11BC645413AEFF63A42391A39145A591A92200D560195E53B478584FDAE231A", - "4E2448A4C6F486BB16B6562C73B4020BF3043E3A731BCE721AE1B303D97E6D4C7181EEBDB6C57E277D0E34957114CBD6C797FC9D95D8B582D225292076D4EEF5", - "378C84A4126E2DC6E56DCC7458377AAC838D00032230F53CE1F5700C0FFB4D3B8421557659EF55C106B4B52AC5A4AAA692ED920052838F3362E86DBD37A8903E", - "F1D754662636FFE92C82EBB9212A484A8D38631EAD4238F5442EE13B8054E41B08BF2A9251C30B6A0B8AAE86177AB4A6F68F673E7207865D5D9819A3DBA4EB3B", - "DC37E008CF9EE69BF11F00ED9ABA26901DD7C28CDEC066CC6AF42E40F82F3A1E08EBA26629129D8FB7CB57211B9281A65517CC879D7B962142C65F5A7AF01467", - "466EF18BABB0154D25B9D38A6414F5C08784372BCCB204D6549C4AFADB6014294D5BD8DF2A6C44E538CD047B2681A51A2C60481E88C5A20B2C2A80CF3A9A083B", - "2A987EA40F917061F5D6F0A0E4644F488A7A5A52DEEE656207C562F988E95C6916BDC8031BC5BE1B7B947639FE050B56939BAAA0ADFF9AE6745B7B181C3BE3FD" - }; - - WhirlpoolDigestTest() - { - super(new WhirlpoolDigest(), messages, digests); - } - - protected Digest cloneDigest(Digest digest) - { - return new WhirlpoolDigest((WhirlpoolDigest)digest); - } - - private static String _millionAResultVector = "0C99005BEB57EFF50A7CF005560DDF5D29057FD86B20BFD62DECA0F1CCEA4AF51FC15490EDDC47AF32BB2B66C34FF9AD8C6008AD677F77126953B226E4ED8B01"; - - private static String _thirtyOneZeros = "3E3F188F8FEBBEB17A933FEAF7FE53A4858D80C915AD6A1418F0318E68D49B4E459223CD414E0FBC8A57578FD755D86E827ABEF4070FC1503E25D99E382F72BA"; - - public String getName() - { - return "Whirlpool"; - } - - public void performTest() - { - super.performTest(); - - byte[] thirtyOneZeros = new byte[31]; - performStandardVectorTest("31 zeroes test", - thirtyOneZeros, _thirtyOneZeros); - - byte[] millionAInByteArray = new byte[1000000]; - Arrays.fill(millionAInByteArray, (byte)'a'); - - performStandardVectorTest("Million 'a' test", - millionAInByteArray, _millionAResultVector); - } - - private void performStandardVectorTest(String testTitle, byte[] inputBytes, - String resultsAsHex) - { - doPerformTest(testTitle, inputBytes, resultsAsHex); - } - - private void doPerformTest(String testTitle, byte[] inputBytes, String resultsAsHex) - { - String resStr = createHexOutputFromDigest(inputBytes); - if (!resultsAsHex.equals(resStr.toUpperCase())) - { - fail(testTitle, resultsAsHex, resStr); - } - } - - private String createHexOutputFromDigest(byte[] digestBytes) - { - String resStr; - Digest digest = new WhirlpoolDigest(); - byte[] resBuf = new byte[digest.getDigestSize()]; - digest.update(digestBytes, 0, digestBytes.length); - digest.doFinal(resBuf, 0); - resStr = new String(Hex.encode(resBuf)); - return resStr; - } - - public static void main(String[] args) - { - runTest(new WhirlpoolDigestTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/X25519Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/X25519Test.java deleted file mode 100644 index 2b6c5447f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/X25519Test.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.agreement.X25519Agreement; -import com.fr.third.org.bouncycastle.crypto.generators.X25519KeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.X25519KeyGenerationParameters; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class X25519Test - extends SimpleTest -{ - private static final SecureRandom RANDOM = new SecureRandom(); - - public String getName() - { - return "X25519"; - } - - public static void main(String[] args) - { - runTest(new X25519Test()); - } - - public void performTest() - { - for (int i = 0; i < 10; ++i) - { - testAgreement(); - } - } - - private void testAgreement() - { - AsymmetricCipherKeyPairGenerator kpGen = new X25519KeyPairGenerator(); - kpGen.init(new X25519KeyGenerationParameters(RANDOM)); - - AsymmetricCipherKeyPair kpA = kpGen.generateKeyPair(); - AsymmetricCipherKeyPair kpB = kpGen.generateKeyPair(); - - X25519Agreement agreeA = new X25519Agreement(); - agreeA.init(kpA.getPrivate()); - byte[] secretA = new byte[agreeA.getAgreementSize()]; - agreeA.calculateAgreement(kpB.getPublic(), secretA, 0); - - X25519Agreement agreeB = new X25519Agreement(); - agreeB.init(kpB.getPrivate()); - byte[] secretB = new byte[agreeB.getAgreementSize()]; - agreeB.calculateAgreement(kpA.getPublic(), secretB, 0); - - if (!areEqual(secretA, secretB)) - { - fail("X25519 agreement failed"); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/X448Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/X448Test.java deleted file mode 100644 index 8f96e2dab..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/X448Test.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.agreement.X448Agreement; -import com.fr.third.org.bouncycastle.crypto.generators.X448KeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.X448KeyGenerationParameters; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class X448Test - extends SimpleTest -{ - private static final SecureRandom RANDOM = new SecureRandom(); - - public String getName() - { - return "X448"; - } - - public static void main(String[] args) - { - runTest(new X448Test()); - } - - public void performTest() - { - for (int i = 0; i < 10; ++i) - { - testAgreement(); - } - } - - private void testAgreement() - { - AsymmetricCipherKeyPairGenerator kpGen = new X448KeyPairGenerator(); - kpGen.init(new X448KeyGenerationParameters(RANDOM)); - - AsymmetricCipherKeyPair kpA = kpGen.generateKeyPair(); - AsymmetricCipherKeyPair kpB = kpGen.generateKeyPair(); - - X448Agreement agreeA = new X448Agreement(); - agreeA.init(kpA.getPrivate()); - byte[] secretA = new byte[agreeA.getAgreementSize()]; - agreeA.calculateAgreement(kpB.getPublic(), secretA, 0); - - X448Agreement agreeB = new X448Agreement(); - agreeB.init(kpB.getPrivate()); - byte[] secretB = new byte[agreeB.getAgreementSize()]; - agreeB.calculateAgreement(kpA.getPublic(), secretB, 0); - - if (!areEqual(secretA, secretB)) - { - fail("X448 agreement failed"); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/X931SignerTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/X931SignerTest.java deleted file mode 100644 index 98a44d9d3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/X931SignerTest.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA224Digest; -import com.fr.third.org.bouncycastle.crypto.engines.RSAEngine; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters; -import com.fr.third.org.bouncycastle.crypto.signers.X931Signer; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class X931SignerTest - extends SimpleTest -{ - public String getName() - { - return "X931Signer"; - } - - public void performTest() throws Exception - { - BigInteger rsaPubMod = new BigInteger(Base64.decode("AIASoe2PQb1IP7bTyC9usjHP7FvnUMVpKW49iuFtrw/dMpYlsMMoIU2jupfifDpdFxIktSB4P+6Ymg5WjvHKTIrvQ7SR4zV4jaPTu56Ys0pZ9EDA6gb3HLjtU+8Bb1mfWM+yjKxcPDuFjwEtjGlPHg1Vq+CA9HNcMSKNn2+tW6qt")); - BigInteger rsaPubExp = new BigInteger(Base64.decode("EQ==")); - BigInteger rsaPrivMod = new BigInteger(Base64.decode("AIASoe2PQb1IP7bTyC9usjHP7FvnUMVpKW49iuFtrw/dMpYlsMMoIU2jupfifDpdFxIktSB4P+6Ymg5WjvHKTIrvQ7SR4zV4jaPTu56Ys0pZ9EDA6gb3HLjtU+8Bb1mfWM+yjKxcPDuFjwEtjGlPHg1Vq+CA9HNcMSKNn2+tW6qt")); - BigInteger rsaPrivDP = new BigInteger(Base64.decode("JXzfzG5v+HtLJIZqYMUefJfFLu8DPuJGaLD6lI3cZ0babWZ/oPGoJa5iHpX4Ul/7l3s1PFsuy1GhzCdOdlfRcQ==")); - BigInteger rsaPrivDQ = new BigInteger(Base64.decode("YNdJhw3cn0gBoVmMIFRZzflPDNthBiWy/dUMSRfJCxoZjSnr1gysZHK01HteV1YYNGcwPdr3j4FbOfri5c6DUQ==")); - BigInteger rsaPrivExp = new BigInteger(Base64.decode("DxFAOhDajr00rBjqX+7nyZ/9sHWRCCp9WEN5wCsFiWVRPtdB+NeLcou7mWXwf1Y+8xNgmmh//fPV45G2dsyBeZbXeJwB7bzx9NMEAfedchyOwjR8PYdjK3NpTLKtZlEJ6Jkh4QihrXpZMO4fKZWUm9bid3+lmiq43FwW+Hof8/E=")); - BigInteger rsaPrivP = new BigInteger(Base64.decode("AJ9StyTVW+AL/1s7RBtFwZGFBgd3zctBqzzwKPda6LbtIFDznmwDCqAlIQH9X14X7UPLokCDhuAa76OnDXb1OiE=")); - BigInteger rsaPrivQ = new BigInteger(Base64.decode("AM3JfD79dNJ5A3beScSzPtWxx/tSLi0QHFtkuhtSizeXdkv5FSba7lVzwEOGKHmW829bRoNxThDy4ds1IihW1w0=")); - BigInteger rsaPrivQinv = new BigInteger(Base64.decode("Lt0g7wrsNsQxuDdB8q/rH8fSFeBXMGLtCIqfOec1j7FEIuYA/ACiRDgXkHa0WgN7nLXSjHoy630wC5Toq8vvUg==")); - RSAKeyParameters rsaPublic = new RSAKeyParameters(false, rsaPubMod, rsaPubExp); - RSAPrivateCrtKeyParameters rsaPrivate = new RSAPrivateCrtKeyParameters(rsaPrivMod, rsaPubExp, rsaPrivExp, rsaPrivP, rsaPrivQ, rsaPrivDP, rsaPrivDQ, rsaPrivQinv); - - byte[] msg = new byte[] { 1, 6, 3, 32, 7, 43, 2, 5, 7, 78, 4, 23 }; - - X931Signer signer = new X931Signer(new RSAEngine(), new SHA1Digest()); - signer.init(true, rsaPrivate); - signer.update(msg, 0, msg.length); - byte[] sig = signer.generateSignature(); - - signer = new X931Signer(new RSAEngine(), new SHA1Digest()); - signer.init(false, rsaPublic); - signer.update(msg, 0, msg.length); - if (!signer.verifySignature(sig)) - { - fail("X9.31 Signer failed."); - } - - shouldPassSignatureTest1(); - shouldPassSignatureTest2(); - shouldPassSignatureTest3(); - } - - private void shouldPassSignatureTest1() - throws Exception - { - BigInteger n = new BigInteger("c9be1b28f8caccca65d86cc3c9bbcc13eccc059df3b80bd2292b811eff3aa0dd75e1e85c333b8e3fa9bed53bb20f5359ff4e6900c5e9a388e3a4772a583a79e2299c76582c2b27694b65e9ba22e66bfb817f8b70b22206d7d8ae488c86dbb7137c26d5eff9b33c90e6cee640630313b7a715802e15142fef498c404a8de19674974785f0f852e2d470fe85a2e54ffca9f5851f672b71df691785a5cdabe8f14aa628942147de7593b2cf962414a5b59c632c4e14f1768c0ab2e9250824beea60a3529f11bf5e070ce90a47686eb0be1086fb21f0827f55295b4a48307db0b048c05a4aec3f488c576ca6f1879d354224c7e84cbcd8e76dd217a3de54dba73c35", 16); - BigInteger e = new BigInteger("e75b1b", 16); - byte[] msg = Hex.decode("5bb0d1c0ef9b5c7af2477fe08d45523d3842a4b2db943f7033126c2a7829bacb3d2cfc6497ec91688189e81b7f8742488224ba320ce983ce9480722f2cc5bc42611f00bb6311884f660ccc244788378673532edb05284fd92e83f6f6dab406209032e6af9a33c998677933e32d6fb95fd27408940d7728f9c9c40267ca1d20ce"); - byte[] sig = Hex.decode("0fe8bb8e3109a1eb7489ef35bf4c1a0780071da789c8bd226a4170538eafefdd30b732d628f0e87a0b9450051feae9754d4fb61f57862d10f0bacc4f660d13281d0cd1141c006ade5186ff7d961a4c6cd0a4b352fc1295c5afd088f80ac1f8e192ef116a010a442655fe8ff5eeacea15807906fb0f0dfa86e680d4c005872357f7ece9aa4e20b15d5f709b30f08648ecaa34f2fbf54eb6b414fa2ff6f87561f70163235e69ccb4ac82a2e46d3be214cc2ef5263b569b2d8fd839b21a9e102665105ea762bda25bb446cfd831487a6b846100dee113ae95ae64f4af22c428c87bab809541c962bb3a56d4c86588e0af4ebc7fcc66dadced311051356d3ea745f7"); - - RSAKeyParameters rsaPublic = new RSAKeyParameters(false, n, e); - X931Signer signer = new X931Signer(new RSAEngine(), new SHA1Digest()); - - signer.init(false, rsaPublic); - - signer.update(msg, 0, msg.length); - - if (!signer.verifySignature(sig)) - { - fail("RSA X931 verify test 1 failed."); - } - } - - private void shouldPassSignatureTest2() - throws Exception - { - BigInteger n = new BigInteger("b746ba6c3c0be64bbe33aa55b2929b0af4e86d773d44bfe5914db9287788c4663984b61a418d2eecca30d752ff6b620a07ec72eeb2b422d2429da352407b99982800b9dd7697be6a7b1baa98ca5f4fc2fe33400f20b9dba337ac25c987804165d4a6e0ee4d18eabd6de5abdfe578cae6713ff91d16c80a5bb20217fe614d9509e75a43e1825327b9da8f0a9f6eeaa1c04b69fb4bacc073569fff4ab491becbe6d0441d437fc3fa823239c4a0f75321666b68dd3f66e2dd394089a15bcc288a68a4eb0a48e17d639743b9dea0a91cc35820544732aff253f8ca9967c609dc01c2f8cd0313a7a91cfa94ff74289a1d2b6f19d1811f4b9a65f4cce9e5759b4cc64f", 16); - BigInteger e = new BigInteger("dcbbdb", 16); - byte[] msg = Hex.decode("a5d3c8a060f897bbbc20ae0955052f37fbc70986b6e11c65075c9f457142bfa93856897c69020aa81a91b5e4f39e05cdeecc63395ab849c8262ca8bc5c96870aecb8edb0aba0024a9bdb71e06de6100344e5c318bc979ef32b8a49a8278ba99d4861bce42ebbc5c8c666aaa6cac39aff8779f2cae367620f9edd4cb1d80b6c8c"); - byte[] sig = Hex.decode("39fbbd1804c689a533b0043f84da0f06081038c0fbf31e443e46a05e58f50de5198bbca40522afefaba3aed7082a6cb93b1da39f1f5a42246bf64930781948d300549bef0f8d554ecfca60a1b1ecba95a7014ee4545ad4f0c4e3a31942c6738b4ccd6244b6a21267dadf0826a5f713f13b1f5a9ab8501d957a26d4948278ac67851071a315674bdab173bfef2c2690c8373da6bf3d69f30c0e5da8883de872f59521b40793854085641adf98d13db991c5d0a8aaa0222934fa33332e90ef0b954e195cb267d6ffb36c96e14d1ec7b915a87598b4461a3146566354dc2ae748c84ee0cd46543b53ebff8cdf47725b280a1f799fb6ebb4a31ad2bdd5178250f83a"); - - RSAKeyParameters rsaPublic = new RSAKeyParameters(false, n, e); - X931Signer signer = new X931Signer(new RSAEngine(), new SHA224Digest()); - - signer.init(false, rsaPublic); - - signer.update(msg, 0, msg.length); - - if (!signer.verifySignature(sig)) - { - fail("RSA X931 verify test 2 failed."); - } - } - - private void shouldPassSignatureTest3() - throws Exception - { - BigInteger n = new BigInteger("dcb5686a3d2063a3f9cf7b9b32d2d3765b4c449b09b4960245a9111cd3b0cbd3260496885b8e1fa5db33b03efcc759d9c1afe29d93c6faebc7e0efada334b5b9a29655e2da2c8f11103d8203be311feab7ae88e9f1b2ec7d8fc655d77202b1681dd9717ec0f525b35584987e19539635a1ed23ca482a00149c609a23dc1645fd", 16); - BigInteger e = new BigInteger("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dc9f7", 16); - BigInteger d = new BigInteger("189d6345099098992e0c9ca5f281e1338092342fa0acc85cc2a111f30f9bd2fb4753cd1a48ef0ddca9bf1af33ec76fb2e23a9fb4896c26f2235b516f7c05ef7ae81e70f4b491a5fedba9b935e9c76d761a813ce7776ff8a1e5efe1166ff2eca26aa900da88c908d51af9de26977fe39719cc781df32216fa41b838f0c63803c3", 16); - - byte[] msg = Hex.decode("911475c6e210ef4ac65b6fe8d2bfe5e01b959771b137c4ef69b88716e0d2ff9ebc1fad0f358c1dd7d50cc99a7b893ac9a6207076f08d8467d9e48c69c683bfe64a44dabaa3f7c243880f6ab7229bf7bb587822314fc5de5131983bfb2eef8b4bc1eac36f353724b567cd1ae8cddd64ddb7057549d5c81ad5fa3b5e751f00abf5"); - byte[] sig = Hex.decode("02c50ec0ac8a7f38ef5630c396964d6a6daaa7e3083ab5b57fa2a2632f3b70e2e85c8456cd774d45d7e44fcb063f0f04fff9f1e3adfda11272535a92cb59320b190b5ee4261f23d6ceaa925df3a7bfa42e26bf61ea9645d9d64b3c90a820802768a6e209c9f83705375a3867afccc037e8242a98fa4c3db6b2d9877754d47289"); - - RSAKeyParameters rsaPublic = new RSAKeyParameters(false, n, e); - X931Signer signer = new X931Signer(new RSAEngine(), new SHA1Digest()); - - signer.init(true, new RSAKeyParameters(true, n, d)); - - signer.update(msg, 0, msg.length); - - byte[] s = signer.generateSignature(); - - if (!Arrays.areEqual(sig, s)) - { - fail("RSA X931 sig test 3 failed."); - } - - signer.init(false, rsaPublic); - - signer.update(msg, 0, msg.length); - - if (!signer.verifySignature(sig)) - { - fail("RSA X931 verify test 3 failed."); - } - } - - public static void main(String[] args) - { - runTest(new X931SignerTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/XSalsa20Test.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/XSalsa20Test.java deleted file mode 100644 index 47cfcd139..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/XSalsa20Test.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.XSalsa20Engine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -public class XSalsa20Test extends SimpleTest -{ - private static class TestCase - { - - private byte[] key; - private byte[] iv; - private byte[] plaintext; - private byte[] ciphertext; - - public TestCase(String key, String iv, String plaintext, String ciphertext) - { - this.key = Hex.decode(key); - this.iv = Hex.decode(iv); - this.plaintext = Hex.decode(plaintext); - this.ciphertext = Hex.decode(ciphertext); - } - - public byte[] getKey() - { - return key; - } - - public byte[] getIv() - { - return iv; - } - - public byte[] getPlaintext() - { - return plaintext; - } - - public byte[] getCiphertext() - { - return ciphertext; - } - } - - // Test cases generated by naclcrypto-20090308, as used by cryptopp - private static final TestCase[] TEST_CASES = new TestCase[] { - new TestCase( - "a6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff88030", - "9e645a74e9e0a60d8243acd9177ab51a1beb8d5a2f5d700c", - "093c5e5585579625337bd3ab619d615760d8c5b224a85b1d0efe0eb8a7ee163abb0376529fcc09bab506c618e13ce777d82c3ae9d1a6f972d4160287cbfe60bf2130fc0a6ff6049d0a5c8a82f429231f008082e845d7e189d37f9ed2b464e6b919e6523a8c1210bd52a02a4c3fe406d3085f5068d1909eeeca6369abc981a42e87fe665583f0ab85ae71f6f84f528e6b397af86f6917d9754b7320dbdc2fea81496f2732f532ac78c4e9c6cfb18f8e9bdf74622eb126141416776971a84f94d156beaf67aecbf2ad412e76e66e8fad7633f5b6d7f3d64b5c6c69ce29003c6024465ae3b89be78e915d88b4b5621d", - "b2af688e7d8fc4b508c05cc39dd583d6714322c64d7f3e63147aede2d9534934b04ff6f337b031815cd094bdbc6d7a92077dce709412286822ef0737ee47f6b7ffa22f9d53f11dd2b0a3bb9fc01d9a88f9d53c26e9365c2c3c063bc4840bfc812e4b80463e69d179530b25c158f543191cff993106511aa036043bbc75866ab7e34afc57e2cce4934a5faae6eabe4f221770183dd060467827c27a354159a081275a291f69d946d6fe28ed0b9ce08206cf484925a51b9498dbde178ddd3ae91a8581b91682d860f840782f6eea49dbb9bd721501d2c67122dea3b7283848c5f13e0c0de876bd227a856e4de593a3"), - new TestCase( - "9e1da239d155f52ad37f75c7368a536668b051952923ad44f57e75ab588e475a", - "af06f17859dffa799891c4288f6635b5c5a45eee9017fd72", - "feac9d54fc8c115ae247d9a7e919dd76cfcbc72d32cae4944860817cbdfb8c04e6b1df76a16517cd33ccf1acda9206389e9e318f5966c093cfb3ec2d9ee2de856437ed581f552f26ac2907609df8c613b9e33d44bfc21ff79153e9ef81a9d66cc317857f752cc175fd8891fefebb7d041e6517c3162d197e2112837d3bc4104312ad35b75ea686e7c70d4ec04746b52ff09c421451459fb59f", - "2c261a2f4e61a62e1b27689916bf03453fcbc97bb2af6f329391ef063b5a219bf984d07d70f602d85f6db61474e9d9f5a2deecb4fcd90184d16f3b5b5e168ee03ea8c93f3933a22bc3d1a5ae8c2d8b02757c87c073409052a2a8a41e7f487e041f9a49a0997b540e18621cad3a24f0a56d9b19227929057ab3ba950f6274b121f193e32e06e5388781a1cb57317c0ba6305e910961d01002f0"), - new TestCase("d5c7f6797b7e7e9c1d7fd2610b2abf2bc5a7885fb3ff78092fb3abe8986d35e2", - "744e17312b27969d826444640e9c4a378ae334f185369c95", - "7758298c628eb3a4b6963c5445ef66971222be5d1a4ad839715d1188071739b77cc6e05d5410f963a64167629757", - "27b8cfe81416a76301fd1eec6a4d99675069b2da2776c360db1bdfea7c0aa613913e10f7a60fec04d11e65f2d64e"), - new TestCase( - "737d7811ce96472efed12258b78122f11deaec8759ccbd71eac6bbefa627785c", - "6fb2ee3dda6dbd12f1274f126701ec75c35c86607adb3edd", - "501325fb2645264864df11faa17bbd58312b77cad3d94ac8fb8542f0eb653ad73d7fce932bb874cb89ac39fc47f8267cf0f0c209f204b2d8578a3bdf461cb6a271a468bebaccd9685014ccbc9a73618c6a5e778a21cc8416c60ad24ddc417a130d53eda6dfbfe47d09170a7be1a708b7b5f3ad464310be36d9a2a95dc39e83d38667e842eb6411e8a23712297b165f690c2d7ca1b1346e3c1fccf5cafd4f8be0", - "6724c372d2e9074da5e27a6c54b2d703dc1d4c9b1f8d90f00c122e692ace7700eadca942544507f1375b6581d5a8fb39981c1c0e6e1ff2140b082e9ec016fce141d5199647d43b0b68bfd0fea5e00f468962c7384dd6129aea6a3fdfe75abb210ed5607cef8fa0e152833d5ac37d52e557b91098a322e76a45bbbcf4899e790618aa3f4c2e5e0fc3de93269a577d77a5502e8ea02f717b1dd2df1ec69d8b61ca"), - new TestCase( - "760158da09f89bbab2c99e6997f9523a95fcef10239bcca2573b7105f6898d34", - "43636b2cc346fc8b7c85a19bf507bdc3dafe953b88c69dba", - "d30a6d42dff49f0ed039a306bae9dec8d9e88366cc19e8c3642fd58fa0794ebf8029d949730339b0823a51f0f49f0d2c71f1051c1e0e2c86941f172789cdb1b0107413e70f982ff9761877bb526ef1c3eb1106a948d60ef21bd35d32cfd64f89b79ed63ecc5cca56246af736766f285d8e6b0da9cb1cd21020223ffacc5a32", - "c815b6b79b64f9369aec8dce8c753df8a50f2bc97c70ce2f014db33a65ac5816bac9e30ac08bdded308c65cb87e28e2e71b677dc25c5a6499c1553555daf1f55270a56959dffa0c66f24e0af00951ec4bb59ccc3a6c5f52e0981647e53e439313a52c40fa7004c855b6e6eb25b212a138e843a9ba46edb2a039ee82a263abe"), - new TestCase( - "27ba7e81e7edd4e71be53c07ce8e633138f287e155c7fa9e84c4ad804b7fa1b9", - "ea05f4ebcd2fb6b000da0612861ba54ff5c176fb601391aa", - "e09ff5d2cb050d69b2d42494bde5825238c756d6991d99d7a20d1ef0b83c371c89872690b2fc11d5369f4fc4971b6d3d6c078aef9b0f05c0e61ab89c025168054defeb03fef633858700c58b1262ce011300012673e893e44901dc18eee3105699c44c805897bdaf776af1833162a21a", - "a23e7ef93c5d0667c96d9e404dcbe6be62026fa98f7a3ff9ba5d458643a16a1cef7272dc6097a9b52f35983557c77a11b314b4f7d5dc2cca15ee47616f861873cbfed1d32372171a61e38e447f3cf362b3abbb2ed4170d89dcb28187b7bfd206a3e026f084a7e0ed63d319de6bc9afc0"), - new TestCase("6799d76e5ffb5b4920bc2768bafd3f8c16554e65efcf9a16f4683a7a06927c11", - "61ab951921e54ff06d9b77f313a4e49df7a057d5fd627989", "472766", "8fd7df"), - new TestCase( - "f68238c08365bb293d26980a606488d09c2f109edafa0bbae9937b5cc219a49c", - "5190b51e9b708624820b5abdf4e40fad1fb950ad1adc2d26", - "47ec6b1f73c4b7ff5274a0bfd7f45f864812c85a12fbcb3c2cf8a3e90cf66ccf2eacb521e748363c77f52eb426ae57a0c6c78f75af71284569e79d1a92f949a9d69c4efc0b69902f1e36d7562765543e2d3942d9f6ff5948d8a312cff72c1afd9ea3088aff7640bfd265f7a9946e606abc77bcedae6bddc75a0dba0bd917d73e3bd1268f727e0096345da1ed25cf553ea7a98fea6b6f285732de37431561ee1b3064887fbcbd71935e02", - "36160e88d3500529ba4edba17bc24d8cfaca9a0680b3b1fc97cf03f3675b7ac301c883a68c071bc54acdd3b63af4a2d72f985e51f9d60a4c7fd481af10b2fc75e252fdee7ea6b6453190617dcc6e2fe1cd56585fc2f0b0e97c5c3f8ad7eb4f31bc4890c03882aac24cc53acc1982296526690a220271c2f6e326750d3fbda5d5b63512c831f67830f59ac49aae330b3e0e02c9ea0091d19841f1b0e13d69c9fbfe8a12d6f30bb734d9d2"), - new TestCase( - "45b2bd0de4ed9293ec3e26c4840faaf64b7d619d51e9d7a2c7e36c83d584c3df", - "546c8c5d6be8f90952cab3f36d7c1957baaa7a59abe3d7e5", - "5007c8cd5b3c40e17d7fe423a87ae0ced86bec1c39dc07a25772f3e96dabd56cd3fd7319f6c9654925f2d87087a700e1b130da796895d1c9b9acd62b266144067d373ed51e787498b03c52faad16bb3826fa511b0ed2a19a8663f5ba2d6ea7c38e7212e9697d91486c49d8a000b9a1935d6a7ff7ef23e720a45855481440463b4ac8c4f6e7062adc1f1e1e25d3d65a31812f58a71160", - "8eacfba568898b10c0957a7d44100685e8763a71a69a8d16bc7b3f88085bb9a2f09642e4d09a9f0ad09d0aad66b22610c8bd02ff6679bb92c2c026a216bf425c6be35fb8dae7ff0c72b0efd6a18037c70eed0ca90062a49a3c97fdc90a8f9c2ea536bfdc41918a7582c9927fae47efaa3dc87967b7887dee1bf071734c7665901d9105dae2fdf66b4918e51d8f4a48c60d19fbfbbcba"), - new TestCase( - "fe559c9a282beb40814d016d6bfcb2c0c0d8bf077b1110b8703a3ce39d70e0e1", - "b076200cc7011259805e18b304092754002723ebec5d6200", - "6db65b9ec8b114a944137c821fd606be75478d928366d5284096cdef782fcff7e8f59cb8ffcda979757902c5ffa6bc477ceaa4cb5d5ea76f94d91e833f823a6bc78f1055dfa6a97bea8965c1cde67a668e001257334a585727d9e0f7c1a06e88d3d25a4e6d9096c968bf138e116a3ebeffd4bb4808adb1fd698164ba0a35c709a47f16f1f4435a2345a9194a00b95abd51851d505809a6077da9baca5831afff31578c487ee68f2767974a98a7e803aac788da98319c4ea8eaa3d394855651f484cef543f537e35158ee29", - "4dce9c8f97a028051b0727f34e1b9ef21f06f0760f36e71713204027902090ba2bb6b13436ee778d9f50530efbd7a32b0d41443f58ccaee781c7b716d3a96fdec0e3764ed7959f34c3941278591ea033b5cbadc0f1916032e9bebbd1a8395b83fb63b1454bd775bd20b3a2a96f951246ac14daf68166ba62f6cbff8bd121ac9498ff8852fd2be975df52b5daef3829d18eda42e715022dcbf930d0a789ee6a146c2c7088c35773c63c06b4af4559856ac199ced86863e4294707825337c5857970eb7fddeb263781309011"), - new TestCase( - "0ae10012d7e56614b03dcc89b14bae9242ffe630f3d7e35ce8bbb97bbc2c92c3", - "f96b025d6cf46a8a12ac2af1e2aef1fb83590adadaa5c5ea", - "ea0f354e96f12bc72bbaa3d12b4a8ed879b042f0689878f46b651cc4116d6f78409b11430b3aaa30b2076891e8e1fa528f2fd169ed93dc9f84e24409eec2101daf4d057be2492d11de640cbd7b355ad29fb70400fffd7cd6d425abeeb732a0eaa4330af4c656252c4173deab653eb85c58462d7ab0f35fd12b613d29d473d330310dc323d3c66348bbdbb68a326324657cae7b77a9e34358f2cec50c85609e73056856796e3be8d62b6e2fe9f953", - "e8abd48924b54e5b80866be7d4ebe5cf4274cafff08b39cb2d40a8f0b472398aedc776e0793812fbf1f60078635d2ed86b15efcdba60411ee23b07233592a44ec31b1013ce8964236675f8f183aef885e864f2a72edf4215b5338fa2b54653dfa1a8c55ce5d95cc605b9b311527f2e3463ffbec78a9d1d65dabad2f338769c9f43f133a791a11c7eca9af0b771a4ac32963dc8f631a2c11217ac6e1b9430c1aae1ceebe22703f429998a8fb8c641"), - new TestCase( - "082c539bc5b20f97d767cd3f229eda80b2adc4fe49c86329b5cd6250a9877450", - "845543502e8b64912d8f2c8d9fffb3c69365686587c08d0c", - "a96bb7e910281a6dfad7c8a9c370674f0ceec1ad8d4f0de32f9ae4a23ed329e3d6bc708f876640a229153ac0e7281a8188dd77695138f01cda5f41d5215fd5c6bdd46d982cb73b1efe2997970a9fdbdb1e768d7e5db712068d8ba1af6067b5753495e23e6e1963af012f9c7ce450bf2de619d3d59542fb55f3", - "835da74fc6de08cbda277a7966a07c8dcd627e7b17adde6d930b6581e3124b8baad096f693991fedb1572930601fc7709541839b8e3ffd5f033d2060d999c6c6e3048276613e648000acb5212cc632a916afce290e20ebdf612d08a6aa4c79a74b070d3f872a861f8dc6bb07614db515d363349d3a8e3336a3"), - new TestCase("3d02bff3375d403027356b94f514203737ee9a85d2052db3e4e5a217c259d18a", - "74216c95031895f48c1dba651555ebfa3ca326a755237025", - "0d4b0f54fd09ae39baa5fa4baccf2e6682e61b257e01f42b8f", - "16c4006c28365190411eb1593814cf15e74c22238f210afc3d"), - new TestCase( - "ad1a5c47688874e6663a0f3fa16fa7efb7ecadc175c468e5432914bdb480ffc6", - "e489eed440f1aae1fac8fb7a9825635454f8f8f1f52e2fcc", - "aa6c1e53580f03a9abb73bfdadedfecada4c6b0ebe020ef10db745e54ba861caf65f0e40dfc520203bb54d29e0a8f78f16b3f1aa525d6bfa33c54726e59988cfbec78056", - "02fe84ce81e178e7aabdd3ba925a766c3c24756eefae33942af75e8b464556b5997e616f3f2dfc7fce91848afd79912d9fb55201b5813a5a074d2c0d4292c1fd441807c5"), - new TestCase( - "053a02bedd6368c1fb8afc7a1b199f7f7ea2220c9a4b642a6850091c9d20ab9c", - "c713eea5c26dad75ad3f52451e003a9cb0d649f917c89dde", - "8f0a8a164760426567e388840276de3f95cb5e3fadc6ed3f3e4fe8bc169d9388804dcb94b6587dbb66cb0bd5f87b8e98b52af37ba290629b858e0e2aa7378047a26602", - "516710e59843e6fbd4f25d0d8ca0ec0d47d39d125e9dad987e0518d49107014cb0ae405e30c2eb3794750bca142ce95e290cf95abe15e822823e2e7d3ab21bc8fbd445"), - new TestCase( - "5b14ab0fbed4c58952548a6cb1e0000cf4481421f41288ea0aa84add9f7deb96", - "54bf52b911231b952ba1a6af8e45b1c5a29d97e2abad7c83", - "37fb44a675978b560ff9a4a87011d6f3ad2d37a2c3815b45a3c0e6d1b1d8b1784cd468927c2ee39e1dccd4765e1c3d676a335be1ccd6900a45f5d41a317648315d8a8c24adc64eb285f6aeba05b9029586353d303f17a807658b9ff790474e1737bd5fdc604aeff8dfcaf1427dcc3aacbb0256badcd183ed75a2dc52452f87d3c1ed2aa583472b0ab91cda20614e9b6fdbda3b49b098c95823cc72d8e5b717f2314b0324e9ce", - "ae6deb5d6ce43d4b09d0e6b1c0e9f46157bcd8ab50eaa3197ff9fa2bf7af649eb52c68544fd3adfe6b1eb316f1f23538d470c30dbfec7e57b60cbcd096c782e7736b669199c8253e70214cf2a098fda8eac5da79a9496a3aae754d03b17c6d70d1027f42bf7f95ce3d1d9c338854e158fcc803e4d6262fb639521e47116ef78a7a437ca9427ba645cd646832feab822a208278e45e93e118d780b988d65397eddfd7a819526e"), - new TestCase( - "d74636e3413a88d85f322ca80fb0bd650bd0bf0134e2329160b69609cd58a4b0", - "efb606aa1d9d9f0f465eaa7f8165f1ac09f5cb46fecf2a57", - "f85471b75f6ec81abac2799ec09e98e280b2ffd64ca285e5a0109cfb31ffab2d617b2c2952a2a8a788fc0da2af7f530758f74f1ab56391ab5ff2adbcc5be2d6c7f49fbe8118104c6ff9a23c6dfe52f57954e6a69dcee5db06f514f4a0a572a9a8525d961dae72269b987189d465df6107119c7fa790853e063cba0fab7800ca932e258880fd74c33c784675bedad0e7c09e9cc4d63dd5e9713d5d4a0196e6b562226ac31b4f57c04f90a181973737ddc7e80f364112a9fbb435ebdbcabf7d490ce52", - "b2b795fe6c1d4c83c1327e015a67d4465fd8e32813575cbab263e20ef05864d2dc17e0e4eb81436adfe9f638dcc1c8d78f6b0306baf938e5d2ab0b3e05e735cc6fff2d6e02e3d60484bea7c7a8e13e23197fea7b04d47d48f4a4e5944174539492800d3ef51e2ee5e4c8a0bdf050c2dd3dd74fce5e7e5c37364f7547a11480a3063b9a0a157b15b10a5a954de2731ced055aa2e2767f0891d4329c426f3808ee867bed0dc75b5922b7cfb895700fda016105a4c7b7f0bb90f029f6bbcb04ac36ac16") }; - - public String getName() - { - return "XSalsa20"; - } - - public void performTest() throws Exception - { - for (int i = 0; i < TEST_CASES.length; i++) - { - performTest(i, TEST_CASES[i]); - } - } - - private void performTest(int number, TestCase testCase) - { - final byte[] plaintext = testCase.getPlaintext(); - byte[] output = new byte[plaintext.length]; - - XSalsa20Engine engine = new XSalsa20Engine(); - engine.init(false, new ParametersWithIV(new KeyParameter(testCase.getKey()), testCase.getIv())); - - engine.processBytes(testCase.getPlaintext(), 0, testCase.getPlaintext().length, output, 0); - - if (!Arrays.areEqual(testCase.getCiphertext(), output)) - { - fail("mismatch on " + number, new String(Hex.encode(testCase.getCiphertext())), - new String(Hex.encode(output))); - } - } - - public static void main(String[] args) - { - runTest(new XSalsa20Test()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/XTEATest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/XTEATest.java deleted file mode 100644 index 7f3ba4019..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/XTEATest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.engines.XTEAEngine; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * TEA tester - based on C implementation results from http://www.simonshepherd.supanet.com/tea.htm - */ -public class XTEATest - extends CipherTest -{ - static SimpleTest[] tests = { - new BlockCipherVectorTest(0, new XTEAEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "0000000000000000", - "dee9d4d8f7131ed9"), - new BlockCipherVectorTest(1, new XTEAEngine(), - new KeyParameter(Hex.decode("00000000000000000000000000000000")), - "0102030405060708", - "065c1b8975c6a816"), - new BlockCipherVectorTest(2, new XTEAEngine(), - new KeyParameter(Hex.decode("0123456712345678234567893456789A")), - "0000000000000000", - "1ff9a0261ac64264"), - new BlockCipherVectorTest(3, new XTEAEngine(), - new KeyParameter(Hex.decode("0123456712345678234567893456789A")), - "0102030405060708", - "8c67155b2ef91ead"), - }; - - XTEATest() - { - super(tests, new XTEAEngine(), new KeyParameter(new byte[16])); - } - - public String getName() - { - return "XTEA"; - } - - public static void main( - String[] args) - { - runTest(new XTEATest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ZucTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ZucTest.java deleted file mode 100644 index 4bfedf758..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/ZucTest.java +++ /dev/null @@ -1,497 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test; - -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.crypto.engines.Zuc128CoreEngine; -import com.fr.third.org.bouncycastle.crypto.engines.Zuc128Engine; -import com.fr.third.org.bouncycastle.crypto.engines.Zuc256CoreEngine; -import com.fr.third.org.bouncycastle.crypto.engines.Zuc256Engine; -import com.fr.third.org.bouncycastle.crypto.macs.Zuc128Mac; -import com.fr.third.org.bouncycastle.crypto.macs.Zuc256Mac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTest; - -/** - * Test Cases for Zuc128 and Zuc256. - * Test Vectors taken from https://www.gsma.com/aboutus/wp-content/uploads/2014/12/eea3eia3zucv16.pdf for Zuc128 - * and http://www.is.cas.cn/ztzl2016/zouchongzhi/201801/W020180126529970733243.pdf for Zuc256. - */ -public class ZucTest - extends SimpleTest -{ - private static final int INT_SIZE = 32; - private static final int BYTE_SIZE = 8; - - /** - * Test Keys and IV. - */ - private static final String KEY128_1 = - "00000000000000000000000000000000"; - private static final String KEY128_2 = - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; - private static final String KEY256_1 = - "00000000000000000000000000000000" + - "00000000000000000000000000000000"; - private static final String KEY256_2 = - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; - private static final String IV128_1 = "00000000000000000000000000000000"; - private static final String IV128_2 = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; - private static final String IV200_1 = "00000000000000000000000000000000000000000000000000"; - private static final String IV200_2 = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F3F3F3F3F3F3F"; - - /** - * Define the bit limits for engines. - */ - private static final int ZUC256LIMIT = 20000; - private static final int ZUC128LIMIT = 65504; - - public String getName() - { - return "Zuc"; - } - - public void performTest() - throws Exception - { - new Zuc128Test().testTheCipher(); - new Zuc256Test().testTheCipher(); - new Zuc128MacTest().testTheMac(); - new Zuc256Mac32Test().testTheMac(); - new Zuc256Mac64Test().testTheMac(); - new Zuc256Mac128Test().testTheMac(); - } - - /** - * The TestCase. - */ - private static class TestCase - { - /** - * The testCase. - */ - private final String theKey; - private final String theIV; - private final String thePlainText; - private final String theExpected; - - /** - * Constructor. - * - * @param pKey the key - * @param pIV the IV - * @param pExpected the expected results. - */ - TestCase(final String pKey, - final String pIV, - final String pExpected) - { - this(pKey, pIV, null, pExpected); - } - - /** - * Constructor. - * - * @param pKey the key - * @param pIV the IV - * @param pPlain the plainText - * @param pExpected the expected results. - */ - TestCase(final String pKey, - final String pIV, - final String pPlain, - final String pExpected) - { - theKey = pKey; - theIV = pIV; - thePlainText = pPlain; - theExpected = pExpected; - } - } - - /** - * Zuc128. - */ - class Zuc128Test - { - /** - * TestCases. - */ - private final TestCase TEST4 = new TestCase(KEY128_1, IV128_1, - "27bede74018082da87d4e5b69f18bf6632070e0f39b7b692b4673edc3184a48e27636f4414510d62cc15cfe194ec4f6d4b8c8fcc630648badf41b6f9d16a36ca" - ); - private final TestCase TEST5 = new TestCase(KEY128_2, IV128_2, - "0657cfa07096398b734b6cb4883eedf4257a76eb97595208d884adcdb1cbffb8e0f9d15846a0eed015328503351138f740d079af17296c232c4f022d6e4acac6" - ); - - /** - * Test cipher. - */ - void testTheCipher() - { - final Zuc128CoreEngine myEngine = new Zuc128Engine(); - testCipher(myEngine, TEST4); - testCipher(myEngine, TEST5); - testStreamLimit(myEngine, TEST5, ZUC128LIMIT); - } - } - - /** - * Zuc256. - */ - class Zuc256Test - { - /** - * TestCases. - */ - private final TestCase TEST4 = new TestCase(KEY256_1, IV200_1, - "58d03ad62e032ce2dafc683a39bdcb0352a2bc67f1b7de74163ce3a101ef55589639d75b95fa681b7f090df756391ccc903b7612744d544c17bc3fad8b163b08" - ); - private final TestCase TEST5 = new TestCase(KEY256_2, IV200_2, - "3356cbaed1a1c18b6baa4ffe343f777c9e15128f251ab65b949f7b26ef7157f296dd2fa9df95e3ee7a5be02ec32ba585505af316c2f9ded27cdbd935e441ce11" - ); - - /** - * Test cipher. - */ - void testTheCipher() - { - final Zuc256CoreEngine myEngine = new Zuc256Engine(); - testCipher(myEngine, TEST4); - testCipher(myEngine, TEST5); - testStreamLimit(myEngine, TEST5, ZUC256LIMIT); - } - } - - /** - * Zuc128Mac. - */ - class Zuc128MacTest - { - - /** - * TestCases. - */ - private final TestCase TEST1 = new TestCase(KEY128_1, IV128_1, - "508dd5ff" - ); - private final TestCase TEST2 = new TestCase(KEY128_1, IV128_1, - "fbed4c12" - ); - private final TestCase TEST3 = new TestCase(KEY128_2, IV128_2, - "55e01504" - ); - private final TestCase TEST4 = new TestCase(KEY128_2, IV128_2, - "9ce9a0c4" - ); - - /** - * Test Mac. - */ - void testTheMac() - { - final Zuc128Mac myMac = new Zuc128Mac(); - testMac(myMac, false, TEST1); - testMac(myMac, true, TEST2); - testMac(myMac, false, TEST3); - testMac(myMac, true, TEST4); - testMacLimit(myMac, TEST4, ZUC128LIMIT - (2 * INT_SIZE)); - - // reset without init(). - Zuc128Mac xMac = new Zuc128Mac(); - - xMac.reset(); - } - } - - /** - * Zuc256Mac32. - */ - class Zuc256Mac32Test - { - /** - * TestCases. - */ - private final TestCase TEST1 = new TestCase(KEY256_1, IV200_1, - "9b972a74" - ); - private final TestCase TEST2 = new TestCase(KEY256_1, IV200_1, - "8754f5cf" - ); - private final TestCase TEST3 = new TestCase(KEY256_2, IV200_2, - "1f3079b4" - ); - private final TestCase TEST4 = new TestCase(KEY256_2, IV200_2, - "5c7c8b88" - ); - - /** - * Test Mac. - */ - void testTheMac() - { - final Zuc256Mac myMac = new Zuc256Mac(32); - testMac(myMac, false, TEST1); - testMac(myMac, true, TEST2); - testMac(myMac, false, TEST3); - testMac(myMac, true, TEST4); - testMacLimit(myMac, TEST4, ZUC256LIMIT - (2 * myMac.getMacSize() * BYTE_SIZE)); - - // reset without init(). - Zuc256Mac xMac = new Zuc256Mac(32); - - xMac.reset(); - } - } - - /** - * Zuc256Mac64. - */ - class Zuc256Mac64Test - { - /** - * TestCases. - */ - private final TestCase TEST1 = new TestCase(KEY256_1, IV200_1, - "673e54990034d38c" - ); - private final TestCase TEST2 = new TestCase(KEY256_1, IV200_1, - "130dc225e72240cc" - ); - private final TestCase TEST3 = new TestCase(KEY256_2, IV200_2, - "8c71394d39957725" - ); - private final TestCase TEST4 = new TestCase(KEY256_2, IV200_2, - "ea1dee544bb6223b" - ); - - /** - * Test Mac. - */ - void testTheMac() - { - final Zuc256Mac myMac = new Zuc256Mac(64); - testMac(myMac, false, TEST1); - testMac(myMac, true, TEST2); - testMac(myMac, false, TEST3); - testMac(myMac, true, TEST4); - testMacLimit(myMac, TEST4, ZUC256LIMIT - (2 * myMac.getMacSize() * BYTE_SIZE)); - } - } - - /** - * Zuc256Mac128. - */ - class Zuc256Mac128Test - { - /** - * TestCases. - */ - private final TestCase TEST1 = new TestCase(KEY256_1, IV200_1, - "d85e54bbcb9600967084c952a1654b26" - ); - private final TestCase TEST2 = new TestCase(KEY256_1, IV200_1, - "df1e8307b31cc62beca1ac6f8190c22f" - ); - private final TestCase TEST3 = new TestCase(KEY256_2, IV200_2, - "a35bb274b567c48b28319f111af34fbd" - ); - private final TestCase TEST4 = new TestCase(KEY256_2, IV200_2, - "3a83b554be408ca5494124ed9d473205" - ); - - /** - * Test Mac. - */ - void testTheMac() - { - final Zuc256Mac myMac = new Zuc256Mac(128); - testMac(myMac, false, TEST1); - testMac(myMac, true, TEST2); - testMac(myMac, false, TEST3); - testMac(myMac, true, TEST4); - testMacLimit(myMac, TEST4, ZUC256LIMIT - (2 * myMac.getMacSize() * BYTE_SIZE)); - } - } - - /** - * Test the Cipher against the results. - * - * @param pCipher the cipher to test. - * @param pTestCase the testCase - */ - void testCipher(final StreamCipher pCipher, - final TestCase pTestCase) - { - /* Access the expected bytes */ - final byte[] myExpected = Hex.decode(pTestCase.theExpected); - - /* Create the output buffer */ - final byte[] myOutput = new byte[myExpected.length]; - - /* Access plainText or nulls */ - final byte[] myData = pTestCase.thePlainText != null - ? Hex.decode(pTestCase.thePlainText) - : new byte[myExpected.length]; - - /* Access the key and the iv */ - final KeyParameter myKey = new KeyParameter(Hex.decode(pTestCase.theKey)); - final byte[] myIV = Hex.decode(pTestCase.theIV); - final ParametersWithIV myParms = new ParametersWithIV(myKey, myIV); - - /* Initialise the cipher and create the keyStream */ - pCipher.init(true, myParms); - pCipher.processBytes(myData, 0, myData.length, myOutput, 0); - - /* Check the encryption */ - isTrue("Encryption mismatch", Arrays.areEqual(myExpected, myOutput)); - } - - /** - * Test the Mac against the results. - * - * @param pMac the mac to test. - * @param pOnes use all ones as data? - * @param pTestCase the testCase - */ - void testMac(final Mac pMac, - final boolean pOnes, - final TestCase pTestCase) - { - /* Access the expected bytes */ - final byte[] myExpected = Hex.decode(pTestCase.theExpected); - - /* Create the output buffer and the data */ - final byte[] myOutput = new byte[pMac.getMacSize()]; - final byte[] myData = new byte[(pOnes ? 4000 : 400) / 8]; - Arrays.fill(myData, (byte)(pOnes ? 0x11 : 0)); - - /* Access the key and the iv */ - final KeyParameter myKey = new KeyParameter(Hex.decode(pTestCase.theKey)); - final byte[] myIV = Hex.decode(pTestCase.theIV); - final ParametersWithIV myParms = new ParametersWithIV(myKey, myIV); - - /* Initialise the cipher and create the keyStream */ - pMac.init(myParms); - pMac.update(myData, 0, myData.length); - pMac.doFinal(myOutput, 0); - - /* Check the mac */ - isTrue("Mac mismatch", Arrays.areEqual(myExpected, myOutput)); - - /* Check doFinal reset */ - pMac.update(myData, 0, myData.length); - pMac.doFinal(myOutput, 0); - - isTrue("DoFinal Mac mismatch", Arrays.areEqual(myExpected, myOutput)); - - /* Check reset() */ - pMac.update(myData, 0, myData.length); - - pMac.reset(); - - pMac.update(myData, 0, myData.length); - pMac.doFinal(myOutput, 0); - - isTrue("Reset Mac mismatch", Arrays.areEqual(myExpected, myOutput)); - } - - /** - * Test the Stream Cipher against the limit. - * - * @param pCipher the cipher to test. - * @param pTestCase the testCase - * @param pLimit the limit in bits. - */ - void testStreamLimit(final StreamCipher pCipher, - final TestCase pTestCase, - final int pLimit) - { - /* Check the limit is a whole number of integers */ - isTrue("Invalid limit", (pLimit % INT_SIZE == 0)); - final int myNumBytes = pLimit / BYTE_SIZE; - - /* Create the maximum # of bytes */ - final byte[] myData = new byte[myNumBytes]; - final byte[] myOutput = new byte[myNumBytes]; - - /* Access the key and the iv */ - final KeyParameter myKey = new KeyParameter(Hex.decode(pTestCase.theKey)); - final byte[] myIV = Hex.decode(pTestCase.theIV); - final ParametersWithIV myParms = new ParametersWithIV(myKey, myIV); - - /* Initialise the cipher and create the keyStream */ - pCipher.init(true, myParms); - pCipher.processBytes(myData, 0, myData.length, myOutput, 0); - - /* Check that next encryption throws exception */ - try - { - pCipher.processBytes(myData, 0, 1, myOutput, 0); - fail("Limit Failure"); - } - catch (IllegalStateException e) - { - /* OK */ - } - } - - /** - * Test the Mac against the limit. - * - * @param pMac the mac to test. - * @param pTestCase the testCase - * @param pLimit the limit in bits. - */ - void testMacLimit(final Mac pMac, - final TestCase pTestCase, - final int pLimit) - { - /* Check the limit is a whole numbet of integers */ - isTrue("Invalid limit", (pLimit % INT_SIZE == 0)); - final int myNumBytes = pLimit / BYTE_SIZE; - - /* Create the maximum # of bytes */ - final byte[] myData = new byte[myNumBytes]; - final byte[] myOutput = new byte[myNumBytes]; - - /* Access the key and the iv */ - final KeyParameter myKey = new KeyParameter(Hex.decode(pTestCase.theKey)); - final byte[] myIV = Hex.decode(pTestCase.theIV); - final ParametersWithIV myParms = new ParametersWithIV(myKey, myIV); - - /* Initialise the mac and create the result */ - pMac.init(myParms); - pMac.update(myData, 0, myData.length); - pMac.doFinal(myOutput, 0); - - /* Initialise the mac and process as much data as possible */ - pMac.init(myParms); - pMac.update(myData, 0, myData.length); - - /* We expect a failure on processing a further byte */ - try - { - pMac.update(myData, 0, 1); - pMac.doFinal(myOutput, 0); - fail("Limit Failure"); - } - catch (IllegalStateException e) - { - /* OK */ - } - } - - /** - * Main entry point. - * - * @param args the argyments - */ - public static void main(String[] args) - { - runTest(new ZucTest()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/CAVPListener.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/CAVPListener.java deleted file mode 100644 index d9a4c60d0..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/CAVPListener.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test.cavp; - -import java.util.Properties; - -public interface CAVPListener -{ - public void setup(); - - public void receiveStart(String name); - - public void receiveCAVPVectors(String name, Properties config, Properties vectors); - - public void receiveCommentLine(String commentLine); - - public void receiveEnd(); - - public void tearDown(); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/CAVPReader.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/CAVPReader.java deleted file mode 100644 index ae7947e9c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/CAVPReader.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test.cavp; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.Reader; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA224Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA384Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512Digest; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESedeEngine; -import com.fr.third.org.bouncycastle.crypto.macs.CMac; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; - -public class CAVPReader -{ - - private static final Pattern COMMENT_PATTERN = Pattern.compile("^\\s*\\#\\s*(.*)$"); - private static final Pattern CONFIG_PATTERN = Pattern.compile("^\\s*+\\[\\s*+(.*?)\\s*+=\\s*+(.*?)\\s*+\\]\\s*+$"); - private static final Pattern VECTOR_PATTERN = Pattern.compile("^\\s*+(.*?)\\s*+=\\s*+(.*?)\\s*+$"); - private static final Pattern EMPTY_PATTERN = Pattern.compile("^\\s*+$"); - static final Pattern PATTERN_FOR_R = Pattern.compile("(\\d+)_BITS"); - private final CAVPListener listener; - private String name; - private BufferedReader lineReader; - - - public CAVPReader(CAVPListener listener) - { - this.listener = listener; - } - - public void setInput(String name, Reader reader) - { - this.name = name; - this.lineReader = new BufferedReader(reader); - } - - public void readAll() - throws IOException - { - - listener.setup(); - - Properties config = new Properties(); - - boolean startNewVector = true; - - Properties vectors = new Properties(); - - while (true) - { - final String line = lineReader.readLine(); - if (line == null) - { - listener.receiveEnd(); - break; - } - - final Matcher commentMatcher = COMMENT_PATTERN.matcher(line); - if (commentMatcher.matches()) - { - listener.receiveCommentLine(commentMatcher.group(1)); - continue; - } - - final Matcher configMatcher = CONFIG_PATTERN.matcher(line); - if (configMatcher.matches()) - { - config.put(configMatcher.group(1), configMatcher.group(2)); - continue; - } - - final Matcher vectorMatcher = VECTOR_PATTERN.matcher(line); - if (vectorMatcher.matches()) - { - vectors.put(vectorMatcher.group(1), vectorMatcher.group(2)); - startNewVector = false; - continue; - } - - final Matcher emptyMatcher = EMPTY_PATTERN.matcher(line); - if (emptyMatcher.matches()) - { - if (startNewVector) - { - continue; - } - - listener.receiveCAVPVectors(name, config, vectors); - vectors = new Properties(); - startNewVector = true; - } - } - - listener.tearDown(); - } - - static Mac createPRF(Properties config) - { - final Mac prf; - if (config.getProperty("PRF").matches("CMAC_AES\\d\\d\\d")) - { - BlockCipher blockCipher = new AESEngine(); - prf = new CMac(blockCipher); - } - else if (config.getProperty("PRF").matches("CMAC_TDES\\d")) - { - BlockCipher blockCipher = new DESedeEngine(); - prf = new CMac(blockCipher); - } - else if (config.getProperty("PRF").matches("HMAC_SHA1")) - { - Digest digest = new SHA1Digest(); - prf = new HMac(digest); - } - else if (config.getProperty("PRF").matches("HMAC_SHA224")) - { - Digest digest = new SHA224Digest(); - prf = new HMac(digest); - } - else if (config.getProperty("PRF").matches("HMAC_SHA256")) - { - Digest digest = new SHA256Digest(); - prf = new HMac(digest); - } - else if (config.getProperty("PRF").matches("HMAC_SHA384")) - { - Digest digest = new SHA384Digest(); - prf = new HMac(digest); - } - else if (config.getProperty("PRF").matches("HMAC_SHA512")) - { - Digest digest = new SHA512Digest(); - prf = new HMac(digest); - } - else - { - throw new IllegalStateException("Unknown Mac for PRF"); - } - return prf; - } - -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFCounterTests.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFCounterTests.java deleted file mode 100644 index 34e284e77..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFCounterTests.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test.cavp; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Properties; -import java.util.regex.Matcher; - -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.generators.KDFCounterBytesGenerator; -import com.fr.third.org.bouncycastle.crypto.params.KDFCounterParameters; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.TestFailedException; - -public final class KDFCounterTests - implements CAVPListener -{ - private PrintWriter out; - - public void receiveCAVPVectors(String name, Properties config, - Properties vectors) - { - - // create Mac based PRF from PRF property, create the KDF - final Mac prf = CAVPReader.createPRF(config); - final KDFCounterBytesGenerator gen = new KDFCounterBytesGenerator(prf); - - - Matcher matcherForR = CAVPReader.PATTERN_FOR_R.matcher(config.getProperty("RLEN")); - if (!matcherForR.matches()) - { - throw new IllegalStateException("RLEN value should always match"); - } - final int r = Integer.parseInt(matcherForR.group(1)); - - final int count = Integer.parseInt(vectors.getProperty("COUNT")); - final int l = Integer.parseInt(vectors.getProperty("L")); - final byte[] ki = Hex.decode(vectors.getProperty("KI")); - - //Three variants of this KDF are possible, with the counter before the fixed data, after the fixed data, or in the middle of the fixed data. - if (config.getProperty("CTRLOCATION").matches("BEFORE_FIXED")) - { - final byte[] fixedInputData = Hex.decode(vectors.getProperty("FixedInputData")); - final KDFCounterParameters params = new KDFCounterParameters(ki, null, fixedInputData, r); - gen.init(params); - } - else if (config.getProperty("CTRLOCATION").matches("AFTER_FIXED")) - { - final byte[] fixedInputData = Hex.decode(vectors.getProperty("FixedInputData")); - final KDFCounterParameters params = new KDFCounterParameters(ki, fixedInputData, null, r); - gen.init(params); - } - else if (config.getProperty("CTRLOCATION").matches("MIDDLE_FIXED")) - { - final byte[] DataBeforeCtrData = Hex.decode(vectors.getProperty("DataBeforeCtrData")); - final byte[] DataAfterCtrData = Hex.decode(vectors.getProperty("DataAfterCtrData")); - final KDFCounterParameters params = new KDFCounterParameters(ki, DataBeforeCtrData, DataAfterCtrData, r); - gen.init(params); - } - else - { - return; // Unknown CTRLOCATION - } - - - final byte[] koGenerated = new byte[l / 8]; - gen.generateBytes(koGenerated, 0, koGenerated.length); - - final byte[] koVectors = Hex.decode(vectors.getProperty("KO")); - - compareKO(name, config, count, koGenerated, koVectors); - } - - private static void compareKO( - String name, Properties config, int test, byte[] calculatedOKM, byte[] testOKM) - { - - if (!Arrays.areEqual(calculatedOKM, testOKM)) - { - throw new TestFailedException(new SimpleTestResult( - false, name + " using " + config + " test " + test + " failed")); - - } - } - - public void receiveCommentLine(String commentLine) - { - // out.println("# " + commentLine); - } - - public void receiveStart(String name) - { - // do nothing - } - - public void receiveEnd() - { - out.println(" *** *** *** "); - } - - public void setup() - { - try - { - out = new PrintWriter(new FileWriter("KDFCTR.gen")); - } - catch (IOException e) - { - throw new IllegalStateException(e); - } - } - - public void tearDown() - { - out.close(); - } -} \ No newline at end of file diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFDoublePipelineCounterTests.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFDoublePipelineCounterTests.java deleted file mode 100644 index e7fa9f6fa..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFDoublePipelineCounterTests.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test.cavp; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Properties; -import java.util.regex.Matcher; - -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.generators.KDFDoublePipelineIterationBytesGenerator; -import com.fr.third.org.bouncycastle.crypto.params.KDFDoublePipelineIterationParameters; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.TestFailedException; - -public final class KDFDoublePipelineCounterTests - implements CAVPListener -{ - private PrintWriter out; - - public void receiveCAVPVectors(String name, Properties config, - Properties vectors) - { - // out.println(" === " + name + " === "); - // out.println(" --- config --- "); - // out.println(config); - // out.println(" --- vectors --- "); - // out.println(vectors); - - // always skip AFTER_FIXED - if (!config.getProperty("CTRLOCATION").matches("AFTER_ITER")) - { - return; - } - - // create Mac based PRF from PRF property, create the KDF - final Mac prf = CAVPReader.createPRF(config); - final KDFDoublePipelineIterationBytesGenerator gen = new KDFDoublePipelineIterationBytesGenerator(prf); - - - Matcher matcherForR = CAVPReader.PATTERN_FOR_R.matcher(config.getProperty("RLEN")); - if (!matcherForR.matches()) - { - throw new IllegalStateException("RLEN value should always match"); - } - final int r = Integer.parseInt(matcherForR.group(1)); - - final int count = Integer.parseInt(vectors.getProperty("COUNT")); - final int l = Integer.parseInt(vectors.getProperty("L")); - final byte[] ki = Hex.decode(vectors.getProperty("KI")); - final byte[] fixedInputData = Hex.decode(vectors.getProperty("FixedInputData")); - final KDFDoublePipelineIterationParameters params = KDFDoublePipelineIterationParameters.createWithCounter(ki, fixedInputData, r); - gen.init(params); - - final byte[] koGenerated = new byte[l / 8]; - gen.generateBytes(koGenerated, 0, koGenerated.length); - - final byte[] koVectors = Hex.decode(vectors.getProperty("KO")); - - compareKO(name, config, count, koGenerated, koVectors); - } - - private static void compareKO( - String name, Properties config, int test, byte[] calculatedOKM, byte[] testOKM) - { - - if (!Arrays.areEqual(calculatedOKM, testOKM)) - { - throw new TestFailedException(new SimpleTestResult( - false, name + " using " + config + " test " + test + " failed")); - - } - } - - public void receiveCommentLine(String commentLine) - { - // out.println("# " + commentLine); - } - - public void receiveStart(String name) - { - // do nothing - } - - public void receiveEnd() - { - out.println(" *** *** *** "); - } - - public void setup() - { - try - { - out = new PrintWriter(new FileWriter("KDFDblPipelineCounter.gen")); - } - catch (IOException e) - { - throw new IllegalStateException(e); - } - } - - public void tearDown() - { - out.close(); - } -} \ No newline at end of file diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFDoublePipelineIterationNoCounterTests.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFDoublePipelineIterationNoCounterTests.java deleted file mode 100644 index 36ead842b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFDoublePipelineIterationNoCounterTests.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test.cavp; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Properties; - -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.generators.KDFDoublePipelineIterationBytesGenerator; -import com.fr.third.org.bouncycastle.crypto.params.KDFDoublePipelineIterationParameters; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.TestFailedException; - -public final class KDFDoublePipelineIterationNoCounterTests - implements CAVPListener -{ - private PrintWriter out; - - public void receiveCAVPVectors(String name, Properties config, - Properties vectors) - { - - - // create Mac based PRF from PRF property, create the KDF - final Mac prf = CAVPReader.createPRF(config); - final KDFDoublePipelineIterationBytesGenerator gen = new KDFDoublePipelineIterationBytesGenerator(prf); - - final int count = Integer.parseInt(vectors.getProperty("COUNT")); - final int l = Integer.parseInt(vectors.getProperty("L")); - final byte[] ki = Hex.decode(vectors.getProperty("KI")); - final byte[] fixedInputData = Hex.decode(vectors.getProperty("FixedInputData")); - final KDFDoublePipelineIterationParameters params = KDFDoublePipelineIterationParameters.createWithoutCounter(ki, fixedInputData); - gen.init(params); - - final byte[] koGenerated = new byte[l / 8]; - gen.generateBytes(koGenerated, 0, koGenerated.length); - - final byte[] koVectors = Hex.decode(vectors.getProperty("KO")); - - compareKO(name, config, count, koGenerated, koVectors); - } - - private static void compareKO( - String name, Properties config, int test, byte[] calculatedOKM, byte[] testOKM) - { - - if (!Arrays.areEqual(calculatedOKM, testOKM)) - { - throw new TestFailedException(new SimpleTestResult( - false, name + " using " + config + " test " + test + " failed")); - - } - } - - public void receiveCommentLine(String commentLine) - { - // out.println("# " + commentLine); - } - - public void receiveStart(String name) - { - // do nothing - } - - public void receiveEnd() - { - out.println(" *** *** *** "); - } - - public void setup() - { - try - { - out = new PrintWriter(new FileWriter("KDFDblPipelineNoCounter.gen")); - } - catch (IOException e) - { - throw new IllegalStateException(e); - } - } - - public void tearDown() - { - out.close(); - } -} \ No newline at end of file diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFFeedbackCounterTests.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFFeedbackCounterTests.java deleted file mode 100644 index ad7165837..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFFeedbackCounterTests.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test.cavp; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Properties; -import java.util.regex.Matcher; - -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.generators.KDFFeedbackBytesGenerator; -import com.fr.third.org.bouncycastle.crypto.params.KDFFeedbackParameters; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.TestFailedException; - -public final class KDFFeedbackCounterTests - implements CAVPListener -{ - private PrintWriter out; - - public void receiveCAVPVectors(String name, Properties config, - Properties vectors) - { - // out.println(" === " + name + " === "); - // out.println(" --- config --- "); - // out.println(config); - // out.println(" --- vectors --- "); - // out.println(vectors); - - // always skip AFTER_FIXED - if (!config.getProperty("CTRLOCATION").matches("AFTER_ITER")) - { - return; - } - - // create Mac based PRF from PRF property, create the KDF - final Mac prf = CAVPReader.createPRF(config); - final KDFFeedbackBytesGenerator gen = new KDFFeedbackBytesGenerator(prf); - - - Matcher matcherForR = CAVPReader.PATTERN_FOR_R.matcher(config.getProperty("RLEN")); - if (!matcherForR.matches()) - { - throw new IllegalStateException("RLEN value should always match"); - } - final int r = Integer.parseInt(matcherForR.group(1)); - - final int count = Integer.parseInt(vectors.getProperty("COUNT")); - final int l = Integer.parseInt(vectors.getProperty("L")); - final byte[] ki = Hex.decode(vectors.getProperty("KI")); - final byte[] iv = Hex.decode(vectors.getProperty("IV")); - final byte[] fixedInputData = Hex.decode(vectors.getProperty("FixedInputData")); - final KDFFeedbackParameters params = KDFFeedbackParameters.createWithCounter(ki, iv, fixedInputData, r); - gen.init(params); - - final byte[] koGenerated = new byte[l / 8]; - gen.generateBytes(koGenerated, 0, koGenerated.length); - - final byte[] koVectors = Hex.decode(vectors.getProperty("KO")); - - compareKO(name, config, count, koGenerated, koVectors); - } - - private static void compareKO( - String name, Properties config, int test, byte[] calculatedOKM, byte[] testOKM) - { - - if (!Arrays.areEqual(calculatedOKM, testOKM)) - { - throw new TestFailedException(new SimpleTestResult( - false, name + " using " + config + " test " + test + " failed")); - - } - } - - public void receiveCommentLine(String commentLine) - { - // out.println("# " + commentLine); - } - - public void receiveStart(String name) - { - // do nothing - } - - public void receiveEnd() - { - out.println(" *** *** *** "); - } - - public void setup() - { - try - { - out = new PrintWriter(new FileWriter("KDFFeedbackCounter.gen")); - } - catch (IOException e) - { - throw new IllegalStateException(e); - } - } - - public void tearDown() - { - out.close(); - } -} \ No newline at end of file diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFFeedbackNoCounterTests.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFFeedbackNoCounterTests.java deleted file mode 100644 index 946adb49d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/cavp/KDFFeedbackNoCounterTests.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.test.cavp; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Properties; - -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.generators.KDFFeedbackBytesGenerator; -import com.fr.third.org.bouncycastle.crypto.params.KDFFeedbackParameters; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.test.SimpleTestResult; -import com.fr.third.org.bouncycastle.util.test.TestFailedException; - -public final class KDFFeedbackNoCounterTests - implements CAVPListener -{ - private PrintWriter out; - - public void receiveCAVPVectors(String name, Properties config, - Properties vectors) - { - - - // create Mac based PRF from PRF property, create the KDF - final Mac prf = CAVPReader.createPRF(config); - final KDFFeedbackBytesGenerator gen = new KDFFeedbackBytesGenerator(prf); - - final int count = Integer.parseInt(vectors.getProperty("COUNT")); - final int l = Integer.parseInt(vectors.getProperty("L")); - final byte[] ki = Hex.decode(vectors.getProperty("KI")); - final byte[] iv = Hex.decode(vectors.getProperty("IV")); - final byte[] fixedInputData = Hex.decode(vectors.getProperty("FixedInputData")); - final KDFFeedbackParameters params = KDFFeedbackParameters.createWithoutCounter(ki, iv, fixedInputData); - gen.init(params); - - final byte[] koGenerated = new byte[l / 8]; - gen.generateBytes(koGenerated, 0, koGenerated.length); - - final byte[] koVectors = Hex.decode(vectors.getProperty("KO")); - - compareKO(name, config, count, koGenerated, koVectors); - } - - private static void compareKO( - String name, Properties config, int test, byte[] calculatedOKM, byte[] testOKM) - { - - if (!Arrays.areEqual(calculatedOKM, testOKM)) - { - throw new TestFailedException(new SimpleTestResult( - false, name + " using " + config + " test " + test + " failed")); - - } - } - - public void receiveCommentLine(String commentLine) - { -// out.println("# " + commentLine); - } - - public void receiveStart(String name) - { - // do nothing - } - - public void receiveEnd() - { - out.println(" *** *** *** "); - } - - public void setup() - { - try - { - out = new PrintWriter(new FileWriter("KDFFeedbackNoCounter.gen")); - } - catch (IOException e) - { - throw new IllegalStateException(e); - } - } - - public void tearDown() - { - out.close(); - } -} \ No newline at end of file diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/package.html deleted file mode 100644 index 7bb5e6b1a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/test/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Example code and test classes for the lightweight API. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsAgreementCredentials.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsAgreementCredentials.java deleted file mode 100644 index 26953b5c1..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsAgreementCredentials.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class AbstractTlsAgreementCredentials - extends AbstractTlsCredentials - implements TlsAgreementCredentials -{ -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsCipherFactory.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsCipherFactory.java deleted file mode 100644 index 2718b8919..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsCipherFactory.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class AbstractTlsCipherFactory - implements TlsCipherFactory -{ - public TlsCipher createCipher(TlsContext context, int encryptionAlgorithm, int macAlgorithm) - throws IOException - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsClient.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsClient.java deleted file mode 100644 index 323bb3460..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsClient.java +++ /dev/null @@ -1,269 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.util.Hashtable; -import java.util.Vector; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class AbstractTlsClient - extends AbstractTlsPeer - implements TlsClient -{ - protected TlsCipherFactory cipherFactory; - - protected TlsClientContext context; - - protected Vector supportedSignatureAlgorithms; - protected int[] namedCurves; - protected short[] clientECPointFormats, serverECPointFormats; - - protected int selectedCipherSuite; - protected short selectedCompressionMethod; - - public AbstractTlsClient() - { - this(new DefaultTlsCipherFactory()); - } - - public AbstractTlsClient(TlsCipherFactory cipherFactory) - { - this.cipherFactory = cipherFactory; - } - - protected boolean allowUnexpectedServerExtension(Integer extensionType, byte[] extensionData) - throws IOException - { - switch (extensionType.intValue()) - { - case ExtensionType.elliptic_curves: - /* - * Exception added based on field reports that some servers do send this, although the - * Supported Elliptic Curves Extension is clearly intended to be client-only. If - * present, we still require that it is a valid EllipticCurveList. - */ - TlsECCUtils.readSupportedEllipticCurvesExtension(extensionData); - return true; - - case ExtensionType.ec_point_formats: - /* - * Exception added based on field reports that some servers send this even when they - * didn't negotiate an ECC cipher suite. If present, we still require that it is a valid - * ECPointFormatList. - */ - TlsECCUtils.readSupportedPointFormatsExtension(extensionData); - return true; - - default: - return false; - } - } - - protected void checkForUnexpectedServerExtension(Hashtable serverExtensions, Integer extensionType) - throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(serverExtensions, extensionType); - if (extensionData != null && !allowUnexpectedServerExtension(extensionType, extensionData)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - - public void init(TlsClientContext context) - { - this.context = context; - } - - public TlsSession getSessionToResume() - { - return null; - } - - public ProtocolVersion getClientHelloRecordLayerVersion() - { - // "{03,00}" - // return ProtocolVersion.SSLv3; - - // "the lowest version number supported by the client" - // return getMinimumVersion(); - - // "the value of ClientHello.client_version" - return getClientVersion(); - } - - public ProtocolVersion getClientVersion() - { - return ProtocolVersion.TLSv12; - } - - public boolean isFallback() - { - /* - * RFC 7507 4. The TLS_FALLBACK_SCSV cipher suite value is meant for use by clients that - * repeat a connection attempt with a downgraded protocol (perform a "fallback retry") in - * order to work around interoperability problems with legacy servers. - */ - return false; - } - - public Hashtable getClientExtensions() - throws IOException - { - Hashtable clientExtensions = null; - - ProtocolVersion clientVersion = context.getClientVersion(); - - /* - * RFC 5246 7.4.1.4.1. Note: this extension is not meaningful for TLS versions prior to 1.2. - * Clients MUST NOT offer it if they are offering prior versions. - */ - if (TlsUtils.isSignatureAlgorithmsExtensionAllowed(clientVersion)) - { - // TODO Provide a way for the user to specify the acceptable hash/signature algorithms. - - this.supportedSignatureAlgorithms = TlsUtils.getDefaultSupportedSignatureAlgorithms(); - - clientExtensions = TlsExtensionsUtils.ensureExtensionsInitialised(clientExtensions); - - TlsUtils.addSignatureAlgorithmsExtension(clientExtensions, supportedSignatureAlgorithms); - } - - if (TlsECCUtils.containsECCCipherSuites(getCipherSuites())) - { - /* - * RFC 4492 5.1. A client that proposes ECC cipher suites in its ClientHello message - * appends these extensions (along with any others), enumerating the curves it supports - * and the point formats it can parse. Clients SHOULD send both the Supported Elliptic - * Curves Extension and the Supported Point Formats Extension. - */ - /* - * TODO Could just add all the curves since we support them all, but users may not want - * to use unnecessarily large fields. Need configuration options. - */ - this.namedCurves = new int[]{ NamedCurve.secp256r1, NamedCurve.secp384r1 }; - this.clientECPointFormats = new short[]{ ECPointFormat.uncompressed, - ECPointFormat.ansiX962_compressed_prime, ECPointFormat.ansiX962_compressed_char2, }; - - clientExtensions = TlsExtensionsUtils.ensureExtensionsInitialised(clientExtensions); - - TlsECCUtils.addSupportedEllipticCurvesExtension(clientExtensions, namedCurves); - TlsECCUtils.addSupportedPointFormatsExtension(clientExtensions, clientECPointFormats); - } - - return clientExtensions; - } - - public ProtocolVersion getMinimumVersion() - { - return ProtocolVersion.TLSv10; - } - - public void notifyServerVersion(ProtocolVersion serverVersion) - throws IOException - { - if (!getMinimumVersion().isEqualOrEarlierVersionOf(serverVersion)) - { - throw new TlsFatalAlert(AlertDescription.protocol_version); - } - } - - public short[] getCompressionMethods() - { - return new short[]{CompressionMethod._null}; - } - - public void notifySessionID(byte[] sessionID) - { - // Currently ignored - } - - public void notifySelectedCipherSuite(int selectedCipherSuite) - { - this.selectedCipherSuite = selectedCipherSuite; - } - - public void notifySelectedCompressionMethod(short selectedCompressionMethod) - { - this.selectedCompressionMethod = selectedCompressionMethod; - } - - public void processServerExtensions(Hashtable serverExtensions) - throws IOException - { - /* - * TlsProtocol implementation validates that any server extensions received correspond to - * client extensions sent. By default, we don't send any, and this method is not called. - */ - if (serverExtensions != null) - { - /* - * RFC 5246 7.4.1.4.1. Servers MUST NOT send this extension. - */ - checkForUnexpectedServerExtension(serverExtensions, TlsUtils.EXT_signature_algorithms); - - checkForUnexpectedServerExtension(serverExtensions, TlsECCUtils.EXT_elliptic_curves); - - if (TlsECCUtils.isECCCipherSuite(this.selectedCipherSuite)) - { - this.serverECPointFormats = TlsECCUtils.getSupportedPointFormatsExtension(serverExtensions); - } - else - { - checkForUnexpectedServerExtension(serverExtensions, TlsECCUtils.EXT_ec_point_formats); - } - - /* - * RFC 7685 3. The server MUST NOT echo the extension. - */ - checkForUnexpectedServerExtension(serverExtensions, TlsExtensionsUtils.EXT_padding); - } - } - - public void processServerSupplementalData(Vector serverSupplementalData) - throws IOException - { - if (serverSupplementalData != null) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - - public Vector getClientSupplementalData() - throws IOException - { - return null; - } - - public TlsCompression getCompression() - throws IOException - { - switch (selectedCompressionMethod) - { - case CompressionMethod._null: - return new TlsNullCompression(); - - default: - /* - * Note: internal error here; the TlsProtocol implementation verifies that the - * server-selected compression method was in the list of client-offered compression - * methods, so if we now can't produce an implementation, we shouldn't have offered it! - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public TlsCipher getCipher() - throws IOException - { - int encryptionAlgorithm = TlsUtils.getEncryptionAlgorithm(selectedCipherSuite); - int macAlgorithm = TlsUtils.getMACAlgorithm(selectedCipherSuite); - - return cipherFactory.createCipher(context, encryptionAlgorithm, macAlgorithm); - } - - public void notifyNewSessionTicket(NewSessionTicket newSessionTicket) - throws IOException - { - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsContext.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsContext.java deleted file mode 100644 index 92b46d03f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsContext.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.prng.DigestRandomGenerator; -import com.fr.third.org.bouncycastle.crypto.prng.RandomGenerator; -import com.fr.third.org.bouncycastle.util.Times; - -abstract class AbstractTlsContext - implements TlsContext -{ - private static long counter = Times.nanoTime(); - - private synchronized static long nextCounterValue() - { - return ++counter; - } - - private RandomGenerator nonceRandom; - private SecureRandom secureRandom; - private SecurityParameters securityParameters; - - private ProtocolVersion clientVersion = null; - private ProtocolVersion serverVersion = null; - private TlsSession session = null; - private Object userObject = null; - - AbstractTlsContext(SecureRandom secureRandom, SecurityParameters securityParameters) - { - Digest d = TlsUtils.createHash(HashAlgorithm.sha256); - byte[] seed = new byte[d.getDigestSize()]; - secureRandom.nextBytes(seed); - - this.nonceRandom = new DigestRandomGenerator(d); - nonceRandom.addSeedMaterial(nextCounterValue()); - nonceRandom.addSeedMaterial(Times.nanoTime()); - nonceRandom.addSeedMaterial(seed); - - this.secureRandom = secureRandom; - this.securityParameters = securityParameters; - } - - public RandomGenerator getNonceRandomGenerator() - { - return nonceRandom; - } - - public SecureRandom getSecureRandom() - { - return secureRandom; - } - - public SecurityParameters getSecurityParameters() - { - return securityParameters; - } - - public ProtocolVersion getClientVersion() - { - return clientVersion; - } - - void setClientVersion(ProtocolVersion clientVersion) - { - this.clientVersion = clientVersion; - } - - public ProtocolVersion getServerVersion() - { - return serverVersion; - } - - void setServerVersion(ProtocolVersion serverVersion) - { - this.serverVersion = serverVersion; - } - - public TlsSession getResumableSession() - { - return session; - } - - void setResumableSession(TlsSession session) - { - this.session = session; - } - - public Object getUserObject() - { - return userObject; - } - - public void setUserObject(Object userObject) - { - this.userObject = userObject; - } - - public byte[] exportKeyingMaterial(String asciiLabel, byte[] context_value, int length) - { - if (context_value != null && !TlsUtils.isValidUint16(context_value.length)) - { - throw new IllegalArgumentException("'context_value' must have length less than 2^16 (or be null)"); - } - - SecurityParameters sp = getSecurityParameters(); - if (!sp.isExtendedMasterSecret()) - { - /* - * RFC 7627 5.4. If a client or server chooses to continue with a full handshake without - * the extended master secret extension, [..] the client or server MUST NOT export any - * key material based on the new master secret for any subsequent application-level - * authentication. In particular, it MUST disable [RFC5705] [..]. - */ - throw new IllegalStateException("cannot export keying material without extended_master_secret"); - } - - byte[] cr = sp.getClientRandom(), sr = sp.getServerRandom(); - - int seedLength = cr.length + sr.length; - if (context_value != null) - { - seedLength += (2 + context_value.length); - } - - byte[] seed = new byte[seedLength]; - int seedPos = 0; - - System.arraycopy(cr, 0, seed, seedPos, cr.length); - seedPos += cr.length; - System.arraycopy(sr, 0, seed, seedPos, sr.length); - seedPos += sr.length; - if (context_value != null) - { - TlsUtils.writeUint16(context_value.length, seed, seedPos); - seedPos += 2; - System.arraycopy(context_value, 0, seed, seedPos, context_value.length); - seedPos += context_value.length; - } - - if (seedPos != seedLength) - { - throw new IllegalStateException("error in calculation of seed for export"); - } - - return TlsUtils.PRF(this, sp.getMasterSecret(), asciiLabel, seed, length); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsCredentials.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsCredentials.java deleted file mode 100644 index 040bcb88c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsCredentials.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class AbstractTlsCredentials - implements TlsCredentials -{ -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsEncryptionCredentials.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsEncryptionCredentials.java deleted file mode 100644 index d5250301d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsEncryptionCredentials.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class AbstractTlsEncryptionCredentials - extends AbstractTlsCredentials - implements TlsEncryptionCredentials -{ -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsKeyExchange.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsKeyExchange.java deleted file mode 100644 index 2147196b3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsKeyExchange.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Vector; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class AbstractTlsKeyExchange - implements TlsKeyExchange -{ - protected int keyExchange; - protected Vector supportedSignatureAlgorithms; - - protected TlsContext context; - - protected AbstractTlsKeyExchange(int keyExchange, Vector supportedSignatureAlgorithms) - { - this.keyExchange = keyExchange; - this.supportedSignatureAlgorithms = supportedSignatureAlgorithms; - } - - protected DigitallySigned parseSignature(InputStream input) throws IOException - { - DigitallySigned signature = DigitallySigned.parse(context, input); - SignatureAndHashAlgorithm signatureAlgorithm = signature.getAlgorithm(); - if (signatureAlgorithm != null) - { - TlsUtils.verifySupportedSignatureAlgorithm(supportedSignatureAlgorithms, signatureAlgorithm); - } - return signature; - } - - public void init(TlsContext context) - { - this.context = context; - - ProtocolVersion clientVersion = context.getClientVersion(); - - if (TlsUtils.isSignatureAlgorithmsExtensionAllowed(clientVersion)) - { - /* - * RFC 5246 7.4.1.4.1. If the client does not send the signature_algorithms extension, - * the server MUST do the following: - * - * - If the negotiated key exchange algorithm is one of (RSA, DHE_RSA, DH_RSA, RSA_PSK, - * ECDH_RSA, ECDHE_RSA), behave as if client had sent the value {sha1,rsa}. - * - * - If the negotiated key exchange algorithm is one of (DHE_DSS, DH_DSS), behave as if - * the client had sent the value {sha1,dsa}. - * - * - If the negotiated key exchange algorithm is one of (ECDH_ECDSA, ECDHE_ECDSA), - * behave as if the client had sent value {sha1,ecdsa}. - */ - if (this.supportedSignatureAlgorithms == null) - { - switch (keyExchange) - { - case KeyExchangeAlgorithm.DH_DSS: - case KeyExchangeAlgorithm.DHE_DSS: - case KeyExchangeAlgorithm.SRP_DSS: - { - this.supportedSignatureAlgorithms = TlsUtils.getDefaultDSSSignatureAlgorithms(); - break; - } - - case KeyExchangeAlgorithm.ECDH_ECDSA: - case KeyExchangeAlgorithm.ECDHE_ECDSA: - { - this.supportedSignatureAlgorithms = TlsUtils.getDefaultECDSASignatureAlgorithms(); - break; - } - - case KeyExchangeAlgorithm.DH_RSA: - case KeyExchangeAlgorithm.DHE_RSA: - case KeyExchangeAlgorithm.ECDH_RSA: - case KeyExchangeAlgorithm.ECDHE_RSA: - case KeyExchangeAlgorithm.RSA: - case KeyExchangeAlgorithm.RSA_PSK: - case KeyExchangeAlgorithm.SRP_RSA: - { - this.supportedSignatureAlgorithms = TlsUtils.getDefaultRSASignatureAlgorithms(); - break; - } - - case KeyExchangeAlgorithm.DHE_PSK: - case KeyExchangeAlgorithm.ECDHE_PSK: - case KeyExchangeAlgorithm.PSK: - case KeyExchangeAlgorithm.SRP: - break; - - default: - throw new IllegalStateException("unsupported key exchange algorithm"); - } - } - } - else if (this.supportedSignatureAlgorithms != null) - { - throw new IllegalStateException("supported_signature_algorithms not allowed for " + clientVersion); - } - } - - public void processServerCertificate(Certificate serverCertificate) - throws IOException - { - if (supportedSignatureAlgorithms == null) - { - /* - * TODO RFC 2246 7.4.2. Unless otherwise specified, the signing algorithm for the - * certificate must be the same as the algorithm for the certificate key. - */ - } - else - { - /* - * TODO RFC 5246 7.4.2. If the client provided a "signature_algorithms" extension, then - * all certificates provided by the server MUST be signed by a hash/signature algorithm - * pair that appears in that extension. - */ - } - } - - public void processServerCredentials(TlsCredentials serverCredentials) - throws IOException - { - processServerCertificate(serverCredentials.getCertificate()); - } - - public boolean requiresServerKeyExchange() - { - return false; - } - - public byte[] generateServerKeyExchange() - throws IOException - { - if (requiresServerKeyExchange()) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - return null; - } - - public void skipServerKeyExchange() - throws IOException - { - if (requiresServerKeyExchange()) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - - public void processServerKeyExchange(InputStream input) - throws IOException - { - if (!requiresServerKeyExchange()) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - - public void skipClientCredentials() - throws IOException - { - } - - public void processClientCertificate(Certificate clientCertificate) - throws IOException - { - } - - public void processClientKeyExchange(InputStream input) - throws IOException - { - // Key exchange implementation MUST support client key exchange - throw new TlsFatalAlert(AlertDescription.internal_error); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsPeer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsPeer.java deleted file mode 100644 index cae77e1ea..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsPeer.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class AbstractTlsPeer - implements TlsPeer -{ - private volatile TlsCloseable closeHandle; - - public void cancel() throws IOException - { - TlsCloseable closeHandle = this.closeHandle; - if (null != closeHandle) - { - closeHandle.close(); - } - } - - public void notifyCloseHandle(TlsCloseable closeHandle) - { - this.closeHandle = closeHandle; - } - - public boolean requiresExtendedMasterSecret() - { - return false; - } - - public boolean shouldUseGMTUnixTime() - { - /* - * draft-mathewson-no-gmtunixtime-00 2. For the reasons we discuss above, we recommend that - * TLS implementors MUST by default set the entire value the ClientHello.Random and - * ServerHello.Random fields, including gmt_unix_time, to a cryptographically random - * sequence. - */ - return false; - } - - public void notifySecureRenegotiation(boolean secureRenegotiation) throws IOException - { - if (!secureRenegotiation) - { - /* - * RFC 5746 3.4/3.6. In this case, some clients/servers may want to terminate the handshake instead - * of continuing; see Section 4.1/4.3 for discussion. - */ - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - } - - public void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) - { - } - - public void notifyAlertReceived(short alertLevel, short alertDescription) - { - } - - public void notifyHandshakeComplete() throws IOException - { - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsServer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsServer.java deleted file mode 100644 index 9b7dc0b30..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsServer.java +++ /dev/null @@ -1,374 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.util.Hashtable; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class AbstractTlsServer - extends AbstractTlsPeer - implements TlsServer -{ - protected TlsCipherFactory cipherFactory; - - protected TlsServerContext context; - - protected ProtocolVersion clientVersion; - protected int[] offeredCipherSuites; - protected short[] offeredCompressionMethods; - protected Hashtable clientExtensions; - - protected boolean encryptThenMACOffered; - protected short maxFragmentLengthOffered; - protected boolean truncatedHMacOffered; - protected Vector supportedSignatureAlgorithms; - protected boolean eccCipherSuitesOffered; - protected int[] namedCurves; - protected short[] clientECPointFormats, serverECPointFormats; - - protected ProtocolVersion serverVersion; - protected int selectedCipherSuite; - protected short selectedCompressionMethod; - protected Hashtable serverExtensions; - - public AbstractTlsServer() - { - this(new DefaultTlsCipherFactory()); - } - - public AbstractTlsServer(TlsCipherFactory cipherFactory) - { - this.cipherFactory = cipherFactory; - } - - protected boolean allowEncryptThenMAC() - { - return true; - } - - protected boolean allowTruncatedHMac() - { - return false; - } - - protected Hashtable checkServerExtensions() - { - return this.serverExtensions = TlsExtensionsUtils.ensureExtensionsInitialised(this.serverExtensions); - } - - protected abstract int[] getCipherSuites(); - - protected short[] getCompressionMethods() - { - return new short[]{CompressionMethod._null}; - } - - protected ProtocolVersion getMaximumVersion() - { - return ProtocolVersion.TLSv11; - } - - protected ProtocolVersion getMinimumVersion() - { - return ProtocolVersion.TLSv10; - } - - protected boolean supportsClientECCCapabilities(int[] namedCurves, short[] ecPointFormats) - { - // NOTE: BC supports all the current set of point formats so we don't check them here - - if (namedCurves == null) - { - /* - * RFC 4492 4. A client that proposes ECC cipher suites may choose not to include these - * extensions. In this case, the server is free to choose any one of the elliptic curves - * or point formats [...]. - */ - return TlsECCUtils.hasAnySupportedNamedCurves(); - } - - for (int i = 0; i < namedCurves.length; ++i) - { - int namedCurve = namedCurves[i]; - if (NamedCurve.isValid(namedCurve) - && (!NamedCurve.refersToASpecificNamedCurve(namedCurve) || TlsECCUtils.isSupportedNamedCurve(namedCurve))) - { - return true; - } - } - - return false; - } - - public void init(TlsServerContext context) - { - this.context = context; - } - - public void notifyClientVersion(ProtocolVersion clientVersion) - throws IOException - { - this.clientVersion = clientVersion; - } - - public void notifyFallback(boolean isFallback) throws IOException - { - /* - * RFC 7507 3. If TLS_FALLBACK_SCSV appears in ClientHello.cipher_suites and the highest - * protocol version supported by the server is higher than the version indicated in - * ClientHello.client_version, the server MUST respond with a fatal inappropriate_fallback - * alert [..]. - */ - if (isFallback && getMaximumVersion().isLaterVersionOf(clientVersion)) - { - throw new TlsFatalAlert(AlertDescription.inappropriate_fallback); - } - } - - public void notifyOfferedCipherSuites(int[] offeredCipherSuites) - throws IOException - { - this.offeredCipherSuites = offeredCipherSuites; - this.eccCipherSuitesOffered = TlsECCUtils.containsECCCipherSuites(this.offeredCipherSuites); - } - - public void notifyOfferedCompressionMethods(short[] offeredCompressionMethods) - throws IOException - { - this.offeredCompressionMethods = offeredCompressionMethods; - } - - public void processClientExtensions(Hashtable clientExtensions) - throws IOException - { - this.clientExtensions = clientExtensions; - - if (clientExtensions != null) - { - this.encryptThenMACOffered = TlsExtensionsUtils.hasEncryptThenMACExtension(clientExtensions); - - this.maxFragmentLengthOffered = TlsExtensionsUtils.getMaxFragmentLengthExtension(clientExtensions); - if (maxFragmentLengthOffered >= 0 && !MaxFragmentLength.isValid(maxFragmentLengthOffered)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - this.truncatedHMacOffered = TlsExtensionsUtils.hasTruncatedHMacExtension(clientExtensions); - - this.supportedSignatureAlgorithms = TlsUtils.getSignatureAlgorithmsExtension(clientExtensions); - if (this.supportedSignatureAlgorithms != null) - { - /* - * RFC 5246 7.4.1.4.1. Note: this extension is not meaningful for TLS versions prior - * to 1.2. Clients MUST NOT offer it if they are offering prior versions. - */ - if (!TlsUtils.isSignatureAlgorithmsExtensionAllowed(clientVersion)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - - this.namedCurves = TlsECCUtils.getSupportedEllipticCurvesExtension(clientExtensions); - this.clientECPointFormats = TlsECCUtils.getSupportedPointFormatsExtension(clientExtensions); - } - - /* - * RFC 4429 4. The client MUST NOT include these extensions in the ClientHello message if it - * does not propose any ECC cipher suites. - * - * NOTE: This was overly strict as there may be ECC cipher suites that we don't recognize. - * Also, draft-ietf-tls-negotiated-ff-dhe will be overloading the 'elliptic_curves' - * extension to explicitly allow FFDHE (i.e. non-ECC) groups. - */ -// if (!this.eccCipherSuitesOffered && (this.namedCurves != null || this.clientECPointFormats != null)) -// { -// throw new TlsFatalAlert(AlertDescription.illegal_parameter); -// } - } - - public ProtocolVersion getServerVersion() - throws IOException - { - if (getMinimumVersion().isEqualOrEarlierVersionOf(clientVersion)) - { - ProtocolVersion maximumVersion = getMaximumVersion(); - if (clientVersion.isEqualOrEarlierVersionOf(maximumVersion)) - { - return serverVersion = clientVersion; - } - if (clientVersion.isLaterVersionOf(maximumVersion)) - { - return serverVersion = maximumVersion; - } - } - throw new TlsFatalAlert(AlertDescription.protocol_version); - } - - public int getSelectedCipherSuite() - throws IOException - { - /* - * RFC 5246 7.4.3. In order to negotiate correctly, the server MUST check any candidate - * cipher suites against the "signature_algorithms" extension before selecting them. This is - * somewhat inelegant but is a compromise designed to minimize changes to the original - * cipher suite design. - */ - Vector sigAlgs = TlsUtils.getUsableSignatureAlgorithms(supportedSignatureAlgorithms); - - /* - * RFC 4429 5.1. A server that receives a ClientHello containing one or both of these - * extensions MUST use the client's enumerated capabilities to guide its selection of an - * appropriate cipher suite. One of the proposed ECC cipher suites must be negotiated only - * if the server can successfully complete the handshake while using the curves and point - * formats supported by the client [...]. - */ - boolean eccCipherSuitesEnabled = supportsClientECCCapabilities(this.namedCurves, this.clientECPointFormats); - - int[] cipherSuites = getCipherSuites(); - for (int i = 0; i < cipherSuites.length; ++i) - { - int cipherSuite = cipherSuites[i]; - - if (Arrays.contains(this.offeredCipherSuites, cipherSuite) - && (eccCipherSuitesEnabled || !TlsECCUtils.isECCCipherSuite(cipherSuite)) - && TlsUtils.isValidCipherSuiteForVersion(cipherSuite, serverVersion) - && TlsUtils.isValidCipherSuiteForSignatureAlgorithms(cipherSuite, sigAlgs)) - { - return this.selectedCipherSuite = cipherSuite; - } - } - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - public short getSelectedCompressionMethod() - throws IOException - { - short[] compressionMethods = getCompressionMethods(); - for (int i = 0; i < compressionMethods.length; ++i) - { - if (Arrays.contains(offeredCompressionMethods, compressionMethods[i])) - { - return this.selectedCompressionMethod = compressionMethods[i]; - } - } - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - // Hashtable is (Integer -> byte[]) - public Hashtable getServerExtensions() - throws IOException - { - if (this.encryptThenMACOffered && allowEncryptThenMAC()) - { - /* - * RFC 7366 3. If a server receives an encrypt-then-MAC request extension from a client - * and then selects a stream or Authenticated Encryption with Associated Data (AEAD) - * ciphersuite, it MUST NOT send an encrypt-then-MAC response extension back to the - * client. - */ - if (TlsUtils.isBlockCipherSuite(this.selectedCipherSuite)) - { - TlsExtensionsUtils.addEncryptThenMACExtension(checkServerExtensions()); - } - } - - if (this.maxFragmentLengthOffered >= 0 && MaxFragmentLength.isValid(maxFragmentLengthOffered)) - { - TlsExtensionsUtils.addMaxFragmentLengthExtension(checkServerExtensions(), this.maxFragmentLengthOffered); - } - - if (this.truncatedHMacOffered && allowTruncatedHMac()) - { - TlsExtensionsUtils.addTruncatedHMacExtension(checkServerExtensions()); - } - - if (this.clientECPointFormats != null && TlsECCUtils.isECCCipherSuite(this.selectedCipherSuite)) - { - /* - * RFC 4492 5.2. A server that selects an ECC cipher suite in response to a ClientHello - * message including a Supported Point Formats Extension appends this extension (along - * with others) to its ServerHello message, enumerating the point formats it can parse. - */ - this.serverECPointFormats = new short[]{ ECPointFormat.uncompressed, - ECPointFormat.ansiX962_compressed_prime, ECPointFormat.ansiX962_compressed_char2, }; - - TlsECCUtils.addSupportedPointFormatsExtension(checkServerExtensions(), serverECPointFormats); - } - - return serverExtensions; - } - - public Vector getServerSupplementalData() - throws IOException - { - return null; - } - - public CertificateStatus getCertificateStatus() - throws IOException - { - return null; - } - - public CertificateRequest getCertificateRequest() - throws IOException - { - return null; - } - - public void processClientSupplementalData(Vector clientSupplementalData) - throws IOException - { - if (clientSupplementalData != null) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - - public void notifyClientCertificate(Certificate clientCertificate) - throws IOException - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - public TlsCompression getCompression() - throws IOException - { - switch (selectedCompressionMethod) - { - case CompressionMethod._null: - return new TlsNullCompression(); - - default: - /* - * Note: internal error here; we selected the compression method, so if we now can't - * produce an implementation, we shouldn't have chosen it! - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public TlsCipher getCipher() - throws IOException - { - int encryptionAlgorithm = TlsUtils.getEncryptionAlgorithm(selectedCipherSuite); - int macAlgorithm = TlsUtils.getMACAlgorithm(selectedCipherSuite); - - return cipherFactory.createCipher(context, encryptionAlgorithm, macAlgorithm); - } - - public NewSessionTicket getNewSessionTicket() - throws IOException - { - /* - * RFC 5077 3.3. If the server determines that it does not want to include a ticket after it - * has included the SessionTicket extension in the ServerHello, then it sends a zero-length - * ticket in the NewSessionTicket handshake message. - */ - return new NewSessionTicket(0L, TlsUtils.EMPTY_BYTES); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsSigner.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsSigner.java deleted file mode 100644 index 872169516..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsSigner.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.crypto.CryptoException; -import com.fr.third.org.bouncycastle.crypto.Signer; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class AbstractTlsSigner - implements TlsSigner -{ - protected TlsContext context; - - public void init(TlsContext context) - { - this.context = context; - } - - public byte[] generateRawSignature(AsymmetricKeyParameter privateKey, byte[] md5AndSha1) - throws CryptoException - { - return generateRawSignature(null, privateKey, md5AndSha1); - } - - public boolean verifyRawSignature(byte[] sigBytes, AsymmetricKeyParameter publicKey, byte[] md5AndSha1) - throws CryptoException - { - return verifyRawSignature(null, sigBytes, publicKey, md5AndSha1); - } - - public Signer createSigner(AsymmetricKeyParameter privateKey) - { - return createSigner(null, privateKey); - } - - public Signer createVerifyer(AsymmetricKeyParameter publicKey) - { - return createVerifyer(null, publicKey); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsSignerCredentials.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsSignerCredentials.java deleted file mode 100644 index d397d1868..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AbstractTlsSignerCredentials.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class AbstractTlsSignerCredentials - extends AbstractTlsCredentials - implements TlsSignerCredentials -{ - public SignatureAndHashAlgorithm getSignatureAndHashAlgorithm() - { - throw new IllegalStateException("TlsSignerCredentials implementation does not support (D)TLS 1.2+"); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AlertDescription.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AlertDescription.java deleted file mode 100644 index 89b1be0d9..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AlertDescription.java +++ /dev/null @@ -1,305 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 5246 7.2. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class AlertDescription -{ - /** - * This message notifies the recipient that the sender will not send any more messages on this - * connection. Note that as of TLS 1.1, failure to properly close a connection no longer - * requires that a session not be resumed. This is a change from TLS 1.0 ("The session becomes - * unresumable if any connection is terminated without proper close_notify messages with level - * equal to warning.") to conform with widespread implementation practice. - */ - public static final short close_notify = 0; - - /** - * An inappropriate message was received. This alert is always fatal and should never be - * observed in communication between proper implementations. - */ - public static final short unexpected_message = 10; - - /** - * This alert is returned if a record is received with an incorrect MAC. This alert also MUST be - * returned if an alert is sent because a TLSCiphertext decrypted in an invalid way: either it - * wasn't an even multiple of the block length, or its padding values, when checked, weren't - * correct. This message is always fatal and should never be observed in communication between - * proper implementations (except when messages were corrupted in the network). - */ - public static final short bad_record_mac = 20; - - /** - * This alert was used in some earlier versions of TLS, and may have permitted certain attacks - * against the CBC mode [CBCATT]. It MUST NOT be sent by compliant implementations. - */ - public static final short decryption_failed = 21; - - /** - * A TLSCiphertext record was received that had a length more than 2^14+2048 bytes, or a record - * decrypted to a TLSCompressed record with more than 2^14+1024 bytes. This message is always - * fatal and should never be observed in communication between proper implementations (except - * when messages were corrupted in the network). - */ - public static final short record_overflow = 22; - - /** - * The decompression function received improper input (e.g., data that would expand to excessive - * length). This message is always fatal and should never be observed in communication between - * proper implementations. - */ - public static final short decompression_failure = 30; - - /** - * Reception of a handshake_failure alert message indicates that the sender was unable to - * negotiate an acceptable set of security parameters given the options available. This is a - * fatal error. - */ - public static final short handshake_failure = 40; - - /** - * This alert was used in SSLv3 but not any version of TLS. It MUST NOT be sent by compliant - * implementations. - */ - public static final short no_certificate = 41; - - /** - * A certificate was corrupt, contained signatures that did not verify correctly, etc. - */ - public static final short bad_certificate = 42; - - /** - * A certificate was of an unsupported type. - */ - public static final short unsupported_certificate = 43; - - /** - * A certificate was revoked by its signer. - */ - public static final short certificate_revoked = 44; - - /** - * A certificate has expired or is not currently valid. - */ - public static final short certificate_expired = 45; - - /** - * Some other (unspecified) issue arose in processing the certificate, rendering it - * unacceptable. - */ - public static final short certificate_unknown = 46; - - /** - * A field in the handshake was out of range or inconsistent with other fields. This message is - * always fatal. - */ - public static final short illegal_parameter = 47; - - /** - * A valid certificate chain or partial chain was received, but the certificate was not accepted - * because the CA certificate could not be located or couldn't be matched with a known, trusted - * CA. This message is always fatal. - */ - public static final short unknown_ca = 48; - - /** - * A valid certificate was received, but when access control was applied, the sender decided not - * to proceed with negotiation. This message is always fatal. - */ - public static final short access_denied = 49; - - /** - * A message could not be decoded because some field was out of the specified range or the - * length of the message was incorrect. This message is always fatal and should never be - * observed in communication between proper implementations (except when messages were corrupted - * in the network). - */ - public static final short decode_error = 50; - - /** - * A handshake cryptographic operation failed, including being unable to correctly verify a - * signature or validate a Finished message. This message is always fatal. - */ - public static final short decrypt_error = 51; - - /** - * This alert was used in some earlier versions of TLS. It MUST NOT be sent by compliant - * implementations. - */ - public static final short export_restriction = 60; - - /** - * The protocol version the client has attempted to negotiate is recognized but not supported. - * (For example, old protocol versions might be avoided for security reasons.) This message is - * always fatal. - */ - public static final short protocol_version = 70; - - /** - * Returned instead of handshake_failure when a negotiation has failed specifically because the - * server requires ciphers more secure than those supported by the client. This message is - * always fatal. - */ - public static final short insufficient_security = 71; - - /** - * An internal error unrelated to the peer or the correctness of the protocol (such as a memory - * allocation failure) makes it impossible to continue. This message is always fatal. - */ - public static final short internal_error = 80; - - /** - * This handshake is being canceled for some reason unrelated to a protocol failure. If the user - * cancels an operation after the handshake is complete, just closing the connection by sending - * a close_notify is more appropriate. This alert should be followed by a close_notify. This - * message is generally a warning. - */ - public static final short user_canceled = 90; - - /** - * Sent by the client in response to a hello request or by the server in response to a client - * hello after initial handshaking. Either of these would normally lead to renegotiation; when - * that is not appropriate, the recipient should respond with this alert. At that point, the - * original requester can decide whether to proceed with the connection. One case where this - * would be appropriate is where a server has spawned a process to satisfy a request; the - * process might receive security parameters (key length, authentication, etc.) at startup, and - * it might be difficult to communicate changes to these parameters after that point. This - * message is always a warning. - */ - public static final short no_renegotiation = 100; - - /** - * Sent by clients that receive an extended server hello containing an extension that they did - * not put in the corresponding client hello. This message is always fatal. - */ - public static final short unsupported_extension = 110; - - /* - * RFC 3546 - */ - - /** - * This alert is sent by servers who are unable to retrieve a certificate chain from the URL - * supplied by the client (see Section 3.3). This message MAY be fatal - for example if client - * authentication is required by the server for the handshake to continue and the server is - * unable to retrieve the certificate chain, it may send a fatal alert. - */ - public static final short certificate_unobtainable = 111; - - /** - * This alert is sent by servers that receive a server_name extension request, but do not - * recognize the server name. This message MAY be fatal. - */ - public static final short unrecognized_name = 112; - - /** - * This alert is sent by clients that receive an invalid certificate status response (see - * Section 3.6). This message is always fatal. - */ - public static final short bad_certificate_status_response = 113; - - /** - * This alert is sent by servers when a certificate hash does not match a client provided - * certificate_hash. This message is always fatal. - */ - public static final short bad_certificate_hash_value = 114; - - /* - * RFC 4279 - */ - - /** - * If the server does not recognize the PSK identity, it MAY respond with an - * "unknown_psk_identity" alert message. - */ - public static final short unknown_psk_identity = 115; - - /* - * RFC 7507 - */ - - /** - * If TLS_FALLBACK_SCSV appears in ClientHello.cipher_suites and the highest protocol version - * supported by the server is higher than the version indicated in ClientHello.client_version, - * the server MUST respond with a fatal inappropriate_fallback alert [..]. - */ - public static final short inappropriate_fallback = 86; - - public static String getName(short alertDescription) - { - switch (alertDescription) - { - case close_notify: - return "close_notify"; - case unexpected_message: - return "unexpected_message"; - case bad_record_mac: - return "bad_record_mac"; - case decryption_failed: - return "decryption_failed"; - case record_overflow: - return "record_overflow"; - case decompression_failure: - return "decompression_failure"; - case handshake_failure: - return "handshake_failure"; - case no_certificate: - return "no_certificate"; - case bad_certificate: - return "bad_certificate"; - case unsupported_certificate: - return "unsupported_certificate"; - case certificate_revoked: - return "certificate_revoked"; - case certificate_expired: - return "certificate_expired"; - case certificate_unknown: - return "certificate_unknown"; - case illegal_parameter: - return "illegal_parameter"; - case unknown_ca: - return "unknown_ca"; - case access_denied: - return "access_denied"; - case decode_error: - return "decode_error"; - case decrypt_error: - return "decrypt_error"; - case export_restriction: - return "export_restriction"; - case protocol_version: - return "protocol_version"; - case insufficient_security: - return "insufficient_security"; - case internal_error: - return "internal_error"; - case user_canceled: - return "user_canceled"; - case no_renegotiation: - return "no_renegotiation"; - case unsupported_extension: - return "unsupported_extension"; - case certificate_unobtainable: - return "certificate_unobtainable"; - case unrecognized_name: - return "unrecognized_name"; - case bad_certificate_status_response: - return "bad_certificate_status_response"; - case bad_certificate_hash_value: - return "bad_certificate_hash_value"; - case unknown_psk_identity: - return "unknown_psk_identity"; - case inappropriate_fallback: - return "inappropriate_fallback"; - default: - return "UNKNOWN"; - } - } - - public static String getText(short alertDescription) - { - return getName(alertDescription) + "(" + alertDescription + ")"; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AlertLevel.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AlertLevel.java deleted file mode 100644 index 29744cb26..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/AlertLevel.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 5246 7.2 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class AlertLevel -{ - public static final short warning = 1; - public static final short fatal = 2; - - public static String getName(short alertDescription) - { - switch (alertDescription) - { - case warning: - return "warning"; - case fatal: - return "fatal"; - default: - return "UNKNOWN"; - } - } - - public static String getText(short alertDescription) - { - return getName(alertDescription) + "(" + alertDescription + ")"; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/BasicTlsPSKIdentity.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/BasicTlsPSKIdentity.java deleted file mode 100644 index c8f6590ec..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/BasicTlsPSKIdentity.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class BasicTlsPSKIdentity - implements TlsPSKIdentity -{ - protected byte[] identity; - protected byte[] psk; - - public BasicTlsPSKIdentity(byte[] identity, byte[] psk) - { - this.identity = Arrays.clone(identity); - this.psk = Arrays.clone(psk); - } - - public BasicTlsPSKIdentity(String identity, byte[] psk) - { - this.identity = Strings.toUTF8ByteArray(identity); - this.psk = Arrays.clone(psk); - } - - public void skipIdentityHint() - { - } - - public void notifyIdentityHint(byte[] psk_identity_hint) - { - } - - public byte[] getPSKIdentity() - { - return identity; - } - - public byte[] getPSK() - { - return Arrays.clone(psk); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/BulkCipherAlgorithm.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/BulkCipherAlgorithm.java deleted file mode 100644 index 87eef0ab1..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/BulkCipherAlgorithm.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 2246 - *- * Note that the values here are implementation-specific and arbitrary. It is recommended not to - * depend on the particular values (e.g. serialization). - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class BulkCipherAlgorithm -{ - public static final int _null = 0; - public static final int rc4 = 1; - public static final int rc2 = 2; - public static final int des = 3; - public static final int _3des = 4; - public static final int des40 = 5; - - /* - * RFC 4346 - */ - public static final int aes = 6; - public static final int idea = 7; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ByteQueue.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ByteQueue.java deleted file mode 100644 index 974d00309..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ByteQueue.java +++ /dev/null @@ -1,230 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.OutputStream; - -/** - * A queue for bytes. This file could be more optimized. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ByteQueue -{ - /** - * @return The smallest number which can be written as 2^x which is bigger than i. - */ - public static int nextTwoPow(int i) - { - /* - * This code is based of a lot of code I found on the Internet which mostly - * referenced a book called "Hacking delight". - */ - i |= (i >> 1); - i |= (i >> 2); - i |= (i >> 4); - i |= (i >> 8); - i |= (i >> 16); - return i + 1; - } - - /** - * The initial size for our buffer. - */ - private static final int DEFAULT_CAPACITY = 1024; - - /** - * The buffer where we store our data. - */ - private byte[] databuf; - - /** - * How many bytes at the beginning of the buffer are skipped. - */ - private int skipped = 0; - - /** - * How many bytes in the buffer are valid data. - */ - private int available = 0; - - private boolean readOnlyBuf = false; - - public ByteQueue() - { - this(DEFAULT_CAPACITY); - } - - public ByteQueue(int capacity) - { - databuf = capacity == 0 ? TlsUtils.EMPTY_BYTES : new byte[capacity]; - } - - public ByteQueue(byte[] buf, int off, int len) - { - this.databuf = buf; - this.skipped = off; - this.available = len; - this.readOnlyBuf = true; - } - - /** - * Add some data to our buffer. - * - * @param buf A byte-array to read data from. - * @param off How many bytes to skip at the beginning of the array. - * @param len How many bytes to read from the array. - */ - public void addData(byte[] buf, int off, int len) - { - if (readOnlyBuf) - { - throw new IllegalStateException("Cannot add data to read-only buffer"); - } - - if ((skipped + available + len) > databuf.length) - { - int desiredSize = ByteQueue.nextTwoPow(available + len); - if (desiredSize > databuf.length) - { - byte[] tmp = new byte[desiredSize]; - System.arraycopy(databuf, skipped, tmp, 0, available); - databuf = tmp; - } - else - { - System.arraycopy(databuf, skipped, databuf, 0, available); - } - skipped = 0; - } - - System.arraycopy(buf, off, databuf, skipped + available, len); - available += len; - } - - /** - * @return The number of bytes which are available in this buffer. - */ - public int available() - { - return available; - } - - /** - * Copy some bytes from the beginning of the data to the provided {@link OutputStream}. - * - * @param output The {@link OutputStream} to copy the bytes to. - * @param length How many bytes to copy. - */ - public void copyTo(OutputStream output, int length) throws IOException - { - if (length > available) - { - throw new IllegalStateException("Cannot copy " + length + " bytes, only got " + available); - } - - output.write(databuf, skipped, length); - } - - /** - * Read data from the buffer. - * - * @param buf The buffer where the read data will be copied to. - * @param offset How many bytes to skip at the beginning of buf. - * @param len How many bytes to read at all. - * @param skip How many bytes from our data to skip. - */ - public void read(byte[] buf, int offset, int len, int skip) - { - if ((buf.length - offset) < len) - { - throw new IllegalArgumentException("Buffer size of " + buf.length - + " is too small for a read of " + len + " bytes"); - } - if ((available - skip) < len) - { - throw new IllegalStateException("Not enough data to read"); - } - System.arraycopy(databuf, skipped + skip, buf, offset, len); - } - - /** - * Return a {@link ByteArrayInputStream} over some bytes at the beginning of the data. - * @param length How many bytes will be readable. - * @return A {@link ByteArrayInputStream} over the data. - */ - public ByteArrayInputStream readFrom(int length) - { - if (length > available) - { - throw new IllegalStateException("Cannot read " + length + " bytes, only got " + available); - } - - int position = skipped; - - available -= length; - skipped += length; - - return new ByteArrayInputStream(databuf, position, length); - } - - /** - * Remove some bytes from our data from the beginning. - * - * @param i How many bytes to remove. - */ - public void removeData(int i) - { - if (i > available) - { - throw new IllegalStateException("Cannot remove " + i + " bytes, only got " + available); - } - - /* - * Skip the data. - */ - available -= i; - skipped += i; - } - - /** - * Remove data from the buffer. - * - * @param buf The buffer where the removed data will be copied to. - * @param off How many bytes to skip at the beginning of buf. - * @param len How many bytes to read at all. - * @param skip How many bytes from our data to skip. - */ - public void removeData(byte[] buf, int off, int len, int skip) - { - read(buf, off, len, skip); - removeData(skip + len); - } - - public byte[] removeData(int len, int skip) - { - byte[] buf = new byte[len]; - removeData(buf, 0, len, skip); - return buf; - } - - public void shrink() - { - if (available == 0) - { - databuf = TlsUtils.EMPTY_BYTES; - skipped = 0; - } - else - { - int desiredSize = ByteQueue.nextTwoPow(available); - if (desiredSize < databuf.length) - { - byte[] tmp = new byte[desiredSize]; - System.arraycopy(databuf, skipped, tmp, 0, available); - databuf = tmp; - skipped = 0; - } - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ByteQueueInputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ByteQueueInputStream.java deleted file mode 100644 index 5aa37cf30..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ByteQueueInputStream.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.InputStream; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ByteQueueInputStream - extends InputStream -{ - private ByteQueue buffer; - - public ByteQueueInputStream() - { - buffer = new ByteQueue(); - } - - public void addBytes(byte[] buf) - { - buffer.addData(buf, 0, buf.length); - } - - public void addBytes(byte[] buf, int bufOff, int bufLen) - { - buffer.addData(buf, bufOff, bufLen); - } - - public int peek(byte[] buf) - { - int bytesToRead = Math.min(buffer.available(), buf.length); - buffer.read(buf, 0, bytesToRead, 0); - return bytesToRead; - } - - public int read() - { - if (buffer.available() == 0) - { - return -1; - } - return buffer.removeData(1, 0)[0] & 0xFF; - } - - public int read(byte[] b) - { - return read(b, 0, b.length); - } - - public int read(byte[] b, int off, int len) - { - int bytesToRead = Math.min(buffer.available(), len); - buffer.removeData(b, off, bytesToRead, 0); - return bytesToRead; - } - - public long skip(long n) - { - int bytesToRemove = Math.min((int)n, buffer.available()); - buffer.removeData(bytesToRemove); - return bytesToRemove; - } - - public int available() - { - return buffer.available(); - } - - public void close() - { - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ByteQueueOutputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ByteQueueOutputStream.java deleted file mode 100644 index 6ca18b5f5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ByteQueueOutputStream.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ByteQueueOutputStream - extends OutputStream -{ - private ByteQueue buffer; - - public ByteQueueOutputStream() - { - buffer = new ByteQueue(); - } - - public ByteQueue getBuffer() - { - return buffer; - } - - public void write(int b) throws IOException - { - buffer.addData(new byte[]{ (byte)b }, 0, 1); - } - - public void write(byte[] b, int off, int len) throws IOException - { - buffer.addData(b, off, len); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertChainType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertChainType.java deleted file mode 100644 index 5eaa84c4c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertChainType.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/* - * RFC 3546 3.3. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class CertChainType -{ - public static final short individual_certs = 0; - public static final short pkipath = 1; - - public static boolean isValid(short certChainType) - { - return certChainType >= individual_certs && certChainType <= pkipath; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/Certificate.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/Certificate.java deleted file mode 100644 index f4d913a1f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/Certificate.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encoding; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; - -/** - * Parsing and encoding of a Certificate struct from RFC 4346. - *
- * opaque ASN.1Cert<2^24-1>; - * - * struct { - * ASN.1Cert certificate_list<0..2^24-1>; - * } Certificate; - *- * - * @see com.fr.third.org.bouncycastle.asn1.x509.Certificate - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class Certificate -{ - public static final Certificate EMPTY_CHAIN = new Certificate( - new com.fr.third.org.bouncycastle.asn1.x509.Certificate[0]); - - protected com.fr.third.org.bouncycastle.asn1.x509.Certificate[] certificateList; - - public Certificate(com.fr.third.org.bouncycastle.asn1.x509.Certificate[] certificateList) - { - if (certificateList == null) - { - throw new IllegalArgumentException("'certificateList' cannot be null"); - } - - this.certificateList = certificateList; - } - - /** - * @return an array of {@link com.fr.third.org.bouncycastle.asn1.x509.Certificate} representing a certificate - * chain. - */ - public com.fr.third.org.bouncycastle.asn1.x509.Certificate[] getCertificateList() - { - return cloneCertificateList(); - } - - public com.fr.third.org.bouncycastle.asn1.x509.Certificate getCertificateAt(int index) - { - return certificateList[index]; - } - - public int getLength() - { - return certificateList.length; - } - - /** - * @returntrue
if this certificate chain contains no certificates, or - *false
otherwise. - */ - public boolean isEmpty() - { - return certificateList.length == 0; - } - - /** - * Encode this {@link Certificate} to an {@link OutputStream}. - * - * @param output the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) - throws IOException - { - Vector derEncodings = new Vector(this.certificateList.length); - - int totalLength = 0; - for (int i = 0; i < this.certificateList.length; ++i) - { - byte[] derEncoding = certificateList[i].getEncoded(ASN1Encoding.DER); - derEncodings.addElement(derEncoding); - totalLength += derEncoding.length + 3; - } - - TlsUtils.checkUint24(totalLength); - TlsUtils.writeUint24(totalLength, output); - - for (int i = 0; i < derEncodings.size(); ++i) - { - byte[] derEncoding = (byte[])derEncodings.elementAt(i); - TlsUtils.writeOpaque24(derEncoding, output); - } - } - - /** - * Parse a {@link Certificate} from an {@link InputStream}. - * - * @param input the {@link InputStream} to parse from. - * @return a {@link Certificate} object. - * @throws IOException - */ - public static Certificate parse(InputStream input) - throws IOException - { - int totalLength = TlsUtils.readUint24(input); - if (totalLength == 0) - { - return EMPTY_CHAIN; - } - - byte[] certListData = TlsUtils.readFully(totalLength, input); - - ByteArrayInputStream buf = new ByteArrayInputStream(certListData); - - Vector certificate_list = new Vector(); - while (buf.available() > 0) - { - byte[] berEncoding = TlsUtils.readOpaque24(buf); - ASN1Primitive asn1Cert = TlsUtils.readASN1Object(berEncoding); - certificate_list.addElement(com.fr.third.org.bouncycastle.asn1.x509.Certificate.getInstance(asn1Cert)); - } - - com.fr.third.org.bouncycastle.asn1.x509.Certificate[] certificateList = new com.fr.third.org.bouncycastle.asn1.x509.Certificate[certificate_list.size()]; - for (int i = 0; i < certificate_list.size(); i++) - { - certificateList[i] = (com.fr.third.org.bouncycastle.asn1.x509.Certificate)certificate_list.elementAt(i); - } - return new Certificate(certificateList); - } - - protected com.fr.third.org.bouncycastle.asn1.x509.Certificate[] cloneCertificateList() - { - com.fr.third.org.bouncycastle.asn1.x509.Certificate[] result = new com.fr.third.org.bouncycastle.asn1.x509.Certificate[certificateList.length]; - System.arraycopy(certificateList, 0, result, 0, result.length); - return result; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateRequest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateRequest.java deleted file mode 100644 index b22d2b37a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateRequest.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encoding; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.x500.X500Name; - -/** - * Parsing and encoding of a CertificateRequest struct from RFC 4346. - *- * struct { - * ClientCertificateType certificate_types<1..2^8-1>; - * DistinguishedName certificate_authorities<3..2^16-1>; - * } CertificateRequest; - *- * - * @see ClientCertificateType - * @see X500Name - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class CertificateRequest -{ - protected short[] certificateTypes; - protected Vector supportedSignatureAlgorithms; - protected Vector certificateAuthorities; - - /** - * @param certificateTypes see {@link ClientCertificateType} for valid constants. - * @param certificateAuthorities a {@link Vector} of {@link X500Name}. - */ - public CertificateRequest(short[] certificateTypes, Vector supportedSignatureAlgorithms, Vector certificateAuthorities) - { - this.certificateTypes = certificateTypes; - this.supportedSignatureAlgorithms = supportedSignatureAlgorithms; - this.certificateAuthorities = certificateAuthorities; - } - - /** - * @return an array of certificate types - * @see ClientCertificateType - */ - public short[] getCertificateTypes() - { - return certificateTypes; - } - - /** - * @return a {@link Vector} of {@link SignatureAndHashAlgorithm} (or null before TLS 1.2). - */ - public Vector getSupportedSignatureAlgorithms() - { - return supportedSignatureAlgorithms; - } - - /** - * @return a {@link Vector} of {@link X500Name} - */ - public Vector getCertificateAuthorities() - { - return certificateAuthorities; - } - - /** - * Encode this {@link CertificateRequest} to an {@link OutputStream}. - * - * @param output the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) - throws IOException - { - if (certificateTypes == null || certificateTypes.length == 0) - { - TlsUtils.writeUint8(0, output); - } - else - { - TlsUtils.writeUint8ArrayWithUint8Length(certificateTypes, output); - } - - if (supportedSignatureAlgorithms != null) - { - // TODO Check whether SignatureAlgorithm.anonymous is allowed here - TlsUtils.encodeSupportedSignatureAlgorithms(supportedSignatureAlgorithms, false, output); - } - - if (certificateAuthorities == null || certificateAuthorities.isEmpty()) - { - TlsUtils.writeUint16(0, output); - } - else - { - Vector derEncodings = new Vector(certificateAuthorities.size()); - - int totalLength = 0; - for (int i = 0; i < certificateAuthorities.size(); ++i) - { - X500Name certificateAuthority = (X500Name)certificateAuthorities.elementAt(i); - byte[] derEncoding = certificateAuthority.getEncoded(ASN1Encoding.DER); - derEncodings.addElement(derEncoding); - totalLength += derEncoding.length + 2; - } - - TlsUtils.checkUint16(totalLength); - TlsUtils.writeUint16(totalLength, output); - - for (int i = 0; i < derEncodings.size(); ++i) - { - byte[] derEncoding = (byte[])derEncodings.elementAt(i); - TlsUtils.writeOpaque16(derEncoding, output); - } - } - } - - /** - * Parse a {@link CertificateRequest} from an {@link InputStream}. - * - * @param context - * the {@link TlsContext} of the current connection. - * @param input - * the {@link InputStream} to parse from. - * @return a {@link CertificateRequest} object. - * @throws IOException - */ - public static CertificateRequest parse(TlsContext context, InputStream input) - throws IOException - { - int numTypes = TlsUtils.readUint8(input); - short[] certificateTypes = new short[numTypes]; - for (int i = 0; i < numTypes; ++i) - { - certificateTypes[i] = TlsUtils.readUint8(input); - } - - Vector supportedSignatureAlgorithms = null; - if (TlsUtils.isTLSv12(context)) - { - // TODO Check whether SignatureAlgorithm.anonymous is allowed here - supportedSignatureAlgorithms = TlsUtils.parseSupportedSignatureAlgorithms(false, input); - } - - Vector certificateAuthorities = new Vector(); - byte[] certAuthData = TlsUtils.readOpaque16(input); - ByteArrayInputStream bis = new ByteArrayInputStream(certAuthData); - while (bis.available() > 0) - { - byte[] derEncoding = TlsUtils.readOpaque16(bis); - ASN1Primitive asn1 = TlsUtils.readDERObject(derEncoding); - certificateAuthorities.addElement(X500Name.getInstance(asn1)); - } - - return new CertificateRequest(certificateTypes, supportedSignatureAlgorithms, certificateAuthorities); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateStatus.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateStatus.java deleted file mode 100644 index e20563850..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateStatus.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encoding; -import com.fr.third.org.bouncycastle.asn1.ocsp.OCSPResponse; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class CertificateStatus -{ - protected short statusType; - protected Object response; - - public CertificateStatus(short statusType, Object response) - { - if (!isCorrectType(statusType, response)) - { - throw new IllegalArgumentException("'response' is not an instance of the correct type"); - } - - this.statusType = statusType; - this.response = response; - } - - public short getStatusType() - { - return statusType; - } - - public Object getResponse() - { - return response; - } - - public OCSPResponse getOCSPResponse() - { - if (!isCorrectType(CertificateStatusType.ocsp, response)) - { - throw new IllegalStateException("'response' is not an OCSPResponse"); - } - return (OCSPResponse)response; - } - - /** - * Encode this {@link CertificateStatus} to an {@link OutputStream}. - * - * @param output - * the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) throws IOException - { - TlsUtils.writeUint8(statusType, output); - - switch (statusType) - { - case CertificateStatusType.ocsp: - byte[] derEncoding = ((OCSPResponse) response).getEncoded(ASN1Encoding.DER); - TlsUtils.writeOpaque24(derEncoding, output); - break; - default: - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - /** - * Parse a {@link CertificateStatus} from an {@link InputStream}. - * - * @param input - * the {@link InputStream} to parse from. - * @return a {@link CertificateStatus} object. - * @throws IOException - */ - public static CertificateStatus parse(InputStream input) throws IOException - { - short status_type = TlsUtils.readUint8(input); - Object response; - - switch (status_type) - { - case CertificateStatusType.ocsp: - { - byte[] derEncoding = TlsUtils.readOpaque24(input); - response = OCSPResponse.getInstance(TlsUtils.readDERObject(derEncoding)); - break; - } - default: - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - return new CertificateStatus(status_type, response); - } - - protected static boolean isCorrectType(short statusType, Object response) - { - switch (statusType) - { - case CertificateStatusType.ocsp: - return response instanceof OCSPResponse; - default: - throw new IllegalArgumentException("'statusType' is an unsupported CertificateStatusType"); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateStatusRequest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateStatusRequest.java deleted file mode 100644 index 2f527a5ce..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateStatusRequest.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class CertificateStatusRequest -{ - protected short statusType; - protected Object request; - - public CertificateStatusRequest(short statusType, Object request) - { - if (!isCorrectType(statusType, request)) - { - throw new IllegalArgumentException("'request' is not an instance of the correct type"); - } - - this.statusType = statusType; - this.request = request; - } - - public short getStatusType() - { - return statusType; - } - - public Object getRequest() - { - return request; - } - - public OCSPStatusRequest getOCSPStatusRequest() - { - if (!isCorrectType(CertificateStatusType.ocsp, request)) - { - throw new IllegalStateException("'request' is not an OCSPStatusRequest"); - } - return (OCSPStatusRequest)request; - } - - /** - * Encode this {@link CertificateStatusRequest} to an {@link OutputStream}. - * - * @param output - * the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) throws IOException - { - TlsUtils.writeUint8(statusType, output); - - switch (statusType) - { - case CertificateStatusType.ocsp: - ((OCSPStatusRequest) request).encode(output); - break; - default: - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - /** - * Parse a {@link CertificateStatusRequest} from an {@link InputStream}. - * - * @param input - * the {@link InputStream} to parse from. - * @return a {@link CertificateStatusRequest} object. - * @throws IOException - */ - public static CertificateStatusRequest parse(InputStream input) throws IOException - { - short status_type = TlsUtils.readUint8(input); - Object result; - - switch (status_type) - { - case CertificateStatusType.ocsp: - result = OCSPStatusRequest.parse(input); - break; - default: - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - return new CertificateStatusRequest(status_type, result); - } - - protected static boolean isCorrectType(short statusType, Object request) - { - switch (statusType) - { - case CertificateStatusType.ocsp: - return request instanceof OCSPStatusRequest; - default: - throw new IllegalArgumentException("'statusType' is an unsupported CertificateStatusType"); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateStatusType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateStatusType.java deleted file mode 100644 index 18ac5e1ad..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateStatusType.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class CertificateStatusType -{ - /* - * RFC 3546 3.6 - */ - public static final short ocsp = 1; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateType.java deleted file mode 100644 index 8fa4fd187..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateType.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 6091 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class CertificateType -{ - public static final short X509 = 0; - public static final short OpenPGP = 1; - - /* - * RFC 7250 - */ - public static final short RawPublicKey = 2; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateURL.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateURL.java deleted file mode 100644 index ca99a24f2..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CertificateURL.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Vector; - -/* - * RFC 3546 3.3 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class CertificateURL -{ - protected short type; - protected Vector urlAndHashList; - - /** - * @param type - * see {@link CertChainType} for valid constants. - * @param urlAndHashList - * a {@link Vector} of {@link URLAndHash}. - */ - public CertificateURL(short type, Vector urlAndHashList) - { - if (!CertChainType.isValid(type)) - { - throw new IllegalArgumentException("'type' is not a valid CertChainType value"); - } - if (urlAndHashList == null || urlAndHashList.isEmpty()) - { - throw new IllegalArgumentException("'urlAndHashList' must have length > 0"); - } - - this.type = type; - this.urlAndHashList = urlAndHashList; - } - - /** - * @return {@link CertChainType} - */ - public short getType() - { - return type; - } - - /** - * @return a {@link Vector} of {@link URLAndHash} - */ - public Vector getURLAndHashList() - { - return urlAndHashList; - } - - /** - * Encode this {@link CertificateURL} to an {@link OutputStream}. - * - * @param output the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) - throws IOException - { - TlsUtils.writeUint8(this.type, output); - - ListBuffer16 buf = new ListBuffer16(); - for (int i = 0; i < this.urlAndHashList.size(); ++i) - { - URLAndHash urlAndHash = (URLAndHash)this.urlAndHashList.elementAt(i); - urlAndHash.encode(buf); - } - buf.encodeTo(output); - } - - /** - * Parse a {@link CertificateURL} from an {@link InputStream}. - * - * @param context - * the {@link TlsContext} of the current connection. - * @param input - * the {@link InputStream} to parse from. - * @return a {@link CertificateURL} object. - * @throws IOException - */ - public static CertificateURL parse(TlsContext context, InputStream input) - throws IOException - { - short type = TlsUtils.readUint8(input); - if (!CertChainType.isValid(type)) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - int totalLength = TlsUtils.readUint16(input); - if (totalLength < 1) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - byte[] urlAndHashListData = TlsUtils.readFully(totalLength, input); - - ByteArrayInputStream buf = new ByteArrayInputStream(urlAndHashListData); - - Vector url_and_hash_list = new Vector(); - while (buf.available() > 0) - { - URLAndHash url_and_hash = URLAndHash.parse(context, buf); - url_and_hash_list.addElement(url_and_hash); - } - - return new CertificateURL(type, url_and_hash_list); - } - - // TODO Could be more generally useful - class ListBuffer16 extends ByteArrayOutputStream - { - ListBuffer16() throws IOException - { - // Reserve space for length - TlsUtils.writeUint16(0, this); - } - - void encodeTo(OutputStream output) throws IOException - { - // Patch actual length back in - int length = count - 2; - TlsUtils.checkUint16(length); - TlsUtils.writeUint16(length, buf, 0); - output.write(buf, 0, count); - buf = null; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/Chacha20Poly1305.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/Chacha20Poly1305.java deleted file mode 100644 index a9790d710..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/Chacha20Poly1305.java +++ /dev/null @@ -1,205 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.crypto.engines.ChaCha7539Engine; -import com.fr.third.org.bouncycastle.crypto.macs.Poly1305; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Pack; - -/** - * draft-ietf-tls-chacha20-poly1305-04 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class Chacha20Poly1305 implements TlsCipher -{ - private static final byte[] ZEROES = new byte[15]; - - protected TlsContext context; - - protected ChaCha7539Engine encryptCipher, decryptCipher; - protected byte[] encryptIV, decryptIV; - - public Chacha20Poly1305(TlsContext context) throws IOException - { - if (!TlsUtils.isTLSv12(context)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - this.context = context; - - int cipherKeySize = 32; - // TODO SecurityParameters.fixed_iv_length - int fixed_iv_length = 12; - // TODO SecurityParameters.record_iv_length = 0 - - int key_block_size = (2 * cipherKeySize) + (2 * fixed_iv_length); - - byte[] key_block = TlsUtils.calculateKeyBlock(context, key_block_size); - - int offset = 0; - - KeyParameter client_write_key = new KeyParameter(key_block, offset, cipherKeySize); - offset += cipherKeySize; - KeyParameter server_write_key = new KeyParameter(key_block, offset, cipherKeySize); - offset += cipherKeySize; - byte[] client_write_IV = Arrays.copyOfRange(key_block, offset, offset + fixed_iv_length); - offset += fixed_iv_length; - byte[] server_write_IV = Arrays.copyOfRange(key_block, offset, offset + fixed_iv_length); - offset += fixed_iv_length; - - if (offset != key_block_size) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - this.encryptCipher = new ChaCha7539Engine(); - this.decryptCipher = new ChaCha7539Engine(); - - KeyParameter encryptKey, decryptKey; - if (context.isServer()) - { - encryptKey = server_write_key; - decryptKey = client_write_key; - this.encryptIV = server_write_IV; - this.decryptIV = client_write_IV; - } - else - { - encryptKey = client_write_key; - decryptKey = server_write_key; - this.encryptIV = client_write_IV; - this.decryptIV = server_write_IV; - } - - this.encryptCipher.init(true, new ParametersWithIV(encryptKey, encryptIV)); - this.decryptCipher.init(false, new ParametersWithIV(decryptKey, decryptIV)); - } - - public int getPlaintextLimit(int ciphertextLimit) - { - return ciphertextLimit - 16; - } - - public byte[] encodePlaintext(long seqNo, short type, byte[] plaintext, int offset, int len) throws IOException - { - KeyParameter macKey = initRecord(encryptCipher, true, seqNo, encryptIV); - - byte[] output = new byte[len + 16]; - encryptCipher.processBytes(plaintext, offset, len, output, 0); - - byte[] additionalData = getAdditionalData(seqNo, type, len); - byte[] mac = calculateRecordMAC(macKey, additionalData, output, 0, len); - System.arraycopy(mac, 0, output, len, mac.length); - - return output; - } - - public byte[] decodeCiphertext(long seqNo, short type, byte[] ciphertext, int offset, int len) throws IOException - { - if (getPlaintextLimit(len) < 0) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - KeyParameter macKey = initRecord(decryptCipher, false, seqNo, decryptIV); - - int plaintextLength = len - 16; - - byte[] additionalData = getAdditionalData(seqNo, type, plaintextLength); - byte[] calculatedMAC = calculateRecordMAC(macKey, additionalData, ciphertext, offset, plaintextLength); - byte[] receivedMAC = Arrays.copyOfRange(ciphertext, offset + plaintextLength, offset + len); - - if (!Arrays.constantTimeAreEqual(calculatedMAC, receivedMAC)) - { - throw new TlsFatalAlert(AlertDescription.bad_record_mac); - } - - byte[] output = new byte[plaintextLength]; - decryptCipher.processBytes(ciphertext, offset, plaintextLength, output, 0); - return output; - } - - protected KeyParameter initRecord(StreamCipher cipher, boolean forEncryption, long seqNo, byte[] iv) - { - byte[] nonce = calculateNonce(seqNo, iv); - cipher.init(forEncryption, new ParametersWithIV(null, nonce)); - return generateRecordMACKey(cipher); - } - - protected byte[] calculateNonce(long seqNo, byte[] iv) - { - byte[] nonce = new byte[12]; - TlsUtils.writeUint64(seqNo, nonce, 4); - - for (int i = 0; i < 12; ++i) - { - nonce[i] ^= iv[i]; - } - - return nonce; - } - - protected KeyParameter generateRecordMACKey(StreamCipher cipher) - { - byte[] firstBlock = new byte[64]; - cipher.processBytes(firstBlock, 0, firstBlock.length, firstBlock, 0); - - KeyParameter macKey = new KeyParameter(firstBlock, 0, 32); - Arrays.fill(firstBlock, (byte)0); - return macKey; - } - - protected byte[] calculateRecordMAC(KeyParameter macKey, byte[] additionalData, byte[] buf, int off, int len) - { - Mac mac = new Poly1305(); - mac.init(macKey); - - updateRecordMACText(mac, additionalData, 0, additionalData.length); - updateRecordMACText(mac, buf, off, len); - updateRecordMACLength(mac, additionalData.length); - updateRecordMACLength(mac, len); - - byte[] output = new byte[mac.getMacSize()]; - mac.doFinal(output, 0); - return output; - } - - protected void updateRecordMACLength(Mac mac, int len) - { - byte[] longLen = Pack.longToLittleEndian(len & 0xFFFFFFFFL); - mac.update(longLen, 0, longLen.length); - } - - protected void updateRecordMACText(Mac mac, byte[] buf, int off, int len) - { - mac.update(buf, off, len); - - int partial = len % 16; - if (partial != 0) - { - mac.update(ZEROES, 0, 16 - partial); - } - } - - protected byte[] getAdditionalData(long seqNo, short type, int len) throws IOException - { - /* - * additional_data = seq_num + TLSCompressed.type + TLSCompressed.version + - * TLSCompressed.length - */ - byte[] additional_data = new byte[13]; - TlsUtils.writeUint64(seqNo, additional_data, 0); - TlsUtils.writeUint8(type, additional_data, 8); - TlsUtils.writeVersion(context.getServerVersion(), additional_data, 9); - TlsUtils.writeUint16(len, additional_data, 11); - - return additional_data; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ChangeCipherSpec.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ChangeCipherSpec.java deleted file mode 100644 index 9ab727056..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ChangeCipherSpec.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ChangeCipherSpec -{ - public static final short change_cipher_spec = 1; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CipherSuite.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CipherSuite.java deleted file mode 100644 index 0e8007724..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CipherSuite.java +++ /dev/null @@ -1,378 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 2246 A.5 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class CipherSuite -{ - public static final int TLS_NULL_WITH_NULL_NULL = 0x0000; - public static final int TLS_RSA_WITH_NULL_MD5 = 0x0001; - public static final int TLS_RSA_WITH_NULL_SHA = 0x0002; - public static final int TLS_RSA_EXPORT_WITH_RC4_40_MD5 = 0x0003; - public static final int TLS_RSA_WITH_RC4_128_MD5 = 0x0004; - public static final int TLS_RSA_WITH_RC4_128_SHA = 0x0005; - public static final int TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 = 0x0006; - public static final int TLS_RSA_WITH_IDEA_CBC_SHA = 0x0007; - public static final int TLS_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x0008; - public static final int TLS_RSA_WITH_DES_CBC_SHA = 0x0009; - public static final int TLS_RSA_WITH_3DES_EDE_CBC_SHA = 0x000A; - public static final int TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA = 0x000B; - public static final int TLS_DH_DSS_WITH_DES_CBC_SHA = 0x000C; - public static final int TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA = 0x000D; - public static final int TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x000E; - public static final int TLS_DH_RSA_WITH_DES_CBC_SHA = 0x000F; - public static final int TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA = 0x0010; - public static final int TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA = 0x0011; - public static final int TLS_DHE_DSS_WITH_DES_CBC_SHA = 0x0012; - public static final int TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA = 0x0013; - public static final int TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA = 0x0014; - public static final int TLS_DHE_RSA_WITH_DES_CBC_SHA = 0x0015; - public static final int TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x0016; - public static final int TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 = 0x0017; - public static final int TLS_DH_anon_WITH_RC4_128_MD5 = 0x0018; - public static final int TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA = 0x0019; - public static final int TLS_DH_anon_WITH_DES_CBC_SHA = 0x001A; - public static final int TLS_DH_anon_WITH_3DES_EDE_CBC_SHA = 0x001B; - - /* - * Note: The cipher suite values { 0x00, 0x1C } and { 0x00, 0x1D } are reserved to avoid - * collision with Fortezza-based cipher suites in SSL 3. - */ - - /* - * RFC 3268 - */ - public static final int TLS_RSA_WITH_AES_128_CBC_SHA = 0x002F; - public static final int TLS_DH_DSS_WITH_AES_128_CBC_SHA = 0x0030; - public static final int TLS_DH_RSA_WITH_AES_128_CBC_SHA = 0x0031; - public static final int TLS_DHE_DSS_WITH_AES_128_CBC_SHA = 0x0032; - public static final int TLS_DHE_RSA_WITH_AES_128_CBC_SHA = 0x0033; - public static final int TLS_DH_anon_WITH_AES_128_CBC_SHA = 0x0034; - public static final int TLS_RSA_WITH_AES_256_CBC_SHA = 0x0035; - public static final int TLS_DH_DSS_WITH_AES_256_CBC_SHA = 0x0036; - public static final int TLS_DH_RSA_WITH_AES_256_CBC_SHA = 0x0037; - public static final int TLS_DHE_DSS_WITH_AES_256_CBC_SHA = 0x0038; - public static final int TLS_DHE_RSA_WITH_AES_256_CBC_SHA = 0x0039; - public static final int TLS_DH_anon_WITH_AES_256_CBC_SHA = 0x003A; - - /* - * RFC 5932 - */ - public static final int TLS_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x0041; - public static final int TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA = 0x0042; - public static final int TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x0043; - public static final int TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA = 0x0044; - public static final int TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x0045; - public static final int TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA = 0x0046; - - public static final int TLS_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x0084; - public static final int TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA = 0x0085; - public static final int TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x0086; - public static final int TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA = 0x0087; - public static final int TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x0088; - public static final int TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA = 0x0089; - - public static final int TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BA; - public static final int TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BB; - public static final int TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BC; - public static final int TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BD; - public static final int TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BE; - public static final int TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256 = 0x00BF; - - public static final int TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C0; - public static final int TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C1; - public static final int TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C2; - public static final int TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C3; - public static final int TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C4; - public static final int TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256 = 0x00C5; - - /* - * RFC 4162 - */ - public static final int TLS_RSA_WITH_SEED_CBC_SHA = 0x0096; - public static final int TLS_DH_DSS_WITH_SEED_CBC_SHA = 0x0097; - public static final int TLS_DH_RSA_WITH_SEED_CBC_SHA = 0x0098; - public static final int TLS_DHE_DSS_WITH_SEED_CBC_SHA = 0x0099; - public static final int TLS_DHE_RSA_WITH_SEED_CBC_SHA = 0x009A; - public static final int TLS_DH_anon_WITH_SEED_CBC_SHA = 0x009B; - - /* - * RFC 4279 - */ - public static final int TLS_PSK_WITH_RC4_128_SHA = 0x008A; - public static final int TLS_PSK_WITH_3DES_EDE_CBC_SHA = 0x008B; - public static final int TLS_PSK_WITH_AES_128_CBC_SHA = 0x008C; - public static final int TLS_PSK_WITH_AES_256_CBC_SHA = 0x008D; - public static final int TLS_DHE_PSK_WITH_RC4_128_SHA = 0x008E; - public static final int TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA = 0x008F; - public static final int TLS_DHE_PSK_WITH_AES_128_CBC_SHA = 0x0090; - public static final int TLS_DHE_PSK_WITH_AES_256_CBC_SHA = 0x0091; - public static final int TLS_RSA_PSK_WITH_RC4_128_SHA = 0x0092; - public static final int TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA = 0x0093; - public static final int TLS_RSA_PSK_WITH_AES_128_CBC_SHA = 0x0094; - public static final int TLS_RSA_PSK_WITH_AES_256_CBC_SHA = 0x0095; - - /* - * RFC 4492 - */ - public static final int TLS_ECDH_ECDSA_WITH_NULL_SHA = 0xC001; - public static final int TLS_ECDH_ECDSA_WITH_RC4_128_SHA = 0xC002; - public static final int TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA = 0xC003; - public static final int TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA = 0xC004; - public static final int TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA = 0xC005; - public static final int TLS_ECDHE_ECDSA_WITH_NULL_SHA = 0xC006; - public static final int TLS_ECDHE_ECDSA_WITH_RC4_128_SHA = 0xC007; - public static final int TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA = 0xC008; - public static final int TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0xC009; - public static final int TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0xC00A; - public static final int TLS_ECDH_RSA_WITH_NULL_SHA = 0xC00B; - public static final int TLS_ECDH_RSA_WITH_RC4_128_SHA = 0xC00C; - public static final int TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA = 0xC00D; - public static final int TLS_ECDH_RSA_WITH_AES_128_CBC_SHA = 0xC00E; - public static final int TLS_ECDH_RSA_WITH_AES_256_CBC_SHA = 0xC00F; - public static final int TLS_ECDHE_RSA_WITH_NULL_SHA = 0xC010; - public static final int TLS_ECDHE_RSA_WITH_RC4_128_SHA = 0xC011; - public static final int TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA = 0xC012; - public static final int TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 0xC013; - public static final int TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0xC014; - public static final int TLS_ECDH_anon_WITH_NULL_SHA = 0xC015; - public static final int TLS_ECDH_anon_WITH_RC4_128_SHA = 0xC016; - public static final int TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA = 0xC017; - public static final int TLS_ECDH_anon_WITH_AES_128_CBC_SHA = 0xC018; - public static final int TLS_ECDH_anon_WITH_AES_256_CBC_SHA = 0xC019; - - /* - * RFC 4785 - */ - public static final int TLS_PSK_WITH_NULL_SHA = 0x002C; - public static final int TLS_DHE_PSK_WITH_NULL_SHA = 0x002D; - public static final int TLS_RSA_PSK_WITH_NULL_SHA = 0x002E; - - /* - * RFC 5054 - */ - public static final int TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA = 0xC01A; - public static final int TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA = 0xC01B; - public static final int TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA = 0xC01C; - public static final int TLS_SRP_SHA_WITH_AES_128_CBC_SHA = 0xC01D; - public static final int TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA = 0xC01E; - public static final int TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA = 0xC01F; - public static final int TLS_SRP_SHA_WITH_AES_256_CBC_SHA = 0xC020; - public static final int TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA = 0xC021; - public static final int TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA = 0xC022; - - /* - * RFC 5246 - */ - public static final int TLS_RSA_WITH_NULL_SHA256 = 0x003B; - public static final int TLS_RSA_WITH_AES_128_CBC_SHA256 = 0x003C; - public static final int TLS_RSA_WITH_AES_256_CBC_SHA256 = 0x003D; - public static final int TLS_DH_DSS_WITH_AES_128_CBC_SHA256 = 0x003E; - public static final int TLS_DH_RSA_WITH_AES_128_CBC_SHA256 = 0x003F; - public static final int TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 = 0x0040; - public static final int TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 = 0x0067; - public static final int TLS_DH_DSS_WITH_AES_256_CBC_SHA256 = 0x0068; - public static final int TLS_DH_RSA_WITH_AES_256_CBC_SHA256 = 0x0069; - public static final int TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 = 0x006A; - public static final int TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 = 0x006B; - public static final int TLS_DH_anon_WITH_AES_128_CBC_SHA256 = 0x006C; - public static final int TLS_DH_anon_WITH_AES_256_CBC_SHA256 = 0x006D; - - /* - * RFC 5288 - */ - public static final int TLS_RSA_WITH_AES_128_GCM_SHA256 = 0x009C; - public static final int TLS_RSA_WITH_AES_256_GCM_SHA384 = 0x009D; - public static final int TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 = 0x009E; - public static final int TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 = 0x009F; - public static final int TLS_DH_RSA_WITH_AES_128_GCM_SHA256 = 0x00A0; - public static final int TLS_DH_RSA_WITH_AES_256_GCM_SHA384 = 0x00A1; - public static final int TLS_DHE_DSS_WITH_AES_128_GCM_SHA256 = 0x00A2; - public static final int TLS_DHE_DSS_WITH_AES_256_GCM_SHA384 = 0x00A3; - public static final int TLS_DH_DSS_WITH_AES_128_GCM_SHA256 = 0x00A4; - public static final int TLS_DH_DSS_WITH_AES_256_GCM_SHA384 = 0x00A5; - public static final int TLS_DH_anon_WITH_AES_128_GCM_SHA256 = 0x00A6; - public static final int TLS_DH_anon_WITH_AES_256_GCM_SHA384 = 0x00A7; - - /* - * RFC 5289 - */ - public static final int TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = 0xC023; - public static final int TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = 0xC024; - public static final int TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 = 0xC025; - public static final int TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 = 0xC026; - public static final int TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 = 0xC027; - public static final int TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 = 0xC028; - public static final int TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 = 0xC029; - public static final int TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 = 0xC02A; - public static final int TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0xC02B; - public static final int TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 0xC02C; - public static final int TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 = 0xC02D; - public static final int TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 = 0xC02E; - public static final int TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0xC02F; - public static final int TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0xC030; - public static final int TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 = 0xC031; - public static final int TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 = 0xC032; - - /* - * RFC 5487 - */ - public static final int TLS_PSK_WITH_AES_128_GCM_SHA256 = 0x00A8; - public static final int TLS_PSK_WITH_AES_256_GCM_SHA384 = 0x00A9; - public static final int TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 = 0x00AA; - public static final int TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 = 0x00AB; - public static final int TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 = 0x00AC; - public static final int TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 = 0x00AD; - public static final int TLS_PSK_WITH_AES_128_CBC_SHA256 = 0x00AE; - public static final int TLS_PSK_WITH_AES_256_CBC_SHA384 = 0x00AF; - public static final int TLS_PSK_WITH_NULL_SHA256 = 0x00B0; - public static final int TLS_PSK_WITH_NULL_SHA384 = 0x00B1; - public static final int TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 = 0x00B2; - public static final int TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 = 0x00B3; - public static final int TLS_DHE_PSK_WITH_NULL_SHA256 = 0x00B4; - public static final int TLS_DHE_PSK_WITH_NULL_SHA384 = 0x00B5; - public static final int TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 = 0x00B6; - public static final int TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 = 0x00B7; - public static final int TLS_RSA_PSK_WITH_NULL_SHA256 = 0x00B8; - public static final int TLS_RSA_PSK_WITH_NULL_SHA384 = 0x00B9; - - /* - * RFC 5489 - */ - public static final int TLS_ECDHE_PSK_WITH_RC4_128_SHA = 0xC033; - public static final int TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA = 0xC034; - public static final int TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA = 0xC035; - public static final int TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA = 0xC036; - public static final int TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 = 0xC037; - public static final int TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 = 0xC038; - public static final int TLS_ECDHE_PSK_WITH_NULL_SHA = 0xC039; - public static final int TLS_ECDHE_PSK_WITH_NULL_SHA256 = 0xC03A; - public static final int TLS_ECDHE_PSK_WITH_NULL_SHA384 = 0xC03B; - - /* - * RFC 5746 - */ - public static final int TLS_EMPTY_RENEGOTIATION_INFO_SCSV = 0x00FF; - - /* - * RFC 6367 - */ - public static final int TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xC072; - public static final int TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 = 0xC073; - public static final int TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xC074; - public static final int TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 = 0xC075; - public static final int TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xC076; - public static final int TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 = 0xC077; - public static final int TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xC078; - public static final int TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 = 0xC079; - - public static final int TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC07A; - public static final int TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC07B; - public static final int TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC07C; - public static final int TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC07D; - public static final int TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC07E; - public static final int TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC07F; - public static final int TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256 = 0xC080; - public static final int TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384 = 0xC081; - public static final int TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256 = 0xC082; - public static final int TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384 = 0xC083; - public static final int TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256 = 0xC084; - public static final int TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384 = 0xC085; - public static final int TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC086; - public static final int TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC087; - public static final int TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC088; - public static final int TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC089; - public static final int TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC08A; - public static final int TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC08B; - public static final int TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 = 0xC08C; - public static final int TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 = 0xC08D; - - public static final int TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 = 0xC08E; - public static final int TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 = 0xC08F; - public static final int TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 = 0xC090; - public static final int TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 = 0xC091; - public static final int TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 = 0xC092; - public static final int TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 = 0xC093; - public static final int TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 = 0xC094; - public static final int TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 = 0xC095; - public static final int TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 = 0xC096; - public static final int TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 = 0xC097; - public static final int TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 = 0xC098; - public static final int TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 = 0xC099; - public static final int TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 = 0xC09A; - public static final int TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 = 0xC09B; - - /* - * RFC 6655 - */ - public static final int TLS_RSA_WITH_AES_128_CCM = 0xC09C; - public static final int TLS_RSA_WITH_AES_256_CCM = 0xC09D; - public static final int TLS_DHE_RSA_WITH_AES_128_CCM = 0xC09E; - public static final int TLS_DHE_RSA_WITH_AES_256_CCM = 0xC09F; - public static final int TLS_RSA_WITH_AES_128_CCM_8 = 0xC0A0; - public static final int TLS_RSA_WITH_AES_256_CCM_8 = 0xC0A1; - public static final int TLS_DHE_RSA_WITH_AES_128_CCM_8 = 0xC0A2; - public static final int TLS_DHE_RSA_WITH_AES_256_CCM_8 = 0xC0A3; - public static final int TLS_PSK_WITH_AES_128_CCM = 0xC0A4; - public static final int TLS_PSK_WITH_AES_256_CCM = 0xC0A5; - public static final int TLS_DHE_PSK_WITH_AES_128_CCM = 0xC0A6; - public static final int TLS_DHE_PSK_WITH_AES_256_CCM = 0xC0A7; - public static final int TLS_PSK_WITH_AES_128_CCM_8 = 0xC0A8; - public static final int TLS_PSK_WITH_AES_256_CCM_8 = 0xC0A9; - public static final int TLS_PSK_DHE_WITH_AES_128_CCM_8 = 0xC0AA; - public static final int TLS_PSK_DHE_WITH_AES_256_CCM_8 = 0xC0AB; - - /* - * RFC 7251 - */ - public static final int TLS_ECDHE_ECDSA_WITH_AES_128_CCM = 0xC0AC; - public static final int TLS_ECDHE_ECDSA_WITH_AES_256_CCM = 0xC0AD; - public static final int TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 = 0xC0AE; - public static final int TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 = 0xC0AF; - - /* - * RFC 7507 - */ - public static final int TLS_FALLBACK_SCSV = 0x5600; - - /* - * draft-ietf-tls-chacha20-poly1305-04 - */ - public static final int DRAFT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xCCA8; - public static final int DRAFT_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = 0xCCA9; - public static final int DRAFT_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xCCAA; - public static final int DRAFT_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xCCAB; - public static final int DRAFT_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xCCAC; - public static final int DRAFT_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xCCAD; - public static final int DRAFT_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xCCAE; - - /* - * draft-zauner-tls-aes-ocb-04 (code points TBD) - */ - public static final int DRAFT_TLS_DHE_RSA_WITH_AES_128_OCB = 0xFF00; - public static final int DRAFT_TLS_DHE_RSA_WITH_AES_256_OCB = 0xFF01; - public static final int DRAFT_TLS_ECDHE_RSA_WITH_AES_128_OCB = 0xFF02; - public static final int DRAFT_TLS_ECDHE_RSA_WITH_AES_256_OCB = 0xFF03; - public static final int DRAFT_TLS_ECDHE_ECDSA_WITH_AES_128_OCB = 0xFF04; - public static final int DRAFT_TLS_ECDHE_ECDSA_WITH_AES_256_OCB = 0xFF05; - public static final int DRAFT_TLS_PSK_WITH_AES_128_OCB = 0xFF10; - public static final int DRAFT_TLS_PSK_WITH_AES_256_OCB = 0xFF11; - public static final int DRAFT_TLS_DHE_PSK_WITH_AES_128_OCB = 0xFF12; - public static final int DRAFT_TLS_DHE_PSK_WITH_AES_256_OCB = 0xFF13; - public static final int DRAFT_TLS_ECDHE_PSK_WITH_AES_128_OCB = 0xFF14; - public static final int DRAFT_TLS_ECDHE_PSK_WITH_AES_256_OCB = 0xFF15; - - public static boolean isSCSV(int cipherSuite) - { - switch (cipherSuite) - { - case TLS_EMPTY_RENEGOTIATION_INFO_SCSV: - case TLS_FALLBACK_SCSV: - return true; - default: - return false; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CipherType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CipherType.java deleted file mode 100644 index 06f8fd9ed..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CipherType.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 2246 - *- * Note that the values here are implementation-specific and arbitrary. It is recommended not to - * depend on the particular values (e.g. serialization). - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class CipherType -{ - public static final int stream = 0; - public static final int block = 1; - - /* - * RFC 5246 - */ - public static final int aead = 2; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ClientAuthenticationType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ClientAuthenticationType.java deleted file mode 100644 index 0ed738bd4..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ClientAuthenticationType.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ClientAuthenticationType -{ - /* - * RFC 5077 4 - */ - public static final short anonymous = 0; - public static final short certificate_based = 1; - public static final short psk = 2; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ClientCertificateType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ClientCertificateType.java deleted file mode 100644 index 4b093dc42..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ClientCertificateType.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ClientCertificateType -{ - /* - * RFC 4346 7.4.4 - */ - public static final short rsa_sign = 1; - public static final short dss_sign = 2; - public static final short rsa_fixed_dh = 3; - public static final short dss_fixed_dh = 4; - public static final short rsa_ephemeral_dh_RESERVED = 5; - public static final short dss_ephemeral_dh_RESERVED = 6; - public static final short fortezza_dms_RESERVED = 20; - - /* - * RFC 4492 5.5 - */ - public static final short ecdsa_sign = 64; - public static final short rsa_fixed_ecdh = 65; - public static final short ecdsa_fixed_ecdh = 66; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CombinedHash.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CombinedHash.java deleted file mode 100644 index 00da3493d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CombinedHash.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.crypto.Digest; - -/** - * A combined hash, which implements md5(m) || sha1(m). - */ -class CombinedHash - implements TlsHandshakeHash -{ - protected TlsContext context; - protected Digest md5; - protected Digest sha1; - - CombinedHash() - { - this.md5 = TlsUtils.createHash(HashAlgorithm.md5); - this.sha1 = TlsUtils.createHash(HashAlgorithm.sha1); - } - - CombinedHash(CombinedHash t) - { - this.context = t.context; - this.md5 = TlsUtils.cloneHash(HashAlgorithm.md5, t.md5); - this.sha1 = TlsUtils.cloneHash(HashAlgorithm.sha1, t.sha1); - } - - public void init(TlsContext context) - { - this.context = context; - } - - public TlsHandshakeHash notifyPRFDetermined() - { - return this; - } - - public void trackHashAlgorithm(short hashAlgorithm) - { - throw new IllegalStateException("CombinedHash only supports calculating the legacy PRF for handshake hash"); - } - - public void sealHashAlgorithms() - { - } - - public TlsHandshakeHash stopTracking() - { - return new CombinedHash(this); - } - - public Digest forkPRFHash() - { - return new CombinedHash(this); - } - - public byte[] getFinalHash(short hashAlgorithm) - { - throw new IllegalStateException("CombinedHash doesn't support multiple hashes"); - } - - /** - * @see com.fr.third.org.bouncycastle.crypto.Digest#getAlgorithmName() - */ - public String getAlgorithmName() - { - return md5.getAlgorithmName() + " and " + sha1.getAlgorithmName(); - } - - /** - * @see com.fr.third.org.bouncycastle.crypto.Digest#getDigestSize() - */ - public int getDigestSize() - { - return md5.getDigestSize() + sha1.getDigestSize(); - } - - /** - * @see com.fr.third.org.bouncycastle.crypto.Digest#update(byte) - */ - public void update(byte input) - { - md5.update(input); - sha1.update(input); - } - - /** - * @see com.fr.third.org.bouncycastle.crypto.Digest#update(byte[], int, int) - */ - public void update(byte[] input, int inOff, int len) - { - md5.update(input, inOff, len); - sha1.update(input, inOff, len); - } - - /** - * @see com.fr.third.org.bouncycastle.crypto.Digest#doFinal(byte[], int) - */ - public int doFinal(byte[] output, int outOff) - { - if (context != null && TlsUtils.isSSL(context)) - { - ssl3Complete(md5, SSL3Mac.IPAD, SSL3Mac.OPAD, 48); - ssl3Complete(sha1, SSL3Mac.IPAD, SSL3Mac.OPAD, 40); - } - - int i1 = md5.doFinal(output, outOff); - int i2 = sha1.doFinal(output, outOff + i1); - return i1 + i2; - } - - /** - * @see com.fr.third.org.bouncycastle.crypto.Digest#reset() - */ - public void reset() - { - md5.reset(); - sha1.reset(); - } - - protected void ssl3Complete(Digest d, byte[] ipad, byte[] opad, int padLength) - { - byte[] master_secret = context.getSecurityParameters().masterSecret; - - d.update(master_secret, 0, master_secret.length); - d.update(ipad, 0, padLength); - - byte[] tmp = new byte[d.getDigestSize()]; - d.doFinal(tmp, 0); - - d.update(master_secret, 0, master_secret.length); - d.update(opad, 0, padLength); - d.update(tmp, 0, tmp.length); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CompressionMethod.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CompressionMethod.java deleted file mode 100644 index 8b72717ad..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/CompressionMethod.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 2246 6.1 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class CompressionMethod -{ - public static final short _null = 0; - - /* - * RFC 3749 2 - */ - public static final short DEFLATE = 1; - - /* - * Values from 224 decimal (0xE0) through 255 decimal (0xFF) - * inclusive are reserved for private use. - */ -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ConnectionEnd.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ConnectionEnd.java deleted file mode 100644 index 708c78522..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ConnectionEnd.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 2246 - *
- * Note that the values here are implementation-specific and arbitrary. It is recommended not to - * depend on the particular values (e.g. serialization). - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ConnectionEnd -{ - public static final int server = 0; - public static final int client = 1; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ContentType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ContentType.java deleted file mode 100644 index 441629505..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ContentType.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 2246 6.2.1 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ContentType -{ - public static final short change_cipher_spec = 20; - public static final short alert = 21; - public static final short handshake = 22; - public static final short application_data = 23; - public static final short heartbeat = 24; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSClientProtocol.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSClientProtocol.java deleted file mode 100644 index 7e29ea1a7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSClientProtocol.java +++ /dev/null @@ -1,913 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.security.SecureRandom; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class DTLSClientProtocol - extends DTLSProtocol -{ - public DTLSClientProtocol(SecureRandom secureRandom) - { - super(secureRandom); - } - - public DTLSTransport connect(TlsClient client, DatagramTransport transport) - throws IOException - { - if (client == null) - { - throw new IllegalArgumentException("'client' cannot be null"); - } - if (transport == null) - { - throw new IllegalArgumentException("'transport' cannot be null"); - } - - SecurityParameters securityParameters = new SecurityParameters(); - securityParameters.entity = ConnectionEnd.client; - - ClientHandshakeState state = new ClientHandshakeState(); - state.client = client; - state.clientContext = new TlsClientContextImpl(secureRandom, securityParameters); - - securityParameters.clientRandom = TlsProtocol.createRandomBlock(client.shouldUseGMTUnixTime(), - state.clientContext.getNonceRandomGenerator()); - - client.init(state.clientContext); - - DTLSRecordLayer recordLayer = new DTLSRecordLayer(transport, state.clientContext, client, ContentType.handshake); - client.notifyCloseHandle(recordLayer); - - TlsSession sessionToResume = state.client.getSessionToResume(); - if (sessionToResume != null && sessionToResume.isResumable()) - { - SessionParameters sessionParameters = sessionToResume.exportSessionParameters(); - if (sessionParameters != null && sessionParameters.isExtendedMasterSecret()) - { - state.tlsSession = sessionToResume; - state.sessionParameters = sessionParameters; - } - } - - try - { - return clientHandshake(state, recordLayer); - } - catch (TlsFatalAlert fatalAlert) - { - abortClientHandshake(state, recordLayer, fatalAlert.getAlertDescription()); - throw fatalAlert; - } - catch (IOException e) - { - abortClientHandshake(state, recordLayer, AlertDescription.internal_error); - throw e; - } - catch (RuntimeException e) - { - abortClientHandshake(state, recordLayer, AlertDescription.internal_error); - throw new TlsFatalAlert(AlertDescription.internal_error, e); - } - finally - { - securityParameters.clear(); - } - } - - protected void abortClientHandshake(ClientHandshakeState state, DTLSRecordLayer recordLayer, short alertDescription) - { - recordLayer.fail(alertDescription); - invalidateSession(state); - } - - protected DTLSTransport clientHandshake(ClientHandshakeState state, DTLSRecordLayer recordLayer) - throws IOException - { - SecurityParameters securityParameters = state.clientContext.getSecurityParameters(); - DTLSReliableHandshake handshake = new DTLSReliableHandshake(state.clientContext, recordLayer); - - byte[] clientHelloBody = generateClientHello(state, state.client); - - recordLayer.setWriteVersion(ProtocolVersion.DTLSv10); - - handshake.sendMessage(HandshakeType.client_hello, clientHelloBody); - - DTLSReliableHandshake.Message serverMessage = handshake.receiveMessage(); - - while (serverMessage.getType() == HandshakeType.hello_verify_request) - { - ProtocolVersion recordLayerVersion = recordLayer.getReadVersion(); - ProtocolVersion client_version = state.clientContext.getClientVersion(); - - /* - * RFC 6347 4.2.1 DTLS 1.2 server implementations SHOULD use DTLS version 1.0 regardless of - * the version of TLS that is expected to be negotiated. DTLS 1.2 and 1.0 clients MUST use - * the version solely to indicate packet formatting (which is the same in both DTLS 1.2 and - * 1.0) and not as part of version negotiation. - */ - if (!recordLayerVersion.isEqualOrEarlierVersionOf(client_version)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - recordLayer.setReadVersion(null); - - byte[] cookie = processHelloVerifyRequest(state, serverMessage.getBody()); - byte[] patched = patchClientHelloWithCookie(clientHelloBody, cookie); - - handshake.resetHandshakeMessagesDigest(); - handshake.sendMessage(HandshakeType.client_hello, patched); - - serverMessage = handshake.receiveMessage(); - } - - if (serverMessage.getType() == HandshakeType.server_hello) - { - ProtocolVersion recordLayerVersion = recordLayer.getReadVersion(); - reportServerVersion(state, recordLayerVersion); - recordLayer.setWriteVersion(recordLayerVersion); - - processServerHello(state, serverMessage.getBody()); - } - else - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - handshake.notifyHelloComplete(); - - applyMaxFragmentLengthExtension(recordLayer, securityParameters.maxFragmentLength); - - if (state.resumedSession) - { - securityParameters.masterSecret = Arrays.clone(state.sessionParameters.getMasterSecret()); - recordLayer.initPendingEpoch(state.client.getCipher()); - - // NOTE: Calculated exclusive of the actual Finished message from the server - byte[] expectedServerVerifyData = TlsUtils.calculateVerifyData(state.clientContext, ExporterLabel.server_finished, - TlsProtocol.getCurrentPRFHash(state.clientContext, handshake.getHandshakeHash(), null)); - processFinished(handshake.receiveMessageBody(HandshakeType.finished), expectedServerVerifyData); - - // NOTE: Calculated exclusive of the Finished message itself - byte[] clientVerifyData = TlsUtils.calculateVerifyData(state.clientContext, ExporterLabel.client_finished, - TlsProtocol.getCurrentPRFHash(state.clientContext, handshake.getHandshakeHash(), null)); - handshake.sendMessage(HandshakeType.finished, clientVerifyData); - - handshake.finish(); - - state.clientContext.setResumableSession(state.tlsSession); - - state.client.notifyHandshakeComplete(); - - return new DTLSTransport(recordLayer); - } - - invalidateSession(state); - - if (state.selectedSessionID.length > 0) - { - state.tlsSession = new TlsSessionImpl(state.selectedSessionID, null); - } - - serverMessage = handshake.receiveMessage(); - - if (serverMessage.getType() == HandshakeType.supplemental_data) - { - processServerSupplementalData(state, serverMessage.getBody()); - serverMessage = handshake.receiveMessage(); - } - else - { - state.client.processServerSupplementalData(null); - } - - state.keyExchange = state.client.getKeyExchange(); - state.keyExchange.init(state.clientContext); - - Certificate serverCertificate = null; - - if (serverMessage.getType() == HandshakeType.certificate) - { - serverCertificate = processServerCertificate(state, serverMessage.getBody()); - serverMessage = handshake.receiveMessage(); - } - else - { - // Okay, Certificate is optional - state.keyExchange.skipServerCredentials(); - } - - // TODO[RFC 3546] Check whether empty certificates is possible, allowed, or excludes CertificateStatus - if (serverCertificate == null || serverCertificate.isEmpty()) - { - state.allowCertificateStatus = false; - } - - if (serverMessage.getType() == HandshakeType.certificate_status) - { - processCertificateStatus(state, serverMessage.getBody()); - serverMessage = handshake.receiveMessage(); - } - else - { - // Okay, CertificateStatus is optional - } - - if (serverMessage.getType() == HandshakeType.server_key_exchange) - { - processServerKeyExchange(state, serverMessage.getBody()); - serverMessage = handshake.receiveMessage(); - } - else - { - // Okay, ServerKeyExchange is optional - state.keyExchange.skipServerKeyExchange(); - } - - if (serverMessage.getType() == HandshakeType.certificate_request) - { - processCertificateRequest(state, serverMessage.getBody()); - - /* - * TODO Give the client a chance to immediately select the CertificateVerify hash - * algorithm here to avoid tracking the other hash algorithms unnecessarily? - */ - TlsUtils.trackHashAlgorithms(handshake.getHandshakeHash(), - state.certificateRequest.getSupportedSignatureAlgorithms()); - - serverMessage = handshake.receiveMessage(); - } - else - { - // Okay, CertificateRequest is optional - } - - if (serverMessage.getType() == HandshakeType.server_hello_done) - { - if (serverMessage.getBody().length != 0) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - } - else - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - handshake.getHandshakeHash().sealHashAlgorithms(); - - Vector clientSupplementalData = state.client.getClientSupplementalData(); - if (clientSupplementalData != null) - { - byte[] supplementalDataBody = generateSupplementalData(clientSupplementalData); - handshake.sendMessage(HandshakeType.supplemental_data, supplementalDataBody); - } - - if (state.certificateRequest != null) - { - state.clientCredentials = state.authentication.getClientCredentials(state.certificateRequest); - - /* - * RFC 5246 If no suitable certificate is available, the client MUST send a certificate - * message containing no certificates. - * - * NOTE: In previous RFCs, this was SHOULD instead of MUST. - */ - Certificate clientCertificate = null; - if (state.clientCredentials != null) - { - clientCertificate = state.clientCredentials.getCertificate(); - } - if (clientCertificate == null) - { - clientCertificate = Certificate.EMPTY_CHAIN; - } - - byte[] certificateBody = generateCertificate(clientCertificate); - handshake.sendMessage(HandshakeType.certificate, certificateBody); - } - - if (state.clientCredentials != null) - { - state.keyExchange.processClientCredentials(state.clientCredentials); - } - else - { - state.keyExchange.skipClientCredentials(); - } - - byte[] clientKeyExchangeBody = generateClientKeyExchange(state); - handshake.sendMessage(HandshakeType.client_key_exchange, clientKeyExchangeBody); - - TlsHandshakeHash prepareFinishHash = handshake.prepareToFinish(); - securityParameters.sessionHash = TlsProtocol.getCurrentPRFHash(state.clientContext, prepareFinishHash, null); - - TlsProtocol.establishMasterSecret(state.clientContext, state.keyExchange); - recordLayer.initPendingEpoch(state.client.getCipher()); - - if (state.clientCredentials != null && state.clientCredentials instanceof TlsSignerCredentials) - { - TlsSignerCredentials signerCredentials = (TlsSignerCredentials)state.clientCredentials; - - /* - * RFC 5246 4.7. digitally-signed element needs SignatureAndHashAlgorithm from TLS 1.2 - */ - SignatureAndHashAlgorithm signatureAndHashAlgorithm = TlsUtils.getSignatureAndHashAlgorithm( - state.clientContext, signerCredentials); - - byte[] hash; - if (signatureAndHashAlgorithm == null) - { - hash = securityParameters.getSessionHash(); - } - else - { - hash = prepareFinishHash.getFinalHash(signatureAndHashAlgorithm.getHash()); - } - - byte[] signature = signerCredentials.generateCertificateSignature(hash); - DigitallySigned certificateVerify = new DigitallySigned(signatureAndHashAlgorithm, signature); - byte[] certificateVerifyBody = generateCertificateVerify(state, certificateVerify); - handshake.sendMessage(HandshakeType.certificate_verify, certificateVerifyBody); - } - - // NOTE: Calculated exclusive of the Finished message itself - byte[] clientVerifyData = TlsUtils.calculateVerifyData(state.clientContext, ExporterLabel.client_finished, - TlsProtocol.getCurrentPRFHash(state.clientContext, handshake.getHandshakeHash(), null)); - handshake.sendMessage(HandshakeType.finished, clientVerifyData); - - if (state.expectSessionTicket) - { - serverMessage = handshake.receiveMessage(); - if (serverMessage.getType() == HandshakeType.session_ticket) - { - processNewSessionTicket(state, serverMessage.getBody()); - } - else - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - - // NOTE: Calculated exclusive of the actual Finished message from the server - byte[] expectedServerVerifyData = TlsUtils.calculateVerifyData(state.clientContext, ExporterLabel.server_finished, - TlsProtocol.getCurrentPRFHash(state.clientContext, handshake.getHandshakeHash(), null)); - processFinished(handshake.receiveMessageBody(HandshakeType.finished), expectedServerVerifyData); - - handshake.finish(); - - if (state.tlsSession != null) - { - state.sessionParameters = new SessionParameters.Builder() - .setCipherSuite(securityParameters.getCipherSuite()) - .setCompressionAlgorithm(securityParameters.getCompressionAlgorithm()) - .setExtendedMasterSecret(securityParameters.isExtendedMasterSecret()) - .setMasterSecret(securityParameters.getMasterSecret()) - .setPeerCertificate(serverCertificate) - .setPSKIdentity(securityParameters.getPSKIdentity()) - .setSRPIdentity(securityParameters.getSRPIdentity()) - // TODO Consider filtering extensions that aren't relevant to resumed sessions - .setServerExtensions(state.serverExtensions) - .build(); - - state.tlsSession = TlsUtils.importSession(state.tlsSession.getSessionID(), state.sessionParameters); - - state.clientContext.setResumableSession(state.tlsSession); - } - - state.client.notifyHandshakeComplete(); - - return new DTLSTransport(recordLayer); - } - - protected byte[] generateCertificateVerify(ClientHandshakeState state, DigitallySigned certificateVerify) - throws IOException - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - certificateVerify.encode(buf); - return buf.toByteArray(); - } - - protected byte[] generateClientHello(ClientHandshakeState state, TlsClient client) - throws IOException - { - ProtocolVersion client_version = client.getClientVersion(); - if (!client_version.isDTLS()) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - TlsClientContextImpl context = state.clientContext; - - context.setClientVersion(client_version); - - SecurityParameters securityParameters = context.getSecurityParameters(); - - // Session ID - byte[] session_id = TlsUtils.EMPTY_BYTES; - if (state.tlsSession != null) - { - session_id = state.tlsSession.getSessionID(); - if (session_id == null || session_id.length > 32) - { - session_id = TlsUtils.EMPTY_BYTES; - } - } - - boolean fallback = client.isFallback(); - - state.offeredCipherSuites = client.getCipherSuites(); - - if (session_id.length > 0 && state.sessionParameters != null) - { - if (!state.sessionParameters.isExtendedMasterSecret() - || !Arrays.contains(state.offeredCipherSuites, state.sessionParameters.getCipherSuite()) - || CompressionMethod._null != state.sessionParameters.getCompressionAlgorithm()) - { - session_id = TlsUtils.EMPTY_BYTES; - } - } - - state.clientExtensions = TlsExtensionsUtils.ensureExtensionsInitialised(client.getClientExtensions()); - - TlsExtensionsUtils.addExtendedMasterSecretExtension(state.clientExtensions); - - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - TlsUtils.writeVersion(client_version, buf); - - buf.write(securityParameters.getClientRandom()); - - TlsUtils.writeOpaque8(session_id, buf); - - // Cookie - TlsUtils.writeOpaque8(TlsUtils.EMPTY_BYTES, buf); - - // Cipher Suites (and SCSV) - { - /* - * RFC 5746 3.4. The client MUST include either an empty "renegotiation_info" extension, - * or the TLS_EMPTY_RENEGOTIATION_INFO_SCSV signaling cipher suite value in the - * ClientHello. Including both is NOT RECOMMENDED. - */ - byte[] renegExtData = TlsUtils.getExtensionData(state.clientExtensions, TlsProtocol.EXT_RenegotiationInfo); - boolean noRenegExt = (null == renegExtData); - - boolean noRenegSCSV = !Arrays.contains(state.offeredCipherSuites, CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV); - - if (noRenegExt && noRenegSCSV) - { - // TODO Consider whether to default to a client extension instead - state.offeredCipherSuites = Arrays.append(state.offeredCipherSuites, CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV); - } - - /* - * RFC 7507 4. If a client sends a ClientHello.client_version containing a lower value - * than the latest (highest-valued) version supported by the client, it SHOULD include - * the TLS_FALLBACK_SCSV cipher suite value in ClientHello.cipher_suites [..]. (The - * client SHOULD put TLS_FALLBACK_SCSV after all cipher suites that it actually intends - * to negotiate.) - */ - if (fallback && !Arrays.contains(state.offeredCipherSuites, CipherSuite.TLS_FALLBACK_SCSV)) - { - state.offeredCipherSuites = Arrays.append(state.offeredCipherSuites, CipherSuite.TLS_FALLBACK_SCSV); - } - - TlsUtils.writeUint16ArrayWithUint16Length(state.offeredCipherSuites, buf); - } - - TlsUtils.writeUint8ArrayWithUint8Length(new short[]{ CompressionMethod._null }, buf); - - // Extensions - TlsProtocol.writeExtensions(buf, state.clientExtensions); - - return buf.toByteArray(); - } - - protected byte[] generateClientKeyExchange(ClientHandshakeState state) - throws IOException - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - state.keyExchange.generateClientKeyExchange(buf); - return buf.toByteArray(); - } - - protected void invalidateSession(ClientHandshakeState state) - { - if (state.sessionParameters != null) - { - state.sessionParameters.clear(); - state.sessionParameters = null; - } - - if (state.tlsSession != null) - { - state.tlsSession.invalidate(); - state.tlsSession = null; - } - } - - protected void processCertificateRequest(ClientHandshakeState state, byte[] body) - throws IOException - { - if (state.authentication == null) - { - /* - * RFC 2246 7.4.4. It is a fatal handshake_failure alert for an anonymous server to - * request client identification. - */ - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - ByteArrayInputStream buf = new ByteArrayInputStream(body); - - state.certificateRequest = CertificateRequest.parse(state.clientContext, buf); - - TlsProtocol.assertEmpty(buf); - - state.keyExchange.validateCertificateRequest(state.certificateRequest); - } - - protected void processCertificateStatus(ClientHandshakeState state, byte[] body) - throws IOException - { - if (!state.allowCertificateStatus) - { - /* - * RFC 3546 3.6. If a server returns a "CertificateStatus" message, then the - * server MUST have included an extension of type "status_request" with empty - * "extension_data" in the extended server hello.. - */ - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - ByteArrayInputStream buf = new ByteArrayInputStream(body); - - state.certificateStatus = CertificateStatus.parse(buf); - - TlsProtocol.assertEmpty(buf); - - // TODO[RFC 3546] Figure out how to provide this to the client/authentication. - } - - protected byte[] processHelloVerifyRequest(ClientHandshakeState state, byte[] body) - throws IOException - { - ByteArrayInputStream buf = new ByteArrayInputStream(body); - - ProtocolVersion server_version = TlsUtils.readVersion(buf); - byte[] cookie = TlsUtils.readOpaque8(buf); - - TlsProtocol.assertEmpty(buf); - - // TODO Seems this behaviour is not yet in line with OpenSSL for DTLS 1.2 -// reportServerVersion(state, server_version); - if (!server_version.isEqualOrEarlierVersionOf(state.clientContext.getClientVersion())) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - /* - * RFC 6347 This specification increases the cookie size limit to 255 bytes for greater - * future flexibility. The limit remains 32 for previous versions of DTLS. - */ - if (!ProtocolVersion.DTLSv12.isEqualOrEarlierVersionOf(server_version) && cookie.length > 32) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - return cookie; - } - - protected void processNewSessionTicket(ClientHandshakeState state, byte[] body) - throws IOException - { - ByteArrayInputStream buf = new ByteArrayInputStream(body); - - NewSessionTicket newSessionTicket = NewSessionTicket.parse(buf); - - TlsProtocol.assertEmpty(buf); - - state.client.notifyNewSessionTicket(newSessionTicket); - } - - protected Certificate processServerCertificate(ClientHandshakeState state, byte[] body) - throws IOException - { - ByteArrayInputStream buf = new ByteArrayInputStream(body); - - Certificate serverCertificate = Certificate.parse(buf); - - TlsProtocol.assertEmpty(buf); - - state.keyExchange.processServerCertificate(serverCertificate); - state.authentication = state.client.getAuthentication(); - state.authentication.notifyServerCertificate(serverCertificate); - - return serverCertificate; - } - - protected void processServerHello(ClientHandshakeState state, byte[] body) - throws IOException - { - SecurityParameters securityParameters = state.clientContext.getSecurityParameters(); - - ByteArrayInputStream buf = new ByteArrayInputStream(body); - - { - ProtocolVersion server_version = TlsUtils.readVersion(buf); - reportServerVersion(state, server_version); - } - - securityParameters.serverRandom = TlsUtils.readFully(32, buf); - - state.selectedSessionID = TlsUtils.readOpaque8(buf); - if (state.selectedSessionID.length > 32) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - state.client.notifySessionID(state.selectedSessionID); - state.resumedSession = state.selectedSessionID.length > 0 && state.tlsSession != null - && Arrays.areEqual(state.selectedSessionID, state.tlsSession.getSessionID()); - - int selectedCipherSuite = TlsUtils.readUint16(buf); - if (!Arrays.contains(state.offeredCipherSuites, selectedCipherSuite) - || selectedCipherSuite == CipherSuite.TLS_NULL_WITH_NULL_NULL - || CipherSuite.isSCSV(selectedCipherSuite) - || !TlsUtils.isValidCipherSuiteForVersion(selectedCipherSuite, state.clientContext.getServerVersion())) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - validateSelectedCipherSuite(selectedCipherSuite, AlertDescription.illegal_parameter); - state.client.notifySelectedCipherSuite(selectedCipherSuite); - - short selectedCompressionMethod = TlsUtils.readUint8(buf); - if (CompressionMethod._null != selectedCompressionMethod) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - state.client.notifySelectedCompressionMethod(selectedCompressionMethod); - - /* - * RFC3546 2.2 The extended server hello message format MAY be sent in place of the server - * hello message when the client has requested extended functionality via the extended - * client hello message specified in Section 2.1. ... Note that the extended server hello - * message is only sent in response to an extended client hello message. This prevents the - * possibility that the extended server hello message could "break" existing TLS 1.0 - * clients. - */ - - /* - * TODO RFC 3546 2.3 If [...] the older session is resumed, then the server MUST ignore - * extensions appearing in the client hello, and send a server hello containing no - * extensions. - */ - - // Integer -> byte[] - state.serverExtensions = TlsProtocol.readExtensions(buf); - - /* - * RFC 7627 4. Clients and servers SHOULD NOT accept handshakes that do not use the extended - * master secret [..]. (and see 5.2, 5.3) - */ - securityParameters.extendedMasterSecret = TlsExtensionsUtils.hasExtendedMasterSecretExtension(state.serverExtensions); - - if (!securityParameters.isExtendedMasterSecret() - && (state.resumedSession || state.client.requiresExtendedMasterSecret())) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - /* - * RFC 3546 2.2 Note that the extended server hello message is only sent in response to an - * extended client hello message. However, see RFC 5746 exception below. We always include - * the SCSV, so an Extended Server Hello is always allowed. - */ - if (state.serverExtensions != null) - { - Enumeration e = state.serverExtensions.keys(); - while (e.hasMoreElements()) - { - Integer extType = (Integer)e.nextElement(); - - /* - * RFC 5746 3.6. Note that sending a "renegotiation_info" extension in response to a - * ClientHello containing only the SCSV is an explicit exception to the prohibition - * in RFC 5246, Section 7.4.1.4, on the server sending unsolicited extensions and is - * only allowed because the client is signaling its willingness to receive the - * extension via the TLS_EMPTY_RENEGOTIATION_INFO_SCSV SCSV. - */ - if (extType.equals(TlsProtocol.EXT_RenegotiationInfo)) - { - continue; - } - - /* - * RFC 5246 7.4.1.4 An extension type MUST NOT appear in the ServerHello unless the - * same extension type appeared in the corresponding ClientHello. If a client - * receives an extension type in ServerHello that it did not request in the - * associated ClientHello, it MUST abort the handshake with an unsupported_extension - * fatal alert. - */ - if (null == TlsUtils.getExtensionData(state.clientExtensions, extType)) - { - throw new TlsFatalAlert(AlertDescription.unsupported_extension); - } - - /* - * RFC 3546 2.3. If [...] the older session is resumed, then the server MUST ignore - * extensions appearing in the client hello, and send a server hello containing no - * extensions[.] - */ - if (state.resumedSession) - { - // TODO[compat-gnutls] GnuTLS test server sends server extensions e.g. ec_point_formats - // TODO[compat-openssl] OpenSSL test server sends server extensions e.g. ec_point_formats - // TODO[compat-polarssl] PolarSSL test server sends server extensions e.g. ec_point_formats -// throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - } - - /* - * RFC 5746 3.4. Client Behavior: Initial Handshake - */ - { - /* - * When a ServerHello is received, the client MUST check if it includes the - * "renegotiation_info" extension: - */ - byte[] renegExtData = TlsUtils.getExtensionData(state.serverExtensions, TlsProtocol.EXT_RenegotiationInfo); - if (renegExtData != null) - { - /* - * If the extension is present, set the secure_renegotiation flag to TRUE. The - * client MUST then verify that the length of the "renegotiated_connection" - * field is zero, and if it is not, MUST abort the handshake (by sending a fatal - * handshake_failure alert). - */ - state.secure_renegotiation = true; - - if (!Arrays.constantTimeAreEqual(renegExtData, - TlsProtocol.createRenegotiationInfo(TlsUtils.EMPTY_BYTES))) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - } - } - - // TODO[compat-gnutls] GnuTLS test server fails to send renegotiation_info extension when resuming - state.client.notifySecureRenegotiation(state.secure_renegotiation); - - Hashtable sessionClientExtensions = state.clientExtensions, sessionServerExtensions = state.serverExtensions; - if (state.resumedSession) - { - if (selectedCipherSuite != state.sessionParameters.getCipherSuite() - || selectedCompressionMethod != state.sessionParameters.getCompressionAlgorithm()) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - sessionClientExtensions = null; - sessionServerExtensions = state.sessionParameters.readServerExtensions(); - } - - securityParameters.cipherSuite = selectedCipherSuite; - securityParameters.compressionAlgorithm = selectedCompressionMethod; - - if (sessionServerExtensions != null && !sessionServerExtensions.isEmpty()) - { - { - /* - * RFC 7366 3. If a server receives an encrypt-then-MAC request extension from a client - * and then selects a stream or Authenticated Encryption with Associated Data (AEAD) - * ciphersuite, it MUST NOT send an encrypt-then-MAC response extension back to the - * client. - */ - boolean serverSentEncryptThenMAC = TlsExtensionsUtils.hasEncryptThenMACExtension(sessionServerExtensions); - if (serverSentEncryptThenMAC && !TlsUtils.isBlockCipherSuite(securityParameters.getCipherSuite())) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - securityParameters.encryptThenMAC = serverSentEncryptThenMAC; - } - - securityParameters.maxFragmentLength = evaluateMaxFragmentLengthExtension(state.resumedSession, - sessionClientExtensions, sessionServerExtensions, AlertDescription.illegal_parameter); - - securityParameters.truncatedHMac = TlsExtensionsUtils.hasTruncatedHMacExtension(sessionServerExtensions); - - /* - * TODO It's surprising that there's no provision to allow a 'fresh' CertificateStatus to be - * sent in a session resumption handshake. - */ - state.allowCertificateStatus = !state.resumedSession - && TlsUtils.hasExpectedEmptyExtensionData(sessionServerExtensions, TlsExtensionsUtils.EXT_status_request, - AlertDescription.illegal_parameter); - - state.expectSessionTicket = !state.resumedSession - && TlsUtils.hasExpectedEmptyExtensionData(sessionServerExtensions, TlsProtocol.EXT_SessionTicket, - AlertDescription.illegal_parameter); - } - - if (sessionClientExtensions != null) - { - state.client.processServerExtensions(sessionServerExtensions); - } - - securityParameters.prfAlgorithm = TlsProtocol.getPRFAlgorithm(state.clientContext, - securityParameters.getCipherSuite()); - - /* - * RFC 5246 7.4.9. Any cipher suite which does not explicitly specify verify_data_length has - * a verify_data_length equal to 12. This includes all existing cipher suites. - */ - securityParameters.verifyDataLength = 12; - } - - protected void processServerKeyExchange(ClientHandshakeState state, byte[] body) - throws IOException - { - ByteArrayInputStream buf = new ByteArrayInputStream(body); - - state.keyExchange.processServerKeyExchange(buf); - - TlsProtocol.assertEmpty(buf); - } - - protected void processServerSupplementalData(ClientHandshakeState state, byte[] body) - throws IOException - { - ByteArrayInputStream buf = new ByteArrayInputStream(body); - Vector serverSupplementalData = TlsProtocol.readSupplementalDataMessage(buf); - state.client.processServerSupplementalData(serverSupplementalData); - } - - protected void reportServerVersion(ClientHandshakeState state, ProtocolVersion server_version) - throws IOException - { - TlsClientContextImpl clientContext = state.clientContext; - ProtocolVersion currentServerVersion = clientContext.getServerVersion(); - if (null == currentServerVersion) - { - clientContext.setServerVersion(server_version); - state.client.notifyServerVersion(server_version); - } - else if (!currentServerVersion.equals(server_version)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - - protected static byte[] patchClientHelloWithCookie(byte[] clientHelloBody, byte[] cookie) - throws IOException - { - int sessionIDPos = 34; - int sessionIDLength = TlsUtils.readUint8(clientHelloBody, sessionIDPos); - - int cookieLengthPos = sessionIDPos + 1 + sessionIDLength; - int cookiePos = cookieLengthPos + 1; - - byte[] patched = new byte[clientHelloBody.length + cookie.length]; - System.arraycopy(clientHelloBody, 0, patched, 0, cookieLengthPos); - TlsUtils.checkUint8(cookie.length); - TlsUtils.writeUint8(cookie.length, patched, cookieLengthPos); - System.arraycopy(cookie, 0, patched, cookiePos, cookie.length); - System.arraycopy(clientHelloBody, cookiePos, patched, cookiePos + cookie.length, clientHelloBody.length - - cookiePos); - - return patched; - } - - protected static class ClientHandshakeState - { - TlsClient client = null; - TlsClientContextImpl clientContext = null; - TlsSession tlsSession = null; - SessionParameters sessionParameters = null; - SessionParameters.Builder sessionParametersBuilder = null; - int[] offeredCipherSuites = null; - Hashtable clientExtensions = null; - Hashtable serverExtensions = null; - byte[] selectedSessionID = null; - boolean resumedSession = false; - boolean secure_renegotiation = false; - boolean allowCertificateStatus = false; - boolean expectSessionTicket = false; - TlsKeyExchange keyExchange = null; - TlsAuthentication authentication = null; - CertificateStatus certificateStatus = null; - CertificateRequest certificateRequest = null; - TlsCredentials clientCredentials = null; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSEpoch.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSEpoch.java deleted file mode 100644 index 2e0cd6531..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSEpoch.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -class DTLSEpoch -{ - private final DTLSReplayWindow replayWindow = new DTLSReplayWindow(); - - private final int epoch; - private final TlsCipher cipher; - - private long sequenceNumber = 0; - - DTLSEpoch(int epoch, TlsCipher cipher) - { - if (epoch < 0) - { - throw new IllegalArgumentException("'epoch' must be >= 0"); - } - if (cipher == null) - { - throw new IllegalArgumentException("'cipher' cannot be null"); - } - - this.epoch = epoch; - this.cipher = cipher; - } - - synchronized long allocateSequenceNumber() throws IOException - { - if (sequenceNumber >= (1L << 48)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - return sequenceNumber++; - } - - TlsCipher getCipher() - { - return cipher; - } - - int getEpoch() - { - return epoch; - } - - DTLSReplayWindow getReplayWindow() - { - return replayWindow; - } - - synchronized long getSequenceNumber() - { - return sequenceNumber; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSHandshakeRetransmit.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSHandshakeRetransmit.java deleted file mode 100644 index 0953b0849..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSHandshakeRetransmit.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -interface DTLSHandshakeRetransmit -{ - void receivedHandshakeRecord(int epoch, byte[] buf, int off, int len) - throws IOException; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSProtocol.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSProtocol.java deleted file mode 100644 index 3bec6508d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSProtocol.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.security.SecureRandom; -import java.util.Hashtable; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class DTLSProtocol -{ - protected final SecureRandom secureRandom; - - protected DTLSProtocol(SecureRandom secureRandom) - { - if (secureRandom == null) - { - throw new IllegalArgumentException("'secureRandom' cannot be null"); - } - - this.secureRandom = secureRandom; - } - - protected void processFinished(byte[] body, byte[] expected_verify_data) - throws IOException - { - ByteArrayInputStream buf = new ByteArrayInputStream(body); - - byte[] verify_data = TlsUtils.readFully(expected_verify_data.length, buf); - - TlsProtocol.assertEmpty(buf); - - if (!Arrays.constantTimeAreEqual(expected_verify_data, verify_data)) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - } - - protected static void applyMaxFragmentLengthExtension(DTLSRecordLayer recordLayer, short maxFragmentLength) - throws IOException - { - if (maxFragmentLength >= 0) - { - if (!MaxFragmentLength.isValid(maxFragmentLength)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - int plainTextLimit = 1 << (8 + maxFragmentLength); - recordLayer.setPlaintextLimit(plainTextLimit); - } - } - - protected static short evaluateMaxFragmentLengthExtension(boolean resumedSession, Hashtable clientExtensions, - Hashtable serverExtensions, short alertDescription) throws IOException - { - short maxFragmentLength = TlsExtensionsUtils.getMaxFragmentLengthExtension(serverExtensions); - if (maxFragmentLength >= 0) - { - if (!MaxFragmentLength.isValid(maxFragmentLength) - || (!resumedSession && maxFragmentLength != TlsExtensionsUtils - .getMaxFragmentLengthExtension(clientExtensions))) - { - throw new TlsFatalAlert(alertDescription); - } - } - return maxFragmentLength; - } - - protected static byte[] generateCertificate(Certificate certificate) - throws IOException - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - certificate.encode(buf); - return buf.toByteArray(); - } - - protected static byte[] generateSupplementalData(Vector supplementalData) - throws IOException - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - TlsProtocol.writeSupplementalData(buf, supplementalData); - return buf.toByteArray(); - } - - protected static void validateSelectedCipherSuite(int selectedCipherSuite, short alertDescription) - throws IOException - { - switch (TlsUtils.getEncryptionAlgorithm(selectedCipherSuite)) - { - case EncryptionAlgorithm.RC4_40: - case EncryptionAlgorithm.RC4_128: - throw new TlsFatalAlert(alertDescription); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSReassembler.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSReassembler.java deleted file mode 100644 index be0f3eaba..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSReassembler.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.util.Vector; - -class DTLSReassembler -{ - /* - * No 'final' modifiers so that it works in earlier JDKs - */ - private short msg_type; - private byte[] body; - - private Vector missing = new Vector(); - - DTLSReassembler(short msg_type, int length) - { - this.msg_type = msg_type; - this.body = new byte[length]; - this.missing.addElement(new Range(0, length)); - } - - short getMsgType() - { - return msg_type; - } - - byte[] getBodyIfComplete() - { - return missing.isEmpty() ? body : null; - } - - void contributeFragment(short msg_type, int length, byte[] buf, int off, int fragment_offset, - int fragment_length) - { - int fragment_end = fragment_offset + fragment_length; - - if (this.msg_type != msg_type || this.body.length != length || fragment_end > length) - { - return; - } - - if (fragment_length == 0) - { - // NOTE: Empty messages still require an empty fragment to complete it - if (fragment_offset == 0 && !missing.isEmpty()) - { - Range firstRange = (Range)missing.firstElement(); - if (firstRange.getEnd() == 0) - { - missing.removeElementAt(0); - } - } - return; - } - - for (int i = 0; i < missing.size(); ++i) - { - Range range = (Range)missing.elementAt(i); - if (range.getStart() >= fragment_end) - { - break; - } - if (range.getEnd() > fragment_offset) - { - - int copyStart = Math.max(range.getStart(), fragment_offset); - int copyEnd = Math.min(range.getEnd(), fragment_end); - int copyLength = copyEnd - copyStart; - - System.arraycopy(buf, off + copyStart - fragment_offset, body, copyStart, - copyLength); - - if (copyStart == range.getStart()) - { - if (copyEnd == range.getEnd()) - { - missing.removeElementAt(i--); - } - else - { - range.setStart(copyEnd); - } - } - else - { - if (copyEnd != range.getEnd()) - { - missing.insertElementAt(new Range(copyEnd, range.getEnd()), ++i); - } - range.setEnd(copyStart); - } - } - } - } - - void reset() - { - this.missing.removeAllElements(); - this.missing.addElement(new Range(0, body.length)); - } - - private static class Range - { - private int start, end; - - Range(int start, int end) - { - this.start = start; - this.end = end; - } - - public int getStart() - { - return start; - } - - public void setStart(int start) - { - this.start = start; - } - - public int getEnd() - { - return end; - } - - public void setEnd(int end) - { - this.end = end; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSRecordLayer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSRecordLayer.java deleted file mode 100644 index f5faf82f6..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSRecordLayer.java +++ /dev/null @@ -1,549 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -class DTLSRecordLayer - implements DatagramTransport -{ - private static final int RECORD_HEADER_LENGTH = 13; - private static final int MAX_FRAGMENT_LENGTH = 1 << 14; - private static final long TCP_MSL = 1000L * 60 * 2; - private static final long RETRANSMIT_TIMEOUT = TCP_MSL * 2; - - private final DatagramTransport transport; - private final TlsContext context; - private final TlsPeer peer; - - private final ByteQueue recordQueue = new ByteQueue(); - - private volatile boolean closed = false; - private volatile boolean failed = false; - private volatile ProtocolVersion readVersion = null, writeVersion = null; - private volatile boolean inHandshake; - private volatile int plaintextLimit; - private DTLSEpoch currentEpoch, pendingEpoch; - private DTLSEpoch readEpoch, writeEpoch; - - private DTLSHandshakeRetransmit retransmit = null; - private DTLSEpoch retransmitEpoch = null; - private long retransmitExpiry = 0; - - DTLSRecordLayer(DatagramTransport transport, TlsContext context, TlsPeer peer, short contentType) - { - this.transport = transport; - this.context = context; - this.peer = peer; - - this.inHandshake = true; - - this.currentEpoch = new DTLSEpoch(0, new TlsNullCipher(context)); - this.pendingEpoch = null; - this.readEpoch = currentEpoch; - this.writeEpoch = currentEpoch; - - setPlaintextLimit(MAX_FRAGMENT_LENGTH); - } - - boolean isClosed() - { - return closed; - } - - void setPlaintextLimit(int plaintextLimit) - { - this.plaintextLimit = plaintextLimit; - } - - int getReadEpoch() - { - return readEpoch.getEpoch(); - } - - ProtocolVersion getReadVersion() - { - return readVersion; - } - - void setReadVersion(ProtocolVersion readVersion) - { - this.readVersion = readVersion; - } - - void setWriteVersion(ProtocolVersion writeVersion) - { - this.writeVersion = writeVersion; - } - - void initPendingEpoch(TlsCipher pendingCipher) - { - if (pendingEpoch != null) - { - throw new IllegalStateException(); - } - - /* - * TODO "In order to ensure that any given sequence/epoch pair is unique, implementations - * MUST NOT allow the same epoch value to be reused within two times the TCP maximum segment - * lifetime." - */ - - // TODO Check for overflow - this.pendingEpoch = new DTLSEpoch(writeEpoch.getEpoch() + 1, pendingCipher); - } - - void handshakeSuccessful(DTLSHandshakeRetransmit retransmit) - { - if (readEpoch == currentEpoch || writeEpoch == currentEpoch) - { - // TODO - throw new IllegalStateException(); - } - - if (retransmit != null) - { - this.retransmit = retransmit; - this.retransmitEpoch = currentEpoch; - this.retransmitExpiry = System.currentTimeMillis() + RETRANSMIT_TIMEOUT; - } - - this.inHandshake = false; - this.currentEpoch = pendingEpoch; - this.pendingEpoch = null; - } - - void resetWriteEpoch() - { - if (retransmitEpoch != null) - { - this.writeEpoch = retransmitEpoch; - } - else - { - this.writeEpoch = currentEpoch; - } - } - - public int getReceiveLimit() - throws IOException - { - return Math.min(this.plaintextLimit, - readEpoch.getCipher().getPlaintextLimit(transport.getReceiveLimit() - RECORD_HEADER_LENGTH)); - } - - public int getSendLimit() - throws IOException - { - return Math.min(this.plaintextLimit, - writeEpoch.getCipher().getPlaintextLimit(transport.getSendLimit() - RECORD_HEADER_LENGTH)); - } - - public int receive(byte[] buf, int off, int len, int waitMillis) - throws IOException - { - byte[] record = null; - - for (;;) - { - int receiveLimit = Math.min(len, getReceiveLimit()) + RECORD_HEADER_LENGTH; - if (record == null || record.length < receiveLimit) - { - record = new byte[receiveLimit]; - } - - try - { - if (retransmit != null && System.currentTimeMillis() > retransmitExpiry) - { - retransmit = null; - retransmitEpoch = null; - } - - int received = receiveRecord(record, 0, receiveLimit, waitMillis); - if (received < 0) - { - return received; - } - if (received < RECORD_HEADER_LENGTH) - { - continue; - } - int length = TlsUtils.readUint16(record, 11); - if (received != (length + RECORD_HEADER_LENGTH)) - { - continue; - } - - short type = TlsUtils.readUint8(record, 0); - - // TODO Support user-specified custom protocols? - switch (type) - { - case ContentType.alert: - case ContentType.application_data: - case ContentType.change_cipher_spec: - case ContentType.handshake: - case ContentType.heartbeat: - break; - default: - // TODO Exception? - continue; - } - - int epoch = TlsUtils.readUint16(record, 3); - - DTLSEpoch recordEpoch = null; - if (epoch == readEpoch.getEpoch()) - { - recordEpoch = readEpoch; - } - else if (type == ContentType.handshake && retransmitEpoch != null - && epoch == retransmitEpoch.getEpoch()) - { - recordEpoch = retransmitEpoch; - } - - if (recordEpoch == null) - { - continue; - } - - long seq = TlsUtils.readUint48(record, 5); - if (recordEpoch.getReplayWindow().shouldDiscard(seq)) - { - continue; - } - - ProtocolVersion version = TlsUtils.readVersion(record, 1); - if (!version.isDTLS()) - { - continue; - } - - if (readVersion != null && !readVersion.equals(version)) - { - continue; - } - - byte[] plaintext = recordEpoch.getCipher().decodeCiphertext( - getMacSequenceNumber(recordEpoch.getEpoch(), seq), type, record, RECORD_HEADER_LENGTH, - received - RECORD_HEADER_LENGTH); - - recordEpoch.getReplayWindow().reportAuthenticated(seq); - - if (plaintext.length > this.plaintextLimit) - { - continue; - } - - if (readVersion == null) - { - readVersion = version; - } - - switch (type) - { - case ContentType.alert: - { - if (plaintext.length == 2) - { - short alertLevel = plaintext[0]; - short alertDescription = plaintext[1]; - - peer.notifyAlertReceived(alertLevel, alertDescription); - - if (alertLevel == AlertLevel.fatal) - { - failed(); - throw new TlsFatalAlert(alertDescription); - } - - // TODO Can close_notify be a fatal alert? - if (alertDescription == AlertDescription.close_notify) - { - closeTransport(); - } - } - - continue; - } - case ContentType.application_data: - { - if (inHandshake) - { - // TODO Consider buffering application data for new epoch that arrives - // out-of-order with the Finished message - continue; - } - break; - } - case ContentType.change_cipher_spec: - { - // Implicitly receive change_cipher_spec and change to pending cipher state - - for (int i = 0; i < plaintext.length; ++i) - { - short message = TlsUtils.readUint8(plaintext, i); - if (message != ChangeCipherSpec.change_cipher_spec) - { - continue; - } - - if (pendingEpoch != null) - { - readEpoch = pendingEpoch; - } - } - - continue; - } - case ContentType.handshake: - { - if (!inHandshake) - { - if (retransmit != null) - { - retransmit.receivedHandshakeRecord(epoch, plaintext, 0, plaintext.length); - } - - // TODO Consider support for HelloRequest - continue; - } - break; - } - case ContentType.heartbeat: - { - // TODO[RFC 6520] - continue; - } - } - - /* - * NOTE: If we receive any non-handshake data in the new epoch implies the peer has - * received our final flight. - */ - if (!inHandshake && retransmit != null) - { - this.retransmit = null; - this.retransmitEpoch = null; - } - - System.arraycopy(plaintext, 0, buf, off, plaintext.length); - return plaintext.length; - } - catch (IOException e) - { - // NOTE: Assume this is a timeout for the moment - throw e; - } - } - } - - public void send(byte[] buf, int off, int len) - throws IOException - { - short contentType = ContentType.application_data; - - if (this.inHandshake || this.writeEpoch == this.retransmitEpoch) - { - contentType = ContentType.handshake; - - short handshakeType = TlsUtils.readUint8(buf, off); - if (handshakeType == HandshakeType.finished) - { - DTLSEpoch nextEpoch = null; - if (this.inHandshake) - { - nextEpoch = pendingEpoch; - } - else if (this.writeEpoch == this.retransmitEpoch) - { - nextEpoch = currentEpoch; - } - - if (nextEpoch == null) - { - // TODO - throw new IllegalStateException(); - } - - // Implicitly send change_cipher_spec and change to pending cipher state - - // TODO Send change_cipher_spec and finished records in single datagram? - byte[] data = new byte[]{ 1 }; - sendRecord(ContentType.change_cipher_spec, data, 0, data.length); - - writeEpoch = nextEpoch; - } - } - - sendRecord(contentType, buf, off, len); - } - - public void close() - throws IOException - { - if (!closed) - { - if (inHandshake) - { - warn(AlertDescription.user_canceled, "User canceled handshake"); - } - closeTransport(); - } - } - - void fail(short alertDescription) - { - if (!closed) - { - try - { - raiseAlert(AlertLevel.fatal, alertDescription, null, null); - } - catch (Exception e) - { - // Ignore - } - - failed = true; - - closeTransport(); - } - } - - void failed() - { - if (!closed) - { - failed = true; - - closeTransport(); - } - } - - void warn(short alertDescription, String message) - throws IOException - { - raiseAlert(AlertLevel.warning, alertDescription, message, null); - } - - private void closeTransport() - { - if (!closed) - { - /* - * RFC 5246 7.2.1. Unless some other fatal alert has been transmitted, each party is - * required to send a close_notify alert before closing the write side of the - * connection. The other party MUST respond with a close_notify alert of its own and - * close down the connection immediately, discarding any pending writes. - */ - - try - { - if (!failed) - { - warn(AlertDescription.close_notify, null); - } - transport.close(); - } - catch (Exception e) - { - // Ignore - } - - closed = true; - } - } - - private void raiseAlert(short alertLevel, short alertDescription, String message, Throwable cause) - throws IOException - { - peer.notifyAlertRaised(alertLevel, alertDescription, message, cause); - - byte[] error = new byte[2]; - error[0] = (byte)alertLevel; - error[1] = (byte)alertDescription; - - sendRecord(ContentType.alert, error, 0, 2); - } - - private int receiveRecord(byte[] buf, int off, int len, int waitMillis) - throws IOException - { - if (recordQueue.available() > 0) - { - int length = 0; - if (recordQueue.available() >= RECORD_HEADER_LENGTH) - { - byte[] lengthBytes = new byte[2]; - recordQueue.read(lengthBytes, 0, 2, 11); - length = TlsUtils.readUint16(lengthBytes, 0); - } - - int received = Math.min(recordQueue.available(), RECORD_HEADER_LENGTH + length); - recordQueue.removeData(buf, off, received, 0); - return received; - } - - int received = transport.receive(buf, off, len, waitMillis); - if (received >= RECORD_HEADER_LENGTH) - { - int fragmentLength = TlsUtils.readUint16(buf, off + 11); - int recordLength = RECORD_HEADER_LENGTH + fragmentLength; - if (received > recordLength) - { - recordQueue.addData(buf, off + recordLength, received - recordLength); - received = recordLength; - } - } - - return received; - } - - private void sendRecord(short contentType, byte[] buf, int off, int len) - throws IOException - { - // Never send anything until a valid ClientHello has been received - if (writeVersion == null) - { - return; - } - - if (len > this.plaintextLimit) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - /* - * RFC 5246 6.2.1 Implementations MUST NOT send zero-length fragments of Handshake, Alert, - * or ChangeCipherSpec content types. - */ - if (len < 1 && contentType != ContentType.application_data) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - int recordEpoch = writeEpoch.getEpoch(); - long recordSequenceNumber = writeEpoch.allocateSequenceNumber(); - - byte[] ciphertext = writeEpoch.getCipher().encodePlaintext( - getMacSequenceNumber(recordEpoch, recordSequenceNumber), contentType, buf, off, len); - - // TODO Check the ciphertext length? - - byte[] record = new byte[ciphertext.length + RECORD_HEADER_LENGTH]; - TlsUtils.writeUint8(contentType, record, 0); - TlsUtils.writeVersion(writeVersion, record, 1); - TlsUtils.writeUint16(recordEpoch, record, 3); - TlsUtils.writeUint48(recordSequenceNumber, record, 5); - TlsUtils.writeUint16(ciphertext.length, record, 11); - System.arraycopy(ciphertext, 0, record, RECORD_HEADER_LENGTH, ciphertext.length); - - transport.send(record, 0, record.length); - } - - private static long getMacSequenceNumber(int epoch, long sequence_number) - { - return ((epoch & 0xFFFFFFFFL) << 48) | sequence_number; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSReliableHandshake.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSReliableHandshake.java deleted file mode 100644 index 5a386cab3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSReliableHandshake.java +++ /dev/null @@ -1,442 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.util.Integers; - -class DTLSReliableHandshake -{ - private final static int MAX_RECEIVE_AHEAD = 16; - private static final int MESSAGE_HEADER_LENGTH = 12; - - /* - * No 'final' modifiers so that it works in earlier JDKs - */ - private DTLSRecordLayer recordLayer; - - private TlsHandshakeHash handshakeHash; - - private Hashtable currentInboundFlight = new Hashtable(); - private Hashtable previousInboundFlight = null; - private Vector outboundFlight = new Vector(); - private boolean sending = true; - - private int message_seq = 0, next_receive_seq = 0; - - DTLSReliableHandshake(TlsContext context, DTLSRecordLayer transport) - { - this.recordLayer = transport; - this.handshakeHash = new DeferredHash(); - this.handshakeHash.init(context); - } - - void notifyHelloComplete() - { - this.handshakeHash = handshakeHash.notifyPRFDetermined(); - } - - TlsHandshakeHash getHandshakeHash() - { - return handshakeHash; - } - - TlsHandshakeHash prepareToFinish() - { - TlsHandshakeHash result = handshakeHash; - this.handshakeHash = handshakeHash.stopTracking(); - return result; - } - - void sendMessage(short msg_type, byte[] body) - throws IOException - { - TlsUtils.checkUint24(body.length); - - if (!sending) - { - checkInboundFlight(); - sending = true; - outboundFlight.removeAllElements(); - } - - Message message = new Message(message_seq++, msg_type, body); - - outboundFlight.addElement(message); - - writeMessage(message); - updateHandshakeMessagesDigest(message); - } - - byte[] receiveMessageBody(short msg_type) - throws IOException - { - Message message = receiveMessage(); - if (message.getType() != msg_type) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - return message.getBody(); - } - - Message receiveMessage() - throws IOException - { - if (sending) - { - sending = false; - prepareInboundFlight(new Hashtable()); - } - - byte[] buf = null; - - // TODO Check the conditions under which we should reset this - int readTimeoutMillis = 1000; - - for (;;) - { - try - { - for (;;) - { - if (recordLayer.isClosed()) - { - throw new TlsFatalAlert(AlertDescription.user_canceled); - } - - Message pending = getPendingMessage(); - if (pending != null) - { - return pending; - } - - int receiveLimit = recordLayer.getReceiveLimit(); - if (buf == null || buf.length < receiveLimit) - { - buf = new byte[receiveLimit]; - } - - int received = recordLayer.receive(buf, 0, receiveLimit, readTimeoutMillis); - if (received < 0) - { - break; - } - - boolean resentOutbound = processRecord(MAX_RECEIVE_AHEAD, recordLayer.getReadEpoch(), buf, 0, received); - if (resentOutbound) - { - readTimeoutMillis = backOff(readTimeoutMillis); - } - } - } - catch (IOException e) - { - // NOTE: Assume this is a timeout for the moment - } - - resendOutboundFlight(); - readTimeoutMillis = backOff(readTimeoutMillis); - } - } - - void finish() - { - DTLSHandshakeRetransmit retransmit = null; - if (!sending) - { - checkInboundFlight(); - } - else - { - prepareInboundFlight(null); - - if (previousInboundFlight != null) - { - /* - * RFC 6347 4.2.4. In addition, for at least twice the default MSL defined for [TCP], - * when in the FINISHED state, the node that transmits the last flight (the server in an - * ordinary handshake or the client in a resumed handshake) MUST respond to a retransmit - * of the peer's last flight with a retransmit of the last flight. - */ - retransmit = new DTLSHandshakeRetransmit() - { - public void receivedHandshakeRecord(int epoch, byte[] buf, int off, int len) - throws IOException - { - processRecord(0, epoch, buf, off, len); - } - }; - } - } - - recordLayer.handshakeSuccessful(retransmit); - } - - void resetHandshakeMessagesDigest() - { - handshakeHash.reset(); - } - - private int backOff(int timeoutMillis) - { - /* - * TODO[DTLS] implementations SHOULD back off handshake packet size during the - * retransmit backoff. - */ - return Math.min(timeoutMillis * 2, 60000); - } - - /** - * Check that there are no "extra" messages left in the current inbound flight - */ - private void checkInboundFlight() - { - Enumeration e = currentInboundFlight.keys(); - while (e.hasMoreElements()) - { - Integer key = (Integer)e.nextElement(); - if (key.intValue() >= next_receive_seq) - { - // TODO Should this be considered an error? - } - } - } - - private Message getPendingMessage() throws IOException - { - DTLSReassembler next = (DTLSReassembler)currentInboundFlight.get(Integers.valueOf(next_receive_seq)); - if (next != null) - { - byte[] body = next.getBodyIfComplete(); - if (body != null) - { - previousInboundFlight = null; - return updateHandshakeMessagesDigest(new Message(next_receive_seq++, next.getMsgType(), body)); - } - } - return null; - } - - private void prepareInboundFlight(Hashtable nextFlight) - { - resetAll(currentInboundFlight); - previousInboundFlight = currentInboundFlight; - currentInboundFlight = nextFlight; - } - - private boolean processRecord(int windowSize, int epoch, byte[] buf, int off, int len) throws IOException - { - boolean checkPreviousFlight = false; - - while (len >= MESSAGE_HEADER_LENGTH) - { - int fragment_length = TlsUtils.readUint24(buf, off + 9); - int message_length = fragment_length + MESSAGE_HEADER_LENGTH; - if (len < message_length) - { - // NOTE: Truncated message - ignore it - break; - } - - int length = TlsUtils.readUint24(buf, off + 1); - int fragment_offset = TlsUtils.readUint24(buf, off + 6); - if (fragment_offset + fragment_length > length) - { - // NOTE: Malformed fragment - ignore it and the rest of the record - break; - } - - /* - * NOTE: This very simple epoch check will only work until we want to support - * renegotiation (and we're not likely to do that anyway). - */ - short msg_type = TlsUtils.readUint8(buf, off + 0); - int expectedEpoch = msg_type == HandshakeType.finished ? 1 : 0; - if (epoch != expectedEpoch) - { - break; - } - - int message_seq = TlsUtils.readUint16(buf, off + 4); - if (message_seq >= (next_receive_seq + windowSize)) - { - // NOTE: Too far ahead - ignore - } - else if (message_seq >= next_receive_seq) - { - DTLSReassembler reassembler = (DTLSReassembler)currentInboundFlight.get(Integers.valueOf(message_seq)); - if (reassembler == null) - { - reassembler = new DTLSReassembler(msg_type, length); - currentInboundFlight.put(Integers.valueOf(message_seq), reassembler); - } - - reassembler.contributeFragment(msg_type, length, buf, off + MESSAGE_HEADER_LENGTH, fragment_offset, - fragment_length); - } - else if (previousInboundFlight != null) - { - /* - * NOTE: If we receive the previous flight of incoming messages in full again, - * retransmit our last flight - */ - - DTLSReassembler reassembler = (DTLSReassembler)previousInboundFlight.get(Integers.valueOf(message_seq)); - if (reassembler != null) - { - reassembler.contributeFragment(msg_type, length, buf, off + MESSAGE_HEADER_LENGTH, fragment_offset, - fragment_length); - checkPreviousFlight = true; - } - } - - off += message_length; - len -= message_length; - } - - boolean result = checkPreviousFlight && checkAll(previousInboundFlight); - if (result) - { - resendOutboundFlight(); - resetAll(previousInboundFlight); - } - return result; - } - - private void resendOutboundFlight() - throws IOException - { - recordLayer.resetWriteEpoch(); - for (int i = 0; i < outboundFlight.size(); ++i) - { - writeMessage((Message)outboundFlight.elementAt(i)); - } - } - - private Message updateHandshakeMessagesDigest(Message message) - throws IOException - { - if (message.getType() != HandshakeType.hello_request) - { - byte[] body = message.getBody(); - byte[] buf = new byte[MESSAGE_HEADER_LENGTH]; - TlsUtils.writeUint8(message.getType(), buf, 0); - TlsUtils.writeUint24(body.length, buf, 1); - TlsUtils.writeUint16(message.getSeq(), buf, 4); - TlsUtils.writeUint24(0, buf, 6); - TlsUtils.writeUint24(body.length, buf, 9); - handshakeHash.update(buf, 0, buf.length); - handshakeHash.update(body, 0, body.length); - } - return message; - } - - private void writeMessage(Message message) - throws IOException - { - int sendLimit = recordLayer.getSendLimit(); - int fragmentLimit = sendLimit - MESSAGE_HEADER_LENGTH; - - // TODO Support a higher minimum fragment size? - if (fragmentLimit < 1) - { - // TODO Should we be throwing an exception here? - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - int length = message.getBody().length; - - // NOTE: Must still send a fragment if body is empty - int fragment_offset = 0; - do - { - int fragment_length = Math.min(length - fragment_offset, fragmentLimit); - writeHandshakeFragment(message, fragment_offset, fragment_length); - fragment_offset += fragment_length; - } - while (fragment_offset < length); - } - - private void writeHandshakeFragment(Message message, int fragment_offset, int fragment_length) - throws IOException - { - RecordLayerBuffer fragment = new RecordLayerBuffer(MESSAGE_HEADER_LENGTH + fragment_length); - TlsUtils.writeUint8(message.getType(), fragment); - TlsUtils.writeUint24(message.getBody().length, fragment); - TlsUtils.writeUint16(message.getSeq(), fragment); - TlsUtils.writeUint24(fragment_offset, fragment); - TlsUtils.writeUint24(fragment_length, fragment); - fragment.write(message.getBody(), fragment_offset, fragment_length); - - fragment.sendToRecordLayer(recordLayer); - } - - private static boolean checkAll(Hashtable inboundFlight) - { - Enumeration e = inboundFlight.elements(); - while (e.hasMoreElements()) - { - if (((DTLSReassembler)e.nextElement()).getBodyIfComplete() == null) - { - return false; - } - } - return true; - } - - private static void resetAll(Hashtable inboundFlight) - { - Enumeration e = inboundFlight.elements(); - while (e.hasMoreElements()) - { - ((DTLSReassembler)e.nextElement()).reset(); - } - } - - static class Message - { - private final int message_seq; - private final short msg_type; - private final byte[] body; - - private Message(int message_seq, short msg_type, byte[] body) - { - this.message_seq = message_seq; - this.msg_type = msg_type; - this.body = body; - } - - public int getSeq() - { - return message_seq; - } - - public short getType() - { - return msg_type; - } - - public byte[] getBody() - { - return body; - } - } - - static class RecordLayerBuffer extends ByteArrayOutputStream - { - RecordLayerBuffer(int size) - { - super(size); - } - - void sendToRecordLayer(DTLSRecordLayer recordLayer) throws IOException - { - recordLayer.send(buf, 0, count); - buf = null; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSReplayWindow.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSReplayWindow.java deleted file mode 100644 index 21ec072f0..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSReplayWindow.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 4347 4.1.2.5 Anti-replay - *
- * Support fast rejection of duplicate records by maintaining a sliding receive window - *
- */ -class DTLSReplayWindow -{ - private static final long VALID_SEQ_MASK = 0x0000FFFFFFFFFFFFL; - - private static final long WINDOW_SIZE = 64L; - - private long latestConfirmedSeq = -1; - private long bitmap = 0; - - /** - * Check whether a received record with the given sequence number should be rejected as a duplicate. - * - * @param seq the 48-bit DTLSPlainText.sequence_number field of a received record. - * @return true if the record should be discarded without further processing. - */ - boolean shouldDiscard(long seq) - { - if ((seq & VALID_SEQ_MASK) != seq) - { - return true; - } - - if (seq <= latestConfirmedSeq) - { - long diff = latestConfirmedSeq - seq; - if (diff >= WINDOW_SIZE) - { - return true; - } - if ((bitmap & (1L << diff)) != 0) - { - return true; - } - } - - return false; - } - - /** - * Report that a received record with the given sequence number passed authentication checks. - * - * @param seq the 48-bit DTLSPlainText.sequence_number field of an authenticated record. - */ - void reportAuthenticated(long seq) - { - if ((seq & VALID_SEQ_MASK) != seq) - { - throw new IllegalArgumentException("'seq' out of range"); - } - - if (seq <= latestConfirmedSeq) - { - long diff = latestConfirmedSeq - seq; - if (diff < WINDOW_SIZE) - { - bitmap |= (1L << diff); - } - } - else - { - long diff = seq - latestConfirmedSeq; - if (diff >= WINDOW_SIZE) - { - bitmap = 1; - } - else - { - bitmap <<= (int)diff; // for earlier JDKs - bitmap |= 1; - } - latestConfirmedSeq = seq; - } - } - - /** - * When a new epoch begins, sequence numbers begin again at 0 - */ - void reset() - { - latestConfirmedSeq = -1; - bitmap = 0; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSServerProtocol.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSServerProtocol.java deleted file mode 100644 index ef3435b09..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSServerProtocol.java +++ /dev/null @@ -1,765 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.security.SecureRandom; -import java.util.Hashtable; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.util.PublicKeyFactory; -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class DTLSServerProtocol - extends DTLSProtocol -{ - protected boolean verifyRequests = true; - - public DTLSServerProtocol(SecureRandom secureRandom) - { - super(secureRandom); - } - - public boolean getVerifyRequests() - { - return verifyRequests; - } - - public void setVerifyRequests(boolean verifyRequests) - { - this.verifyRequests = verifyRequests; - } - - public DTLSTransport accept(TlsServer server, DatagramTransport transport) - throws IOException - { - if (server == null) - { - throw new IllegalArgumentException("'server' cannot be null"); - } - if (transport == null) - { - throw new IllegalArgumentException("'transport' cannot be null"); - } - - SecurityParameters securityParameters = new SecurityParameters(); - securityParameters.entity = ConnectionEnd.server; - - ServerHandshakeState state = new ServerHandshakeState(); - state.server = server; - state.serverContext = new TlsServerContextImpl(secureRandom, securityParameters); - - securityParameters.serverRandom = TlsProtocol.createRandomBlock(server.shouldUseGMTUnixTime(), - state.serverContext.getNonceRandomGenerator()); - - server.init(state.serverContext); - - DTLSRecordLayer recordLayer = new DTLSRecordLayer(transport, state.serverContext, server, ContentType.handshake); - server.notifyCloseHandle(recordLayer); - - // TODO Need to handle sending of HelloVerifyRequest without entering a full connection - - try - { - return serverHandshake(state, recordLayer); - } - catch (TlsFatalAlert fatalAlert) - { - abortServerHandshake(state, recordLayer, fatalAlert.getAlertDescription()); - throw fatalAlert; - } - catch (IOException e) - { - abortServerHandshake(state, recordLayer, AlertDescription.internal_error); - throw e; - } - catch (RuntimeException e) - { - abortServerHandshake(state, recordLayer, AlertDescription.internal_error); - throw new TlsFatalAlert(AlertDescription.internal_error, e); - } - finally - { - securityParameters.clear(); - } - } - - protected void abortServerHandshake(ServerHandshakeState state, DTLSRecordLayer recordLayer, short alertDescription) - { - recordLayer.fail(alertDescription); - invalidateSession(state); - } - - protected DTLSTransport serverHandshake(ServerHandshakeState state, DTLSRecordLayer recordLayer) - throws IOException - { - SecurityParameters securityParameters = state.serverContext.getSecurityParameters(); - DTLSReliableHandshake handshake = new DTLSReliableHandshake(state.serverContext, recordLayer); - - DTLSReliableHandshake.Message clientMessage = handshake.receiveMessage(); - - // NOTE: DTLSRecordLayer requires any DTLS version, we don't otherwise constrain this -// ProtocolVersion recordLayerVersion = recordLayer.getReadVersion(); - - if (clientMessage.getType() == HandshakeType.client_hello) - { - processClientHello(state, clientMessage.getBody()); - } - else - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - { - byte[] serverHelloBody = generateServerHello(state); - - applyMaxFragmentLengthExtension(recordLayer, securityParameters.maxFragmentLength); - - ProtocolVersion recordLayerVersion = state.serverContext.getServerVersion(); - recordLayer.setReadVersion(recordLayerVersion); - recordLayer.setWriteVersion(recordLayerVersion); - - handshake.sendMessage(HandshakeType.server_hello, serverHelloBody); - } - - handshake.notifyHelloComplete(); - - Vector serverSupplementalData = state.server.getServerSupplementalData(); - if (serverSupplementalData != null) - { - byte[] supplementalDataBody = generateSupplementalData(serverSupplementalData); - handshake.sendMessage(HandshakeType.supplemental_data, supplementalDataBody); - } - - state.keyExchange = state.server.getKeyExchange(); - state.keyExchange.init(state.serverContext); - - state.serverCredentials = state.server.getCredentials(); - - Certificate serverCertificate = null; - - if (state.serverCredentials == null) - { - state.keyExchange.skipServerCredentials(); - } - else - { - state.keyExchange.processServerCredentials(state.serverCredentials); - - serverCertificate = state.serverCredentials.getCertificate(); - byte[] certificateBody = generateCertificate(serverCertificate); - handshake.sendMessage(HandshakeType.certificate, certificateBody); - } - - // TODO[RFC 3546] Check whether empty certificates is possible, allowed, or excludes CertificateStatus - if (serverCertificate == null || serverCertificate.isEmpty()) - { - state.allowCertificateStatus = false; - } - - if (state.allowCertificateStatus) - { - CertificateStatus certificateStatus = state.server.getCertificateStatus(); - if (certificateStatus != null) - { - byte[] certificateStatusBody = generateCertificateStatus(state, certificateStatus); - handshake.sendMessage(HandshakeType.certificate_status, certificateStatusBody); - } - } - - byte[] serverKeyExchange = state.keyExchange.generateServerKeyExchange(); - if (serverKeyExchange != null) - { - handshake.sendMessage(HandshakeType.server_key_exchange, serverKeyExchange); - } - - if (state.serverCredentials != null) - { - state.certificateRequest = state.server.getCertificateRequest(); - if (state.certificateRequest != null) - { - if (TlsUtils.isTLSv12(state.serverContext) != (state.certificateRequest.getSupportedSignatureAlgorithms() != null)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - state.keyExchange.validateCertificateRequest(state.certificateRequest); - - byte[] certificateRequestBody = generateCertificateRequest(state, state.certificateRequest); - handshake.sendMessage(HandshakeType.certificate_request, certificateRequestBody); - - TlsUtils.trackHashAlgorithms(handshake.getHandshakeHash(), - state.certificateRequest.getSupportedSignatureAlgorithms()); - } - } - - handshake.sendMessage(HandshakeType.server_hello_done, TlsUtils.EMPTY_BYTES); - - handshake.getHandshakeHash().sealHashAlgorithms(); - - clientMessage = handshake.receiveMessage(); - - if (clientMessage.getType() == HandshakeType.supplemental_data) - { - processClientSupplementalData(state, clientMessage.getBody()); - clientMessage = handshake.receiveMessage(); - } - else - { - state.server.processClientSupplementalData(null); - } - - if (state.certificateRequest == null) - { - state.keyExchange.skipClientCredentials(); - } - else - { - if (clientMessage.getType() == HandshakeType.certificate) - { - processClientCertificate(state, clientMessage.getBody()); - clientMessage = handshake.receiveMessage(); - } - else - { - if (TlsUtils.isTLSv12(state.serverContext)) - { - /* - * RFC 5246 If no suitable certificate is available, the client MUST send a - * certificate message containing no certificates. - * - * NOTE: In previous RFCs, this was SHOULD instead of MUST. - */ - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - notifyClientCertificate(state, Certificate.EMPTY_CHAIN); - } - } - - if (clientMessage.getType() == HandshakeType.client_key_exchange) - { - processClientKeyExchange(state, clientMessage.getBody()); - } - else - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - TlsHandshakeHash prepareFinishHash = handshake.prepareToFinish(); - securityParameters.sessionHash = TlsProtocol.getCurrentPRFHash(state.serverContext, prepareFinishHash, null); - - TlsProtocol.establishMasterSecret(state.serverContext, state.keyExchange); - recordLayer.initPendingEpoch(state.server.getCipher()); - - /* - * RFC 5246 7.4.8 This message is only sent following a client certificate that has signing - * capability (i.e., all certificates except those containing fixed Diffie-Hellman - * parameters). - */ - if (expectCertificateVerifyMessage(state)) - { - byte[] certificateVerifyBody = handshake.receiveMessageBody(HandshakeType.certificate_verify); - processCertificateVerify(state, certificateVerifyBody, prepareFinishHash); - } - - // NOTE: Calculated exclusive of the actual Finished message from the client - byte[] expectedClientVerifyData = TlsUtils.calculateVerifyData(state.serverContext, ExporterLabel.client_finished, - TlsProtocol.getCurrentPRFHash(state.serverContext, handshake.getHandshakeHash(), null)); - processFinished(handshake.receiveMessageBody(HandshakeType.finished), expectedClientVerifyData); - - if (state.expectSessionTicket) - { - NewSessionTicket newSessionTicket = state.server.getNewSessionTicket(); - byte[] newSessionTicketBody = generateNewSessionTicket(state, newSessionTicket); - handshake.sendMessage(HandshakeType.session_ticket, newSessionTicketBody); - } - - // NOTE: Calculated exclusive of the Finished message itself - byte[] serverVerifyData = TlsUtils.calculateVerifyData(state.serverContext, ExporterLabel.server_finished, - TlsProtocol.getCurrentPRFHash(state.serverContext, handshake.getHandshakeHash(), null)); - handshake.sendMessage(HandshakeType.finished, serverVerifyData); - - handshake.finish(); - -// { -// state.sessionParameters = new SessionParameters.Builder() -// .setCipherSuite(securityParameters.getCipherSuite()) -// .setCompressionAlgorithm(securityParameters.getCompressionAlgorithm()) -// .setExtendedMasterSecret(securityParameters.isExtendedMasterSecret()) -// .setMasterSecret(securityParameters.getMasterSecret()) -// .setPeerCertificate(state.clientCertificate) -// .setPSKIdentity(securityParameters.getPSKIdentity()) -// .setSRPIdentity(securityParameters.getSRPIdentity()) -// // TODO Consider filtering extensions that aren't relevant to resumed sessions -// .setServerExtensions(state.serverExtensions) -// .build(); -// -// state.tlsSession = TlsUtils.importSession(state.tlsSession.getSessionID(), state.sessionParameters); -// -// state.serverContext.setResumableSession(state.tlsSession); -// } - - state.server.notifyHandshakeComplete(); - - return new DTLSTransport(recordLayer); - } - - protected byte[] generateCertificateRequest(ServerHandshakeState state, CertificateRequest certificateRequest) - throws IOException - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - certificateRequest.encode(buf); - return buf.toByteArray(); - } - - protected byte[] generateCertificateStatus(ServerHandshakeState state, CertificateStatus certificateStatus) - throws IOException - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - certificateStatus.encode(buf); - return buf.toByteArray(); - } - - protected byte[] generateNewSessionTicket(ServerHandshakeState state, NewSessionTicket newSessionTicket) - throws IOException - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - newSessionTicket.encode(buf); - return buf.toByteArray(); - } - - protected byte[] generateServerHello(ServerHandshakeState state) - throws IOException - { - SecurityParameters securityParameters = state.serverContext.getSecurityParameters(); - - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - { - ProtocolVersion server_version = state.server.getServerVersion(); - if (!server_version.isEqualOrEarlierVersionOf(state.serverContext.getClientVersion())) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - // TODO Read RFCs for guidance on the expected record layer version number - // recordStream.setReadVersion(server_version); - // recordStream.setWriteVersion(server_version); - // recordStream.setRestrictReadVersion(true); - state.serverContext.setServerVersion(server_version); - - TlsUtils.writeVersion(state.serverContext.getServerVersion(), buf); - } - - buf.write(securityParameters.getServerRandom()); - - /* - * The server may return an empty session_id to indicate that the session will not be cached - * and therefore cannot be resumed. - */ - TlsUtils.writeOpaque8(TlsUtils.EMPTY_BYTES, buf); - - int selectedCipherSuite = state.server.getSelectedCipherSuite(); - if (!Arrays.contains(state.offeredCipherSuites, selectedCipherSuite) - || selectedCipherSuite == CipherSuite.TLS_NULL_WITH_NULL_NULL - || CipherSuite.isSCSV(selectedCipherSuite) - || !TlsUtils.isValidCipherSuiteForVersion(selectedCipherSuite, state.serverContext.getServerVersion())) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - validateSelectedCipherSuite(selectedCipherSuite, AlertDescription.internal_error); - securityParameters.cipherSuite = selectedCipherSuite; - - short selectedCompressionMethod = state.server.getSelectedCompressionMethod(); - if (!Arrays.contains(state.offeredCompressionMethods, selectedCompressionMethod)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - securityParameters.compressionAlgorithm = selectedCompressionMethod; - - TlsUtils.writeUint16(selectedCipherSuite, buf); - TlsUtils.writeUint8(selectedCompressionMethod, buf); - - state.serverExtensions = TlsExtensionsUtils.ensureExtensionsInitialised(state.server.getServerExtensions()); - - /* - * RFC 5746 3.6. Server Behavior: Initial Handshake - */ - if (state.secure_renegotiation) - { - byte[] renegExtData = TlsUtils.getExtensionData(state.serverExtensions, TlsProtocol.EXT_RenegotiationInfo); - boolean noRenegExt = (null == renegExtData); - - if (noRenegExt) - { - /* - * Note that sending a "renegotiation_info" extension in response to a ClientHello - * containing only the SCSV is an explicit exception to the prohibition in RFC 5246, - * Section 7.4.1.4, on the server sending unsolicited extensions and is only allowed - * because the client is signaling its willingness to receive the extension via the - * TLS_EMPTY_RENEGOTIATION_INFO_SCSV SCSV. - */ - - /* - * If the secure_renegotiation flag is set to TRUE, the server MUST include an empty - * "renegotiation_info" extension in the ServerHello message. - */ - state.serverExtensions.put(TlsProtocol.EXT_RenegotiationInfo, - TlsProtocol.createRenegotiationInfo(TlsUtils.EMPTY_BYTES)); - } - } - - if (securityParameters.isExtendedMasterSecret()) - { - TlsExtensionsUtils.addExtendedMasterSecretExtension(state.serverExtensions); - } - - /* - * TODO RFC 3546 2.3 If [...] the older session is resumed, then the server MUST ignore - * extensions appearing in the client hello, and send a server hello containing no - * extensions. - */ - - if (!state.serverExtensions.isEmpty()) - { - securityParameters.encryptThenMAC = TlsExtensionsUtils.hasEncryptThenMACExtension(state.serverExtensions); - - securityParameters.maxFragmentLength = evaluateMaxFragmentLengthExtension(state.resumedSession, - state.clientExtensions, state.serverExtensions, AlertDescription.internal_error); - - securityParameters.truncatedHMac = TlsExtensionsUtils.hasTruncatedHMacExtension(state.serverExtensions); - - /* - * TODO It's surprising that there's no provision to allow a 'fresh' CertificateStatus to be sent in - * a session resumption handshake. - */ - state.allowCertificateStatus = !state.resumedSession - && TlsUtils.hasExpectedEmptyExtensionData(state.serverExtensions, - TlsExtensionsUtils.EXT_status_request, AlertDescription.internal_error); - - state.expectSessionTicket = !state.resumedSession - && TlsUtils.hasExpectedEmptyExtensionData(state.serverExtensions, TlsProtocol.EXT_SessionTicket, - AlertDescription.internal_error); - - TlsProtocol.writeExtensions(buf, state.serverExtensions); - } - - securityParameters.prfAlgorithm = TlsProtocol.getPRFAlgorithm(state.serverContext, - securityParameters.getCipherSuite()); - - /* - * RFC 5246 7.4.9. Any cipher suite which does not explicitly specify verify_data_length - * has a verify_data_length equal to 12. This includes all existing cipher suites. - */ - securityParameters.verifyDataLength = 12; - - return buf.toByteArray(); - } - - protected void invalidateSession(ServerHandshakeState state) - { - if (state.sessionParameters != null) - { - state.sessionParameters.clear(); - state.sessionParameters = null; - } - - if (state.tlsSession != null) - { - state.tlsSession.invalidate(); - state.tlsSession = null; - } - } - - protected void notifyClientCertificate(ServerHandshakeState state, Certificate clientCertificate) - throws IOException - { - if (state.certificateRequest == null) - { - throw new IllegalStateException(); - } - - if (state.clientCertificate != null) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - state.clientCertificate = clientCertificate; - - if (clientCertificate.isEmpty()) - { - state.keyExchange.skipClientCredentials(); - } - else - { - - /* - * TODO RFC 5246 7.4.6. If the certificate_authorities list in the certificate request - * message was non-empty, one of the certificates in the certificate chain SHOULD be - * issued by one of the listed CAs. - */ - - state.clientCertificateType = TlsUtils.getClientCertificateType(clientCertificate, - state.serverCredentials.getCertificate()); - - state.keyExchange.processClientCertificate(clientCertificate); - } - - /* - * RFC 5246 7.4.6. If the client does not send any certificates, the server MAY at its - * discretion either continue the handshake without client authentication, or respond with a - * fatal handshake_failure alert. Also, if some aspect of the certificate chain was - * unacceptable (e.g., it was not signed by a known, trusted CA), the server MAY at its - * discretion either continue the handshake (considering the client unauthenticated) or send - * a fatal alert. - */ - state.server.notifyClientCertificate(clientCertificate); - } - - protected void processClientCertificate(ServerHandshakeState state, byte[] body) - throws IOException - { - ByteArrayInputStream buf = new ByteArrayInputStream(body); - - Certificate clientCertificate = Certificate.parse(buf); - - TlsProtocol.assertEmpty(buf); - - notifyClientCertificate(state, clientCertificate); - } - - protected void processCertificateVerify(ServerHandshakeState state, byte[] body, TlsHandshakeHash prepareFinishHash) - throws IOException - { - if (state.certificateRequest == null) - { - throw new IllegalStateException(); - } - - ByteArrayInputStream buf = new ByteArrayInputStream(body); - - TlsServerContextImpl context = state.serverContext; - DigitallySigned clientCertificateVerify = DigitallySigned.parse(context, buf); - - TlsProtocol.assertEmpty(buf); - - // Verify the CertificateVerify message contains a correct signature. - try - { - SignatureAndHashAlgorithm signatureAlgorithm = clientCertificateVerify.getAlgorithm(); - - byte[] hash; - if (TlsUtils.isTLSv12(context)) - { - TlsUtils.verifySupportedSignatureAlgorithm(state.certificateRequest.getSupportedSignatureAlgorithms(), signatureAlgorithm); - hash = prepareFinishHash.getFinalHash(signatureAlgorithm.getHash()); - } - else - { - hash = context.getSecurityParameters().getSessionHash(); - } - - com.fr.third.org.bouncycastle.asn1.x509.Certificate x509Cert = state.clientCertificate.getCertificateAt(0); - SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo(); - AsymmetricKeyParameter publicKey = PublicKeyFactory.createKey(keyInfo); - - TlsSigner tlsSigner = TlsUtils.createTlsSigner(state.clientCertificateType); - tlsSigner.init(context); - if (!tlsSigner.verifyRawSignature(signatureAlgorithm, clientCertificateVerify.getSignature(), publicKey, hash)) - { - throw new TlsFatalAlert(AlertDescription.decrypt_error); - } - } - catch (TlsFatalAlert e) - { - throw e; - } - catch (Exception e) - { - throw new TlsFatalAlert(AlertDescription.decrypt_error, e); - } - } - - protected void processClientHello(ServerHandshakeState state, byte[] body) - throws IOException - { - ByteArrayInputStream buf = new ByteArrayInputStream(body); - - // TODO Read RFCs for guidance on the expected record layer version number - ProtocolVersion client_version = TlsUtils.readVersion(buf); - if (!client_version.isDTLS()) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - /* - * Read the client random - */ - byte[] client_random = TlsUtils.readFully(32, buf); - - byte[] sessionID = TlsUtils.readOpaque8(buf); - if (sessionID.length > 32) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - // TODO RFC 4347 has the cookie length restricted to 32, but not in RFC 6347 - byte[] cookie = TlsUtils.readOpaque8(buf); - - int cipher_suites_length = TlsUtils.readUint16(buf); - if (cipher_suites_length < 2 || (cipher_suites_length & 1) != 0) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - /* - * NOTE: "If the session_id field is not empty (implying a session resumption request) this - * vector must include at least the cipher_suite from that session." - */ - state.offeredCipherSuites = TlsUtils.readUint16Array(cipher_suites_length / 2, buf); - - int compression_methods_length = TlsUtils.readUint8(buf); - if (compression_methods_length < 1) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - state.offeredCompressionMethods = TlsUtils.readUint8Array(compression_methods_length, buf); - - /* - * TODO RFC 3546 2.3 If [...] the older session is resumed, then the server MUST ignore - * extensions appearing in the client hello, and send a server hello containing no - * extensions. - */ - state.clientExtensions = TlsProtocol.readExtensions(buf); - - TlsServerContextImpl context = state.serverContext; - SecurityParameters securityParameters = context.getSecurityParameters(); - - /* - * TODO[resumption] Check RFC 7627 5.4. for required behaviour - */ - - /* - * RFC 7627 4. Clients and servers SHOULD NOT accept handshakes that do not use the extended - * master secret [..]. (and see 5.2, 5.3) - */ - securityParameters.extendedMasterSecret = TlsExtensionsUtils.hasExtendedMasterSecretExtension(state.clientExtensions); - if (!securityParameters.isExtendedMasterSecret() && state.server.requiresExtendedMasterSecret()) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - context.setClientVersion(client_version); - - state.server.notifyClientVersion(client_version); - state.server.notifyFallback(Arrays.contains(state.offeredCipherSuites, CipherSuite.TLS_FALLBACK_SCSV)); - - securityParameters.clientRandom = client_random; - - state.server.notifyOfferedCipherSuites(state.offeredCipherSuites); - state.server.notifyOfferedCompressionMethods(state.offeredCompressionMethods); - - /* - * RFC 5746 3.6. Server Behavior: Initial Handshake - */ - { - /* - * RFC 5746 3.4. The client MUST include either an empty "renegotiation_info" extension, - * or the TLS_EMPTY_RENEGOTIATION_INFO_SCSV signaling cipher suite value in the - * ClientHello. Including both is NOT RECOMMENDED. - */ - - /* - * When a ClientHello is received, the server MUST check if it includes the - * TLS_EMPTY_RENEGOTIATION_INFO_SCSV SCSV. If it does, set the secure_renegotiation flag - * to TRUE. - */ - if (Arrays.contains(state.offeredCipherSuites, CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV)) - { - state.secure_renegotiation = true; - } - - /* - * The server MUST check if the "renegotiation_info" extension is included in the - * ClientHello. - */ - byte[] renegExtData = TlsUtils.getExtensionData(state.clientExtensions, TlsProtocol.EXT_RenegotiationInfo); - if (renegExtData != null) - { - /* - * If the extension is present, set secure_renegotiation flag to TRUE. The - * server MUST then verify that the length of the "renegotiated_connection" - * field is zero, and if it is not, MUST abort the handshake. - */ - state.secure_renegotiation = true; - - if (!Arrays.constantTimeAreEqual(renegExtData, TlsProtocol.createRenegotiationInfo(TlsUtils.EMPTY_BYTES))) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - } - } - - state.server.notifySecureRenegotiation(state.secure_renegotiation); - - if (state.clientExtensions != null) - { - // NOTE: Validates the padding extension data, if present - TlsExtensionsUtils.getPaddingExtension(state.clientExtensions); - - state.server.processClientExtensions(state.clientExtensions); - } - } - - protected void processClientKeyExchange(ServerHandshakeState state, byte[] body) - throws IOException - { - ByteArrayInputStream buf = new ByteArrayInputStream(body); - - state.keyExchange.processClientKeyExchange(buf); - - TlsProtocol.assertEmpty(buf); - } - - protected void processClientSupplementalData(ServerHandshakeState state, byte[] body) - throws IOException - { - ByteArrayInputStream buf = new ByteArrayInputStream(body); - Vector clientSupplementalData = TlsProtocol.readSupplementalDataMessage(buf); - state.server.processClientSupplementalData(clientSupplementalData); - } - - protected boolean expectCertificateVerifyMessage(ServerHandshakeState state) - { - return state.clientCertificateType >= 0 && TlsUtils.hasSigningCapability(state.clientCertificateType); - } - - protected static class ServerHandshakeState - { - TlsServer server = null; - TlsServerContextImpl serverContext = null; - TlsSession tlsSession = null; - SessionParameters sessionParameters = null; - SessionParameters.Builder sessionParametersBuilder = null; - int[] offeredCipherSuites = null; - short[] offeredCompressionMethods = null; - Hashtable clientExtensions = null; - Hashtable serverExtensions = null; - boolean resumedSession = false; - boolean secure_renegotiation = false; - boolean allowCertificateStatus = false; - boolean expectSessionTicket = false; - TlsKeyExchange keyExchange = null; - TlsCredentials serverCredentials = null; - CertificateRequest certificateRequest = null; - short clientCertificateType = -1; - Certificate clientCertificate = null; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSTransport.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSTransport.java deleted file mode 100644 index 75285a74c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DTLSTransport.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class DTLSTransport - implements DatagramTransport -{ - private final DTLSRecordLayer recordLayer; - - DTLSTransport(DTLSRecordLayer recordLayer) - { - this.recordLayer = recordLayer; - } - - public int getReceiveLimit() - throws IOException - { - return recordLayer.getReceiveLimit(); - } - - public int getSendLimit() - throws IOException - { - return recordLayer.getSendLimit(); - } - - public int receive(byte[] buf, int off, int len, int waitMillis) - throws IOException - { - try - { - return recordLayer.receive(buf, off, len, waitMillis); - } - catch (TlsFatalAlert fatalAlert) - { - recordLayer.fail(fatalAlert.getAlertDescription()); - throw fatalAlert; - } - catch (IOException e) - { - recordLayer.fail(AlertDescription.internal_error); - throw e; - } - catch (RuntimeException e) - { - recordLayer.fail(AlertDescription.internal_error); - throw new TlsFatalAlert(AlertDescription.internal_error, e); - } - } - - public void send(byte[] buf, int off, int len) - throws IOException - { - try - { - recordLayer.send(buf, off, len); - } - catch (TlsFatalAlert fatalAlert) - { - recordLayer.fail(fatalAlert.getAlertDescription()); - throw fatalAlert; - } - catch (IOException e) - { - recordLayer.fail(AlertDescription.internal_error); - throw e; - } - catch (RuntimeException e) - { - recordLayer.fail(AlertDescription.internal_error); - throw new TlsFatalAlert(AlertDescription.internal_error, e); - } - } - - public void close() - throws IOException - { - recordLayer.close(); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DatagramTransport.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DatagramTransport.java deleted file mode 100644 index d1e66625c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DatagramTransport.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * Base interface for an object sending and receiving DTLS data. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface DatagramTransport - extends TlsCloseable -{ - int getReceiveLimit() - throws IOException; - - int getSendLimit() - throws IOException; - - int receive(byte[] buf, int off, int len, int waitMillis) - throws IOException; - - void send(byte[] buf, int off, int len) - throws IOException; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsAgreementCredentials.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsAgreementCredentials.java deleted file mode 100644 index 06f165e0c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsAgreementCredentials.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.crypto.BasicAgreement; -import com.fr.third.org.bouncycastle.crypto.agreement.DHBasicAgreement; -import com.fr.third.org.bouncycastle.crypto.agreement.ECDHBasicAgreement; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.DHPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.util.BigIntegers; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class DefaultTlsAgreementCredentials - extends AbstractTlsAgreementCredentials -{ - protected Certificate certificate; - protected AsymmetricKeyParameter privateKey; - - protected BasicAgreement basicAgreement; - protected boolean truncateAgreement; - - public DefaultTlsAgreementCredentials(Certificate certificate, AsymmetricKeyParameter privateKey) - { - if (certificate == null) - { - throw new IllegalArgumentException("'certificate' cannot be null"); - } - if (certificate.isEmpty()) - { - throw new IllegalArgumentException("'certificate' cannot be empty"); - } - if (privateKey == null) - { - throw new IllegalArgumentException("'privateKey' cannot be null"); - } - if (!privateKey.isPrivate()) - { - throw new IllegalArgumentException("'privateKey' must be private"); - } - - if (privateKey instanceof DHPrivateKeyParameters) - { - basicAgreement = new DHBasicAgreement(); - truncateAgreement = true; - } - else if (privateKey instanceof ECPrivateKeyParameters) - { - basicAgreement = new ECDHBasicAgreement(); - truncateAgreement = false; - } - else - { - throw new IllegalArgumentException("'privateKey' type not supported: " - + privateKey.getClass().getName()); - } - - this.certificate = certificate; - this.privateKey = privateKey; - } - - public Certificate getCertificate() - { - return certificate; - } - - public byte[] generateAgreement(AsymmetricKeyParameter peerPublicKey) - { - basicAgreement.init(privateKey); - BigInteger agreementValue = basicAgreement.calculateAgreement(peerPublicKey); - - if (truncateAgreement) - { - return BigIntegers.asUnsignedByteArray(agreementValue); - } - - return BigIntegers.asUnsignedByteArray(basicAgreement.getFieldSize(), agreementValue); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsCipherFactory.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsCipherFactory.java deleted file mode 100644 index 2e57c4ac5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsCipherFactory.java +++ /dev/null @@ -1,238 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.crypto.engines.AESEngine; -import com.fr.third.org.bouncycastle.crypto.engines.CamelliaEngine; -import com.fr.third.org.bouncycastle.crypto.engines.DESedeEngine; -import com.fr.third.org.bouncycastle.crypto.engines.RC4Engine; -import com.fr.third.org.bouncycastle.crypto.engines.SEEDEngine; -import com.fr.third.org.bouncycastle.crypto.engines.Salsa20Engine; -import com.fr.third.org.bouncycastle.crypto.modes.AEADBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CBCBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.CCMBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.GCMBlockCipher; -import com.fr.third.org.bouncycastle.crypto.modes.OCBBlockCipher; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class DefaultTlsCipherFactory - extends AbstractTlsCipherFactory -{ - public TlsCipher createCipher(TlsContext context, int encryptionAlgorithm, int macAlgorithm) - throws IOException - { - switch (encryptionAlgorithm) - { - case EncryptionAlgorithm._3DES_EDE_CBC: - return createDESedeCipher(context, macAlgorithm); - case EncryptionAlgorithm.AES_128_CBC: - return createAESCipher(context, 16, macAlgorithm); - case EncryptionAlgorithm.AES_128_CCM: - // NOTE: Ignores macAlgorithm - return createCipher_AES_CCM(context, 16, 16); - case EncryptionAlgorithm.AES_128_CCM_8: - // NOTE: Ignores macAlgorithm - return createCipher_AES_CCM(context, 16, 8); - case EncryptionAlgorithm.AES_128_GCM: - // NOTE: Ignores macAlgorithm - return createCipher_AES_GCM(context, 16, 16); - case EncryptionAlgorithm.AES_128_OCB_TAGLEN96: - // NOTE: Ignores macAlgorithm - return createCipher_AES_OCB(context, 16, 12); - case EncryptionAlgorithm.AES_256_CBC: - return createAESCipher(context, 32, macAlgorithm); - case EncryptionAlgorithm.AES_256_CCM: - // NOTE: Ignores macAlgorithm - return createCipher_AES_CCM(context, 32, 16); - case EncryptionAlgorithm.AES_256_CCM_8: - // NOTE: Ignores macAlgorithm - return createCipher_AES_CCM(context, 32, 8); - case EncryptionAlgorithm.AES_256_GCM: - // NOTE: Ignores macAlgorithm - return createCipher_AES_GCM(context, 32, 16); - case EncryptionAlgorithm.AES_256_OCB_TAGLEN96: - // NOTE: Ignores macAlgorithm - return createCipher_AES_OCB(context, 32, 12); - case EncryptionAlgorithm.CAMELLIA_128_CBC: - return createCamelliaCipher(context, 16, macAlgorithm); - case EncryptionAlgorithm.CAMELLIA_128_GCM: - // NOTE: Ignores macAlgorithm - return createCipher_Camellia_GCM(context, 16, 16); - case EncryptionAlgorithm.CAMELLIA_256_CBC: - return createCamelliaCipher(context, 32, macAlgorithm); - case EncryptionAlgorithm.CAMELLIA_256_GCM: - // NOTE: Ignores macAlgorithm - return createCipher_Camellia_GCM(context, 32, 16); - case EncryptionAlgorithm.CHACHA20_POLY1305: - // NOTE: Ignores macAlgorithm - return createChaCha20Poly1305(context); - case EncryptionAlgorithm.NULL: - return createNullCipher(context, macAlgorithm); - case EncryptionAlgorithm.RC4_128: - return createRC4Cipher(context, 16, macAlgorithm); - case EncryptionAlgorithm.SEED_CBC: - return createSEEDCipher(context, macAlgorithm); - default: - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - protected TlsBlockCipher createAESCipher(TlsContext context, int cipherKeySize, int macAlgorithm) - throws IOException - { - return new TlsBlockCipher(context, createAESBlockCipher(), createAESBlockCipher(), - createHMACDigest(macAlgorithm), createHMACDigest(macAlgorithm), cipherKeySize); - } - - protected TlsBlockCipher createCamelliaCipher(TlsContext context, int cipherKeySize, int macAlgorithm) - throws IOException - { - return new TlsBlockCipher(context, createCamelliaBlockCipher(), - createCamelliaBlockCipher(), createHMACDigest(macAlgorithm), - createHMACDigest(macAlgorithm), cipherKeySize); - } - - protected TlsCipher createChaCha20Poly1305(TlsContext context) throws IOException - { - return new Chacha20Poly1305(context); - } - - protected TlsAEADCipher createCipher_AES_CCM(TlsContext context, int cipherKeySize, int macSize) - throws IOException - { - return new TlsAEADCipher(context, createAEADBlockCipher_AES_CCM(), - createAEADBlockCipher_AES_CCM(), cipherKeySize, macSize); - } - - protected TlsAEADCipher createCipher_AES_GCM(TlsContext context, int cipherKeySize, int macSize) - throws IOException - { - return new TlsAEADCipher(context, createAEADBlockCipher_AES_GCM(), - createAEADBlockCipher_AES_GCM(), cipherKeySize, macSize); - } - - protected TlsAEADCipher createCipher_AES_OCB(TlsContext context, int cipherKeySize, int macSize) - throws IOException - { - return new TlsAEADCipher(context, createAEADBlockCipher_AES_OCB(), - createAEADBlockCipher_AES_OCB(), cipherKeySize, macSize, TlsAEADCipher.NONCE_DRAFT_CHACHA20_POLY1305); - } - - protected TlsAEADCipher createCipher_Camellia_GCM(TlsContext context, int cipherKeySize, int macSize) - throws IOException - { - return new TlsAEADCipher(context, createAEADBlockCipher_Camellia_GCM(), - createAEADBlockCipher_Camellia_GCM(), cipherKeySize, macSize); - } - - protected TlsBlockCipher createDESedeCipher(TlsContext context, int macAlgorithm) - throws IOException - { - return new TlsBlockCipher(context, createDESedeBlockCipher(), createDESedeBlockCipher(), - createHMACDigest(macAlgorithm), createHMACDigest(macAlgorithm), 24); - } - - protected TlsNullCipher createNullCipher(TlsContext context, int macAlgorithm) - throws IOException - { - return new TlsNullCipher(context, createHMACDigest(macAlgorithm), - createHMACDigest(macAlgorithm)); - } - - protected TlsStreamCipher createRC4Cipher(TlsContext context, int cipherKeySize, int macAlgorithm) - throws IOException - { - return new TlsStreamCipher(context, createRC4StreamCipher(), createRC4StreamCipher(), - createHMACDigest(macAlgorithm), createHMACDigest(macAlgorithm), cipherKeySize, false); - } - - protected TlsBlockCipher createSEEDCipher(TlsContext context, int macAlgorithm) - throws IOException - { - return new TlsBlockCipher(context, createSEEDBlockCipher(), createSEEDBlockCipher(), - createHMACDigest(macAlgorithm), createHMACDigest(macAlgorithm), 16); - } - - protected BlockCipher createAESEngine() - { - return new AESEngine(); - } - - protected BlockCipher createCamelliaEngine() - { - return new CamelliaEngine(); - } - - protected BlockCipher createAESBlockCipher() - { - return new CBCBlockCipher(createAESEngine()); - } - - protected AEADBlockCipher createAEADBlockCipher_AES_CCM() - { - return new CCMBlockCipher(createAESEngine()); - } - - protected AEADBlockCipher createAEADBlockCipher_AES_GCM() - { - // TODO Consider allowing custom configuration of multiplier - return new GCMBlockCipher(createAESEngine()); - } - - protected AEADBlockCipher createAEADBlockCipher_AES_OCB() - { - return new OCBBlockCipher(createAESEngine(), createAESEngine()); - } - - protected AEADBlockCipher createAEADBlockCipher_Camellia_GCM() - { - // TODO Consider allowing custom configuration of multiplier - return new GCMBlockCipher(createCamelliaEngine()); - } - - protected BlockCipher createCamelliaBlockCipher() - { - return new CBCBlockCipher(createCamelliaEngine()); - } - - protected BlockCipher createDESedeBlockCipher() - { - return new CBCBlockCipher(new DESedeEngine()); - } - - protected StreamCipher createRC4StreamCipher() - { - return new RC4Engine(); - } - - protected BlockCipher createSEEDBlockCipher() - { - return new CBCBlockCipher(new SEEDEngine()); - } - - protected Digest createHMACDigest(int macAlgorithm) throws IOException - { - switch (macAlgorithm) - { - case MACAlgorithm._null: - return null; - case MACAlgorithm.hmac_md5: - return TlsUtils.createHash(HashAlgorithm.md5); - case MACAlgorithm.hmac_sha1: - return TlsUtils.createHash(HashAlgorithm.sha1); - case MACAlgorithm.hmac_sha256: - return TlsUtils.createHash(HashAlgorithm.sha256); - case MACAlgorithm.hmac_sha384: - return TlsUtils.createHash(HashAlgorithm.sha384); - case MACAlgorithm.hmac_sha512: - return TlsUtils.createHash(HashAlgorithm.sha512); - default: - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsClient.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsClient.java deleted file mode 100644 index 4f2ab0153..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsClient.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class DefaultTlsClient - extends AbstractTlsClient -{ - protected TlsDHVerifier dhVerifier; - - public DefaultTlsClient() - { - this(new DefaultTlsCipherFactory()); - } - - public DefaultTlsClient(TlsCipherFactory cipherFactory) - { - this(cipherFactory, new DefaultTlsDHVerifier()); - } - - public DefaultTlsClient(TlsCipherFactory cipherFactory, TlsDHVerifier dhVerifier) - { - super(cipherFactory); - - this.dhVerifier = dhVerifier; - } - - public int[] getCipherSuites() - { - return new int[] - { - CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, - CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, - CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, - CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, - CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, - CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, - CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256, - CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA256, - CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA, - }; - } - - public TlsKeyExchange getKeyExchange() - throws IOException - { - int keyExchangeAlgorithm = TlsUtils.getKeyExchangeAlgorithm(selectedCipherSuite); - - switch (keyExchangeAlgorithm) - { - case KeyExchangeAlgorithm.DH_anon: - case KeyExchangeAlgorithm.DH_DSS: - case KeyExchangeAlgorithm.DH_RSA: - return createDHKeyExchange(keyExchangeAlgorithm); - - case KeyExchangeAlgorithm.DHE_DSS: - case KeyExchangeAlgorithm.DHE_RSA: - return createDHEKeyExchange(keyExchangeAlgorithm); - - case KeyExchangeAlgorithm.ECDH_anon: - case KeyExchangeAlgorithm.ECDH_ECDSA: - case KeyExchangeAlgorithm.ECDH_RSA: - return createECDHKeyExchange(keyExchangeAlgorithm); - - case KeyExchangeAlgorithm.ECDHE_ECDSA: - case KeyExchangeAlgorithm.ECDHE_RSA: - return createECDHEKeyExchange(keyExchangeAlgorithm); - - case KeyExchangeAlgorithm.RSA: - return createRSAKeyExchange(); - - default: - /* - * Note: internal error here; the TlsProtocol implementation verifies that the - * server-selected cipher suite was in the list of client-offered cipher suites, so if - * we now can't produce an implementation, we shouldn't have offered it! - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - protected TlsKeyExchange createDHKeyExchange(int keyExchange) - { - return new TlsDHKeyExchange(keyExchange, supportedSignatureAlgorithms, dhVerifier, null); - } - - protected TlsKeyExchange createDHEKeyExchange(int keyExchange) - { - return new TlsDHEKeyExchange(keyExchange, supportedSignatureAlgorithms, dhVerifier, null); - } - - protected TlsKeyExchange createECDHKeyExchange(int keyExchange) - { - return new TlsECDHKeyExchange(keyExchange, supportedSignatureAlgorithms, namedCurves, clientECPointFormats, - serverECPointFormats); - } - - protected TlsKeyExchange createECDHEKeyExchange(int keyExchange) - { - return new TlsECDHEKeyExchange(keyExchange, supportedSignatureAlgorithms, namedCurves, clientECPointFormats, - serverECPointFormats); - } - - protected TlsKeyExchange createRSAKeyExchange() - { - return new TlsRSAKeyExchange(supportedSignatureAlgorithms); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsDHVerifier.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsDHVerifier.java deleted file mode 100644 index 057c18519..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsDHVerifier.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.math.BigInteger; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.crypto.agreement.DHStandardGroups; -import com.fr.third.org.bouncycastle.crypto.params.DHParameters; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class DefaultTlsDHVerifier - implements TlsDHVerifier -{ - public static final int DEFAULT_MINIMUM_PRIME_BITS = 2048; - - protected static final Vector DEFAULT_GROUPS = new Vector(); - - private static void addDefaultGroup(DHParameters dhParameters) - { - DEFAULT_GROUPS.addElement(dhParameters); - } - - static - { - addDefaultGroup(DHStandardGroups.rfc7919_ffdhe2048); - addDefaultGroup(DHStandardGroups.rfc7919_ffdhe3072); - addDefaultGroup(DHStandardGroups.rfc7919_ffdhe4096); - addDefaultGroup(DHStandardGroups.rfc7919_ffdhe6144); - addDefaultGroup(DHStandardGroups.rfc7919_ffdhe8192); - - addDefaultGroup(DHStandardGroups.rfc3526_1536); - addDefaultGroup(DHStandardGroups.rfc3526_2048); - addDefaultGroup(DHStandardGroups.rfc3526_3072); - addDefaultGroup(DHStandardGroups.rfc3526_4096); - addDefaultGroup(DHStandardGroups.rfc3526_6144); - addDefaultGroup(DHStandardGroups.rfc3526_8192); - } - - // Vector is (DHParameters) - protected Vector groups; - protected int minimumPrimeBits; - - /** - * Accept various standard DH groups with 'P' at least {@link #DEFAULT_MINIMUM_PRIME_BITS} bits. - */ - public DefaultTlsDHVerifier() - { - this(DEFAULT_MINIMUM_PRIME_BITS); - } - - /** - * Accept various standard DH groups with 'P' at least the specified number of bits. - */ - public DefaultTlsDHVerifier(int minimumPrimeBits) - { - this(DEFAULT_GROUPS, minimumPrimeBits); - } - - /** - * Accept a custom set of group parameters, subject to a minimum bitlength for 'P'. - * - * @param groups a {@link Vector} of acceptable {@link DHParameters}. - */ - public DefaultTlsDHVerifier(Vector groups, int minimumPrimeBits) - { - this.groups = groups; - this.minimumPrimeBits = minimumPrimeBits; - } - - public boolean accept(DHParameters dhParameters) - { - return checkMinimumPrimeBits(dhParameters) && checkGroup(dhParameters); - } - - public int getMinimumPrimeBits() - { - return minimumPrimeBits; - } - - protected boolean areGroupsEqual(DHParameters a, DHParameters b) - { - return a == b || (areParametersEqual(a.getP(), b.getP()) && areParametersEqual(a.getG(), b.getG())); - } - - protected boolean areParametersEqual(BigInteger a, BigInteger b) - { - return a == b || a.equals(b); - } - - protected boolean checkGroup(DHParameters dhParameters) - { - for (int i = 0; i < groups.size(); ++i) - { - if (areGroupsEqual(dhParameters, (DHParameters)groups.elementAt(i))) - { - return true; - } - } - return false; - } - - protected boolean checkMinimumPrimeBits(DHParameters dhParameters) - { - return dhParameters.getP().bitLength() >= getMinimumPrimeBits(); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsEncryptionCredentials.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsEncryptionCredentials.java deleted file mode 100644 index 7715840c4..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsEncryptionCredentials.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class DefaultTlsEncryptionCredentials extends AbstractTlsEncryptionCredentials -{ - protected TlsContext context; - protected Certificate certificate; - protected AsymmetricKeyParameter privateKey; - - public DefaultTlsEncryptionCredentials(TlsContext context, Certificate certificate, - AsymmetricKeyParameter privateKey) - { - if (certificate == null) - { - throw new IllegalArgumentException("'certificate' cannot be null"); - } - if (certificate.isEmpty()) - { - throw new IllegalArgumentException("'certificate' cannot be empty"); - } - if (privateKey == null) - { - throw new IllegalArgumentException("'privateKey' cannot be null"); - } - if (!privateKey.isPrivate()) - { - throw new IllegalArgumentException("'privateKey' must be private"); - } - - if (privateKey instanceof RSAKeyParameters) - { - } - else - { - throw new IllegalArgumentException("'privateKey' type not supported: " - + privateKey.getClass().getName()); - } - - this.context = context; - this.certificate = certificate; - this.privateKey = privateKey; - } - - public Certificate getCertificate() - { - return certificate; - } - - public byte[] decryptPreMasterSecret(byte[] encryptedPreMasterSecret) - throws IOException - { - return TlsRSAUtils.safeDecryptPreMasterSecret(context, (RSAKeyParameters)privateKey, encryptedPreMasterSecret); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsSRPGroupVerifier.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsSRPGroupVerifier.java deleted file mode 100644 index ea31e9c3d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsSRPGroupVerifier.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.math.BigInteger; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.crypto.agreement.srp.SRP6StandardGroups; -import com.fr.third.org.bouncycastle.crypto.params.SRP6GroupParameters; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class DefaultTlsSRPGroupVerifier - implements TlsSRPGroupVerifier -{ - protected static final Vector DEFAULT_GROUPS = new Vector(); - - static - { - DEFAULT_GROUPS.addElement(SRP6StandardGroups.rfc5054_1024); - DEFAULT_GROUPS.addElement(SRP6StandardGroups.rfc5054_1536); - DEFAULT_GROUPS.addElement(SRP6StandardGroups.rfc5054_2048); - DEFAULT_GROUPS.addElement(SRP6StandardGroups.rfc5054_3072); - DEFAULT_GROUPS.addElement(SRP6StandardGroups.rfc5054_4096); - DEFAULT_GROUPS.addElement(SRP6StandardGroups.rfc5054_6144); - DEFAULT_GROUPS.addElement(SRP6StandardGroups.rfc5054_8192); - } - - // Vector is (SRP6GroupParameters) - protected Vector groups; - - /** - * Accept only the group parameters specified in RFC 5054 Appendix A. - */ - public DefaultTlsSRPGroupVerifier() - { - this(DEFAULT_GROUPS); - } - - /** - * Specify a custom set of acceptable group parameters. - * - * @param groups a {@link Vector} of acceptable {@link SRP6GroupParameters} - */ - public DefaultTlsSRPGroupVerifier(Vector groups) - { - this.groups = groups; - } - - public boolean accept(SRP6GroupParameters group) - { - for (int i = 0; i < groups.size(); ++i) - { - if (areGroupsEqual(group, (SRP6GroupParameters)groups.elementAt(i))) - { - return true; - } - } - return false; - } - - protected boolean areGroupsEqual(SRP6GroupParameters a, SRP6GroupParameters b) - { - return a == b || (areParametersEqual(a.getN(), b.getN()) && areParametersEqual(a.getG(), b.getG())); - } - - protected boolean areParametersEqual(BigInteger a, BigInteger b) - { - return a == b || a.equals(b); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsServer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsServer.java deleted file mode 100644 index 371aa8eeb..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsServer.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.crypto.agreement.DHStandardGroups; -import com.fr.third.org.bouncycastle.crypto.params.DHParameters; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class DefaultTlsServer - extends AbstractTlsServer -{ - public DefaultTlsServer() - { - super(); - } - - public DefaultTlsServer(TlsCipherFactory cipherFactory) - { - super(cipherFactory); - } - - protected TlsSignerCredentials getDSASignerCredentials() - throws IOException - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - protected TlsSignerCredentials getECDSASignerCredentials() - throws IOException - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - protected TlsEncryptionCredentials getRSAEncryptionCredentials() - throws IOException - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - protected TlsSignerCredentials getRSASignerCredentials() - throws IOException - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - protected DHParameters getDHParameters() - { - return DHStandardGroups.rfc7919_ffdhe2048; - } - - protected int[] getCipherSuites() - { - return new int[] - { - CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, - CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, - CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, - CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, - CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, - CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, - CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, - CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, - CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, - CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, - CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA, - CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA, - CipherSuite.TLS_RSA_WITH_AES_256_GCM_SHA384, - CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256, - CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA256, - CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA256, - CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA, - CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA, - }; - } - - public TlsCredentials getCredentials() - throws IOException - { - int keyExchangeAlgorithm = TlsUtils.getKeyExchangeAlgorithm(selectedCipherSuite); - - switch (keyExchangeAlgorithm) - { - case KeyExchangeAlgorithm.DHE_DSS: - return getDSASignerCredentials(); - - case KeyExchangeAlgorithm.DH_anon: - case KeyExchangeAlgorithm.ECDH_anon: - return null; - - case KeyExchangeAlgorithm.ECDHE_ECDSA: - return getECDSASignerCredentials(); - - case KeyExchangeAlgorithm.DHE_RSA: - case KeyExchangeAlgorithm.ECDHE_RSA: - return getRSASignerCredentials(); - - case KeyExchangeAlgorithm.RSA: - return getRSAEncryptionCredentials(); - - default: - /* Note: internal error here; selected a key exchange we don't implement! */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public TlsKeyExchange getKeyExchange() - throws IOException - { - int keyExchangeAlgorithm = TlsUtils.getKeyExchangeAlgorithm(selectedCipherSuite); - - switch (keyExchangeAlgorithm) - { - case KeyExchangeAlgorithm.DH_anon: - case KeyExchangeAlgorithm.DH_DSS: - case KeyExchangeAlgorithm.DH_RSA: - return createDHKeyExchange(keyExchangeAlgorithm); - - case KeyExchangeAlgorithm.DHE_DSS: - case KeyExchangeAlgorithm.DHE_RSA: - return createDHEKeyExchange(keyExchangeAlgorithm); - - case KeyExchangeAlgorithm.ECDH_anon: - case KeyExchangeAlgorithm.ECDH_ECDSA: - case KeyExchangeAlgorithm.ECDH_RSA: - return createECDHKeyExchange(keyExchangeAlgorithm); - - case KeyExchangeAlgorithm.ECDHE_ECDSA: - case KeyExchangeAlgorithm.ECDHE_RSA: - return createECDHEKeyExchange(keyExchangeAlgorithm); - - case KeyExchangeAlgorithm.RSA: - return createRSAKeyExchange(); - - default: - /* - * Note: internal error here; the TlsProtocol implementation verifies that the - * server-selected cipher suite was in the list of client-offered cipher suites, so if - * we now can't produce an implementation, we shouldn't have offered it! - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - protected TlsKeyExchange createDHKeyExchange(int keyExchange) - { - return new TlsDHKeyExchange(keyExchange, supportedSignatureAlgorithms, null, getDHParameters()); - } - - protected TlsKeyExchange createDHEKeyExchange(int keyExchange) - { - return new TlsDHEKeyExchange(keyExchange, supportedSignatureAlgorithms, null, getDHParameters()); - } - - protected TlsKeyExchange createECDHKeyExchange(int keyExchange) - { - return new TlsECDHKeyExchange(keyExchange, supportedSignatureAlgorithms, namedCurves, clientECPointFormats, - serverECPointFormats); - } - - protected TlsKeyExchange createECDHEKeyExchange(int keyExchange) - { - return new TlsECDHEKeyExchange(keyExchange, supportedSignatureAlgorithms, namedCurves, clientECPointFormats, - serverECPointFormats); - } - - protected TlsKeyExchange createRSAKeyExchange() - { - return new TlsRSAKeyExchange(supportedSignatureAlgorithms); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsSignerCredentials.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsSignerCredentials.java deleted file mode 100644 index 1ee7fdf37..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DefaultTlsSignerCredentials.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.crypto.CryptoException; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.DSAPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class DefaultTlsSignerCredentials - extends AbstractTlsSignerCredentials -{ - protected TlsContext context; - protected Certificate certificate; - protected AsymmetricKeyParameter privateKey; - protected SignatureAndHashAlgorithm signatureAndHashAlgorithm; - - protected TlsSigner signer; - - public DefaultTlsSignerCredentials(TlsContext context, Certificate certificate, AsymmetricKeyParameter privateKey) - { - this(context, certificate, privateKey, null); - } - - public DefaultTlsSignerCredentials(TlsContext context, Certificate certificate, AsymmetricKeyParameter privateKey, - SignatureAndHashAlgorithm signatureAndHashAlgorithm) - { - if (certificate == null) - { - throw new IllegalArgumentException("'certificate' cannot be null"); - } - if (certificate.isEmpty()) - { - throw new IllegalArgumentException("'certificate' cannot be empty"); - } - if (privateKey == null) - { - throw new IllegalArgumentException("'privateKey' cannot be null"); - } - if (!privateKey.isPrivate()) - { - throw new IllegalArgumentException("'privateKey' must be private"); - } - if (TlsUtils.isTLSv12(context) && signatureAndHashAlgorithm == null) - { - throw new IllegalArgumentException("'signatureAndHashAlgorithm' cannot be null for (D)TLS 1.2+"); - } - - if (privateKey instanceof RSAKeyParameters) - { - this.signer = new TlsRSASigner(); - } - else if (privateKey instanceof DSAPrivateKeyParameters) - { - this.signer = new TlsDSSSigner(); - } - else if (privateKey instanceof ECPrivateKeyParameters) - { - this.signer = new TlsECDSASigner(); - } - else - { - throw new IllegalArgumentException("'privateKey' type not supported: " + privateKey.getClass().getName()); - } - - this.signer.init(context); - - this.context = context; - this.certificate = certificate; - this.privateKey = privateKey; - this.signatureAndHashAlgorithm = signatureAndHashAlgorithm; - } - - public Certificate getCertificate() - { - return certificate; - } - - public byte[] generateCertificateSignature(byte[] hash) - throws IOException - { - try - { - if (TlsUtils.isTLSv12(context)) - { - return signer.generateRawSignature(signatureAndHashAlgorithm, privateKey, hash); - } - else - { - return signer.generateRawSignature(privateKey, hash); - } - } - catch (CryptoException e) - { - throw new TlsFatalAlert(AlertDescription.internal_error, e); - } - } - - public SignatureAndHashAlgorithm getSignatureAndHashAlgorithm() - { - return signatureAndHashAlgorithm; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DeferredHash.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DeferredHash.java deleted file mode 100644 index 2973203fb..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DeferredHash.java +++ /dev/null @@ -1,207 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.util.Enumeration; -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.util.Shorts; - -/** - * Buffers input until the hash algorithm is determined. - */ -class DeferredHash - implements TlsHandshakeHash -{ - protected static final int BUFFERING_HASH_LIMIT = 4; - - protected TlsContext context; - - private DigestInputBuffer buf; - private Hashtable hashes; - private Short prfHashAlgorithm; - - DeferredHash() - { - this.buf = new DigestInputBuffer(); - this.hashes = new Hashtable(); - this.prfHashAlgorithm = null; - } - - private DeferredHash(Short prfHashAlgorithm, Digest prfHash) - { - this.buf = null; - this.hashes = new Hashtable(); - this.prfHashAlgorithm = prfHashAlgorithm; - hashes.put(prfHashAlgorithm, prfHash); - } - - public void init(TlsContext context) - { - this.context = context; - } - - public TlsHandshakeHash notifyPRFDetermined() - { - int prfAlgorithm = context.getSecurityParameters().getPrfAlgorithm(); - if (prfAlgorithm == PRFAlgorithm.tls_prf_legacy) - { - CombinedHash legacyHash = new CombinedHash(); - legacyHash.init(context); - buf.updateDigest(legacyHash); - return legacyHash.notifyPRFDetermined(); - } - - this.prfHashAlgorithm = Shorts.valueOf(TlsUtils.getHashAlgorithmForPRFAlgorithm(prfAlgorithm)); - - checkTrackingHash(prfHashAlgorithm); - - return this; - } - - public void trackHashAlgorithm(short hashAlgorithm) - { - if (buf == null) - { - throw new IllegalStateException("Too late to track more hash algorithms"); - } - - checkTrackingHash(Shorts.valueOf(hashAlgorithm)); - } - - public void sealHashAlgorithms() - { - checkStopBuffering(); - } - - public TlsHandshakeHash stopTracking() - { - Digest prfHash = TlsUtils.cloneHash(prfHashAlgorithm.shortValue(), (Digest)hashes.get(prfHashAlgorithm)); - if (buf != null) - { - buf.updateDigest(prfHash); - } - DeferredHash result = new DeferredHash(prfHashAlgorithm, prfHash); - result.init(context); - return result; - } - - public Digest forkPRFHash() - { - checkStopBuffering(); - - if (buf != null) - { - Digest prfHash = TlsUtils.createHash(prfHashAlgorithm.shortValue()); - buf.updateDigest(prfHash); - return prfHash; - } - - return TlsUtils.cloneHash(prfHashAlgorithm.shortValue(), (Digest)hashes.get(prfHashAlgorithm)); - } - - public byte[] getFinalHash(short hashAlgorithm) - { - Digest d = (Digest)hashes.get(Shorts.valueOf(hashAlgorithm)); - if (d == null) - { - throw new IllegalStateException("HashAlgorithm." + HashAlgorithm.getText(hashAlgorithm) + " is not being tracked"); - } - - d = TlsUtils.cloneHash(hashAlgorithm, d); - if (buf != null) - { - buf.updateDigest(d); - } - - byte[] bs = new byte[d.getDigestSize()]; - d.doFinal(bs, 0); - return bs; - } - - public String getAlgorithmName() - { - throw new IllegalStateException("Use fork() to get a definite Digest"); - } - - public int getDigestSize() - { - throw new IllegalStateException("Use fork() to get a definite Digest"); - } - - public void update(byte input) - { - if (buf != null) - { - buf.write(input); - return; - } - - Enumeration e = hashes.elements(); - while (e.hasMoreElements()) - { - Digest hash = (Digest)e.nextElement(); - hash.update(input); - } - } - - public void update(byte[] input, int inOff, int len) - { - if (buf != null) - { - buf.write(input, inOff, len); - return; - } - - Enumeration e = hashes.elements(); - while (e.hasMoreElements()) - { - Digest hash = (Digest)e.nextElement(); - hash.update(input, inOff, len); - } - } - - public int doFinal(byte[] output, int outOff) - { - throw new IllegalStateException("Use fork() to get a definite Digest"); - } - - public void reset() - { - if (buf != null) - { - buf.reset(); - return; - } - - Enumeration e = hashes.elements(); - while (e.hasMoreElements()) - { - Digest hash = (Digest)e.nextElement(); - hash.reset(); - } - } - - protected void checkStopBuffering() - { - if (buf != null && hashes.size() <= BUFFERING_HASH_LIMIT) - { - Enumeration e = hashes.elements(); - while (e.hasMoreElements()) - { - Digest hash = (Digest)e.nextElement(); - buf.updateDigest(hash); - } - - this.buf = null; - } - } - - protected void checkTrackingHash(Short hashAlgorithm) - { - if (!hashes.containsKey(hashAlgorithm)) - { - Digest hash = TlsUtils.createHash(hashAlgorithm.shortValue()); - hashes.put(hashAlgorithm, hash); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DigestInputBuffer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DigestInputBuffer.java deleted file mode 100644 index b6c3f0281..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DigestInputBuffer.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayOutputStream; - -import com.fr.third.org.bouncycastle.crypto.Digest; - -class DigestInputBuffer extends ByteArrayOutputStream -{ - void updateDigest(Digest d) - { - d.update(this.buf, 0, count); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DigitallySigned.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DigitallySigned.java deleted file mode 100644 index 37dd76440..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/DigitallySigned.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class DigitallySigned -{ - protected SignatureAndHashAlgorithm algorithm; - protected byte[] signature; - - public DigitallySigned(SignatureAndHashAlgorithm algorithm, byte[] signature) - { - if (signature == null) - { - throw new IllegalArgumentException("'signature' cannot be null"); - } - - this.algorithm = algorithm; - this.signature = signature; - } - - /** - * @return a {@link SignatureAndHashAlgorithm} (or null before TLS 1.2). - */ - public SignatureAndHashAlgorithm getAlgorithm() - { - return algorithm; - } - - public byte[] getSignature() - { - return signature; - } - - /** - * Encode this {@link DigitallySigned} to an {@link OutputStream}. - * - * @param output - * the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) throws IOException - { - if (algorithm != null) - { - algorithm.encode(output); - } - TlsUtils.writeOpaque16(signature, output); - } - - /** - * Parse a {@link DigitallySigned} from an {@link InputStream}. - * - * @param context - * the {@link TlsContext} of the current connection. - * @param input - * the {@link InputStream} to parse from. - * @return a {@link DigitallySigned} object. - * @throws IOException - */ - public static DigitallySigned parse(TlsContext context, InputStream input) throws IOException - { - SignatureAndHashAlgorithm algorithm = null; - if (TlsUtils.isTLSv12(context)) - { - algorithm = SignatureAndHashAlgorithm.parse(input); - } - byte[] signature = TlsUtils.readOpaque16(input); - return new DigitallySigned(algorithm, signature); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ECBasisType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ECBasisType.java deleted file mode 100644 index 9d0dcd55b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ECBasisType.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 4492 5.4. (Errata ID: 2389) - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ECBasisType -{ - public static final short ec_basis_trinomial = 1; - public static final short ec_basis_pentanomial = 2; - - public static boolean isValid(short ecBasisType) - { - return ecBasisType >= ec_basis_trinomial && ecBasisType <= ec_basis_pentanomial; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ECCurveType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ECCurveType.java deleted file mode 100644 index bb78f8871..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ECCurveType.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 4492 5.4 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ECCurveType -{ - /** - * Indicates the elliptic curve domain parameters are conveyed verbosely, and the - * underlying finite field is a prime field. - */ - public static final short explicit_prime = 1; - - /** - * Indicates the elliptic curve domain parameters are conveyed verbosely, and the - * underlying finite field is a characteristic-2 field. - */ - public static final short explicit_char2 = 2; - - /** - * Indicates that a named curve is used. This option SHOULD be used when applicable. - */ - public static final short named_curve = 3; - - /* - * Values 248 through 255 are reserved for private use. - */ -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ECPointFormat.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ECPointFormat.java deleted file mode 100644 index f1470d763..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ECPointFormat.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 4492 5.1.2 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ECPointFormat -{ - public static final short uncompressed = 0; - public static final short ansiX962_compressed_prime = 1; - public static final short ansiX962_compressed_char2 = 2; - - /* - * reserved (248..255) - */ -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/EncryptionAlgorithm.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/EncryptionAlgorithm.java deleted file mode 100644 index 15f663cd5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/EncryptionAlgorithm.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 2246 - *- * Note that the values here are implementation-specific and arbitrary. It is recommended not to - * depend on the particular values (e.g. serialization). - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class EncryptionAlgorithm -{ - public static final int NULL = 0; - public static final int RC4_40 = 1; - public static final int RC4_128 = 2; - public static final int RC2_CBC_40 = 3; - public static final int IDEA_CBC = 4; - public static final int DES40_CBC = 5; - public static final int DES_CBC = 6; - public static final int _3DES_EDE_CBC = 7; - - /* - * RFC 3268 - */ - public static final int AES_128_CBC = 8; - public static final int AES_256_CBC = 9; - - /* - * RFC 5289 - */ - public static final int AES_128_GCM = 10; - public static final int AES_256_GCM = 11; - - /* - * RFC 5932 - */ - public static final int CAMELLIA_128_CBC = 12; - public static final int CAMELLIA_256_CBC = 13; - - /* - * RFC 4162 - */ - public static final int SEED_CBC = 14; - - /* - * RFC 6655 - */ - public static final int AES_128_CCM = 15; - public static final int AES_128_CCM_8 = 16; - public static final int AES_256_CCM = 17; - public static final int AES_256_CCM_8 = 18; - - /* - * RFC 6367 - */ - public static final int CAMELLIA_128_GCM = 19; - public static final int CAMELLIA_256_GCM = 20; - - /* - * RFC 7905 - */ - public static final int CHACHA20_POLY1305 = 21; - - /* - * draft-zauner-tls-aes-ocb-04 - */ - public static final int AES_128_OCB_TAGLEN96 = 103; - public static final int AES_256_OCB_TAGLEN96 = 104; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ExporterLabel.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ExporterLabel.java deleted file mode 100644 index 09e1eaa9e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ExporterLabel.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 5705 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ExporterLabel -{ - /* - * RFC 5246 - */ - public static final String client_finished = "client finished"; - public static final String server_finished = "server finished"; - public static final String master_secret = "master secret"; - public static final String key_expansion = "key expansion"; - - /* - * RFC 5216 - */ - public static final String client_EAP_encryption = "client EAP encryption"; - - /* - * RFC 5281 - */ - public static final String ttls_keying_material = "ttls keying material"; - public static final String ttls_challenge = "ttls challenge"; - - /* - * RFC 5764 - */ - public static final String dtls_srtp = "EXTRACTOR-dtls_srtp"; - - /* - * RFC 7627 - */ - public static final String extended_master_secret = "extended master secret"; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ExtensionType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ExtensionType.java deleted file mode 100644 index 40d132e2e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ExtensionType.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ExtensionType -{ - /* - * RFC 2546 2.3. - */ - public static final int server_name = 0; - public static final int max_fragment_length = 1; - public static final int client_certificate_url = 2; - public static final int trusted_ca_keys = 3; - public static final int truncated_hmac = 4; - public static final int status_request = 5; - - /* - * RFC 4681 - */ - public static final int user_mapping = 6; - - /* - * RFC 5878 - */ - public static final int client_authz = 7; - public static final int server_authz = 8; - - /* - * RFC RFC6091 - */ - public static final int cert_type = 9; - - /* - * draft-ietf-tls-negotiated-ff-dhe-10 - */ - public static final int supported_groups = 10; - - /* - * RFC 4492 5.1. - */ - /** @deprecated Use {@link #supported_groups} instead */ - public static final int elliptic_curves = supported_groups; - public static final int ec_point_formats = 11; - - /* - * RFC 5054 2.8.1. - */ - public static final int srp = 12; - - /* - * RFC 5246 7.4.1.4. - */ - public static final int signature_algorithms = 13; - - /* - * RFC 5764 9. - */ - public static final int use_srtp = 14; - - /* - * RFC 6520 6. - */ - public static final int heartbeat = 15; - - /* - * RFC 7301 - */ - public static final int application_layer_protocol_negotiation = 16; - - /* - * RFC 6961 - */ - public static final int status_request_v2 = 17; - - /* - * RFC 6962 - */ - public static final int signed_certificate_timestamp = 18; - - /* - * RFC 7250 - */ - public static final int client_certificate_type = 19; - public static final int server_certificate_type = 20; - - /* - * RFC 7685 - */ - public static final int padding = 21; - - /* - * RFC 7366 - */ - public static final int encrypt_then_mac = 22; - - /* - * RFC 7627 - */ - public static final int extended_master_secret = 23; - - /* - * draft-ietf-tokbind-negotiation-08 - */ - public static final int DRAFT_token_binding = 24; - - /* - * RFC 7924 - */ - public static final int cached_info = 25; - - /* - * RFC 5077 7. - */ - public static final int session_ticket = 35; - - /* - * draft-ietf-tls-negotiated-ff-dhe-01 - * - * WARNING: Placeholder value; the real value is TBA - */ - public static final int negotiated_ff_dhe_groups = 101; - - /* - * RFC 5746 3.2. - */ - public static final int renegotiation_info = 0xff01; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/FiniteFieldDHEGroup.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/FiniteFieldDHEGroup.java deleted file mode 100644 index a2e6f101e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/FiniteFieldDHEGroup.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/* - * draft-ietf-tls-negotiated-ff-dhe-01 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class FiniteFieldDHEGroup -{ - public static final short ffdhe2432 = 0; - public static final short ffdhe3072 = 1; - public static final short ffdhe4096 = 2; - public static final short ffdhe6144 = 3; - public static final short ffdhe8192 = 4; - - public static boolean isValid(short group) - { - return group >= ffdhe2432 && group <= ffdhe8192; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HandshakeType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HandshakeType.java deleted file mode 100644 index 59505d39a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HandshakeType.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class HandshakeType -{ - /* - * RFC 2246 7.4 - */ - public static final short hello_request = 0; - public static final short client_hello = 1; - public static final short server_hello = 2; - public static final short certificate = 11; - public static final short server_key_exchange = 12; - public static final short certificate_request = 13; - public static final short server_hello_done = 14; - public static final short certificate_verify = 15; - public static final short client_key_exchange = 16; - public static final short finished = 20; - - /* - * RFC 3546 2.4 - */ - public static final short certificate_url = 21; - public static final short certificate_status = 22; - - /* - * (DTLS) RFC 4347 4.3.2 - */ - public static final short hello_verify_request = 3; - - /* - * RFC 4680 - */ - public static final short supplemental_data = 23; - - /* - * RFC 5077 - */ - public static final short session_ticket = 4; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HashAlgorithm.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HashAlgorithm.java deleted file mode 100644 index a8f3f12ae..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HashAlgorithm.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 5246 7.4.1.4.1 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class HashAlgorithm -{ - public static final short none = 0; - public static final short md5 = 1; - public static final short sha1 = 2; - public static final short sha224 = 3; - public static final short sha256 = 4; - public static final short sha384 = 5; - public static final short sha512 = 6; - - public static String getName(short hashAlgorithm) - { - switch (hashAlgorithm) - { - case none: - return "none"; - case md5: - return "md5"; - case sha1: - return "sha1"; - case sha224: - return "sha224"; - case sha256: - return "sha256"; - case sha384: - return "sha384"; - case sha512: - return "sha512"; - default: - return "UNKNOWN"; - } - } - - public static String getText(short hashAlgorithm) - { - return getName(hashAlgorithm) + "(" + hashAlgorithm + ")"; - } - - public static boolean isPrivate(short hashAlgorithm) - { - return 224 <= hashAlgorithm && hashAlgorithm <= 255; - } - - public static boolean isRecognized(short hashAlgorithm) - { - switch (hashAlgorithm) - { - case md5: - case sha1: - case sha224: - case sha256: - case sha384: - case sha512: - return true; - default: - return false; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HeartbeatExtension.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HeartbeatExtension.java deleted file mode 100644 index 34776f319..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HeartbeatExtension.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class HeartbeatExtension -{ - protected short mode; - - public HeartbeatExtension(short mode) - { - if (!HeartbeatMode.isValid(mode)) - { - throw new IllegalArgumentException("'mode' is not a valid HeartbeatMode value"); - } - - this.mode = mode; - } - - public short getMode() - { - return mode; - } - - /** - * Encode this {@link HeartbeatExtension} to an {@link OutputStream}. - * - * @param output - * the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) throws IOException - { - TlsUtils.writeUint8(mode, output); - } - - /** - * Parse a {@link HeartbeatExtension} from an {@link InputStream}. - * - * @param input - * the {@link InputStream} to parse from. - * @return a {@link HeartbeatExtension} object. - * @throws IOException - */ - public static HeartbeatExtension parse(InputStream input) throws IOException - { - short mode = TlsUtils.readUint8(input); - if (!HeartbeatMode.isValid(mode)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - return new HeartbeatExtension(mode); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HeartbeatMessage.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HeartbeatMessage.java deleted file mode 100644 index e3dd3f831..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HeartbeatMessage.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.io.Streams; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class HeartbeatMessage -{ - protected short type; - protected byte[] payload; - protected int paddingLength; - - public HeartbeatMessage(short type, byte[] payload, int paddingLength) - { - if (!HeartbeatMessageType.isValid(type)) - { - throw new IllegalArgumentException("'type' is not a valid HeartbeatMessageType value"); - } - if (payload == null || payload.length >= (1 << 16)) - { - throw new IllegalArgumentException("'payload' must have length < 2^16"); - } - if (paddingLength < 16) - { - throw new IllegalArgumentException("'paddingLength' must be at least 16"); - } - - this.type = type; - this.payload = payload; - this.paddingLength = paddingLength; - } - - /** - * Encode this {@link HeartbeatMessage} to an {@link OutputStream}. - * - * @param output - * the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(TlsContext context, OutputStream output) throws IOException - { - TlsUtils.writeUint8(type, output); - - TlsUtils.checkUint16(payload.length); - TlsUtils.writeUint16(payload.length, output); - output.write(payload); - - byte[] padding = new byte[paddingLength]; - context.getNonceRandomGenerator().nextBytes(padding); - output.write(padding); - } - - /** - * Parse a {@link HeartbeatMessage} from an {@link InputStream}. - * - * @param input - * the {@link InputStream} to parse from. - * @return a {@link HeartbeatMessage} object. - * @throws IOException - */ - public static HeartbeatMessage parse(InputStream input) throws IOException - { - short type = TlsUtils.readUint8(input); - if (!HeartbeatMessageType.isValid(type)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - int payload_length = TlsUtils.readUint16(input); - - PayloadBuffer buf = new PayloadBuffer(); - Streams.pipeAll(input, buf); - - byte[] payload = buf.toTruncatedByteArray(payload_length); - if (payload == null) - { - /* - * RFC 6520 4. If the payload_length of a received HeartbeatMessage is too large, the - * received HeartbeatMessage MUST be discarded silently. - */ - return null; - } - - int padding_length = buf.size() - payload.length; - - /* - * RFC 6520 4. The padding of a received HeartbeatMessage message MUST be ignored - */ - return new HeartbeatMessage(type, payload, padding_length); - } - - static class PayloadBuffer extends ByteArrayOutputStream - { - byte[] toTruncatedByteArray(int payloadLength) - { - /* - * RFC 6520 4. The padding_length MUST be at least 16. - */ - int minimumCount = payloadLength + 16; - if (count < minimumCount) - { - return null; - } - return Arrays.copyOf(buf, payloadLength); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HeartbeatMessageType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HeartbeatMessageType.java deleted file mode 100644 index c7dc2bc6c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HeartbeatMessageType.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/* - * RFC 6520 3. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class HeartbeatMessageType -{ - public static final short heartbeat_request = 1; - public static final short heartbeat_response = 2; - - public static boolean isValid(short heartbeatMessageType) - { - return heartbeatMessageType >= heartbeat_request && heartbeatMessageType <= heartbeat_response; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HeartbeatMode.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HeartbeatMode.java deleted file mode 100644 index 7d0d04b37..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/HeartbeatMode.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/* - * RFC 6520 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class HeartbeatMode -{ - public static final short peer_allowed_to_send = 1; - public static final short peer_not_allowed_to_send = 2; - - public static boolean isValid(short heartbeatMode) - { - return heartbeatMode >= peer_allowed_to_send && heartbeatMode <= peer_not_allowed_to_send; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/KeyExchangeAlgorithm.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/KeyExchangeAlgorithm.java deleted file mode 100644 index f977b9c35..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/KeyExchangeAlgorithm.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 2246 - *
- * Note that the values here are implementation-specific and arbitrary. It is recommended not to - * depend on the particular values (e.g. serialization). - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class KeyExchangeAlgorithm -{ - public static final int NULL = 0; - public static final int RSA = 1; - public static final int RSA_EXPORT = 2; - public static final int DHE_DSS = 3; - public static final int DHE_DSS_EXPORT = 4; - public static final int DHE_RSA = 5; - public static final int DHE_RSA_EXPORT = 6; - public static final int DH_DSS = 7; - public static final int DH_DSS_EXPORT = 8; - public static final int DH_RSA = 9; - public static final int DH_RSA_EXPORT = 10; - public static final int DH_anon = 11; - public static final int DH_anon_EXPORT = 12; - - /* - * RFC 4279 - */ - public static final int PSK = 13; - public static final int DHE_PSK = 14; - public static final int RSA_PSK = 15; - - /* - * RFC 4429 - */ - public static final int ECDH_ECDSA = 16; - public static final int ECDHE_ECDSA = 17; - public static final int ECDH_RSA = 18; - public static final int ECDHE_RSA = 19; - public static final int ECDH_anon = 20; - - /* - * RFC 5054 - */ - public static final int SRP = 21; - public static final int SRP_DSS = 22; - public static final int SRP_RSA = 23; - - /* - * RFC 5489 - */ - public static final int ECDHE_PSK = 24; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/MACAlgorithm.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/MACAlgorithm.java deleted file mode 100644 index e9156178c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/MACAlgorithm.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 2246 - *
- * Note that the values here are implementation-specific and arbitrary. It is recommended not to - * depend on the particular values (e.g. serialization). - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class MACAlgorithm -{ - public static final int _null = 0; - public static final int md5 = 1; - public static final int sha = 2; - - /* - * RFC 5246 - */ - public static final int hmac_md5 = md5; - public static final int hmac_sha1 = sha; - public static final int hmac_sha256 = 3; - public static final int hmac_sha384 = 4; - public static final int hmac_sha512 = 5; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/MaxFragmentLength.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/MaxFragmentLength.java deleted file mode 100644 index 65de041ec..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/MaxFragmentLength.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class MaxFragmentLength -{ - /* - * RFC 3546 3.2. - */ - public static final short pow2_9 = 1; - public static final short pow2_10 = 2; - public static final short pow2_11 = 3; - public static final short pow2_12 = 4; - - public static boolean isValid(short maxFragmentLength) - { - return maxFragmentLength >= pow2_9 && maxFragmentLength <= pow2_12; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/NameType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/NameType.java deleted file mode 100644 index 286a5f7ad..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/NameType.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class NameType -{ - /* - * RFC 3546 3.1. - */ - public static final short host_name = 0; - - public static boolean isValid(short nameType) - { - return nameType == host_name; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/NamedCurve.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/NamedCurve.java deleted file mode 100644 index bcdd4981b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/NamedCurve.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 4492 5.1.1 - *
- * The named curves defined here are those specified in SEC 2 [13]. Note that many of these curves - * are also recommended in ANSI X9.62 [7] and FIPS 186-2 [11]. Values 0xFE00 through 0xFEFF are - * reserved for private use. Values 0xFF01 and 0xFF02 indicate that the client supports arbitrary - * prime and characteristic-2 curves, respectively (the curve parameters must be encoded explicitly - * in ECParameters). - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class NamedCurve -{ - public static final int sect163k1 = 1; - public static final int sect163r1 = 2; - public static final int sect163r2 = 3; - public static final int sect193r1 = 4; - public static final int sect193r2 = 5; - public static final int sect233k1 = 6; - public static final int sect233r1 = 7; - public static final int sect239k1 = 8; - public static final int sect283k1 = 9; - public static final int sect283r1 = 10; - public static final int sect409k1 = 11; - public static final int sect409r1 = 12; - public static final int sect571k1 = 13; - public static final int sect571r1 = 14; - public static final int secp160k1 = 15; - public static final int secp160r1 = 16; - public static final int secp160r2 = 17; - public static final int secp192k1 = 18; - public static final int secp192r1 = 19; - public static final int secp224k1 = 20; - public static final int secp224r1 = 21; - public static final int secp256k1 = 22; - public static final int secp256r1 = 23; - public static final int secp384r1 = 24; - public static final int secp521r1 = 25; - - /* - * RFC 7027 - */ - public static final int brainpoolP256r1 = 26; - public static final int brainpoolP384r1 = 27; - public static final int brainpoolP512r1 = 28; - - /* - * reserved (0xFE00..0xFEFF) - */ - - public static final int arbitrary_explicit_prime_curves = 0xFF01; - public static final int arbitrary_explicit_char2_curves = 0xFF02; - - public static boolean isValid(int namedCurve) - { - return (namedCurve >= sect163k1 && namedCurve <= brainpoolP512r1) - || (namedCurve >= arbitrary_explicit_prime_curves && namedCurve <= arbitrary_explicit_char2_curves); - } - - public static boolean refersToASpecificNamedCurve(int namedCurve) - { - switch (namedCurve) - { - case arbitrary_explicit_prime_curves: - case arbitrary_explicit_char2_curves: - return false; - default: - return true; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/NewSessionTicket.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/NewSessionTicket.java deleted file mode 100644 index 5610a8b80..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/NewSessionTicket.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class NewSessionTicket -{ - protected long ticketLifetimeHint; - protected byte[] ticket; - - public NewSessionTicket(long ticketLifetimeHint, byte[] ticket) - { - this.ticketLifetimeHint = ticketLifetimeHint; - this.ticket = ticket; - } - - public long getTicketLifetimeHint() - { - return ticketLifetimeHint; - } - - public byte[] getTicket() - { - return ticket; - } - - /** - * Encode this {@link NewSessionTicket} to an {@link OutputStream}. - * - * @param output the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) - throws IOException - { - TlsUtils.writeUint32(ticketLifetimeHint, output); - TlsUtils.writeOpaque16(ticket, output); - } - - /** - * Parse a {@link NewSessionTicket} from an {@link InputStream}. - * - * @param input the {@link InputStream} to parse from. - * @return a {@link NewSessionTicket} object. - * @throws IOException - */ - public static NewSessionTicket parse(InputStream input) - throws IOException - { - long ticketLifetimeHint = TlsUtils.readUint32(input); - byte[] ticket = TlsUtils.readOpaque16(input); - return new NewSessionTicket(ticketLifetimeHint, ticket); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/OCSPStatusRequest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/OCSPStatusRequest.java deleted file mode 100644 index c129a85ca..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/OCSPStatusRequest.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encoding; -import com.fr.third.org.bouncycastle.asn1.ocsp.ResponderID; -import com.fr.third.org.bouncycastle.asn1.x509.Extensions; -import com.fr.third.org.bouncycastle.util.io.Streams; - -/** - * RFC 3546 3.6 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class OCSPStatusRequest -{ - protected Vector responderIDList; - protected Extensions requestExtensions; - - /** - * @param responderIDList - * a {@link Vector} of {@link ResponderID}, specifying the list of trusted OCSP - * responders. An empty list has the special meaning that the responders are - * implicitly known to the server - e.g., by prior arrangement. - * @param requestExtensions - * OCSP request extensions. A null value means that there are no extensions. - */ - public OCSPStatusRequest(Vector responderIDList, Extensions requestExtensions) - { - this.responderIDList = responderIDList; - this.requestExtensions = requestExtensions; - } - - /** - * @return a {@link Vector} of {@link ResponderID} - */ - public Vector getResponderIDList() - { - return responderIDList; - } - - /** - * @return OCSP request extensions - */ - public Extensions getRequestExtensions() - { - return requestExtensions; - } - - /** - * Encode this {@link OCSPStatusRequest} to an {@link OutputStream}. - * - * @param output - * the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) throws IOException - { - if (responderIDList == null || responderIDList.isEmpty()) - { - TlsUtils.writeUint16(0, output); - } - else - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - for (int i = 0; i < responderIDList.size(); ++i) - { - ResponderID responderID = (ResponderID) responderIDList.elementAt(i); - byte[] derEncoding = responderID.getEncoded(ASN1Encoding.DER); - TlsUtils.writeOpaque16(derEncoding, buf); - } - TlsUtils.checkUint16(buf.size()); - TlsUtils.writeUint16(buf.size(), output); - Streams.writeBufTo(buf, output); - } - - if (requestExtensions == null) - { - TlsUtils.writeUint16(0, output); - } - else - { - byte[] derEncoding = requestExtensions.getEncoded(ASN1Encoding.DER); - TlsUtils.checkUint16(derEncoding.length); - TlsUtils.writeUint16(derEncoding.length, output); - output.write(derEncoding); - } - } - - /** - * Parse an {@link OCSPStatusRequest} from an {@link InputStream}. - * - * @param input - * the {@link InputStream} to parse from. - * @return an {@link OCSPStatusRequest} object. - * @throws IOException - */ - public static OCSPStatusRequest parse(InputStream input) throws IOException - { - Vector responderIDList = new Vector(); - { - int length = TlsUtils.readUint16(input); - if (length > 0) - { - byte[] data = TlsUtils.readFully(length, input); - ByteArrayInputStream buf = new ByteArrayInputStream(data); - do - { - byte[] derEncoding = TlsUtils.readOpaque16(buf); - ResponderID responderID = ResponderID.getInstance(TlsUtils.readDERObject(derEncoding)); - responderIDList.addElement(responderID); - } - while (buf.available() > 0); - } - } - - Extensions requestExtensions = null; - { - int length = TlsUtils.readUint16(input); - if (length > 0) - { - byte[] derEncoding = TlsUtils.readFully(length, input); - requestExtensions = Extensions.getInstance(TlsUtils.readDERObject(derEncoding)); - } - } - - return new OCSPStatusRequest(responderIDList, requestExtensions); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/PRFAlgorithm.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/PRFAlgorithm.java deleted file mode 100644 index 7d6e38ab5..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/PRFAlgorithm.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 5246 - *
- * Note that the values here are implementation-specific and arbitrary. It is recommended not to - * depend on the particular values (e.g. serialization). - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class PRFAlgorithm -{ - /* - * Placeholder to refer to the legacy TLS algorithm - */ - public static final int tls_prf_legacy = 0; - - public static final int tls_prf_sha256 = 1; - - /* - * Implied by RFC 5288 - */ - public static final int tls_prf_sha384 = 2; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/PSKTlsClient.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/PSKTlsClient.java deleted file mode 100644 index c36c305bc..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/PSKTlsClient.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class PSKTlsClient - extends AbstractTlsClient -{ - protected TlsDHVerifier dhVerifier; - protected TlsPSKIdentity pskIdentity; - - public PSKTlsClient(TlsPSKIdentity pskIdentity) - { - this(new DefaultTlsCipherFactory(), pskIdentity); - } - - public PSKTlsClient(TlsCipherFactory cipherFactory, TlsPSKIdentity pskIdentity) - { - this(cipherFactory, new DefaultTlsDHVerifier(), pskIdentity); - } - - public PSKTlsClient(TlsCipherFactory cipherFactory, TlsDHVerifier dhVerifier, TlsPSKIdentity pskIdentity) - { - super(cipherFactory); - - this.dhVerifier = dhVerifier; - this.pskIdentity = pskIdentity; - } - - public int[] getCipherSuites() - { - return new int[] - { - CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256, - CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, - }; - } - - public TlsKeyExchange getKeyExchange() throws IOException - { - int keyExchangeAlgorithm = TlsUtils.getKeyExchangeAlgorithm(selectedCipherSuite); - - switch (keyExchangeAlgorithm) - { - case KeyExchangeAlgorithm.DHE_PSK: - case KeyExchangeAlgorithm.ECDHE_PSK: - case KeyExchangeAlgorithm.PSK: - case KeyExchangeAlgorithm.RSA_PSK: - return createPSKKeyExchange(keyExchangeAlgorithm); - - default: - /* - * Note: internal error here; the TlsProtocol implementation verifies that the - * server-selected cipher suite was in the list of client-offered cipher suites, so if - * we now can't produce an implementation, we shouldn't have offered it! - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public TlsAuthentication getAuthentication() throws IOException - { - /* - * Note: This method is not called unless a server certificate is sent, which may be the - * case e.g. for RSA_PSK key exchange. - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - protected TlsKeyExchange createPSKKeyExchange(int keyExchange) - { - return new TlsPSKKeyExchange(keyExchange, supportedSignatureAlgorithms, pskIdentity, null, dhVerifier, null, - namedCurves, clientECPointFormats, serverECPointFormats); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/PSKTlsServer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/PSKTlsServer.java deleted file mode 100644 index 62d2ec80e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/PSKTlsServer.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.crypto.agreement.DHStandardGroups; -import com.fr.third.org.bouncycastle.crypto.params.DHParameters; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class PSKTlsServer - extends AbstractTlsServer -{ - protected TlsPSKIdentityManager pskIdentityManager; - - public PSKTlsServer(TlsPSKIdentityManager pskIdentityManager) - { - this(new DefaultTlsCipherFactory(), pskIdentityManager); - } - - public PSKTlsServer(TlsCipherFactory cipherFactory, TlsPSKIdentityManager pskIdentityManager) - { - super(cipherFactory); - this.pskIdentityManager = pskIdentityManager; - } - - protected TlsEncryptionCredentials getRSAEncryptionCredentials() throws IOException - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - protected DHParameters getDHParameters() - { - return DHStandardGroups.rfc7919_ffdhe2048; - } - - protected int[] getCipherSuites() - { - return new int[] - { - CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256, - CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, - CipherSuite.TLS_DHE_PSK_WITH_AES_128_CBC_SHA256, - CipherSuite.TLS_DHE_PSK_WITH_AES_128_CBC_SHA - }; - } - - public TlsCredentials getCredentials() throws IOException - { - int keyExchangeAlgorithm = TlsUtils.getKeyExchangeAlgorithm(selectedCipherSuite); - - switch (keyExchangeAlgorithm) - { - case KeyExchangeAlgorithm.DHE_PSK: - case KeyExchangeAlgorithm.ECDHE_PSK: - case KeyExchangeAlgorithm.PSK: - return null; - - case KeyExchangeAlgorithm.RSA_PSK: - return getRSAEncryptionCredentials(); - - default: - /* Note: internal error here; selected a key exchange we don't implement! */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public TlsKeyExchange getKeyExchange() throws IOException - { - int keyExchangeAlgorithm = TlsUtils.getKeyExchangeAlgorithm(selectedCipherSuite); - - switch (keyExchangeAlgorithm) - { - case KeyExchangeAlgorithm.DHE_PSK: - case KeyExchangeAlgorithm.ECDHE_PSK: - case KeyExchangeAlgorithm.PSK: - case KeyExchangeAlgorithm.RSA_PSK: - return createPSKKeyExchange(keyExchangeAlgorithm); - - default: - /* - * Note: internal error here; the TlsProtocol implementation verifies that the - * server-selected cipher suite was in the list of client-offered cipher suites, so if - * we now can't produce an implementation, we shouldn't have offered it! - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - protected TlsKeyExchange createPSKKeyExchange(int keyExchange) - { - return new TlsPSKKeyExchange(keyExchange, supportedSignatureAlgorithms, null, pskIdentityManager, - null, getDHParameters(), namedCurves, clientECPointFormats, serverECPointFormats); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ProtocolVersion.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ProtocolVersion.java deleted file mode 100644 index 596c27729..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ProtocolVersion.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.util.Strings; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public final class ProtocolVersion -{ - public static final ProtocolVersion SSLv3 = new ProtocolVersion(0x0300, "SSL 3.0"); - public static final ProtocolVersion TLSv10 = new ProtocolVersion(0x0301, "TLS 1.0"); - public static final ProtocolVersion TLSv11 = new ProtocolVersion(0x0302, "TLS 1.1"); - public static final ProtocolVersion TLSv12 = new ProtocolVersion(0x0303, "TLS 1.2"); - public static final ProtocolVersion DTLSv10 = new ProtocolVersion(0xFEFF, "DTLS 1.0"); - public static final ProtocolVersion DTLSv12 = new ProtocolVersion(0xFEFD, "DTLS 1.2"); - - private int version; - private String name; - - private ProtocolVersion(int v, String name) - { - this.version = v & 0xffff; - this.name = name; - } - - public int getFullVersion() - { - return version; - } - - public int getMajorVersion() - { - return version >> 8; - } - - public int getMinorVersion() - { - return version & 0xff; - } - - public boolean isDTLS() - { - return getMajorVersion() == 0xFE; - } - - public boolean isSSL() - { - return this == SSLv3; - } - - public boolean isTLS() - { - return getMajorVersion() == 0x03; - } - - public ProtocolVersion getEquivalentTLSVersion() - { - if (!isDTLS()) - { - return this; - } - if (this == DTLSv10) - { - return TLSv11; - } - return TLSv12; - } - - public boolean isEqualOrEarlierVersionOf(ProtocolVersion version) - { - if (getMajorVersion() != version.getMajorVersion()) - { - return false; - } - int diffMinorVersion = version.getMinorVersion() - getMinorVersion(); - return isDTLS() ? diffMinorVersion <= 0 : diffMinorVersion >= 0; - } - - public boolean isLaterVersionOf(ProtocolVersion version) - { - if (getMajorVersion() != version.getMajorVersion()) - { - return false; - } - int diffMinorVersion = version.getMinorVersion() - getMinorVersion(); - return isDTLS() ? diffMinorVersion > 0 : diffMinorVersion < 0; - } - - public boolean equals(Object other) - { - return this == other || (other instanceof ProtocolVersion && equals((ProtocolVersion)other)); - } - - public boolean equals(ProtocolVersion other) - { - return other != null && this.version == other.version; - } - - public int hashCode() - { - return version; - } - - public static ProtocolVersion get(int major, int minor) - throws IOException - { - switch (major) - { - case 0x03: - { - switch (minor) - { - case 0x00: - return SSLv3; - case 0x01: - return TLSv10; - case 0x02: - return TLSv11; - case 0x03: - return TLSv12; - } - return getUnknownVersion(major, minor, "TLS"); - } - case 0xFE: - { - switch (minor) - { - case 0xFF: - return DTLSv10; - case 0xFE: - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - case 0xFD: - return DTLSv12; - } - return getUnknownVersion(major, minor, "DTLS"); - } - default: - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - } - - public String toString() - { - return name; - } - - private static ProtocolVersion getUnknownVersion(int major, int minor, String prefix) - throws IOException - { - TlsUtils.checkUint8(major); - TlsUtils.checkUint8(minor); - - int v = (major << 8) | minor; - String hex = Strings.toUpperCase(Integer.toHexString(0x10000 | v).substring(1)); - return new ProtocolVersion(v, prefix + " 0x" + hex); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/RecordStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/RecordStream.java deleted file mode 100644 index b34be64c9..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/RecordStream.java +++ /dev/null @@ -1,432 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import com.fr.third.org.bouncycastle.util.io.SimpleOutputStream; - -/** - * An implementation of the TLS 1.0/1.1/1.2 record layer, allowing downgrade to SSLv3. - */ -class RecordStream -{ - private static int DEFAULT_PLAINTEXT_LIMIT = (1 << 14); - static final int TLS_HEADER_SIZE = 5; - static final int TLS_HEADER_TYPE_OFFSET = 0; - static final int TLS_HEADER_VERSION_OFFSET = 1; - static final int TLS_HEADER_LENGTH_OFFSET = 3; - - private TlsProtocol handler; - private InputStream input; - private OutputStream output; - private TlsCompression pendingCompression = null, readCompression = null, writeCompression = null; - private TlsCipher pendingCipher = null, readCipher = null, writeCipher = null; - private SequenceNumber readSeqNo = new SequenceNumber(), writeSeqNo = new SequenceNumber(); - private ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - - private TlsHandshakeHash handshakeHash = null; - private SimpleOutputStream handshakeHashUpdater = new SimpleOutputStream() - { - public void write(byte[] buf, int off, int len) throws IOException - { - handshakeHash.update(buf, off, len); - } - }; - - private ProtocolVersion readVersion = null, writeVersion = null; - private boolean restrictReadVersion = true; - - private int plaintextLimit, compressedLimit, ciphertextLimit; - - RecordStream(TlsProtocol handler, InputStream input, OutputStream output) - { - this.handler = handler; - this.input = input; - this.output = output; - this.readCompression = new TlsNullCompression(); - this.writeCompression = this.readCompression; - } - - void init(TlsContext context) - { - this.readCipher = new TlsNullCipher(context); - this.writeCipher = this.readCipher; - this.handshakeHash = new DeferredHash(); - this.handshakeHash.init(context); - - setPlaintextLimit(DEFAULT_PLAINTEXT_LIMIT); - } - - int getPlaintextLimit() - { - return plaintextLimit; - } - - void setPlaintextLimit(int plaintextLimit) - { - this.plaintextLimit = plaintextLimit; - this.compressedLimit = this.plaintextLimit + 1024; - this.ciphertextLimit = this.compressedLimit + 1024; - } - - ProtocolVersion getReadVersion() - { - return readVersion; - } - - void setReadVersion(ProtocolVersion readVersion) - { - this.readVersion = readVersion; - } - - void setWriteVersion(ProtocolVersion writeVersion) - { - this.writeVersion = writeVersion; - } - - /** - * RFC 5246 E.1. "Earlier versions of the TLS specification were not fully clear on what the - * record layer version number (TLSPlaintext.version) should contain when sending ClientHello - * (i.e., before it is known which version of the protocol will be employed). Thus, TLS servers - * compliant with this specification MUST accept any value {03,XX} as the record layer version - * number for ClientHello." - */ - void setRestrictReadVersion(boolean enabled) - { - this.restrictReadVersion = enabled; - } - - void setPendingConnectionState(TlsCompression tlsCompression, TlsCipher tlsCipher) - { - this.pendingCompression = tlsCompression; - this.pendingCipher = tlsCipher; - } - - void sentWriteCipherSpec() - throws IOException - { - if (pendingCompression == null || pendingCipher == null) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - this.writeCompression = this.pendingCompression; - this.writeCipher = this.pendingCipher; - this.writeSeqNo = new SequenceNumber(); - } - - void receivedReadCipherSpec() - throws IOException - { - if (pendingCompression == null || pendingCipher == null) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - this.readCompression = this.pendingCompression; - this.readCipher = this.pendingCipher; - this.readSeqNo = new SequenceNumber(); - } - - void finaliseHandshake() - throws IOException - { - if (readCompression != pendingCompression || writeCompression != pendingCompression - || readCipher != pendingCipher || writeCipher != pendingCipher) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - this.pendingCompression = null; - this.pendingCipher = null; - } - - void checkRecordHeader(byte[] recordHeader) throws IOException - { - short type = TlsUtils.readUint8(recordHeader, TLS_HEADER_TYPE_OFFSET); - - /* - * RFC 5246 6. If a TLS implementation receives an unexpected record type, it MUST send an - * unexpected_message alert. - */ - checkType(type, AlertDescription.unexpected_message); - - if (!restrictReadVersion) - { - int version = TlsUtils.readVersionRaw(recordHeader, TLS_HEADER_VERSION_OFFSET); - if ((version & 0xffffff00) != 0x0300) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - else - { - ProtocolVersion version = TlsUtils.readVersion(recordHeader, TLS_HEADER_VERSION_OFFSET); - if (readVersion == null) - { - // Will be set later in 'readRecord' - } - else if (!version.equals(readVersion)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - - int length = TlsUtils.readUint16(recordHeader, TLS_HEADER_LENGTH_OFFSET); - - checkLength(length, ciphertextLimit, AlertDescription.record_overflow); - } - - boolean readRecord() - throws IOException - { - byte[] recordHeader = TlsUtils.readAllOrNothing(TLS_HEADER_SIZE, input); - if (recordHeader == null) - { - return false; - } - - short type = TlsUtils.readUint8(recordHeader, TLS_HEADER_TYPE_OFFSET); - - /* - * RFC 5246 6. If a TLS implementation receives an unexpected record type, it MUST send an - * unexpected_message alert. - */ - checkType(type, AlertDescription.unexpected_message); - - if (!restrictReadVersion) - { - int version = TlsUtils.readVersionRaw(recordHeader, TLS_HEADER_VERSION_OFFSET); - if ((version & 0xffffff00) != 0x0300) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - else - { - ProtocolVersion version = TlsUtils.readVersion(recordHeader, TLS_HEADER_VERSION_OFFSET); - if (readVersion == null) - { - readVersion = version; - } - else if (!version.equals(readVersion)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - - int length = TlsUtils.readUint16(recordHeader, TLS_HEADER_LENGTH_OFFSET); - - checkLength(length, ciphertextLimit, AlertDescription.record_overflow); - - byte[] plaintext = decodeAndVerify(type, input, length); - handler.processRecord(type, plaintext, 0, plaintext.length); - return true; - } - - byte[] decodeAndVerify(short type, InputStream input, int len) - throws IOException - { - byte[] buf = TlsUtils.readFully(len, input); - - long seqNo = readSeqNo.nextValue(AlertDescription.unexpected_message); - byte[] decoded = readCipher.decodeCiphertext(seqNo, type, buf, 0, buf.length); - - checkLength(decoded.length, compressedLimit, AlertDescription.record_overflow); - - /* - * TODO RFC 5246 6.2.2. Implementation note: Decompression functions are responsible for - * ensuring that messages cannot cause internal buffer overflows. - */ - OutputStream cOut = readCompression.decompress(buffer); - if (cOut != buffer) - { - cOut.write(decoded, 0, decoded.length); - cOut.flush(); - decoded = getBufferContents(); - } - - /* - * RFC 5246 6.2.2. If the decompression function encounters a TLSCompressed.fragment that - * would decompress to a length in excess of 2^14 bytes, it should report a fatal - * decompression failure error. - */ - checkLength(decoded.length, plaintextLimit, AlertDescription.decompression_failure); - - /* - * RFC 5246 6.2.1 Implementations MUST NOT send zero-length fragments of Handshake, Alert, - * or ChangeCipherSpec content types. - */ - if (decoded.length < 1 && type != ContentType.application_data) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - return decoded; - } - - void writeRecord(short type, byte[] plaintext, int plaintextOffset, int plaintextLength) - throws IOException - { - // Never send anything until a valid ClientHello has been received - if (writeVersion == null) - { - return; - } - - /* - * RFC 5246 6. Implementations MUST NOT send record types not defined in this document - * unless negotiated by some extension. - */ - checkType(type, AlertDescription.internal_error); - - /* - * RFC 5246 6.2.1 The length should not exceed 2^14. - */ - checkLength(plaintextLength, plaintextLimit, AlertDescription.internal_error); - - /* - * RFC 5246 6.2.1 Implementations MUST NOT send zero-length fragments of Handshake, Alert, - * or ChangeCipherSpec content types. - */ - if (plaintextLength < 1 && type != ContentType.application_data) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - OutputStream cOut = writeCompression.compress(buffer); - - long seqNo = writeSeqNo.nextValue(AlertDescription.internal_error); - - byte[] ciphertext; - if (cOut == buffer) - { - ciphertext = writeCipher.encodePlaintext(seqNo, type, plaintext, plaintextOffset, plaintextLength); - } - else - { - cOut.write(plaintext, plaintextOffset, plaintextLength); - cOut.flush(); - byte[] compressed = getBufferContents(); - - /* - * RFC 5246 6.2.2. Compression must be lossless and may not increase the content length - * by more than 1024 bytes. - */ - checkLength(compressed.length, plaintextLength + 1024, AlertDescription.internal_error); - - ciphertext = writeCipher.encodePlaintext(seqNo, type, compressed, 0, compressed.length); - } - - /* - * RFC 5246 6.2.3. The length may not exceed 2^14 + 2048. - */ - checkLength(ciphertext.length, ciphertextLimit, AlertDescription.internal_error); - - byte[] record = new byte[ciphertext.length + TLS_HEADER_SIZE]; - TlsUtils.writeUint8(type, record, TLS_HEADER_TYPE_OFFSET); - TlsUtils.writeVersion(writeVersion, record, TLS_HEADER_VERSION_OFFSET); - TlsUtils.writeUint16(ciphertext.length, record, TLS_HEADER_LENGTH_OFFSET); - System.arraycopy(ciphertext, 0, record, TLS_HEADER_SIZE, ciphertext.length); - output.write(record); - output.flush(); - } - - void notifyHelloComplete() - { - this.handshakeHash = handshakeHash.notifyPRFDetermined(); - } - - TlsHandshakeHash getHandshakeHash() - { - return handshakeHash; - } - - OutputStream getHandshakeHashUpdater() - { - return handshakeHashUpdater; - } - - TlsHandshakeHash prepareToFinish() - { - TlsHandshakeHash result = handshakeHash; - this.handshakeHash = handshakeHash.stopTracking(); - return result; - } - - void safeClose() - { - try - { - input.close(); - } - catch (IOException e) - { - } - - try - { - output.close(); - } - catch (IOException e) - { - } - } - - void flush() - throws IOException - { - output.flush(); - } - - private byte[] getBufferContents() - { - byte[] contents = buffer.toByteArray(); - buffer.reset(); - return contents; - } - - private static void checkType(short type, short alertDescription) - throws IOException - { - switch (type) - { - case ContentType.application_data: - case ContentType.alert: - case ContentType.change_cipher_spec: - case ContentType.handshake: -// case ContentType.heartbeat: - break; - default: - throw new TlsFatalAlert(alertDescription); - } - } - - private static void checkLength(int length, int limit, short alertDescription) - throws IOException - { - if (length > limit) - { - throw new TlsFatalAlert(alertDescription); - } - } - - private static class SequenceNumber - { - private long value = 0L; - private boolean exhausted = false; - - synchronized long nextValue(short alertDescription) throws TlsFatalAlert - { - if (exhausted) - { - throw new TlsFatalAlert(alertDescription); - } - long result = value; - if (++value == 0) - { - exhausted = true; - } - return result; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SRPTlsClient.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SRPTlsClient.java deleted file mode 100644 index b16ec7c22..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SRPTlsClient.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class SRPTlsClient - extends AbstractTlsClient -{ - protected TlsSRPGroupVerifier groupVerifier; - - protected byte[] identity; - protected byte[] password; - - public SRPTlsClient(byte[] identity, byte[] password) - { - this(new DefaultTlsCipherFactory(), new DefaultTlsSRPGroupVerifier(), identity, password); - } - - public SRPTlsClient(TlsCipherFactory cipherFactory, byte[] identity, byte[] password) - { - this(cipherFactory, new DefaultTlsSRPGroupVerifier(), identity, password); - } - - public SRPTlsClient(TlsCipherFactory cipherFactory, TlsSRPGroupVerifier groupVerifier, - byte[] identity, byte[] password) - { - super(cipherFactory); - this.groupVerifier = groupVerifier; - this.identity = Arrays.clone(identity); - this.password = Arrays.clone(password); - } - - protected boolean requireSRPServerExtension() - { - // No explicit guidance in RFC 5054; by default an (empty) extension from server is optional - return false; - } - - public int[] getCipherSuites() - { - return new int[] - { - CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA - }; - } - - public Hashtable getClientExtensions() - throws IOException - { - Hashtable clientExtensions = TlsExtensionsUtils.ensureExtensionsInitialised(super.getClientExtensions()); - TlsSRPUtils.addSRPExtension(clientExtensions, this.identity); - return clientExtensions; - } - - public void processServerExtensions(Hashtable serverExtensions) - throws IOException - { - if (!TlsUtils.hasExpectedEmptyExtensionData(serverExtensions, TlsSRPUtils.EXT_SRP, - AlertDescription.illegal_parameter)) - { - if (requireSRPServerExtension()) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - - super.processServerExtensions(serverExtensions); - } - - public TlsKeyExchange getKeyExchange() - throws IOException - { - int keyExchangeAlgorithm = TlsUtils.getKeyExchangeAlgorithm(selectedCipherSuite); - - switch (keyExchangeAlgorithm) - { - case KeyExchangeAlgorithm.SRP: - case KeyExchangeAlgorithm.SRP_DSS: - case KeyExchangeAlgorithm.SRP_RSA: - return createSRPKeyExchange(keyExchangeAlgorithm); - - default: - /* - * Note: internal error here; the TlsProtocol implementation verifies that the - * server-selected cipher suite was in the list of client-offered cipher suites, so if - * we now can't produce an implementation, we shouldn't have offered it! - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public TlsAuthentication getAuthentication() throws IOException - { - /* - * Note: This method is not called unless a server certificate is sent, which may be the - * case e.g. for SRP_DSS or SRP_RSA key exchange. - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - protected TlsKeyExchange createSRPKeyExchange(int keyExchange) - { - return new TlsSRPKeyExchange(keyExchange, supportedSignatureAlgorithms, groupVerifier, identity, password); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SRPTlsServer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SRPTlsServer.java deleted file mode 100644 index 25b77dbb1..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SRPTlsServer.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.util.Hashtable; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class SRPTlsServer - extends AbstractTlsServer -{ - protected TlsSRPIdentityManager srpIdentityManager; - - protected byte[] srpIdentity = null; - protected TlsSRPLoginParameters loginParameters = null; - - public SRPTlsServer(TlsSRPIdentityManager srpIdentityManager) - { - this(new DefaultTlsCipherFactory(), srpIdentityManager); - } - - public SRPTlsServer(TlsCipherFactory cipherFactory, TlsSRPIdentityManager srpIdentityManager) - { - super(cipherFactory); - this.srpIdentityManager = srpIdentityManager; - } - - protected TlsSignerCredentials getDSASignerCredentials() - throws IOException - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - protected TlsSignerCredentials getRSASignerCredentials() - throws IOException - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - protected int[] getCipherSuites() - { - return new int[] - { - CipherSuite.TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA, - CipherSuite.TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA, - CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA, - CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA, - CipherSuite.TLS_SRP_SHA_WITH_AES_256_CBC_SHA, - CipherSuite.TLS_SRP_SHA_WITH_AES_128_CBC_SHA - }; - } - - public void processClientExtensions(Hashtable clientExtensions) throws IOException - { - super.processClientExtensions(clientExtensions); - - this.srpIdentity = TlsSRPUtils.getSRPExtension(clientExtensions); - } - - public int getSelectedCipherSuite() throws IOException - { - int cipherSuite = super.getSelectedCipherSuite(); - - if (TlsSRPUtils.isSRPCipherSuite(cipherSuite)) - { - if (srpIdentity != null) - { - this.loginParameters = srpIdentityManager.getLoginParameters(srpIdentity); - } - - if (loginParameters == null) - { - throw new TlsFatalAlert(AlertDescription.unknown_psk_identity); - } - } - - return cipherSuite; - } - - public TlsCredentials getCredentials() throws IOException - { - int keyExchangeAlgorithm = TlsUtils.getKeyExchangeAlgorithm(selectedCipherSuite); - - switch (keyExchangeAlgorithm) - { - case KeyExchangeAlgorithm.SRP: - return null; - - case KeyExchangeAlgorithm.SRP_DSS: - return getDSASignerCredentials(); - - case KeyExchangeAlgorithm.SRP_RSA: - return getRSASignerCredentials(); - - default: - /* Note: internal error here; selected a key exchange we don't implement! */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public TlsKeyExchange getKeyExchange() - throws IOException - { - int keyExchangeAlgorithm = TlsUtils.getKeyExchangeAlgorithm(selectedCipherSuite); - - switch (keyExchangeAlgorithm) - { - case KeyExchangeAlgorithm.SRP: - case KeyExchangeAlgorithm.SRP_DSS: - case KeyExchangeAlgorithm.SRP_RSA: - return createSRPKeyExchange(keyExchangeAlgorithm); - - default: - /* - * Note: internal error here; the TlsProtocol implementation verifies that the - * server-selected cipher suite was in the list of client-offered cipher suites, so if - * we now can't produce an implementation, we shouldn't have offered it! - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - protected TlsKeyExchange createSRPKeyExchange(int keyExchange) - { - return new TlsSRPKeyExchange(keyExchange, supportedSignatureAlgorithms, srpIdentity, loginParameters); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SRTPProtectionProfile.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SRTPProtectionProfile.java deleted file mode 100644 index 831bfa55c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SRTPProtectionProfile.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class SRTPProtectionProfile -{ - /* - * RFC 5764 4.1.2. - */ - public static final int SRTP_AES128_CM_HMAC_SHA1_80 = 0x0001; - public static final int SRTP_AES128_CM_HMAC_SHA1_32 = 0x0002; - public static final int SRTP_NULL_HMAC_SHA1_80 = 0x0005; - public static final int SRTP_NULL_HMAC_SHA1_32 = 0x0006; - - /* - * RFC 7714 14.2. - */ - public static final int SRTP_AEAD_AES_128_GCM = 0x0007; - public static final int SRTP_AEAD_AES_256_GCM = 0x0008; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SSL3Mac.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SSL3Mac.java deleted file mode 100644 index 58140fa8f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SSL3Mac.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * HMAC implementation based on original internet draft for HMAC (RFC 2104) - *
- * The difference is that padding is concatenated versus XORed with the key - *
- * H(K + opad, H(K + ipad, text)) - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class SSL3Mac - implements Mac -{ - private final static byte IPAD_BYTE = (byte)0x36; - private final static byte OPAD_BYTE = (byte)0x5C; - - static final byte[] IPAD = genPad(IPAD_BYTE, 48); - static final byte[] OPAD = genPad(OPAD_BYTE, 48); - - private Digest digest; - private int padLength; - - private byte[] secret; - - /** - * Base constructor for one of the standard digest algorithms that the byteLength of - * the algorithm is know for. Behaviour is undefined for digests other than MD5 or SHA1. - * - * @param digest the digest. - */ - public SSL3Mac(Digest digest) - { - this.digest = digest; - - if (digest.getDigestSize() == 20) - { - this.padLength = 40; - } - else - { - this.padLength = 48; - } - } - - public String getAlgorithmName() - { - return digest.getAlgorithmName() + "/SSL3MAC"; - } - - public Digest getUnderlyingDigest() - { - return digest; - } - - public void init(CipherParameters params) - { - secret = Arrays.clone(((KeyParameter)params).getKey()); - - reset(); - } - - public int getMacSize() - { - return digest.getDigestSize(); - } - - public void update(byte in) - { - digest.update(in); - } - - public void update(byte[] in, int inOff, int len) - { - digest.update(in, inOff, len); - } - - public int doFinal(byte[] out, int outOff) - { - byte[] tmp = new byte[digest.getDigestSize()]; - digest.doFinal(tmp, 0); - - digest.update(secret, 0, secret.length); - digest.update(OPAD, 0, padLength); - digest.update(tmp, 0, tmp.length); - - int len = digest.doFinal(out, outOff); - - reset(); - - return len; - } - - /** - * Reset the mac generator. - */ - public void reset() - { - digest.reset(); - digest.update(secret, 0, secret.length); - digest.update(IPAD, 0, padLength); - } - - private static byte[] genPad(byte b, int count) - { - byte[] padding = new byte[count]; - Arrays.fill(padding, b); - return padding; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SecurityParameters.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SecurityParameters.java deleted file mode 100644 index 438191d36..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SecurityParameters.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class SecurityParameters -{ - int entity = -1; - int cipherSuite = -1; - short compressionAlgorithm = CompressionMethod._null; - int prfAlgorithm = -1; - int verifyDataLength = -1; - byte[] masterSecret = null; - byte[] clientRandom = null; - byte[] serverRandom = null; - byte[] sessionHash = null; - byte[] pskIdentity = null; - byte[] srpIdentity = null; - - // TODO Keep these internal, since it's maybe not the ideal place for them - short maxFragmentLength = -1; - boolean truncatedHMac = false; - boolean encryptThenMAC = false; - boolean extendedMasterSecret = false; - - void clear() - { - if (this.masterSecret != null) - { - Arrays.fill(this.masterSecret, (byte)0); - this.masterSecret = null; - } - } - - /** - * @return {@link ConnectionEnd} - */ - public int getEntity() - { - return entity; - } - - /** - * @return {@link CipherSuite} - */ - public int getCipherSuite() - { - return cipherSuite; - } - - /** - * @return {@link CompressionMethod} - */ - public short getCompressionAlgorithm() - { - return compressionAlgorithm; - } - - /** - * @return {@link PRFAlgorithm} - */ - public int getPrfAlgorithm() - { - return prfAlgorithm; - } - - public int getVerifyDataLength() - { - return verifyDataLength; - } - - public byte[] getMasterSecret() - { - return masterSecret; - } - - public byte[] getClientRandom() - { - return clientRandom; - } - - public byte[] getServerRandom() - { - return serverRandom; - } - - public byte[] getSessionHash() - { - return sessionHash; - } - - /** - * @deprecated Use {@link SecurityParameters#getPSKIdentity()} - */ - public byte[] getPskIdentity() - { - return pskIdentity; - } - - public byte[] getPSKIdentity() - { - return pskIdentity; - } - - public byte[] getSRPIdentity() - { - return srpIdentity; - } - - public boolean isExtendedMasterSecret() - { - return extendedMasterSecret; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ServerName.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ServerName.java deleted file mode 100644 index 92d1134f6..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ServerName.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ServerName -{ - protected short nameType; - protected Object name; - - public ServerName(short nameType, Object name) - { - if (!isCorrectType(nameType, name)) - { - throw new IllegalArgumentException("'name' is not an instance of the correct type"); - } - - this.nameType = nameType; - this.name = name; - } - - public short getNameType() - { - return nameType; - } - - public Object getName() - { - return name; - } - - public String getHostName() - { - if (!isCorrectType(NameType.host_name, name)) - { - throw new IllegalStateException("'name' is not a HostName string"); - } - return (String)name; - } - - /** - * Encode this {@link ServerName} to an {@link OutputStream}. - * - * @param output - * the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) throws IOException - { - TlsUtils.writeUint8(nameType, output); - - switch (nameType) - { - case NameType.host_name: - byte[] asciiEncoding = ((String)name).getBytes("ASCII"); - if (asciiEncoding.length < 1) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - TlsUtils.writeOpaque16(asciiEncoding, output); - break; - default: - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - /** - * Parse a {@link ServerName} from an {@link InputStream}. - * - * @param input - * the {@link InputStream} to parse from. - * @return a {@link ServerName} object. - * @throws IOException - */ - public static ServerName parse(InputStream input) throws IOException - { - short name_type = TlsUtils.readUint8(input); - Object name; - - switch (name_type) - { - case NameType.host_name: - { - byte[] asciiEncoding = TlsUtils.readOpaque16(input); - if (asciiEncoding.length < 1) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - name = new String(asciiEncoding, "ASCII"); - break; - } - default: - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - return new ServerName(name_type, name); - } - - protected static boolean isCorrectType(short nameType, Object name) - { - switch (nameType) - { - case NameType.host_name: - return name instanceof String; - default: - throw new IllegalArgumentException("'nameType' is an unsupported NameType"); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ServerNameList.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ServerNameList.java deleted file mode 100644 index 6456bc8b2..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ServerNameList.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.io.Streams; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ServerNameList -{ - protected Vector serverNameList; - - /** - * @param serverNameList a {@link Vector} of {@link ServerName}. - */ - public ServerNameList(Vector serverNameList) - { - if (serverNameList == null) - { - throw new IllegalArgumentException("'serverNameList' must not be null"); - } - - this.serverNameList = serverNameList; - } - - /** - * @return a {@link Vector} of {@link ServerName}. - */ - public Vector getServerNameList() - { - return serverNameList; - } - - /** - * Encode this {@link ServerNameList} to an {@link OutputStream}. - * - * @param output - * the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) throws IOException - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - short[] nameTypesSeen = new short[0]; - for (int i = 0; i < serverNameList.size(); ++i) - { - ServerName entry = (ServerName)serverNameList.elementAt(i); - - nameTypesSeen = checkNameType(nameTypesSeen, entry.getNameType()); - if (nameTypesSeen == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - entry.encode(buf); - } - - TlsUtils.checkUint16(buf.size()); - TlsUtils.writeUint16(buf.size(), output); - Streams.writeBufTo(buf, output); - } - - /** - * Parse a {@link ServerNameList} from an {@link InputStream}. - * - * @param input - * the {@link InputStream} to parse from. - * @return a {@link ServerNameList} object. - * @throws IOException - */ - public static ServerNameList parse(InputStream input) throws IOException - { - int length = TlsUtils.readUint16(input); - if (length < 1) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - byte[] data = TlsUtils.readFully(length, input); - - ByteArrayInputStream buf = new ByteArrayInputStream(data); - - short[] nameTypesSeen = new short[0]; - Vector server_name_list = new Vector(); - while (buf.available() > 0) - { - ServerName entry = ServerName.parse(buf); - - nameTypesSeen = checkNameType(nameTypesSeen, entry.getNameType()); - if (nameTypesSeen == null) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - server_name_list.addElement(entry); - } - - return new ServerNameList(server_name_list); - } - - private static short[] checkNameType(short[] nameTypesSeen, short nameType) - { - /* - * RFC 6066 3. The ServerNameList MUST NOT contain more than one name of the same - * name_type. - */ - if (!NameType.isValid(nameType) || Arrays.contains(nameTypesSeen, nameType)) - { - return null; - } - return Arrays.append(nameTypesSeen, nameType); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ServerOnlyTlsAuthentication.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ServerOnlyTlsAuthentication.java deleted file mode 100644 index 4860aa609..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ServerOnlyTlsAuthentication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class ServerOnlyTlsAuthentication - implements TlsAuthentication -{ - public final TlsCredentials getClientCredentials(CertificateRequest certificateRequest) - { - return null; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ServerSRPParams.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ServerSRPParams.java deleted file mode 100644 index b7bdf2dd8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/ServerSRPParams.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class ServerSRPParams -{ - protected BigInteger N, g, B; - protected byte[] s; - - public ServerSRPParams(BigInteger N, BigInteger g, byte[] s, BigInteger B) - { - this.N = N; - this.g = g; - this.s = Arrays.clone(s); - this.B = B; - } - - public BigInteger getB() - { - return B; - } - - public BigInteger getG() - { - return g; - } - - public BigInteger getN() - { - return N; - } - - public byte[] getS() - { - return s; - } - - /** - * Encode this {@link ServerSRPParams} to an {@link OutputStream}. - * - * @param output - * the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) throws IOException - { - TlsSRPUtils.writeSRPParameter(N, output); - TlsSRPUtils.writeSRPParameter(g, output); - TlsUtils.writeOpaque8(s, output); - TlsSRPUtils.writeSRPParameter(B, output); - } - - /** - * Parse a {@link ServerSRPParams} from an {@link InputStream}. - * - * @param input - * the {@link InputStream} to parse from. - * @return a {@link ServerSRPParams} object. - * @throws IOException - */ - public static ServerSRPParams parse(InputStream input) throws IOException - { - BigInteger N = TlsSRPUtils.readSRPParameter(input); - BigInteger g = TlsSRPUtils.readSRPParameter(input); - byte[] s = TlsUtils.readOpaque8(input); - BigInteger B = TlsSRPUtils.readSRPParameter(input); - - return new ServerSRPParams(N, g, s, B); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SessionParameters.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SessionParameters.java deleted file mode 100644 index 091ad2ce6..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SessionParameters.java +++ /dev/null @@ -1,204 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public final class SessionParameters -{ - public static final class Builder - { - private int cipherSuite = -1; - private short compressionAlgorithm = -1; - private byte[] masterSecret = null; - private Certificate peerCertificate = null; - private byte[] pskIdentity = null; - private byte[] srpIdentity = null; - private byte[] encodedServerExtensions = null; - private boolean extendedMasterSecret = false; - - public Builder() - { - } - - public SessionParameters build() - { - validate(this.cipherSuite >= 0, "cipherSuite"); - validate(this.compressionAlgorithm >= 0, "compressionAlgorithm"); - validate(this.masterSecret != null, "masterSecret"); - return new SessionParameters(cipherSuite, compressionAlgorithm, masterSecret, peerCertificate, pskIdentity, - srpIdentity, encodedServerExtensions, extendedMasterSecret); - } - - public Builder setCipherSuite(int cipherSuite) - { - this.cipherSuite = cipherSuite; - return this; - } - - public Builder setCompressionAlgorithm(short compressionAlgorithm) - { - this.compressionAlgorithm = compressionAlgorithm; - return this; - } - - public Builder setExtendedMasterSecret(boolean extendedMasterSecret) - { - this.extendedMasterSecret = extendedMasterSecret; - return this; - } - - public Builder setMasterSecret(byte[] masterSecret) - { - this.masterSecret = masterSecret; - return this; - } - - public Builder setPeerCertificate(Certificate peerCertificate) - { - this.peerCertificate = peerCertificate; - return this; - } - - /** - * @deprecated Use {@link #setPSKIdentity(byte[])} - */ - public Builder setPskIdentity(byte[] pskIdentity) - { - this.pskIdentity = pskIdentity; - return this; - } - - public Builder setPSKIdentity(byte[] pskIdentity) - { - this.pskIdentity = pskIdentity; - return this; - } - - public Builder setSRPIdentity(byte[] srpIdentity) - { - this.srpIdentity = srpIdentity; - return this; - } - - public Builder setServerExtensions(Hashtable serverExtensions) throws IOException - { - if (serverExtensions == null) - { - encodedServerExtensions = null; - } - else - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - TlsProtocol.writeExtensions(buf, serverExtensions); - encodedServerExtensions = buf.toByteArray(); - } - return this; - } - - private void validate(boolean condition, String parameter) - { - if (!condition) - { - throw new IllegalStateException("Required session parameter '" + parameter + "' not configured"); - } - } - } - - private int cipherSuite; - private short compressionAlgorithm; - private byte[] masterSecret; - private Certificate peerCertificate; - private byte[] pskIdentity = null; - private byte[] srpIdentity = null; - private byte[] encodedServerExtensions; - private boolean extendedMasterSecret; - - private SessionParameters(int cipherSuite, short compressionAlgorithm, byte[] masterSecret, - Certificate peerCertificate, byte[] pskIdentity, byte[] srpIdentity, byte[] encodedServerExtensions, - boolean extendedMasterSecret) - { - this.cipherSuite = cipherSuite; - this.compressionAlgorithm = compressionAlgorithm; - this.masterSecret = Arrays.clone(masterSecret); - this.peerCertificate = peerCertificate; - this.pskIdentity = Arrays.clone(pskIdentity); - this.srpIdentity = Arrays.clone(srpIdentity); - this.encodedServerExtensions = encodedServerExtensions; - this.extendedMasterSecret = extendedMasterSecret; - } - - public void clear() - { - if (this.masterSecret != null) - { - Arrays.fill(this.masterSecret, (byte)0); - } - } - - public SessionParameters copy() - { - return new SessionParameters(cipherSuite, compressionAlgorithm, masterSecret, peerCertificate, pskIdentity, - srpIdentity, encodedServerExtensions, extendedMasterSecret); - } - - public int getCipherSuite() - { - return cipherSuite; - } - - public short getCompressionAlgorithm() - { - return compressionAlgorithm; - } - - public byte[] getMasterSecret() - { - return masterSecret; - } - - public Certificate getPeerCertificate() - { - return peerCertificate; - } - - /** - * @deprecated Use {@link #getPSKIdentity()} - */ - public byte[] getPskIdentity() - { - return pskIdentity; - } - - public byte[] getPSKIdentity() - { - return pskIdentity; - } - - public byte[] getSRPIdentity() - { - return srpIdentity; - } - - public boolean isExtendedMasterSecret() - { - return extendedMasterSecret; - } - - public Hashtable readServerExtensions() throws IOException - { - if (encodedServerExtensions == null) - { - return null; - } - - ByteArrayInputStream buf = new ByteArrayInputStream(encodedServerExtensions); - return TlsProtocol.readExtensions(buf); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SignatureAlgorithm.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SignatureAlgorithm.java deleted file mode 100644 index 05d0cd1f8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SignatureAlgorithm.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 5246 7.4.1.4.1 (in RFC 2246, there were no specific values assigned) - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class SignatureAlgorithm -{ - public static final short anonymous = 0; - public static final short rsa = 1; - public static final short dsa = 2; - public static final short ecdsa = 3; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SignatureAndHashAlgorithm.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SignatureAndHashAlgorithm.java deleted file mode 100644 index ee320a505..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SignatureAndHashAlgorithm.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * RFC 5246 7.4.1.4.1 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class SignatureAndHashAlgorithm -{ - protected short hash; - protected short signature; - - /** - * @param hash {@link HashAlgorithm} - * @param signature {@link SignatureAlgorithm} - */ - public SignatureAndHashAlgorithm(short hash, short signature) - { - if (!TlsUtils.isValidUint8(hash)) - { - throw new IllegalArgumentException("'hash' should be a uint8"); - } - if (!TlsUtils.isValidUint8(signature)) - { - throw new IllegalArgumentException("'signature' should be a uint8"); - } - if (signature == SignatureAlgorithm.anonymous) - { - throw new IllegalArgumentException("'signature' MUST NOT be \"anonymous\""); - } - - this.hash = hash; - this.signature = signature; - } - - /** - * @return {@link HashAlgorithm} - */ - public short getHash() - { - return hash; - } - - /** - * @return {@link SignatureAlgorithm} - */ - public short getSignature() - { - return signature; - } - - public boolean equals(Object obj) - { - if (!(obj instanceof SignatureAndHashAlgorithm)) - { - return false; - } - SignatureAndHashAlgorithm other = (SignatureAndHashAlgorithm)obj; - return other.getHash() == getHash() && other.getSignature() == getSignature(); - } - - public int hashCode() - { - return (getHash() << 16) | getSignature(); - } - - /** - * Encode this {@link SignatureAndHashAlgorithm} to an {@link OutputStream}. - * - * @param output the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) - throws IOException - { - TlsUtils.writeUint8(getHash(), output); - TlsUtils.writeUint8(getSignature(), output); - } - - /** - * Parse a {@link SignatureAndHashAlgorithm} from an {@link InputStream}. - * - * @param input the {@link InputStream} to parse from. - * @return a {@link SignatureAndHashAlgorithm} object. - * @throws IOException - */ - public static SignatureAndHashAlgorithm parse(InputStream input) - throws IOException - { - short hash = TlsUtils.readUint8(input); - short signature = TlsUtils.readUint8(input); - return new SignatureAndHashAlgorithm(hash, signature); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SignerInputBuffer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SignerInputBuffer.java deleted file mode 100644 index 5e592713e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SignerInputBuffer.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayOutputStream; - -import com.fr.third.org.bouncycastle.crypto.Signer; - -class SignerInputBuffer extends ByteArrayOutputStream -{ - void updateSigner(Signer s) - { - s.update(this.buf, 0, count); - } -} \ No newline at end of file diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SimulatedTlsSRPIdentityManager.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SimulatedTlsSRPIdentityManager.java deleted file mode 100644 index 8db102f1e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SimulatedTlsSRPIdentityManager.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.agreement.srp.SRP6VerifierGenerator; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.SRP6GroupParameters; -import com.fr.third.org.bouncycastle.util.Strings; - -/** - * An implementation of {@link TlsSRPIdentityManager} that simulates the existence of "unknown" identities - * to obscure the fact that there is no verifier for them. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class SimulatedTlsSRPIdentityManager - implements TlsSRPIdentityManager -{ - private static final byte[] PREFIX_PASSWORD = Strings.toByteArray("password"); - private static final byte[] PREFIX_SALT = Strings.toByteArray("salt"); - - /** - * Create a {@link SimulatedTlsSRPIdentityManager} that implements the algorithm from RFC 5054 2.5.1.3 - * - * @param group the {@link SRP6GroupParameters} defining the group that SRP is operating in - * @param seedKey the secret "seed key" referred to in RFC 5054 2.5.1.3 - * @return an instance of {@link SimulatedTlsSRPIdentityManager} - */ - public static SimulatedTlsSRPIdentityManager getRFC5054Default(SRP6GroupParameters group, byte[] seedKey) - { - SRP6VerifierGenerator verifierGenerator = new SRP6VerifierGenerator(); - verifierGenerator.init(group, TlsUtils.createHash(HashAlgorithm.sha1)); - - HMac mac = new HMac(TlsUtils.createHash(HashAlgorithm.sha1)); - mac.init(new KeyParameter(seedKey)); - - return new SimulatedTlsSRPIdentityManager(group, verifierGenerator, mac); - } - - protected SRP6GroupParameters group; - protected SRP6VerifierGenerator verifierGenerator; - protected Mac mac; - - public SimulatedTlsSRPIdentityManager(SRP6GroupParameters group, SRP6VerifierGenerator verifierGenerator, Mac mac) - { - this.group = group; - this.verifierGenerator = verifierGenerator; - this.mac = mac; - } - - public TlsSRPLoginParameters getLoginParameters(byte[] identity) - { - mac.update(PREFIX_SALT, 0, PREFIX_SALT.length); - mac.update(identity, 0, identity.length); - - byte[] salt = new byte[mac.getMacSize()]; - mac.doFinal(salt, 0); - - mac.update(PREFIX_PASSWORD, 0, PREFIX_PASSWORD.length); - mac.update(identity, 0, identity.length); - - byte[] password = new byte[mac.getMacSize()]; - mac.doFinal(password, 0); - - BigInteger verifier = verifierGenerator.generateVerifier(salt, identity, password); - - return new TlsSRPLoginParameters(group, verifier, salt); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SupplementalDataEntry.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SupplementalDataEntry.java deleted file mode 100644 index 0c5666f67..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SupplementalDataEntry.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class SupplementalDataEntry -{ - protected int dataType; - protected byte[] data; - - public SupplementalDataEntry(int dataType, byte[] data) - { - this.dataType = dataType; - this.data = data; - } - - public int getDataType() - { - return dataType; - } - - public byte[] getData() - { - return data; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SupplementalDataType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SupplementalDataType.java deleted file mode 100644 index fea0aff8e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/SupplementalDataType.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 4680 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class SupplementalDataType -{ - /* - * RFC 4681 - */ - public static final int user_mapping_data = 0; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsAEADCipher.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsAEADCipher.java deleted file mode 100644 index c8128f3ca..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsAEADCipher.java +++ /dev/null @@ -1,255 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.crypto.modes.AEADBlockCipher; -import com.fr.third.org.bouncycastle.crypto.params.AEADParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsAEADCipher - implements TlsCipher -{ - // TODO[draft-zauner-tls-aes-ocb-04] Apply data volume limit described in section 8.4 - - public static final int NONCE_RFC5288 = 1; - - /* - * draft-zauner-tls-aes-ocb-04 specifies the nonce construction from draft-ietf-tls-chacha20-poly1305-04 - */ - static final int NONCE_DRAFT_CHACHA20_POLY1305 = 2; - - protected TlsContext context; - protected int macSize; - // TODO SecurityParameters.record_iv_length - protected int record_iv_length; - - protected AEADBlockCipher encryptCipher; - protected AEADBlockCipher decryptCipher; - - protected byte[] encryptImplicitNonce, decryptImplicitNonce; - - protected int nonceMode; - - public TlsAEADCipher(TlsContext context, AEADBlockCipher clientWriteCipher, AEADBlockCipher serverWriteCipher, - int cipherKeySize, int macSize) throws IOException - { - this(context, clientWriteCipher, serverWriteCipher, cipherKeySize, macSize, NONCE_RFC5288); - } - - TlsAEADCipher(TlsContext context, AEADBlockCipher clientWriteCipher, AEADBlockCipher serverWriteCipher, - int cipherKeySize, int macSize, int nonceMode) throws IOException - { - if (!TlsUtils.isTLSv12(context)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - this.nonceMode = nonceMode; - - // TODO SecurityParameters.fixed_iv_length - int fixed_iv_length; - - switch (nonceMode) - { - case NONCE_RFC5288: - fixed_iv_length = 4; - this.record_iv_length = 8; - break; - case NONCE_DRAFT_CHACHA20_POLY1305: - fixed_iv_length = 12; - this.record_iv_length = 0; - break; - default: - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - this.context = context; - this.macSize = macSize; - - int key_block_size = (2 * cipherKeySize) + (2 * fixed_iv_length); - - byte[] key_block = TlsUtils.calculateKeyBlock(context, key_block_size); - - int offset = 0; - - KeyParameter client_write_key = new KeyParameter(key_block, offset, cipherKeySize); - offset += cipherKeySize; - KeyParameter server_write_key = new KeyParameter(key_block, offset, cipherKeySize); - offset += cipherKeySize; - byte[] client_write_IV = Arrays.copyOfRange(key_block, offset, offset + fixed_iv_length); - offset += fixed_iv_length; - byte[] server_write_IV = Arrays.copyOfRange(key_block, offset, offset + fixed_iv_length); - offset += fixed_iv_length; - - if (offset != key_block_size) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - KeyParameter encryptKey, decryptKey; - if (context.isServer()) - { - this.encryptCipher = serverWriteCipher; - this.decryptCipher = clientWriteCipher; - this.encryptImplicitNonce = server_write_IV; - this.decryptImplicitNonce = client_write_IV; - encryptKey = server_write_key; - decryptKey = client_write_key; - } - else - { - this.encryptCipher = clientWriteCipher; - this.decryptCipher = serverWriteCipher; - this.encryptImplicitNonce = client_write_IV; - this.decryptImplicitNonce = server_write_IV; - encryptKey = client_write_key; - decryptKey = server_write_key; - } - - byte[] dummyNonce = new byte[fixed_iv_length + record_iv_length]; - - this.encryptCipher.init(true, new AEADParameters(encryptKey, 8 * macSize, dummyNonce)); - this.decryptCipher.init(false, new AEADParameters(decryptKey, 8 * macSize, dummyNonce)); - } - - public int getPlaintextLimit(int ciphertextLimit) - { - // TODO We ought to be able to ask the decryptCipher (independently of it's current state!) - return ciphertextLimit - macSize - record_iv_length; - } - - public byte[] encodePlaintext(long seqNo, short type, byte[] plaintext, int offset, int len) - throws IOException - { - byte[] nonce = new byte[encryptImplicitNonce.length + record_iv_length]; - - switch (nonceMode) - { - case NONCE_RFC5288: - System.arraycopy(encryptImplicitNonce, 0, nonce, 0, encryptImplicitNonce.length); - // RFC 5288/6655: The nonce_explicit MAY be the 64-bit sequence number. - TlsUtils.writeUint64(seqNo, nonce, encryptImplicitNonce.length); - break; - case NONCE_DRAFT_CHACHA20_POLY1305: - TlsUtils.writeUint64(seqNo, nonce, nonce.length - 8); - for (int i = 0; i < encryptImplicitNonce.length; ++i) - { - nonce[i] ^= encryptImplicitNonce[i]; - } - break; - default: - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - int plaintextOffset = offset; - int plaintextLength = len; - int ciphertextLength = encryptCipher.getOutputSize(plaintextLength); - - byte[] output = new byte[record_iv_length + ciphertextLength]; - if (record_iv_length != 0) - { - System.arraycopy(nonce, nonce.length - record_iv_length, output, 0, record_iv_length); - } - int outputPos = record_iv_length; - - byte[] additionalData = getAdditionalData(seqNo, type, plaintextLength); - AEADParameters parameters = new AEADParameters(null, 8 * macSize, nonce, additionalData); - - try - { - encryptCipher.init(true, parameters); - outputPos += encryptCipher.processBytes(plaintext, plaintextOffset, plaintextLength, output, outputPos); - outputPos += encryptCipher.doFinal(output, outputPos); - } - catch (Exception e) - { - throw new TlsFatalAlert(AlertDescription.internal_error, e); - } - - if (outputPos != output.length) - { - // NOTE: Existing AEAD cipher implementations all give exact output lengths - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - return output; - } - - public byte[] decodeCiphertext(long seqNo, short type, byte[] ciphertext, int offset, int len) - throws IOException - { - if (getPlaintextLimit(len) < 0) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - byte[] nonce = new byte[decryptImplicitNonce.length + record_iv_length]; - - switch (nonceMode) - { - case NONCE_RFC5288: - System.arraycopy(decryptImplicitNonce, 0, nonce, 0, decryptImplicitNonce.length); - System.arraycopy(ciphertext, offset, nonce, nonce.length - record_iv_length, record_iv_length); - break; - case NONCE_DRAFT_CHACHA20_POLY1305: - TlsUtils.writeUint64(seqNo, nonce, nonce.length - 8); - for (int i = 0; i < decryptImplicitNonce.length; ++i) - { - nonce[i] ^= decryptImplicitNonce[i]; - } - break; - default: - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - int ciphertextOffset = offset + record_iv_length; - int ciphertextLength = len - record_iv_length; - int plaintextLength = decryptCipher.getOutputSize(ciphertextLength); - - byte[] output = new byte[plaintextLength]; - int outputPos = 0; - - byte[] additionalData = getAdditionalData(seqNo, type, plaintextLength); - AEADParameters parameters = new AEADParameters(null, 8 * macSize, nonce, additionalData); - - try - { - decryptCipher.init(false, parameters); - outputPos += decryptCipher.processBytes(ciphertext, ciphertextOffset, ciphertextLength, output, outputPos); - outputPos += decryptCipher.doFinal(output, outputPos); - } - catch (Exception e) - { - throw new TlsFatalAlert(AlertDescription.bad_record_mac, e); - } - - if (outputPos != output.length) - { - // NOTE: Existing AEAD cipher implementations all give exact output lengths - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - return output; - } - - protected byte[] getAdditionalData(long seqNo, short type, int len) - throws IOException - { - /* - * additional_data = seq_num + TLSCompressed.type + TLSCompressed.version + - * TLSCompressed.length - */ - - byte[] additional_data = new byte[13]; - TlsUtils.writeUint64(seqNo, additional_data, 0); - TlsUtils.writeUint8(type, additional_data, 8); - TlsUtils.writeVersion(context.getServerVersion(), additional_data, 9); - TlsUtils.writeUint16(len, additional_data, 11); - - return additional_data; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsAgreementCredentials.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsAgreementCredentials.java deleted file mode 100644 index ac55c9c26..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsAgreementCredentials.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsAgreementCredentials - extends TlsCredentials -{ - byte[] generateAgreement(AsymmetricKeyParameter peerPublicKey) - throws IOException; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsAuthentication.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsAuthentication.java deleted file mode 100644 index 25e83355b..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsAuthentication.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * Base interface to provide TLS authentication credentials. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsAuthentication -{ - /** - * Called by the protocol handler to report the server certificate - * Note: this method is responsible for certificate verification and validation - * - * @param serverCertificate the server certificate received - * @throws IOException - */ - void notifyServerCertificate(Certificate serverCertificate) - throws IOException; - - /** - * Return client credentials in response to server's certificate request - * - * @param certificateRequest details of the certificate request - * @return a TlsCredentials object or null for no client authentication - * @throws IOException - */ - TlsCredentials getClientCredentials(CertificateRequest certificateRequest) - throws IOException; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsBlockCipher.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsBlockCipher.java deleted file mode 100644 index 7d2e4f729..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsBlockCipher.java +++ /dev/null @@ -1,405 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.BlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * A generic TLS 1.0-1.2 / SSLv3 block cipher. This can be used for AES or 3DES for example. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsBlockCipher - implements TlsCipher -{ - protected TlsContext context; - protected byte[] randomData; - protected boolean useExplicitIV; - protected boolean encryptThenMAC; - - protected BlockCipher encryptCipher; - protected BlockCipher decryptCipher; - - protected TlsMac writeMac; - protected TlsMac readMac; - - public TlsMac getWriteMac() - { - return writeMac; - } - - public TlsMac getReadMac() - { - return readMac; - } - - public TlsBlockCipher(TlsContext context, BlockCipher clientWriteCipher, BlockCipher serverWriteCipher, - Digest clientWriteDigest, Digest serverWriteDigest, int cipherKeySize) throws IOException - { - this.context = context; - - this.randomData = new byte[256]; - context.getNonceRandomGenerator().nextBytes(randomData); - - this.useExplicitIV = TlsUtils.isTLSv11(context); - this.encryptThenMAC = context.getSecurityParameters().encryptThenMAC; - - int key_block_size = (2 * cipherKeySize) + clientWriteDigest.getDigestSize() - + serverWriteDigest.getDigestSize(); - - // From TLS 1.1 onwards, block ciphers don't need client_write_IV - if (!useExplicitIV) - { - key_block_size += clientWriteCipher.getBlockSize() + serverWriteCipher.getBlockSize(); - } - - byte[] key_block = TlsUtils.calculateKeyBlock(context, key_block_size); - - int offset = 0; - - TlsMac clientWriteMac = new TlsMac(context, clientWriteDigest, key_block, offset, - clientWriteDigest.getDigestSize()); - offset += clientWriteDigest.getDigestSize(); - TlsMac serverWriteMac = new TlsMac(context, serverWriteDigest, key_block, offset, - serverWriteDigest.getDigestSize()); - offset += serverWriteDigest.getDigestSize(); - - KeyParameter client_write_key = new KeyParameter(key_block, offset, cipherKeySize); - offset += cipherKeySize; - KeyParameter server_write_key = new KeyParameter(key_block, offset, cipherKeySize); - offset += cipherKeySize; - - byte[] client_write_IV, server_write_IV; - if (useExplicitIV) - { - client_write_IV = new byte[clientWriteCipher.getBlockSize()]; - server_write_IV = new byte[serverWriteCipher.getBlockSize()]; - } - else - { - client_write_IV = Arrays.copyOfRange(key_block, offset, offset + clientWriteCipher.getBlockSize()); - offset += clientWriteCipher.getBlockSize(); - server_write_IV = Arrays.copyOfRange(key_block, offset, offset + serverWriteCipher.getBlockSize()); - offset += serverWriteCipher.getBlockSize(); - } - - if (offset != key_block_size) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - CipherParameters encryptParams, decryptParams; - if (context.isServer()) - { - this.writeMac = serverWriteMac; - this.readMac = clientWriteMac; - this.encryptCipher = serverWriteCipher; - this.decryptCipher = clientWriteCipher; - encryptParams = new ParametersWithIV(server_write_key, server_write_IV); - decryptParams = new ParametersWithIV(client_write_key, client_write_IV); - } - else - { - this.writeMac = clientWriteMac; - this.readMac = serverWriteMac; - this.encryptCipher = clientWriteCipher; - this.decryptCipher = serverWriteCipher; - encryptParams = new ParametersWithIV(client_write_key, client_write_IV); - decryptParams = new ParametersWithIV(server_write_key, server_write_IV); - } - - this.encryptCipher.init(true, encryptParams); - this.decryptCipher.init(false, decryptParams); - } - - public int getPlaintextLimit(int ciphertextLimit) - { - int blockSize = encryptCipher.getBlockSize(); - int macSize = writeMac.getSize(); - - int plaintextLimit = ciphertextLimit; - - // An explicit IV consumes 1 block - if (useExplicitIV) - { - plaintextLimit -= blockSize; - } - - // Leave room for the MAC, and require block-alignment - if (encryptThenMAC) - { - plaintextLimit -= macSize; - plaintextLimit -= plaintextLimit % blockSize; - } - else - { - plaintextLimit -= plaintextLimit % blockSize; - plaintextLimit -= macSize; - } - - // Minimum 1 byte of padding - --plaintextLimit; - - return plaintextLimit; - } - - public byte[] encodePlaintext(long seqNo, short type, byte[] plaintext, int offset, int len) - { - int blockSize = encryptCipher.getBlockSize(); - int macSize = writeMac.getSize(); - - ProtocolVersion version = context.getServerVersion(); - - int enc_input_length = len; - if (!encryptThenMAC) - { - enc_input_length += macSize; - } - - int padding_length = blockSize - 1 - (enc_input_length % blockSize); - - /* - * Don't use variable-length padding with truncated MACs. - * - * See "Tag Size Does Matter: Attacks and Proofs for the TLS Record Protocol", Paterson, - * Ristenpart, Shrimpton. - */ - if (encryptThenMAC || !context.getSecurityParameters().truncatedHMac) - { - // TODO[DTLS] Consider supporting in DTLS (without exceeding send limit though) - if (!version.isDTLS() && !version.isSSL()) - { - // Add a random number of extra blocks worth of padding - int maxExtraPadBlocks = (255 - padding_length) / blockSize; - int actualExtraPadBlocks = chooseExtraPadBlocks(context.getSecureRandom(), maxExtraPadBlocks); - padding_length += actualExtraPadBlocks * blockSize; - } - } - - int totalSize = len + macSize + padding_length + 1; - if (useExplicitIV) - { - totalSize += blockSize; - } - - byte[] outBuf = new byte[totalSize]; - int outOff = 0; - - if (useExplicitIV) - { - byte[] explicitIV = new byte[blockSize]; - context.getNonceRandomGenerator().nextBytes(explicitIV); - - encryptCipher.init(true, new ParametersWithIV(null, explicitIV)); - - System.arraycopy(explicitIV, 0, outBuf, outOff, blockSize); - outOff += blockSize; - } - - int blocks_start = outOff; - - System.arraycopy(plaintext, offset, outBuf, outOff, len); - outOff += len; - - if (!encryptThenMAC) - { - byte[] mac = writeMac.calculateMac(seqNo, type, plaintext, offset, len); - System.arraycopy(mac, 0, outBuf, outOff, mac.length); - outOff += mac.length; - } - - for (int i = 0; i <= padding_length; i++) - { - outBuf[outOff++] = (byte)padding_length; - } - - for (int i = blocks_start; i < outOff; i += blockSize) - { - encryptCipher.processBlock(outBuf, i, outBuf, i); - } - - if (encryptThenMAC) - { - byte[] mac = writeMac.calculateMac(seqNo, type, outBuf, 0, outOff); - System.arraycopy(mac, 0, outBuf, outOff, mac.length); - outOff += mac.length; - } - -// assert outBuf.length == outOff; - - return outBuf; - } - - public byte[] decodeCiphertext(long seqNo, short type, byte[] ciphertext, int offset, int len) - throws IOException - { - int blockSize = decryptCipher.getBlockSize(); - int macSize = readMac.getSize(); - - int minLen = blockSize; - if (encryptThenMAC) - { - minLen += macSize; - } - else - { - minLen = Math.max(minLen, macSize + 1); - } - - if (useExplicitIV) - { - minLen += blockSize; - } - - if (len < minLen) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - int blocks_length = len; - if (encryptThenMAC) - { - blocks_length -= macSize; - } - - if (blocks_length % blockSize != 0) - { - throw new TlsFatalAlert(AlertDescription.decryption_failed); - } - - if (encryptThenMAC) - { - int end = offset + len; - byte[] receivedMac = Arrays.copyOfRange(ciphertext, end - macSize, end); - byte[] calculatedMac = readMac.calculateMac(seqNo, type, ciphertext, offset, len - macSize); - - boolean badMac = !Arrays.constantTimeAreEqual(calculatedMac, receivedMac); - if (badMac) - { - /* - * RFC 7366 3. The MAC SHALL be evaluated before any further processing such as - * decryption is performed, and if the MAC verification fails, then processing SHALL - * terminate immediately. For TLS, a fatal bad_record_mac MUST be generated [2]. For - * DTLS, the record MUST be discarded, and a fatal bad_record_mac MAY be generated - * [4]. This immediate response to a bad MAC eliminates any timing channels that may - * be available through the use of manipulated packet data. - */ - throw new TlsFatalAlert(AlertDescription.bad_record_mac); - } - } - - if (useExplicitIV) - { - decryptCipher.init(false, new ParametersWithIV(null, ciphertext, offset, blockSize)); - - offset += blockSize; - blocks_length -= blockSize; - } - - for (int i = 0; i < blocks_length; i += blockSize) - { - decryptCipher.processBlock(ciphertext, offset + i, ciphertext, offset + i); - } - - // If there's anything wrong with the padding, this will return zero - int totalPad = checkPaddingConstantTime(ciphertext, offset, blocks_length, blockSize, encryptThenMAC ? 0 : macSize); - boolean badMac = (totalPad == 0); - - int dec_output_length = blocks_length - totalPad; - - if (!encryptThenMAC) - { - dec_output_length -= macSize; - int macInputLen = dec_output_length; - int macOff = offset + macInputLen; - byte[] receivedMac = Arrays.copyOfRange(ciphertext, macOff, macOff + macSize); - byte[] calculatedMac = readMac.calculateMacConstantTime(seqNo, type, ciphertext, offset, macInputLen, - blocks_length - macSize, randomData); - - badMac |= !Arrays.constantTimeAreEqual(calculatedMac, receivedMac); - } - - if (badMac) - { - throw new TlsFatalAlert(AlertDescription.bad_record_mac); - } - - return Arrays.copyOfRange(ciphertext, offset, offset + dec_output_length); - } - - protected int checkPaddingConstantTime(byte[] buf, int off, int len, int blockSize, int macSize) - { - int end = off + len; - byte lastByte = buf[end - 1]; - int padlen = lastByte & 0xff; - int totalPad = padlen + 1; - - int dummyIndex = 0; - byte padDiff = 0; - - if ((TlsUtils.isSSL(context) && totalPad > blockSize) || (macSize + totalPad > len)) - { - totalPad = 0; - } - else - { - int padPos = end - totalPad; - do - { - padDiff |= (buf[padPos++] ^ lastByte); - } - while (padPos < end); - - dummyIndex = totalPad; - - if (padDiff != 0) - { - totalPad = 0; - } - } - - // Run some extra dummy checks so the number of checks is always constant - { - byte[] dummyPad = randomData; - while (dummyIndex < 256) - { - padDiff |= (dummyPad[dummyIndex++] ^ lastByte); - } - // Ensure the above loop is not eliminated - dummyPad[0] ^= padDiff; - } - - return totalPad; - } - - protected int chooseExtraPadBlocks(SecureRandom r, int max) - { - // return r.nextInt(max + 1); - - int x = r.nextInt(); - int n = lowestBitSet(x); - return Math.min(n, max); - } - - protected int lowestBitSet(int x) - { - if (x == 0) - { - return 32; - } - - int n = 0; - while ((x & 1) == 0) - { - ++n; - x >>= 1; - } - return n; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCipher.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCipher.java deleted file mode 100644 index 432e30d8a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCipher.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsCipher -{ - int getPlaintextLimit(int ciphertextLimit); - - byte[] encodePlaintext(long seqNo, short type, byte[] plaintext, int offset, int len) - throws IOException; - - byte[] decodeCiphertext(long seqNo, short type, byte[] ciphertext, int offset, int len) - throws IOException; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCipherFactory.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCipherFactory.java deleted file mode 100644 index 181b16a63..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCipherFactory.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsCipherFactory -{ - /** - * See enumeration classes EncryptionAlgorithm, MACAlgorithm for appropriate argument values - */ - TlsCipher createCipher(TlsContext context, int encryptionAlgorithm, int macAlgorithm) - throws IOException; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsClient.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsClient.java deleted file mode 100644 index 2ff4c442e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsClient.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.util.Hashtable; -import java.util.Vector; - -/** - * Interface describing a TLS client endpoint. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsClient - extends TlsPeer -{ - void init(TlsClientContext context); - - /** - * Return the session this client wants to resume, if any. Note that the peer's certificate - * chain for the session (if any) may need to be periodically revalidated. - * - * @return A {@link TlsSession} representing the resumable session to be used for this - * connection, or null to use a new session. - * @see SessionParameters#getPeerCertificate() - */ - TlsSession getSessionToResume(); - - /** - * Return the {@link ProtocolVersion} to use for the
TLSPlaintext.version
field prior to - * receiving the server version. NOTE: This method is not called for DTLS. - * - *- * See RFC 5246 E.1.: "TLS clients that wish to negotiate with older servers MAY send any value - * {03,XX} as the record layer version number. Typical values would be {03,00}, the lowest - * version number supported by the client, and the value of ClientHello.client_version. No - * single value will guarantee interoperability with all old servers, but this is a complex - * topic beyond the scope of this document." - *
- * - * @return The {@link ProtocolVersion} to use. - */ - ProtocolVersion getClientHelloRecordLayerVersion(); - - ProtocolVersion getClientVersion(); - - boolean isFallback(); - - int[] getCipherSuites(); - - short[] getCompressionMethods(); - - // Hashtable is (Integer -> byte[]) - Hashtable getClientExtensions() - throws IOException; - - void notifyServerVersion(ProtocolVersion selectedVersion) - throws IOException; - - /** - * Notifies the client of the session_id sent in the ServerHello. - * - * @param sessionID - * @see TlsContext#getResumableSession() - */ - void notifySessionID(byte[] sessionID); - - void notifySelectedCipherSuite(int selectedCipherSuite); - - void notifySelectedCompressionMethod(short selectedCompressionMethod); - - // Hashtable is (Integer -> byte[]) - void processServerExtensions(Hashtable serverExtensions) - throws IOException; - - // Vector is (SupplementalDataEntry) - void processServerSupplementalData(Vector serverSupplementalData) - throws IOException; - - TlsKeyExchange getKeyExchange() - throws IOException; - - TlsAuthentication getAuthentication() - throws IOException; - - // Vector is (SupplementalDataEntry) - Vector getClientSupplementalData() - throws IOException; - - /** - * RFC 5077 3.3. NewSessionTicket Handshake Message - *- * This method will be called (only) when a NewSessionTicket handshake message is received. The - * ticket is opaque to the client and clients MUST NOT examine the ticket under the assumption - * that it complies with e.g. RFC 5077 4. Recommended Ticket Construction. - * - * @param newSessionTicket The ticket. - * @throws IOException - */ - void notifyNewSessionTicket(NewSessionTicket newSessionTicket) - throws IOException; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsClientContext.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsClientContext.java deleted file mode 100644 index 548d7239d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsClientContext.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * Marker interface to distinguish a TLS client context. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsClientContext - extends TlsContext -{ -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsClientContextImpl.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsClientContextImpl.java deleted file mode 100644 index 32b60b37a..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsClientContextImpl.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.security.SecureRandom; - -class TlsClientContextImpl - extends AbstractTlsContext - implements TlsClientContext -{ - TlsClientContextImpl(SecureRandom secureRandom, SecurityParameters securityParameters) - { - super(secureRandom, securityParameters); - } - - public boolean isServer() - { - return false; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsClientProtocol.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsClientProtocol.java deleted file mode 100644 index 3cb4aa9c4..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsClientProtocol.java +++ /dev/null @@ -1,948 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.security.SecureRandom; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsClientProtocol - extends TlsProtocol -{ - protected TlsClient tlsClient = null; - TlsClientContextImpl tlsClientContext = null; - - protected byte[] selectedSessionID = null; - - protected TlsKeyExchange keyExchange = null; - protected TlsAuthentication authentication = null; - - protected CertificateStatus certificateStatus = null; - protected CertificateRequest certificateRequest = null; - - /** - * Constructor for blocking mode. - * @param input The stream of data from the server - * @param output The stream of data to the server - * @param secureRandom Random number generator for various cryptographic functions - */ - public TlsClientProtocol(InputStream input, OutputStream output, SecureRandom secureRandom) - { - super(input, output, secureRandom); - } - - /** - * Constructor for non-blocking mode.
- *
- * When data is received, use {@link #offerInput(byte[])} to provide the received ciphertext, - * then use {@link #readInput(byte[], int, int)} to read the corresponding cleartext.
- *
- * Similarly, when data needs to be sent, use {@link #offerOutput(byte[], int, int)} to provide - * the cleartext, then use {@link #readOutput(byte[], int, int)} to get the corresponding - * ciphertext. - * - * @param secureRandom - * Random number generator for various cryptographic functions - */ - public TlsClientProtocol(SecureRandom secureRandom) - { - super(secureRandom); - } - - /** - * Initiates a TLS handshake in the role of client.
- *
- * In blocking mode, this will not return until the handshake is complete. - * In non-blocking mode, use {@link TlsPeer#notifyHandshakeComplete()} to - * receive a callback when the handshake is complete. - * - * @param tlsClient The {@link TlsClient} to use for the handshake. - * @throws IOException If in blocking mode and handshake was not successful. - */ - public void connect(TlsClient tlsClient) throws IOException - { - if (tlsClient == null) - { - throw new IllegalArgumentException("'tlsClient' cannot be null"); - } - if (this.tlsClient != null) - { - throw new IllegalStateException("'connect' can only be called once"); - } - - this.tlsClient = tlsClient; - - this.securityParameters = new SecurityParameters(); - this.securityParameters.entity = ConnectionEnd.client; - - this.tlsClientContext = new TlsClientContextImpl(secureRandom, securityParameters); - - this.securityParameters.clientRandom = createRandomBlock(tlsClient.shouldUseGMTUnixTime(), - tlsClientContext.getNonceRandomGenerator()); - - this.tlsClient.init(tlsClientContext); - this.recordStream.init(tlsClientContext); - - tlsClient.notifyCloseHandle(this); - - TlsSession sessionToResume = tlsClient.getSessionToResume(); - if (sessionToResume != null && sessionToResume.isResumable()) - { - SessionParameters sessionParameters = sessionToResume.exportSessionParameters(); - if (sessionParameters != null && sessionParameters.isExtendedMasterSecret()) - { - this.tlsSession = sessionToResume; - this.sessionParameters = sessionParameters; - } - } - - sendClientHelloMessage(); - this.connection_state = CS_CLIENT_HELLO; - - blockForHandshake(); - } - - protected void cleanupHandshake() - { - super.cleanupHandshake(); - - this.selectedSessionID = null; - this.keyExchange = null; - this.authentication = null; - this.certificateStatus = null; - this.certificateRequest = null; - } - - protected TlsContext getContext() - { - return tlsClientContext; - } - - AbstractTlsContext getContextAdmin() - { - return tlsClientContext; - } - - protected TlsPeer getPeer() - { - return tlsClient; - } - - protected void handleHandshakeMessage(short type, ByteArrayInputStream buf) - throws IOException - { - if (this.resumedSession) - { - if (type != HandshakeType.finished || this.connection_state != CS_SERVER_HELLO) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - processFinishedMessage(buf); - this.connection_state = CS_SERVER_FINISHED; - - sendChangeCipherSpecMessage(); - sendFinishedMessage(); - this.connection_state = CS_CLIENT_FINISHED; - - completeHandshake(); - return; - } - - switch (type) - { - case HandshakeType.certificate: - { - switch (this.connection_state) - { - case CS_SERVER_HELLO: - { - handleSupplementalData(null); - // NB: Fall through to next case label - } - case CS_SERVER_SUPPLEMENTAL_DATA: - { - // Parse the Certificate message and send to cipher suite - - this.peerCertificate = Certificate.parse(buf); - - assertEmpty(buf); - - // TODO[RFC 3546] Check whether empty certificates is possible, allowed, or excludes CertificateStatus - if (this.peerCertificate == null || this.peerCertificate.isEmpty()) - { - this.allowCertificateStatus = false; - } - - this.keyExchange.processServerCertificate(this.peerCertificate); - - this.authentication = tlsClient.getAuthentication(); - this.authentication.notifyServerCertificate(this.peerCertificate); - - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - this.connection_state = CS_SERVER_CERTIFICATE; - break; - } - case HandshakeType.certificate_status: - { - switch (this.connection_state) - { - case CS_SERVER_CERTIFICATE: - { - if (!this.allowCertificateStatus) - { - /* - * RFC 3546 3.6. If a server returns a "CertificateStatus" message, then the - * server MUST have included an extension of type "status_request" with empty - * "extension_data" in the extended server hello.. - */ - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - this.certificateStatus = CertificateStatus.parse(buf); - - assertEmpty(buf); - - // TODO[RFC 3546] Figure out how to provide this to the client/authentication. - - this.connection_state = CS_CERTIFICATE_STATUS; - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - break; - } - case HandshakeType.finished: - { - switch (this.connection_state) - { - case CS_CLIENT_FINISHED: - { - if (this.expectSessionTicket) - { - /* - * RFC 5077 3.3. This message MUST be sent if the server included a - * SessionTicket extension in the ServerHello. - */ - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - // NB: Fall through to next case label - } - case CS_SERVER_SESSION_TICKET: - { - processFinishedMessage(buf); - this.connection_state = CS_SERVER_FINISHED; - - completeHandshake(); - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - break; - } - case HandshakeType.server_hello: - { - switch (this.connection_state) - { - case CS_CLIENT_HELLO: - { - receiveServerHelloMessage(buf); - this.connection_state = CS_SERVER_HELLO; - - this.recordStream.notifyHelloComplete(); - - applyMaxFragmentLengthExtension(); - - if (this.resumedSession) - { - this.securityParameters.masterSecret = Arrays.clone(this.sessionParameters.getMasterSecret()); - this.recordStream.setPendingConnectionState(getPeer().getCompression(), getPeer().getCipher()); - } - else - { - invalidateSession(); - - if (this.selectedSessionID.length > 0) - { - this.tlsSession = new TlsSessionImpl(this.selectedSessionID, null); - } - } - - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - break; - } - case HandshakeType.supplemental_data: - { - switch (this.connection_state) - { - case CS_SERVER_HELLO: - { - handleSupplementalData(readSupplementalDataMessage(buf)); - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - break; - } - case HandshakeType.server_hello_done: - { - switch (this.connection_state) - { - case CS_SERVER_HELLO: - { - handleSupplementalData(null); - // NB: Fall through to next case label - } - case CS_SERVER_SUPPLEMENTAL_DATA: - { - // There was no server certificate message; check it's OK - this.keyExchange.skipServerCredentials(); - this.authentication = null; - - // NB: Fall through to next case label - } - case CS_SERVER_CERTIFICATE: - case CS_CERTIFICATE_STATUS: - { - // There was no server key exchange message; check it's OK - this.keyExchange.skipServerKeyExchange(); - - // NB: Fall through to next case label - } - case CS_SERVER_KEY_EXCHANGE: - case CS_CERTIFICATE_REQUEST: - { - assertEmpty(buf); - - this.connection_state = CS_SERVER_HELLO_DONE; - - this.recordStream.getHandshakeHash().sealHashAlgorithms(); - - Vector clientSupplementalData = tlsClient.getClientSupplementalData(); - if (clientSupplementalData != null) - { - sendSupplementalDataMessage(clientSupplementalData); - } - this.connection_state = CS_CLIENT_SUPPLEMENTAL_DATA; - - TlsCredentials clientCreds = null; - if (certificateRequest == null) - { - this.keyExchange.skipClientCredentials(); - } - else - { - clientCreds = this.authentication.getClientCredentials(certificateRequest); - - if (clientCreds == null) - { - this.keyExchange.skipClientCredentials(); - - /* - * RFC 5246 If no suitable certificate is available, the client MUST send a - * certificate message containing no certificates. - * - * NOTE: In previous RFCs, this was SHOULD instead of MUST. - */ - sendCertificateMessage(Certificate.EMPTY_CHAIN); - } - else - { - this.keyExchange.processClientCredentials(clientCreds); - - sendCertificateMessage(clientCreds.getCertificate()); - } - } - - this.connection_state = CS_CLIENT_CERTIFICATE; - - /* - * Send the client key exchange message, depending on the key exchange we are using - * in our CipherSuite. - */ - sendClientKeyExchangeMessage(); - this.connection_state = CS_CLIENT_KEY_EXCHANGE; - - if (TlsUtils.isSSL(getContext())) - { - establishMasterSecret(getContext(), keyExchange); - } - - TlsHandshakeHash prepareFinishHash = recordStream.prepareToFinish(); - this.securityParameters.sessionHash = getCurrentPRFHash(getContext(), prepareFinishHash, null); - - if (!TlsUtils.isSSL(getContext())) - { - establishMasterSecret(getContext(), keyExchange); - } - - recordStream.setPendingConnectionState(getPeer().getCompression(), getPeer().getCipher()); - - if (clientCreds != null && clientCreds instanceof TlsSignerCredentials) - { - TlsSignerCredentials signerCredentials = (TlsSignerCredentials)clientCreds; - - /* - * RFC 5246 4.7. digitally-signed element needs SignatureAndHashAlgorithm from TLS 1.2 - */ - SignatureAndHashAlgorithm signatureAndHashAlgorithm = TlsUtils.getSignatureAndHashAlgorithm( - getContext(), signerCredentials); - - byte[] hash; - if (signatureAndHashAlgorithm == null) - { - hash = securityParameters.getSessionHash(); - } - else - { - hash = prepareFinishHash.getFinalHash(signatureAndHashAlgorithm.getHash()); - } - - byte[] signature = signerCredentials.generateCertificateSignature(hash); - DigitallySigned certificateVerify = new DigitallySigned(signatureAndHashAlgorithm, signature); - sendCertificateVerifyMessage(certificateVerify); - - this.connection_state = CS_CERTIFICATE_VERIFY; - } - - sendChangeCipherSpecMessage(); - sendFinishedMessage(); - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - this.connection_state = CS_CLIENT_FINISHED; - break; - } - case HandshakeType.server_key_exchange: - { - switch (this.connection_state) - { - case CS_SERVER_HELLO: - { - handleSupplementalData(null); - // NB: Fall through to next case label - } - case CS_SERVER_SUPPLEMENTAL_DATA: - { - // There was no server certificate message; check it's OK - this.keyExchange.skipServerCredentials(); - this.authentication = null; - - // NB: Fall through to next case label - } - case CS_SERVER_CERTIFICATE: - case CS_CERTIFICATE_STATUS: - { - this.keyExchange.processServerKeyExchange(buf); - - assertEmpty(buf); - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - this.connection_state = CS_SERVER_KEY_EXCHANGE; - break; - } - case HandshakeType.certificate_request: - { - switch (this.connection_state) - { - case CS_SERVER_CERTIFICATE: - case CS_CERTIFICATE_STATUS: - { - // There was no server key exchange message; check it's OK - this.keyExchange.skipServerKeyExchange(); - - // NB: Fall through to next case label - } - case CS_SERVER_KEY_EXCHANGE: - { - if (this.authentication == null) - { - /* - * RFC 2246 7.4.4. It is a fatal handshake_failure alert for an anonymous server - * to request client identification. - */ - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - this.certificateRequest = CertificateRequest.parse(getContext(), buf); - - assertEmpty(buf); - - this.keyExchange.validateCertificateRequest(this.certificateRequest); - - /* - * TODO Give the client a chance to immediately select the CertificateVerify hash - * algorithm here to avoid tracking the other hash algorithms unnecessarily? - */ - TlsUtils.trackHashAlgorithms(this.recordStream.getHandshakeHash(), - this.certificateRequest.getSupportedSignatureAlgorithms()); - - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - this.connection_state = CS_CERTIFICATE_REQUEST; - break; - } - case HandshakeType.session_ticket: - { - switch (this.connection_state) - { - case CS_CLIENT_FINISHED: - { - if (!this.expectSessionTicket) - { - /* - * RFC 5077 3.3. This message MUST NOT be sent if the server did not include a - * SessionTicket extension in the ServerHello. - */ - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - /* - * RFC 5077 3.4. If the client receives a session ticket from the server, then it - * discards any Session ID that was sent in the ServerHello. - */ - invalidateSession(); - - receiveNewSessionTicketMessage(buf); - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - this.connection_state = CS_SERVER_SESSION_TICKET; - break; - } - case HandshakeType.hello_request: - { - assertEmpty(buf); - - /* - * RFC 2246 7.4.1.1 Hello request This message will be ignored by the client if the - * client is currently negotiating a session. This message may be ignored by the client - * if it does not wish to renegotiate a session, or the client may, if it wishes, - * respond with a no_renegotiation alert. - */ - if (this.connection_state == CS_END) - { - refuseRenegotiation(); - } - break; - } - case HandshakeType.client_hello: - case HandshakeType.client_key_exchange: - case HandshakeType.certificate_verify: - case HandshakeType.hello_verify_request: - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - - protected void handleSupplementalData(Vector serverSupplementalData) - throws IOException - { - this.tlsClient.processServerSupplementalData(serverSupplementalData); - this.connection_state = CS_SERVER_SUPPLEMENTAL_DATA; - - this.keyExchange = tlsClient.getKeyExchange(); - this.keyExchange.init(getContext()); - } - - protected void receiveNewSessionTicketMessage(ByteArrayInputStream buf) - throws IOException - { - NewSessionTicket newSessionTicket = NewSessionTicket.parse(buf); - - assertEmpty(buf); - - tlsClient.notifyNewSessionTicket(newSessionTicket); - } - - protected void receiveServerHelloMessage(ByteArrayInputStream buf) - throws IOException - { - { - ProtocolVersion server_version = TlsUtils.readVersion(buf); - if (server_version.isDTLS()) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - // Check that this matches what the server is sending in the record layer - if (!server_version.equals(this.recordStream.getReadVersion())) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - ProtocolVersion client_version = getContext().getClientVersion(); - if (!server_version.isEqualOrEarlierVersionOf(client_version)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - this.recordStream.setWriteVersion(server_version); - getContextAdmin().setServerVersion(server_version); - this.tlsClient.notifyServerVersion(server_version); - } - - /* - * Read the server random - */ - this.securityParameters.serverRandom = TlsUtils.readFully(32, buf); - - this.selectedSessionID = TlsUtils.readOpaque8(buf); - if (this.selectedSessionID.length > 32) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - this.tlsClient.notifySessionID(this.selectedSessionID); - this.resumedSession = this.selectedSessionID.length > 0 && this.tlsSession != null - && Arrays.areEqual(this.selectedSessionID, this.tlsSession.getSessionID()); - - /* - * Find out which CipherSuite the server has chosen and check that it was one of the offered - * ones, and is a valid selection for the negotiated version. - */ - int selectedCipherSuite = TlsUtils.readUint16(buf); - if (!Arrays.contains(this.offeredCipherSuites, selectedCipherSuite) - || selectedCipherSuite == CipherSuite.TLS_NULL_WITH_NULL_NULL - || CipherSuite.isSCSV(selectedCipherSuite) - || !TlsUtils.isValidCipherSuiteForVersion(selectedCipherSuite, getContext().getServerVersion())) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - this.tlsClient.notifySelectedCipherSuite(selectedCipherSuite); - - /* - * Find out which CompressionMethod the server has chosen and check that it was one of the - * offered ones. - */ - short selectedCompressionMethod = TlsUtils.readUint8(buf); - if (!Arrays.contains(this.offeredCompressionMethods, selectedCompressionMethod)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - this.tlsClient.notifySelectedCompressionMethod(selectedCompressionMethod); - - /* - * RFC 3546 2.2 The extended server hello message format MAY be sent in place of the server - * hello message when the client has requested extended functionality via the extended - * client hello message specified in Section 2.1. ... Note that the extended server hello - * message is only sent in response to an extended client hello message. This prevents the - * possibility that the extended server hello message could "break" existing TLS 1.0 - * clients. - */ - this.serverExtensions = readExtensions(buf); - - /* - * RFC 7627 4. Clients and servers SHOULD NOT accept handshakes that do not use the extended - * master secret [..]. (and see 5.2, 5.3) - */ - this.securityParameters.extendedMasterSecret = !TlsUtils.isSSL(tlsClientContext) - && TlsExtensionsUtils.hasExtendedMasterSecretExtension(serverExtensions); - - if (!securityParameters.isExtendedMasterSecret() - && (resumedSession || tlsClient.requiresExtendedMasterSecret())) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - /* - * RFC 3546 2.2 Note that the extended server hello message is only sent in response to an - * extended client hello message. - * - * However, see RFC 5746 exception below. We always include the SCSV, so an Extended Server - * Hello is always allowed. - */ - if (this.serverExtensions != null) - { - Enumeration e = this.serverExtensions.keys(); - while (e.hasMoreElements()) - { - Integer extType = (Integer)e.nextElement(); - - /* - * RFC 5746 3.6. Note that sending a "renegotiation_info" extension in response to a - * ClientHello containing only the SCSV is an explicit exception to the prohibition - * in RFC 5246, Section 7.4.1.4, on the server sending unsolicited extensions and is - * only allowed because the client is signaling its willingness to receive the - * extension via the TLS_EMPTY_RENEGOTIATION_INFO_SCSV SCSV. - */ - if (extType.equals(EXT_RenegotiationInfo)) - { - continue; - } - - /* - * RFC 5246 7.4.1.4 An extension type MUST NOT appear in the ServerHello unless the - * same extension type appeared in the corresponding ClientHello. If a client - * receives an extension type in ServerHello that it did not request in the - * associated ClientHello, it MUST abort the handshake with an unsupported_extension - * fatal alert. - */ - if (null == TlsUtils.getExtensionData(this.clientExtensions, extType)) - { - throw new TlsFatalAlert(AlertDescription.unsupported_extension); - } - - /* - * RFC 3546 2.3. If [...] the older session is resumed, then the server MUST ignore - * extensions appearing in the client hello, and send a server hello containing no - * extensions[.] - */ - if (this.resumedSession) - { - // TODO[compat-gnutls] GnuTLS test server sends server extensions e.g. ec_point_formats - // TODO[compat-openssl] OpenSSL test server sends server extensions e.g. ec_point_formats - // TODO[compat-polarssl] PolarSSL test server sends server extensions e.g. ec_point_formats -// throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - } - - /* - * RFC 5746 3.4. Client Behavior: Initial Handshake - */ - { - /* - * When a ServerHello is received, the client MUST check if it includes the - * "renegotiation_info" extension: - */ - byte[] renegExtData = TlsUtils.getExtensionData(this.serverExtensions, EXT_RenegotiationInfo); - if (renegExtData != null) - { - /* - * If the extension is present, set the secure_renegotiation flag to TRUE. The - * client MUST then verify that the length of the "renegotiated_connection" - * field is zero, and if it is not, MUST abort the handshake (by sending a fatal - * handshake_failure alert). - */ - this.secure_renegotiation = true; - - if (!Arrays.constantTimeAreEqual(renegExtData, createRenegotiationInfo(TlsUtils.EMPTY_BYTES))) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - } - } - - // TODO[compat-gnutls] GnuTLS test server fails to send renegotiation_info extension when resuming - this.tlsClient.notifySecureRenegotiation(this.secure_renegotiation); - - Hashtable sessionClientExtensions = clientExtensions, sessionServerExtensions = serverExtensions; - if (this.resumedSession) - { - if (selectedCipherSuite != this.sessionParameters.getCipherSuite() - || selectedCompressionMethod != this.sessionParameters.getCompressionAlgorithm()) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - sessionClientExtensions = null; - sessionServerExtensions = this.sessionParameters.readServerExtensions(); - } - - this.securityParameters.cipherSuite = selectedCipherSuite; - this.securityParameters.compressionAlgorithm = selectedCompressionMethod; - - if (sessionServerExtensions != null && !sessionServerExtensions.isEmpty()) - { - { - /* - * RFC 7366 3. If a server receives an encrypt-then-MAC request extension from a client - * and then selects a stream or Authenticated Encryption with Associated Data (AEAD) - * ciphersuite, it MUST NOT send an encrypt-then-MAC response extension back to the - * client. - */ - boolean serverSentEncryptThenMAC = TlsExtensionsUtils.hasEncryptThenMACExtension(sessionServerExtensions); - if (serverSentEncryptThenMAC && !TlsUtils.isBlockCipherSuite(selectedCipherSuite)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - this.securityParameters.encryptThenMAC = serverSentEncryptThenMAC; - } - - this.securityParameters.maxFragmentLength = processMaxFragmentLengthExtension(sessionClientExtensions, - sessionServerExtensions, AlertDescription.illegal_parameter); - - this.securityParameters.truncatedHMac = TlsExtensionsUtils.hasTruncatedHMacExtension(sessionServerExtensions); - - /* - * TODO It's surprising that there's no provision to allow a 'fresh' CertificateStatus to be sent in - * a session resumption handshake. - */ - this.allowCertificateStatus = !this.resumedSession - && TlsUtils.hasExpectedEmptyExtensionData(sessionServerExtensions, - TlsExtensionsUtils.EXT_status_request, AlertDescription.illegal_parameter); - - this.expectSessionTicket = !this.resumedSession - && TlsUtils.hasExpectedEmptyExtensionData(sessionServerExtensions, TlsProtocol.EXT_SessionTicket, - AlertDescription.illegal_parameter); - } - - if (sessionClientExtensions != null) - { - this.tlsClient.processServerExtensions(sessionServerExtensions); - } - - this.securityParameters.prfAlgorithm = getPRFAlgorithm(getContext(), - this.securityParameters.getCipherSuite()); - - /* - * RFC 5246 7.4.9. Any cipher suite which does not explicitly specify - * verify_data_length has a verify_data_length equal to 12. This includes all - * existing cipher suites. - */ - this.securityParameters.verifyDataLength = 12; - } - - protected void sendCertificateVerifyMessage(DigitallySigned certificateVerify) - throws IOException - { - HandshakeMessage message = new HandshakeMessage(HandshakeType.certificate_verify); - - certificateVerify.encode(message); - - message.writeToRecordStream(); - } - - protected void sendClientHelloMessage() - throws IOException - { - this.recordStream.setWriteVersion(this.tlsClient.getClientHelloRecordLayerVersion()); - - ProtocolVersion client_version = this.tlsClient.getClientVersion(); - if (client_version.isDTLS()) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - getContextAdmin().setClientVersion(client_version); - - /* - * TODO RFC 5077 3.4. When presenting a ticket, the client MAY generate and include a - * Session ID in the TLS ClientHello. - */ - byte[] session_id = TlsUtils.EMPTY_BYTES; - if (this.tlsSession != null) - { - session_id = this.tlsSession.getSessionID(); - if (session_id == null || session_id.length > 32) - { - session_id = TlsUtils.EMPTY_BYTES; - } - } - - boolean fallback = this.tlsClient.isFallback(); - - this.offeredCipherSuites = this.tlsClient.getCipherSuites(); - - this.offeredCompressionMethods = this.tlsClient.getCompressionMethods(); - - if (session_id.length > 0 && this.sessionParameters != null) - { - if (!sessionParameters.isExtendedMasterSecret() - || !Arrays.contains(this.offeredCipherSuites, sessionParameters.getCipherSuite()) - || !Arrays.contains(this.offeredCompressionMethods, sessionParameters.getCompressionAlgorithm())) - { - session_id = TlsUtils.EMPTY_BYTES; - } - } - - this.clientExtensions = TlsExtensionsUtils.ensureExtensionsInitialised(this.tlsClient.getClientExtensions()); - - if (!client_version.isSSL()) - { - TlsExtensionsUtils.addExtendedMasterSecretExtension(this.clientExtensions); - } - - HandshakeMessage message = new HandshakeMessage(HandshakeType.client_hello); - - TlsUtils.writeVersion(client_version, message); - - message.write(this.securityParameters.getClientRandom()); - - TlsUtils.writeOpaque8(session_id, message); - - // Cipher Suites (and SCSV) - { - /* - * RFC 5746 3.4. The client MUST include either an empty "renegotiation_info" extension, - * or the TLS_EMPTY_RENEGOTIATION_INFO_SCSV signaling cipher suite value in the - * ClientHello. Including both is NOT RECOMMENDED. - */ - byte[] renegExtData = TlsUtils.getExtensionData(clientExtensions, EXT_RenegotiationInfo); - boolean noRenegExt = (null == renegExtData); - - boolean noRenegSCSV = !Arrays.contains(offeredCipherSuites, CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV); - - if (noRenegExt && noRenegSCSV) - { - // TODO Consider whether to default to a client extension instead - this.offeredCipherSuites = Arrays.append(offeredCipherSuites, CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV); - } - - /* - * RFC 7507 4. If a client sends a ClientHello.client_version containing a lower value - * than the latest (highest-valued) version supported by the client, it SHOULD include - * the TLS_FALLBACK_SCSV cipher suite value in ClientHello.cipher_suites [..]. (The - * client SHOULD put TLS_FALLBACK_SCSV after all cipher suites that it actually intends - * to negotiate.) - */ - if (fallback && !Arrays.contains(offeredCipherSuites, CipherSuite.TLS_FALLBACK_SCSV)) - { - this.offeredCipherSuites = Arrays.append(offeredCipherSuites, CipherSuite.TLS_FALLBACK_SCSV); - } - - TlsUtils.writeUint16ArrayWithUint16Length(offeredCipherSuites, message); - } - - TlsUtils.writeUint8ArrayWithUint8Length(offeredCompressionMethods, message); - - writeExtensions(message, clientExtensions); - - message.writeToRecordStream(); - } - - protected void sendClientKeyExchangeMessage() - throws IOException - { - HandshakeMessage message = new HandshakeMessage(HandshakeType.client_key_exchange); - - this.keyExchange.generateClientKeyExchange(message); - - message.writeToRecordStream(); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCloseable.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCloseable.java deleted file mode 100644 index de8d874e4..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCloseable.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsCloseable -{ - public void close() throws IOException; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCompression.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCompression.java deleted file mode 100644 index b04b84bfc..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCompression.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.OutputStream; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsCompression -{ - OutputStream compress(OutputStream output); - - OutputStream decompress(OutputStream output); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsContext.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsContext.java deleted file mode 100644 index 6b7d5ea3c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsContext.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.prng.RandomGenerator; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsContext -{ - RandomGenerator getNonceRandomGenerator(); - - SecureRandom getSecureRandom(); - - SecurityParameters getSecurityParameters(); - - boolean isServer(); - - ProtocolVersion getClientVersion(); - - ProtocolVersion getServerVersion(); - - /** - * Used to get the resumable session, if any, used by this connection. Only available after the - * handshake has successfully completed. - * - * @return A {@link TlsSession} representing the resumable session used by this connection, or - * null if no resumable session available. - * @see TlsPeer#notifyHandshakeComplete() - */ - TlsSession getResumableSession(); - - Object getUserObject(); - - void setUserObject(Object userObject); - - /** - * Export keying material according to RFC 5705: "Keying Material Exporters for TLS". - * - * @param asciiLabel indicates which application will use the exported keys. - * @param context_value allows the application using the exporter to mix its own data with the TLS PRF for - * the exporter output. - * @param length the number of bytes to generate - * @return a pseudorandom bit string of 'length' bytes generated from the master_secret. - */ - byte[] exportKeyingMaterial(String asciiLabel, byte[] context_value, int length); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCredentials.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCredentials.java deleted file mode 100644 index 52927c863..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsCredentials.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsCredentials -{ - Certificate getCertificate(); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDHEKeyExchange.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDHEKeyExchange.java deleted file mode 100644 index 017b5c241..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDHEKeyExchange.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.Signer; -import com.fr.third.org.bouncycastle.crypto.params.DHParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHPublicKeyParameters; -import com.fr.third.org.bouncycastle.util.io.TeeInputStream; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsDHEKeyExchange - extends TlsDHKeyExchange -{ - protected TlsSignerCredentials serverCredentials = null; - - /** - * @deprecated Use constructor that takes a TlsDHVerifier - */ - public TlsDHEKeyExchange(int keyExchange, Vector supportedSignatureAlgorithms, DHParameters dhParameters) - { - this(keyExchange, supportedSignatureAlgorithms, new DefaultTlsDHVerifier(), dhParameters); - } - - public TlsDHEKeyExchange(int keyExchange, Vector supportedSignatureAlgorithms, TlsDHVerifier dhVerifier, DHParameters dhParameters) - { - super(keyExchange, supportedSignatureAlgorithms, dhVerifier, dhParameters); - } - - public void processServerCredentials(TlsCredentials serverCredentials) - throws IOException - { - if (!(serverCredentials instanceof TlsSignerCredentials)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - processServerCertificate(serverCredentials.getCertificate()); - - this.serverCredentials = (TlsSignerCredentials)serverCredentials; - } - - public byte[] generateServerKeyExchange() - throws IOException - { - if (this.dhParameters == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - DigestInputBuffer buf = new DigestInputBuffer(); - - this.dhAgreePrivateKey = TlsDHUtils.generateEphemeralServerKeyExchange(context.getSecureRandom(), - this.dhParameters, buf); - - /* - * RFC 5246 4.7. digitally-signed element needs SignatureAndHashAlgorithm from TLS 1.2 - */ - SignatureAndHashAlgorithm signatureAndHashAlgorithm = TlsUtils.getSignatureAndHashAlgorithm( - context, serverCredentials); - - Digest d = TlsUtils.createHash(signatureAndHashAlgorithm); - - SecurityParameters securityParameters = context.getSecurityParameters(); - d.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length); - d.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length); - buf.updateDigest(d); - - byte[] hash = new byte[d.getDigestSize()]; - d.doFinal(hash, 0); - - byte[] signature = serverCredentials.generateCertificateSignature(hash); - - DigitallySigned signed_params = new DigitallySigned(signatureAndHashAlgorithm, signature); - signed_params.encode(buf); - - return buf.toByteArray(); - } - - public void processServerKeyExchange(InputStream input) - throws IOException - { - SecurityParameters securityParameters = context.getSecurityParameters(); - - SignerInputBuffer buf = new SignerInputBuffer(); - InputStream teeIn = new TeeInputStream(input, buf); - - this.dhParameters = TlsDHUtils.receiveDHParameters(dhVerifier, teeIn); - this.dhAgreePublicKey = new DHPublicKeyParameters(TlsDHUtils.readDHParameter(teeIn), dhParameters); - - DigitallySigned signed_params = parseSignature(input); - - Signer signer = initVerifyer(tlsSigner, signed_params.getAlgorithm(), securityParameters); - buf.updateSigner(signer); - if (!signer.verifySignature(signed_params.getSignature())) - { - throw new TlsFatalAlert(AlertDescription.decrypt_error); - } - } - - protected Signer initVerifyer(TlsSigner tlsSigner, SignatureAndHashAlgorithm algorithm, SecurityParameters securityParameters) - { - Signer signer = tlsSigner.createVerifyer(algorithm, this.serverPublicKey); - signer.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length); - signer.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length); - return signer; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDHKeyExchange.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDHKeyExchange.java deleted file mode 100644 index 3ded82874..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDHKeyExchange.java +++ /dev/null @@ -1,280 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.x509.KeyUsage; -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.DHParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.util.PublicKeyFactory; - -/** - * (D)TLS DH key exchange. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsDHKeyExchange - extends AbstractTlsKeyExchange -{ - protected TlsSigner tlsSigner; - protected TlsDHVerifier dhVerifier; - protected DHParameters dhParameters; - - protected AsymmetricKeyParameter serverPublicKey; - protected TlsAgreementCredentials agreementCredentials; - - protected DHPrivateKeyParameters dhAgreePrivateKey; - protected DHPublicKeyParameters dhAgreePublicKey; - - /** - * @deprecated Use constructor that takes a TlsDHVerifier - */ - public TlsDHKeyExchange(int keyExchange, Vector supportedSignatureAlgorithms, DHParameters dhParameters) - { - this(keyExchange, supportedSignatureAlgorithms, new DefaultTlsDHVerifier(), dhParameters); - } - - public TlsDHKeyExchange(int keyExchange, Vector supportedSignatureAlgorithms, TlsDHVerifier dhVerifier, DHParameters dhParameters) - { - super(keyExchange, supportedSignatureAlgorithms); - - switch (keyExchange) - { - case KeyExchangeAlgorithm.DH_anon: - case KeyExchangeAlgorithm.DH_RSA: - case KeyExchangeAlgorithm.DH_DSS: - this.tlsSigner = null; - break; - case KeyExchangeAlgorithm.DHE_RSA: - this.tlsSigner = new TlsRSASigner(); - break; - case KeyExchangeAlgorithm.DHE_DSS: - this.tlsSigner = new TlsDSSSigner(); - break; - default: - throw new IllegalArgumentException("unsupported key exchange algorithm"); - } - - this.dhVerifier = dhVerifier; - this.dhParameters = dhParameters; - } - - public void init(TlsContext context) - { - super.init(context); - - if (this.tlsSigner != null) - { - this.tlsSigner.init(context); - } - } - - public void skipServerCredentials() - throws IOException - { - if (keyExchange != KeyExchangeAlgorithm.DH_anon) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - - public void processServerCertificate(Certificate serverCertificate) - throws IOException - { - if (keyExchange == KeyExchangeAlgorithm.DH_anon) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - if (serverCertificate.isEmpty()) - { - throw new TlsFatalAlert(AlertDescription.bad_certificate); - } - - com.fr.third.org.bouncycastle.asn1.x509.Certificate x509Cert = serverCertificate.getCertificateAt(0); - - SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo(); - try - { - this.serverPublicKey = PublicKeyFactory.createKey(keyInfo); - } - catch (RuntimeException e) - { - throw new TlsFatalAlert(AlertDescription.unsupported_certificate, e); - } - - if (tlsSigner == null) - { - try - { - this.dhAgreePublicKey = (DHPublicKeyParameters)this.serverPublicKey; - this.dhParameters = dhAgreePublicKey.getParameters(); - } - catch (ClassCastException e) - { - throw new TlsFatalAlert(AlertDescription.certificate_unknown, e); - } - - TlsUtils.validateKeyUsage(x509Cert, KeyUsage.keyAgreement); - } - else - { - if (!tlsSigner.isValidPublicKey(this.serverPublicKey)) - { - throw new TlsFatalAlert(AlertDescription.certificate_unknown); - } - - TlsUtils.validateKeyUsage(x509Cert, KeyUsage.digitalSignature); - } - - super.processServerCertificate(serverCertificate); - } - - public boolean requiresServerKeyExchange() - { - switch (keyExchange) - { - case KeyExchangeAlgorithm.DH_anon: - case KeyExchangeAlgorithm.DHE_DSS: - case KeyExchangeAlgorithm.DHE_RSA: - return true; - default: - return false; - } - } - - public byte[] generateServerKeyExchange() throws IOException - { - if (!requiresServerKeyExchange()) - { - return null; - } - - // DH_anon is handled here, DHE_* in a subclass - - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - this.dhAgreePrivateKey = TlsDHUtils.generateEphemeralServerKeyExchange(context.getSecureRandom(), - this.dhParameters, buf); - return buf.toByteArray(); - } - - public void processServerKeyExchange(InputStream input) throws IOException - { - if (!requiresServerKeyExchange()) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - // DH_anon is handled here, DHE_* in a subclass - - this.dhParameters = TlsDHUtils.receiveDHParameters(dhVerifier, input); - this.dhAgreePublicKey = new DHPublicKeyParameters(TlsDHUtils.readDHParameter(input), dhParameters); - } - - public void validateCertificateRequest(CertificateRequest certificateRequest) - throws IOException - { - if (keyExchange == KeyExchangeAlgorithm.DH_anon) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - short[] types = certificateRequest.getCertificateTypes(); - for (int i = 0; i < types.length; ++i) - { - switch (types[i]) - { - case ClientCertificateType.rsa_sign: - case ClientCertificateType.dss_sign: - case ClientCertificateType.rsa_fixed_dh: - case ClientCertificateType.dss_fixed_dh: - case ClientCertificateType.ecdsa_sign: - break; - default: - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - } - - public void processClientCredentials(TlsCredentials clientCredentials) - throws IOException - { - if (keyExchange == KeyExchangeAlgorithm.DH_anon) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - if (clientCredentials instanceof TlsAgreementCredentials) - { - // TODO Validate client cert has matching parameters (see 'areCompatibleParameters')? - - this.agreementCredentials = (TlsAgreementCredentials)clientCredentials; - } - else if (clientCredentials instanceof TlsSignerCredentials) - { - // OK - } - else - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public void generateClientKeyExchange(OutputStream output) - throws IOException - { - /* - * RFC 2246 7.4.7.2 If the client certificate already contains a suitable Diffie-Hellman - * key, then Yc is implicit and does not need to be sent again. In this case, the Client Key - * Exchange message will be sent, but will be empty. - */ - if (agreementCredentials == null) - { - this.dhAgreePrivateKey = TlsDHUtils.generateEphemeralClientKeyExchange(context.getSecureRandom(), - dhParameters, output); - } - } - - public void processClientCertificate(Certificate clientCertificate) throws IOException - { - if (keyExchange == KeyExchangeAlgorithm.DH_anon) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - // TODO Extract the public key - // TODO If the certificate is 'fixed', take the public key as dhAgreePublicKey - } - - public void processClientKeyExchange(InputStream input) throws IOException - { - if (dhAgreePublicKey != null) - { - // For dss_fixed_dh and rsa_fixed_dh, the key arrived in the client certificate - return; - } - - this.dhAgreePublicKey = new DHPublicKeyParameters(TlsDHUtils.readDHParameter(input), dhParameters); - } - - public byte[] generatePremasterSecret() - throws IOException - { - if (agreementCredentials != null) - { - return agreementCredentials.generateAgreement(dhAgreePublicKey); - } - - if (dhAgreePrivateKey != null) - { - return TlsDHUtils.calculateDHBasicAgreement(dhAgreePublicKey, dhAgreePrivateKey); - } - - throw new TlsFatalAlert(AlertDescription.internal_error); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDHUtils.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDHUtils.java deleted file mode 100644 index 9e477300c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDHUtils.java +++ /dev/null @@ -1,523 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.math.BigInteger; -import java.security.SecureRandom; -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.agreement.DHBasicAgreement; -import com.fr.third.org.bouncycastle.crypto.generators.DHBasicKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.DHKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHPublicKeyParameters; -import com.fr.third.org.bouncycastle.util.BigIntegers; -import com.fr.third.org.bouncycastle.util.Integers; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsDHUtils -{ - static final BigInteger TWO = BigInteger.valueOf(2); - - public static final Integer EXT_negotiated_ff_dhe_groups = Integers.valueOf(ExtensionType.negotiated_ff_dhe_groups); - - /* - * TODO[draft-ietf-tls-negotiated-ff-dhe-01] Move these groups to DHStandardGroups once reaches RFC - */ - private static BigInteger fromHex(String hex) - { - return new BigInteger(1, Hex.decodeStrict(hex)); - } - - private static DHParameters fromSafeP(String hexP) - { - BigInteger p = fromHex(hexP), q = p.shiftRight(1); - return new DHParameters(p, TWO, q); - } - - private static final String draft_ffdhe2432_p = - "FFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1" - + "D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF9" - + "7D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD6561" - + "2433F51F5F066ED0856365553DED1AF3B557135E7F57C935" - + "984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE735" - + "30ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FB" - + "B96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB19" - + "0B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F61" - + "9172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD73" - + "3BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA" - + "886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C0238" - + "61B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91C" - + "AEFE13098533C8B3FFFFFFFFFFFFFFFF"; - static final DHParameters draft_ffdhe2432 = fromSafeP(draft_ffdhe2432_p); - - private static final String draft_ffdhe3072_p = - "FFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1" - + "D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF9" - + "7D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD6561" - + "2433F51F5F066ED0856365553DED1AF3B557135E7F57C935" - + "984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE735" - + "30ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FB" - + "B96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB19" - + "0B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F61" - + "9172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD73" - + "3BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA" - + "886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C0238" - + "61B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91C" - + "AEFE130985139270B4130C93BC437944F4FD4452E2D74DD3" - + "64F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0D" - + "ABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF" - + "3C1B20EE3FD59D7C25E41D2B66C62E37FFFFFFFFFFFFFFFF"; - static final DHParameters draft_ffdhe3072 = fromSafeP(draft_ffdhe3072_p); - - private static final String draft_ffdhe4096_p = - "FFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1" - + "D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF9" - + "7D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD6561" - + "2433F51F5F066ED0856365553DED1AF3B557135E7F57C935" - + "984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE735" - + "30ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FB" - + "B96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB19" - + "0B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F61" - + "9172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD73" - + "3BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA" - + "886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C0238" - + "61B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91C" - + "AEFE130985139270B4130C93BC437944F4FD4452E2D74DD3" - + "64F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0D" - + "ABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF" - + "3C1B20EE3FD59D7C25E41D2B669E1EF16E6F52C3164DF4FB" - + "7930E9E4E58857B6AC7D5F42D69F6D187763CF1D55034004" - + "87F55BA57E31CC7A7135C886EFB4318AED6A1E012D9E6832" - + "A907600A918130C46DC778F971AD0038092999A333CB8B7A" - + "1A1DB93D7140003C2A4ECEA9F98D0ACC0A8291CDCEC97DCF" - + "8EC9B55A7F88A46B4DB5A851F44182E1C68A007E5E655F6A" - + "FFFFFFFFFFFFFFFF"; - static final DHParameters draft_ffdhe4096 = fromSafeP(draft_ffdhe4096_p); - - private static final String draft_ffdhe6144_p = - "FFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1" - + "D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF9" - + "7D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD6561" - + "2433F51F5F066ED0856365553DED1AF3B557135E7F57C935" - + "984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE735" - + "30ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FB" - + "B96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB19" - + "0B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F61" - + "9172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD73" - + "3BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA" - + "886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C0238" - + "61B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91C" - + "AEFE130985139270B4130C93BC437944F4FD4452E2D74DD3" - + "64F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0D" - + "ABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF" - + "3C1B20EE3FD59D7C25E41D2B669E1EF16E6F52C3164DF4FB" - + "7930E9E4E58857B6AC7D5F42D69F6D187763CF1D55034004" - + "87F55BA57E31CC7A7135C886EFB4318AED6A1E012D9E6832" - + "A907600A918130C46DC778F971AD0038092999A333CB8B7A" - + "1A1DB93D7140003C2A4ECEA9F98D0ACC0A8291CDCEC97DCF" - + "8EC9B55A7F88A46B4DB5A851F44182E1C68A007E5E0DD902" - + "0BFD64B645036C7A4E677D2C38532A3A23BA4442CAF53EA6" - + "3BB454329B7624C8917BDD64B1C0FD4CB38E8C334C701C3A" - + "CDAD0657FCCFEC719B1F5C3E4E46041F388147FB4CFDB477" - + "A52471F7A9A96910B855322EDB6340D8A00EF092350511E3" - + "0ABEC1FFF9E3A26E7FB29F8C183023C3587E38DA0077D9B4" - + "763E4E4B94B2BBC194C6651E77CAF992EEAAC0232A281BF6" - + "B3A739C1226116820AE8DB5847A67CBEF9C9091B462D538C" - + "D72B03746AE77F5E62292C311562A846505DC82DB854338A" - + "E49F5235C95B91178CCF2DD5CACEF403EC9D1810C6272B04" - + "5B3B71F9DC6B80D63FDD4A8E9ADB1E6962A69526D43161C1" - + "A41D570D7938DAD4A40E329CD0E40E65FFFFFFFFFFFFFFFF"; - static final DHParameters draft_ffdhe6144 = fromSafeP(draft_ffdhe6144_p); - - private static final String draft_ffdhe8192_p = - "FFFFFFFFFFFFFFFFADF85458A2BB4A9AAFDC5620273D3CF1" - + "D8B9C583CE2D3695A9E13641146433FBCC939DCE249B3EF9" - + "7D2FE363630C75D8F681B202AEC4617AD3DF1ED5D5FD6561" - + "2433F51F5F066ED0856365553DED1AF3B557135E7F57C935" - + "984F0C70E0E68B77E2A689DAF3EFE8721DF158A136ADE735" - + "30ACCA4F483A797ABC0AB182B324FB61D108A94BB2C8E3FB" - + "B96ADAB760D7F4681D4F42A3DE394DF4AE56EDE76372BB19" - + "0B07A7C8EE0A6D709E02FCE1CDF7E2ECC03404CD28342F61" - + "9172FE9CE98583FF8E4F1232EEF28183C3FE3B1B4C6FAD73" - + "3BB5FCBC2EC22005C58EF1837D1683B2C6F34A26C1B2EFFA" - + "886B4238611FCFDCDE355B3B6519035BBC34F4DEF99C0238" - + "61B46FC9D6E6C9077AD91D2691F7F7EE598CB0FAC186D91C" - + "AEFE130985139270B4130C93BC437944F4FD4452E2D74DD3" - + "64F2E21E71F54BFF5CAE82AB9C9DF69EE86D2BC522363A0D" - + "ABC521979B0DEADA1DBF9A42D5C4484E0ABCD06BFA53DDEF" - + "3C1B20EE3FD59D7C25E41D2B669E1EF16E6F52C3164DF4FB" - + "7930E9E4E58857B6AC7D5F42D69F6D187763CF1D55034004" - + "87F55BA57E31CC7A7135C886EFB4318AED6A1E012D9E6832" - + "A907600A918130C46DC778F971AD0038092999A333CB8B7A" - + "1A1DB93D7140003C2A4ECEA9F98D0ACC0A8291CDCEC97DCF" - + "8EC9B55A7F88A46B4DB5A851F44182E1C68A007E5E0DD902" - + "0BFD64B645036C7A4E677D2C38532A3A23BA4442CAF53EA6" - + "3BB454329B7624C8917BDD64B1C0FD4CB38E8C334C701C3A" - + "CDAD0657FCCFEC719B1F5C3E4E46041F388147FB4CFDB477" - + "A52471F7A9A96910B855322EDB6340D8A00EF092350511E3" - + "0ABEC1FFF9E3A26E7FB29F8C183023C3587E38DA0077D9B4" - + "763E4E4B94B2BBC194C6651E77CAF992EEAAC0232A281BF6" - + "B3A739C1226116820AE8DB5847A67CBEF9C9091B462D538C" - + "D72B03746AE77F5E62292C311562A846505DC82DB854338A" - + "E49F5235C95B91178CCF2DD5CACEF403EC9D1810C6272B04" - + "5B3B71F9DC6B80D63FDD4A8E9ADB1E6962A69526D43161C1" - + "A41D570D7938DAD4A40E329CCFF46AAA36AD004CF600C838" - + "1E425A31D951AE64FDB23FCEC9509D43687FEB69EDD1CC5E" - + "0B8CC3BDF64B10EF86B63142A3AB8829555B2F747C932665" - + "CB2C0F1CC01BD70229388839D2AF05E454504AC78B758282" - + "2846C0BA35C35F5C59160CC046FD8251541FC68C9C86B022" - + "BB7099876A460E7451A8A93109703FEE1C217E6C3826E52C" - + "51AA691E0E423CFC99E9E31650C1217B624816CDAD9A95F9" - + "D5B8019488D9C0A0A1FE3075A577E23183F81D4A3F2FA457" - + "1EFC8CE0BA8A4FE8B6855DFE72B0A66EDED2FBABFBE58A30" - + "FAFABE1C5D71A87E2F741EF8C1FE86FEA6BBFDE530677F0D" - + "97D11D49F7A8443D0822E506A9F4614E011E2A94838FF88C" - + "D68C8BB7C5C6424CFFFFFFFFFFFFFFFF"; - static final DHParameters draft_ffdhe8192 = fromSafeP(draft_ffdhe8192_p); - - - public static void addNegotiatedDHEGroupsClientExtension(Hashtable extensions, short[] dheGroups) - throws IOException - { - extensions.put(EXT_negotiated_ff_dhe_groups, createNegotiatedDHEGroupsClientExtension(dheGroups)); - } - - public static void addNegotiatedDHEGroupsServerExtension(Hashtable extensions, short dheGroup) - throws IOException - { - extensions.put(EXT_negotiated_ff_dhe_groups, createNegotiatedDHEGroupsServerExtension(dheGroup)); - } - - public static short[] getNegotiatedDHEGroupsClientExtension(Hashtable extensions) throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_negotiated_ff_dhe_groups); - return extensionData == null ? null : readNegotiatedDHEGroupsClientExtension(extensionData); - } - - public static short getNegotiatedDHEGroupsServerExtension(Hashtable extensions) throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_negotiated_ff_dhe_groups); - return extensionData == null ? -1 : readNegotiatedDHEGroupsServerExtension(extensionData); - } - - public static byte[] createNegotiatedDHEGroupsClientExtension(short[] dheGroups) throws IOException - { - if (dheGroups == null || dheGroups.length < 1 || dheGroups.length > 255) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - return TlsUtils.encodeUint8ArrayWithUint8Length(dheGroups); - } - - public static byte[] createNegotiatedDHEGroupsServerExtension(short dheGroup) throws IOException - { - TlsUtils.checkUint8(dheGroup); - - byte[] extensionData = new byte[1]; - TlsUtils.writeUint8(dheGroup, extensionData, 0); - return extensionData; - } - - public static short[] readNegotiatedDHEGroupsClientExtension(byte[] extensionData) throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - - ByteArrayInputStream buf = new ByteArrayInputStream(extensionData); - - short length = TlsUtils.readUint8(buf); - if (length < 1) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - short[] dheGroups = TlsUtils.readUint8Array(length, buf); - - TlsProtocol.assertEmpty(buf); - - return dheGroups; - } - - public static short readNegotiatedDHEGroupsServerExtension(byte[] extensionData) throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - - if (extensionData.length != 1) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - return TlsUtils.readUint8(extensionData, 0); - } - - public static DHParameters getParametersForDHEGroup(short dheGroup) - { - switch (dheGroup) - { - case FiniteFieldDHEGroup.ffdhe2432: - return draft_ffdhe2432; - case FiniteFieldDHEGroup.ffdhe3072: - return draft_ffdhe3072; - case FiniteFieldDHEGroup.ffdhe4096: - return draft_ffdhe4096; - case FiniteFieldDHEGroup.ffdhe6144: - return draft_ffdhe6144; - case FiniteFieldDHEGroup.ffdhe8192: - return draft_ffdhe8192; - default: - return null; - } - } - - public static boolean containsDHECipherSuites(int[] cipherSuites) - { - for (int i = 0; i < cipherSuites.length; ++i) - { - if (isDHECipherSuite(cipherSuites[i])) - { - return true; - } - } - return false; - } - - public static boolean isDHECipherSuite(int cipherSuite) - { - switch (cipherSuite) - { - /* - * RFC 2246 - */ - case CipherSuite.TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_DES_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_DES_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA: - - /* - * RFC 3268 - */ - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA: - - /* - * RFC 5932 - */ - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256: - - /* - * RFC 4162 - */ - case CipherSuite.TLS_DHE_DSS_WITH_SEED_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_SEED_CBC_SHA: - - /* - * RFC 4279 - */ - case CipherSuite.TLS_DHE_PSK_WITH_RC4_128_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA: - - /* - * RFC 4785 - */ - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA: - - /* - * RFC 5246 - */ - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA256: - - /* - * RFC 5288 - */ - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_GCM_SHA384: - - /* - * RFC 5487 - */ - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA384: - - /* - * RFC 6367 - */ - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384: - - /* - * RFC 6655 - */ - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CCM: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CCM: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CCM: - case CipherSuite.TLS_PSK_DHE_WITH_AES_128_CCM_8: - case CipherSuite.TLS_PSK_DHE_WITH_AES_256_CCM_8: - - /* - * draft-ietf-tls-chacha20-poly1305-04 - */ - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256: - - /* - * draft-zauner-tls-aes-ocb-04 - */ - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_256_OCB: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_AES_256_OCB: - - /* - * DH_anon cipher suites are consider ephemeral DH - */ - case CipherSuite.TLS_DH_anon_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5: - case CipherSuite.TLS_DH_anon_WITH_SEED_CBC_SHA: - - return true; - - default: - return false; - } - } - - public static boolean areCompatibleParameters(DHParameters a, DHParameters b) - { - return a.getP().equals(b.getP()) && a.getG().equals(b.getG()) - && (a.getQ() == null || b.getQ() == null || a.getQ().equals(b.getQ())); - } - - public static byte[] calculateDHBasicAgreement(DHPublicKeyParameters publicKey, DHPrivateKeyParameters privateKey) - { - DHBasicAgreement basicAgreement = new DHBasicAgreement(); - basicAgreement.init(privateKey); - BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey); - - /* - * RFC 5246 8.1.2. Leading bytes of Z that contain all zero bits are stripped before it is - * used as the pre_master_secret. - */ - return BigIntegers.asUnsignedByteArray(agreementValue); - } - - public static AsymmetricCipherKeyPair generateDHKeyPair(SecureRandom random, DHParameters dhParams) - { - DHBasicKeyPairGenerator dhGen = new DHBasicKeyPairGenerator(); - dhGen.init(new DHKeyGenerationParameters(random, dhParams)); - return dhGen.generateKeyPair(); - } - - public static DHPrivateKeyParameters generateEphemeralClientKeyExchange(SecureRandom random, DHParameters dhParams, - OutputStream output) throws IOException - { - AsymmetricCipherKeyPair kp = generateDHKeyPair(random, dhParams); - - DHPublicKeyParameters dhPublic = (DHPublicKeyParameters) kp.getPublic(); - writeDHParameter(dhPublic.getY(), output); - - return (DHPrivateKeyParameters) kp.getPrivate(); - } - - public static DHPrivateKeyParameters generateEphemeralServerKeyExchange(SecureRandom random, DHParameters dhParams, - OutputStream output) throws IOException - { - AsymmetricCipherKeyPair kp = generateDHKeyPair(random, dhParams); - - DHPublicKeyParameters dhPublic = (DHPublicKeyParameters)kp.getPublic(); - writeDHParameters(dhParams, output); - writeDHParameter(dhPublic.getY(), output); - - return (DHPrivateKeyParameters)kp.getPrivate(); - } - - public static BigInteger readDHParameter(InputStream input) throws IOException - { - return new BigInteger(1, TlsUtils.readOpaque16(input)); - } - - public static DHParameters readDHParameters(InputStream input) throws IOException - { - BigInteger p = readDHParameter(input); - BigInteger g = readDHParameter(input); - - return new DHParameters(p, g); - } - - public static DHParameters receiveDHParameters(TlsDHVerifier dhVerifier, InputStream input) throws IOException - { - DHParameters dhParameters = readDHParameters(input); - if (!dhVerifier.accept(dhParameters)) - { - throw new TlsFatalAlert(AlertDescription.insufficient_security); - } - return dhParameters; - } - - public static void writeDHParameter(BigInteger x, OutputStream output) throws IOException - { - TlsUtils.writeOpaque16(BigIntegers.asUnsignedByteArray(x), output); - } - - public static void writeDHParameters(DHParameters dhParameters, OutputStream output) throws IOException - { - writeDHParameter(dhParameters.getP(), output); - writeDHParameter(dhParameters.getG(), output); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDHVerifier.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDHVerifier.java deleted file mode 100644 index 9429073c0..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDHVerifier.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.crypto.params.DHParameters; - -/** - * Interface a class for verifying Diffie-Hellman parameters needs to conform to. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsDHVerifier -{ - /** - * Check whether the given DH parameters are acceptable for use. - * - * @param dhParameters the {@link DHParameters} to check - * @return true if (and only if) the specified parameters are acceptable - */ - boolean accept(DHParameters dhParameters); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDSASigner.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDSASigner.java deleted file mode 100644 index bc65716df..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDSASigner.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.CryptoException; -import com.fr.third.org.bouncycastle.crypto.DSA; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.Signer; -import com.fr.third.org.bouncycastle.crypto.digests.NullDigest; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.signers.DSADigestSigner; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class TlsDSASigner - extends AbstractTlsSigner -{ - public byte[] generateRawSignature(SignatureAndHashAlgorithm algorithm, - AsymmetricKeyParameter privateKey, byte[] hash) - throws CryptoException - { - Signer signer = makeSigner(algorithm, true, true, - new ParametersWithRandom(privateKey, this.context.getSecureRandom())); - if (algorithm == null) - { - // Note: Only use the SHA1 part of the (MD5/SHA1) hash - signer.update(hash, 16, 20); - } - else - { - signer.update(hash, 0, hash.length); - } - return signer.generateSignature(); - } - - public boolean verifyRawSignature(SignatureAndHashAlgorithm algorithm, byte[] sigBytes, - AsymmetricKeyParameter publicKey, byte[] hash) - throws CryptoException - { - Signer signer = makeSigner(algorithm, true, false, publicKey); - if (algorithm == null) - { - // Note: Only use the SHA1 part of the (MD5/SHA1) hash - signer.update(hash, 16, 20); - } - else - { - signer.update(hash, 0, hash.length); - } - return signer.verifySignature(sigBytes); - } - - public Signer createSigner(SignatureAndHashAlgorithm algorithm, AsymmetricKeyParameter privateKey) - { - return makeSigner(algorithm, false, true, privateKey); - } - - public Signer createVerifyer(SignatureAndHashAlgorithm algorithm, AsymmetricKeyParameter publicKey) - { - return makeSigner(algorithm, false, false, publicKey); - } - - protected CipherParameters makeInitParameters(boolean forSigning, CipherParameters cp) - { - return cp; - } - - protected Signer makeSigner(SignatureAndHashAlgorithm algorithm, boolean raw, boolean forSigning, - CipherParameters cp) - { - if ((algorithm != null) != TlsUtils.isTLSv12(context)) - { - throw new IllegalStateException(); - } - - if (algorithm != null && algorithm.getSignature() != getSignatureAlgorithm()) - { - throw new IllegalStateException(); - } - - short hashAlgorithm = algorithm == null ? HashAlgorithm.sha1 : algorithm.getHash(); - Digest d = raw ? new NullDigest() : TlsUtils.createHash(hashAlgorithm); - - Signer s = new DSADigestSigner(createDSAImpl(hashAlgorithm), d); - s.init(forSigning, makeInitParameters(forSigning, cp)); - return s; - } - - protected abstract short getSignatureAlgorithm(); - - protected abstract DSA createDSAImpl(short hashAlgorithm); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDSSSigner.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDSSSigner.java deleted file mode 100644 index 8c1baa8f3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsDSSSigner.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.crypto.DSA; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.DSAPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.signers.DSASigner; -import com.fr.third.org.bouncycastle.crypto.signers.HMacDSAKCalculator; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsDSSSigner - extends TlsDSASigner -{ - public boolean isValidPublicKey(AsymmetricKeyParameter publicKey) - { - return publicKey instanceof DSAPublicKeyParameters; - } - - protected DSA createDSAImpl(short hashAlgorithm) - { - return new DSASigner(new HMacDSAKCalculator(TlsUtils.createHash(hashAlgorithm))); - } - - protected short getSignatureAlgorithm() - { - return SignatureAlgorithm.dsa; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsECCUtils.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsECCUtils.java deleted file mode 100644 index 76299b7a4..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsECCUtils.java +++ /dev/null @@ -1,764 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.math.BigInteger; -import java.security.SecureRandom; -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.asn1.x9.ECNamedCurveTable; -import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; -import com.fr.third.org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import com.fr.third.org.bouncycastle.crypto.agreement.ECDHBasicAgreement; -import com.fr.third.org.bouncycastle.crypto.ec.CustomNamedCurves; -import com.fr.third.org.bouncycastle.crypto.generators.ECKeyPairGenerator; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.math.ec.ECAlgorithms; -import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.math.ec.ECFieldElement; -import com.fr.third.org.bouncycastle.math.ec.ECPoint; -import com.fr.third.org.bouncycastle.math.field.PolynomialExtensionField; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.BigIntegers; -import com.fr.third.org.bouncycastle.util.Integers; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsECCUtils -{ - public static final Integer EXT_elliptic_curves = Integers.valueOf(ExtensionType.elliptic_curves); - public static final Integer EXT_ec_point_formats = Integers.valueOf(ExtensionType.ec_point_formats); - - private static final String[] CURVE_NAMES = new String[] { "sect163k1", "sect163r1", "sect163r2", "sect193r1", - "sect193r2", "sect233k1", "sect233r1", "sect239k1", "sect283k1", "sect283r1", "sect409k1", "sect409r1", - "sect571k1", "sect571r1", "secp160k1", "secp160r1", "secp160r2", "secp192k1", "secp192r1", "secp224k1", - "secp224r1", "secp256k1", "secp256r1", "secp384r1", "secp521r1", - "brainpoolP256r1", "brainpoolP384r1", "brainpoolP512r1"}; - - public static void addSupportedEllipticCurvesExtension(Hashtable extensions, int[] namedCurves) throws IOException - { - extensions.put(EXT_elliptic_curves, createSupportedEllipticCurvesExtension(namedCurves)); - } - - public static void addSupportedPointFormatsExtension(Hashtable extensions, short[] ecPointFormats) - throws IOException - { - extensions.put(EXT_ec_point_formats, createSupportedPointFormatsExtension(ecPointFormats)); - } - - public static int[] getSupportedEllipticCurvesExtension(Hashtable extensions) throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_elliptic_curves); - return extensionData == null ? null : readSupportedEllipticCurvesExtension(extensionData); - } - - public static short[] getSupportedPointFormatsExtension(Hashtable extensions) throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_ec_point_formats); - return extensionData == null ? null : readSupportedPointFormatsExtension(extensionData); - } - - public static byte[] createSupportedEllipticCurvesExtension(int[] namedCurves) throws IOException - { - if (namedCurves == null || namedCurves.length < 1) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - return TlsUtils.encodeUint16ArrayWithUint16Length(namedCurves); - } - - public static byte[] createSupportedPointFormatsExtension(short[] ecPointFormats) throws IOException - { - if (ecPointFormats == null || !Arrays.contains(ecPointFormats, ECPointFormat.uncompressed)) - { - /* - * RFC 4492 5.1. If the Supported Point Formats Extension is indeed sent, it MUST - * contain the value 0 (uncompressed) as one of the items in the list of point formats. - */ - - // NOTE: We add it at the end (lowest preference) - ecPointFormats = Arrays.append(ecPointFormats, ECPointFormat.uncompressed); - } - - return TlsUtils.encodeUint8ArrayWithUint8Length(ecPointFormats); - } - - public static int[] readSupportedEllipticCurvesExtension(byte[] extensionData) throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - - ByteArrayInputStream buf = new ByteArrayInputStream(extensionData); - - int length = TlsUtils.readUint16(buf); - if (length < 2 || (length & 1) != 0) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - int[] namedCurves = TlsUtils.readUint16Array(length / 2, buf); - - TlsProtocol.assertEmpty(buf); - - return namedCurves; - } - - public static short[] readSupportedPointFormatsExtension(byte[] extensionData) throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - - ByteArrayInputStream buf = new ByteArrayInputStream(extensionData); - - short length = TlsUtils.readUint8(buf); - if (length < 1) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - short[] ecPointFormats = TlsUtils.readUint8Array(length, buf); - - TlsProtocol.assertEmpty(buf); - - if (!Arrays.contains(ecPointFormats, ECPointFormat.uncompressed)) - { - /* - * RFC 4492 5.1. If the Supported Point Formats Extension is indeed sent, it MUST - * contain the value 0 (uncompressed) as one of the items in the list of point formats. - */ - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - return ecPointFormats; - } - - public static String getNameOfNamedCurve(int namedCurve) - { - return isSupportedNamedCurve(namedCurve) ? CURVE_NAMES[namedCurve - 1] : null; - } - - public static ECDomainParameters getParametersForNamedCurve(int namedCurve) - { - String curveName = getNameOfNamedCurve(namedCurve); - if (curveName == null) - { - return null; - } - - // Parameters are lazily created the first time a particular curve is accessed - - X9ECParameters ecP = CustomNamedCurves.getByName(curveName); - if (ecP == null) - { - ecP = ECNamedCurveTable.getByName(curveName); - if (ecP == null) - { - return null; - } - } - - // It's a bit inefficient to do this conversion every time - return new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed()); - } - - public static boolean hasAnySupportedNamedCurves() - { - return CURVE_NAMES.length > 0; - } - - public static boolean containsECCCipherSuites(int[] cipherSuites) - { - for (int i = 0; i < cipherSuites.length; ++i) - { - if (isECCCipherSuite(cipherSuites[i])) - { - return true; - } - } - return false; - } - - public static boolean isECCCipherSuite(int cipherSuite) - { - switch (cipherSuite) - { - /* - * RFC 4492 - */ - case CipherSuite.TLS_ECDH_ECDSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_NULL_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_AES_256_CBC_SHA: - - /* - * RFC 5289 - */ - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384: - - /* - * RFC 5489 - */ - case CipherSuite.TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_ECDHE_PSK_WITH_RC4_128_SHA: - - /* - * RFC 6367 - */ - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384: - - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384: - - case CipherSuite.TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384: - - /* - * RFC 7251 - */ - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CCM: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8: - - /* - * draft-ietf-tls-chacha20-poly1305-04 - */ - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256: - - /* - * draft-zauner-tls-aes-ocb-04 - */ - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_AES_256_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_AES_256_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_AES_256_OCB: - - return true; - - default: - return false; - } - } - - public static boolean areOnSameCurve(ECDomainParameters a, ECDomainParameters b) - { - return a != null && a.equals(b); - } - - public static boolean isSupportedNamedCurve(int namedCurve) - { - return (namedCurve > 0 && namedCurve <= CURVE_NAMES.length); - } - - public static boolean isCompressionPreferred(short[] ecPointFormats, short compressionFormat) - { - if (ecPointFormats == null) - { - return false; - } - for (int i = 0; i < ecPointFormats.length; ++i) - { - short ecPointFormat = ecPointFormats[i]; - if (ecPointFormat == ECPointFormat.uncompressed) - { - return false; - } - if (ecPointFormat == compressionFormat) - { - return true; - } - } - return false; - } - - public static byte[] serializeECFieldElement(int fieldSize, BigInteger x) throws IOException - { - return BigIntegers.asUnsignedByteArray((fieldSize + 7) / 8, x); - } - - public static byte[] serializeECPoint(short[] ecPointFormats, ECPoint point) throws IOException - { - ECCurve curve = point.getCurve(); - - /* - * RFC 4492 5.7. ...an elliptic curve point in uncompressed or compressed format. Here, the - * format MUST conform to what the server has requested through a Supported Point Formats - * Extension if this extension was used, and MUST be uncompressed if this extension was not - * used. - */ - boolean compressed = false; - if (ECAlgorithms.isFpCurve(curve)) - { - compressed = isCompressionPreferred(ecPointFormats, ECPointFormat.ansiX962_compressed_prime); - } - else if (ECAlgorithms.isF2mCurve(curve)) - { - compressed = isCompressionPreferred(ecPointFormats, ECPointFormat.ansiX962_compressed_char2); - } - return point.getEncoded(compressed); - } - - public static byte[] serializeECPublicKey(short[] ecPointFormats, ECPublicKeyParameters keyParameters) - throws IOException - { - return serializeECPoint(ecPointFormats, keyParameters.getQ()); - } - - public static BigInteger deserializeECFieldElement(int fieldSize, byte[] encoding) throws IOException - { - int requiredLength = (fieldSize + 7) / 8; - if (encoding.length != requiredLength) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - return new BigInteger(1, encoding); - } - - public static ECPoint deserializeECPoint(short[] ecPointFormats, ECCurve curve, byte[] encoding) throws IOException - { - if (encoding == null || encoding.length < 1) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - short actualFormat; - switch (encoding[0]) - { - case 0x02: // compressed - case 0x03: // compressed - { - if (ECAlgorithms.isF2mCurve(curve)) - { - actualFormat = ECPointFormat.ansiX962_compressed_char2; - } - else if (ECAlgorithms.isFpCurve(curve)) - { - actualFormat = ECPointFormat.ansiX962_compressed_prime; - } - else - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - break; - } - case 0x04: // uncompressed - { - actualFormat = ECPointFormat.uncompressed; - break; - } - case 0x00: // infinity - case 0x06: // hybrid - case 0x07: // hybrid - default: - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - if (actualFormat != ECPointFormat.uncompressed - && (ecPointFormats == null || !Arrays.contains(ecPointFormats, actualFormat))) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - return curve.decodePoint(encoding); - } - - public static ECPublicKeyParameters deserializeECPublicKey(short[] ecPointFormats, ECDomainParameters curve_params, - byte[] encoding) throws IOException - { - try - { - ECPoint Y = deserializeECPoint(ecPointFormats, curve_params.getCurve(), encoding); - return new ECPublicKeyParameters(Y, curve_params); - } - catch (RuntimeException e) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter, e); - } - } - - public static byte[] calculateECDHBasicAgreement(ECPublicKeyParameters publicKey, ECPrivateKeyParameters privateKey) - { - ECDHBasicAgreement basicAgreement = new ECDHBasicAgreement(); - basicAgreement.init(privateKey); - BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey); - - /* - * RFC 4492 5.10. Note that this octet string (Z in IEEE 1363 terminology) as output by - * FE2OSP, the Field Element to Octet String Conversion Primitive, has constant length for - * any given field; leading zeros found in this octet string MUST NOT be truncated. - */ - return BigIntegers.asUnsignedByteArray(basicAgreement.getFieldSize(), agreementValue); - } - - public static AsymmetricCipherKeyPair generateECKeyPair(SecureRandom random, ECDomainParameters ecParams) - { - ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator(); - keyPairGenerator.init(new ECKeyGenerationParameters(ecParams, random)); - return keyPairGenerator.generateKeyPair(); - } - - public static ECPrivateKeyParameters generateEphemeralClientKeyExchange(SecureRandom random, short[] ecPointFormats, - ECDomainParameters ecParams, OutputStream output) throws IOException - { - AsymmetricCipherKeyPair kp = generateECKeyPair(random, ecParams); - - ECPublicKeyParameters ecPublicKey = (ECPublicKeyParameters) kp.getPublic(); - writeECPoint(ecPointFormats, ecPublicKey.getQ(), output); - - return (ECPrivateKeyParameters) kp.getPrivate(); - } - - // TODO Refactor around ServerECDHParams before making this public - static ECPrivateKeyParameters generateEphemeralServerKeyExchange(SecureRandom random, int[] namedCurves, - short[] ecPointFormats, OutputStream output) throws IOException - { - /* First we try to find a supported named curve from the client's list. */ - int namedCurve = -1; - if (namedCurves == null) - { - // TODO Let the peer choose the default named curve - namedCurve = NamedCurve.secp256r1; - } - else - { - for (int i = 0; i < namedCurves.length; ++i) - { - int entry = namedCurves[i]; - if (NamedCurve.isValid(entry) && isSupportedNamedCurve(entry)) - { - namedCurve = entry; - break; - } - } - } - - ECDomainParameters ecParams = null; - if (namedCurve >= 0) - { - ecParams = getParametersForNamedCurve(namedCurve); - } - else - { - /* If no named curves are suitable, check if the client supports explicit curves. */ - if (Arrays.contains(namedCurves, NamedCurve.arbitrary_explicit_prime_curves)) - { - ecParams = getParametersForNamedCurve(NamedCurve.secp256r1); - } - else if (Arrays.contains(namedCurves, NamedCurve.arbitrary_explicit_char2_curves)) - { - ecParams = getParametersForNamedCurve(NamedCurve.sect283r1); - } - } - - if (ecParams == null) - { - /* - * NOTE: We shouldn't have negotiated ECDHE key exchange since we apparently can't find - * a suitable curve. - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - if (namedCurve < 0) - { - writeExplicitECParameters(ecPointFormats, ecParams, output); - } - else - { - writeNamedECParameters(namedCurve, output); - } - - return generateEphemeralClientKeyExchange(random, ecPointFormats, ecParams, output); - } - - public static ECPublicKeyParameters validateECPublicKey(ECPublicKeyParameters key) throws IOException - { - // TODO Check RFC 4492 for validation - return key; - } - - public static int readECExponent(int fieldSize, InputStream input) throws IOException - { - BigInteger K = readECParameter(input); - if (K.bitLength() < 32) - { - int k = K.intValue(); - if (k > 0 && k < fieldSize) - { - return k; - } - } - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - public static BigInteger readECFieldElement(int fieldSize, InputStream input) throws IOException - { - return deserializeECFieldElement(fieldSize, TlsUtils.readOpaque8(input)); - } - - public static BigInteger readECParameter(InputStream input) throws IOException - { - // TODO Are leading zeroes okay here? - return new BigInteger(1, TlsUtils.readOpaque8(input)); - } - - public static ECDomainParameters readECParameters(int[] namedCurves, short[] ecPointFormats, InputStream input) - throws IOException - { - try - { - short curveType = TlsUtils.readUint8(input); - - switch (curveType) - { - case ECCurveType.explicit_prime: - { - checkNamedCurve(namedCurves, NamedCurve.arbitrary_explicit_prime_curves); - - BigInteger prime_p = readECParameter(input); - BigInteger a = readECFieldElement(prime_p.bitLength(), input); - BigInteger b = readECFieldElement(prime_p.bitLength(), input); - byte[] baseEncoding = TlsUtils.readOpaque8(input); - BigInteger order = readECParameter(input); - BigInteger cofactor = readECParameter(input); - ECCurve curve = new ECCurve.Fp(prime_p, a, b, order, cofactor); - ECPoint base = deserializeECPoint(ecPointFormats, curve, baseEncoding); - return new ECDomainParameters(curve, base, order, cofactor); - } - case ECCurveType.explicit_char2: - { - checkNamedCurve(namedCurves, NamedCurve.arbitrary_explicit_char2_curves); - - int m = TlsUtils.readUint16(input); - short basis = TlsUtils.readUint8(input); - if (!ECBasisType.isValid(basis)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - int k1 = readECExponent(m, input), k2 = -1, k3 = -1; - if (basis == ECBasisType.ec_basis_pentanomial) - { - k2 = readECExponent(m, input); - k3 = readECExponent(m, input); - } - - BigInteger a = readECFieldElement(m, input); - BigInteger b = readECFieldElement(m, input); - byte[] baseEncoding = TlsUtils.readOpaque8(input); - BigInteger order = readECParameter(input); - BigInteger cofactor = readECParameter(input); - - ECCurve curve = (basis == ECBasisType.ec_basis_pentanomial) - ? new ECCurve.F2m(m, k1, k2, k3, a, b, order, cofactor) - : new ECCurve.F2m(m, k1, a, b, order, cofactor); - - ECPoint base = deserializeECPoint(ecPointFormats, curve, baseEncoding); - - return new ECDomainParameters(curve, base, order, cofactor); - } - case ECCurveType.named_curve: - { - int namedCurve = TlsUtils.readUint16(input); - if (!NamedCurve.refersToASpecificNamedCurve(namedCurve)) - { - /* - * RFC 4492 5.4. All those values of NamedCurve are allowed that refer to a - * specific curve. Values of NamedCurve that indicate support for a class of - * explicitly defined curves are not allowed here [...]. - */ - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - checkNamedCurve(namedCurves, namedCurve); - - return getParametersForNamedCurve(namedCurve); - } - default: - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - catch (RuntimeException e) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter, e); - } - } - - private static void checkNamedCurve(int[] namedCurves, int namedCurve) throws IOException - { - if (namedCurves != null && !Arrays.contains(namedCurves, namedCurve)) - { - /* - * RFC 4492 4. [...] servers MUST NOT negotiate the use of an ECC cipher suite - * unless they can complete the handshake while respecting the choice of curves - * and compression techniques specified by the client. - */ - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - - public static void writeECExponent(int k, OutputStream output) throws IOException - { - BigInteger K = BigInteger.valueOf(k); - writeECParameter(K, output); - } - - public static void writeECFieldElement(ECFieldElement x, OutputStream output) throws IOException - { - TlsUtils.writeOpaque8(x.getEncoded(), output); - } - - public static void writeECFieldElement(int fieldSize, BigInteger x, OutputStream output) throws IOException - { - TlsUtils.writeOpaque8(serializeECFieldElement(fieldSize, x), output); - } - - public static void writeECParameter(BigInteger x, OutputStream output) throws IOException - { - TlsUtils.writeOpaque8(BigIntegers.asUnsignedByteArray(x), output); - } - - public static void writeExplicitECParameters(short[] ecPointFormats, ECDomainParameters ecParameters, - OutputStream output) throws IOException - { - ECCurve curve = ecParameters.getCurve(); - - if (ECAlgorithms.isFpCurve(curve)) - { - TlsUtils.writeUint8(ECCurveType.explicit_prime, output); - - writeECParameter(curve.getField().getCharacteristic(), output); - } - else if (ECAlgorithms.isF2mCurve(curve)) - { - PolynomialExtensionField field = (PolynomialExtensionField)curve.getField(); - int[] exponents = field.getMinimalPolynomial().getExponentsPresent(); - - TlsUtils.writeUint8(ECCurveType.explicit_char2, output); - - int m = exponents[exponents.length - 1]; - TlsUtils.checkUint16(m); - TlsUtils.writeUint16(m, output); - - if (exponents.length == 3) - { - TlsUtils.writeUint8(ECBasisType.ec_basis_trinomial, output); - writeECExponent(exponents[1], output); - } - else if (exponents.length == 5) - { - TlsUtils.writeUint8(ECBasisType.ec_basis_pentanomial, output); - writeECExponent(exponents[1], output); - writeECExponent(exponents[2], output); - writeECExponent(exponents[3], output); - } - else - { - throw new IllegalArgumentException("Only trinomial and pentomial curves are supported"); - } - } - else - { - throw new IllegalArgumentException("'ecParameters' not a known curve type"); - } - - writeECFieldElement(curve.getA(), output); - writeECFieldElement(curve.getB(), output); - TlsUtils.writeOpaque8(serializeECPoint(ecPointFormats, ecParameters.getG()), output); - writeECParameter(ecParameters.getN(), output); - writeECParameter(ecParameters.getH(), output); - } - - public static void writeECPoint(short[] ecPointFormats, ECPoint point, OutputStream output) throws IOException - { - TlsUtils.writeOpaque8(serializeECPoint(ecPointFormats, point), output); - } - - public static void writeNamedECParameters(int namedCurve, OutputStream output) throws IOException - { - if (!NamedCurve.refersToASpecificNamedCurve(namedCurve)) - { - /* - * RFC 4492 5.4. All those values of NamedCurve are allowed that refer to a specific - * curve. Values of NamedCurve that indicate support for a class of explicitly defined - * curves are not allowed here [...]. - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - TlsUtils.writeUint8(ECCurveType.named_curve, output); - TlsUtils.checkUint16(namedCurve); - TlsUtils.writeUint16(namedCurve, output); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsECDHEKeyExchange.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsECDHEKeyExchange.java deleted file mode 100644 index b6306fe32..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsECDHEKeyExchange.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.Signer; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.util.io.TeeInputStream; - -/** - * (D)TLS ECDHE key exchange (see RFC 4492). - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsECDHEKeyExchange - extends TlsECDHKeyExchange -{ - protected TlsSignerCredentials serverCredentials = null; - - public TlsECDHEKeyExchange(int keyExchange, Vector supportedSignatureAlgorithms, int[] namedCurves, - short[] clientECPointFormats, short[] serverECPointFormats) - { - super(keyExchange, supportedSignatureAlgorithms, namedCurves, clientECPointFormats, serverECPointFormats); - } - - public void processServerCredentials(TlsCredentials serverCredentials) - throws IOException - { - if (!(serverCredentials instanceof TlsSignerCredentials)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - processServerCertificate(serverCredentials.getCertificate()); - - this.serverCredentials = (TlsSignerCredentials)serverCredentials; - } - - public byte[] generateServerKeyExchange() - throws IOException - { - DigestInputBuffer buf = new DigestInputBuffer(); - - this.ecAgreePrivateKey = TlsECCUtils.generateEphemeralServerKeyExchange(context.getSecureRandom(), namedCurves, - clientECPointFormats, buf); - - /* - * RFC 5246 4.7. digitally-signed element needs SignatureAndHashAlgorithm from TLS 1.2 - */ - SignatureAndHashAlgorithm signatureAndHashAlgorithm = TlsUtils.getSignatureAndHashAlgorithm( - context, serverCredentials); - - Digest d = TlsUtils.createHash(signatureAndHashAlgorithm); - - SecurityParameters securityParameters = context.getSecurityParameters(); - d.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length); - d.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length); - buf.updateDigest(d); - - byte[] hash = new byte[d.getDigestSize()]; - d.doFinal(hash, 0); - - byte[] signature = serverCredentials.generateCertificateSignature(hash); - - DigitallySigned signed_params = new DigitallySigned(signatureAndHashAlgorithm, signature); - signed_params.encode(buf); - - return buf.toByteArray(); - } - - public void processServerKeyExchange(InputStream input) - throws IOException - { - SecurityParameters securityParameters = context.getSecurityParameters(); - - SignerInputBuffer buf = new SignerInputBuffer(); - InputStream teeIn = new TeeInputStream(input, buf); - - ECDomainParameters curve_params = TlsECCUtils.readECParameters(namedCurves, clientECPointFormats, teeIn); - - byte[] point = TlsUtils.readOpaque8(teeIn); - - DigitallySigned signed_params = parseSignature(input); - - Signer signer = initVerifyer(tlsSigner, signed_params.getAlgorithm(), securityParameters); - buf.updateSigner(signer); - if (!signer.verifySignature(signed_params.getSignature())) - { - throw new TlsFatalAlert(AlertDescription.decrypt_error); - } - - this.ecAgreePublicKey = TlsECCUtils.validateECPublicKey(TlsECCUtils.deserializeECPublicKey( - clientECPointFormats, curve_params, point)); - } - - public void validateCertificateRequest(CertificateRequest certificateRequest) - throws IOException - { - /* - * RFC 4492 3. [...] The ECDSA_fixed_ECDH and RSA_fixed_ECDH mechanisms are usable with - * ECDH_ECDSA and ECDH_RSA. Their use with ECDHE_ECDSA and ECDHE_RSA is prohibited because - * the use of a long-term ECDH client key would jeopardize the forward secrecy property of - * these algorithms. - */ - short[] types = certificateRequest.getCertificateTypes(); - for (int i = 0; i < types.length; ++i) - { - switch (types[i]) - { - case ClientCertificateType.rsa_sign: - case ClientCertificateType.dss_sign: - case ClientCertificateType.ecdsa_sign: - break; - default: - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - } - - public void processClientCredentials(TlsCredentials clientCredentials) - throws IOException - { - if (clientCredentials instanceof TlsSignerCredentials) - { - // OK - } - else - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - protected Signer initVerifyer(TlsSigner tlsSigner, SignatureAndHashAlgorithm algorithm, SecurityParameters securityParameters) - { - Signer signer = tlsSigner.createVerifyer(algorithm, this.serverPublicKey); - signer.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length); - signer.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length); - return signer; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsECDHKeyExchange.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsECDHKeyExchange.java deleted file mode 100644 index eeb491cf9..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsECDHKeyExchange.java +++ /dev/null @@ -1,278 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.x509.KeyUsage; -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.util.PublicKeyFactory; - -/** - * (D)TLS ECDH key exchange (see RFC 4492). - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsECDHKeyExchange extends AbstractTlsKeyExchange -{ - protected TlsSigner tlsSigner; - protected int[] namedCurves; - protected short[] clientECPointFormats, serverECPointFormats; - - protected AsymmetricKeyParameter serverPublicKey; - protected TlsAgreementCredentials agreementCredentials; - - protected ECPrivateKeyParameters ecAgreePrivateKey; - protected ECPublicKeyParameters ecAgreePublicKey; - - public TlsECDHKeyExchange(int keyExchange, Vector supportedSignatureAlgorithms, int[] namedCurves, - short[] clientECPointFormats, short[] serverECPointFormats) - { - super(keyExchange, supportedSignatureAlgorithms); - - switch (keyExchange) - { - case KeyExchangeAlgorithm.ECDHE_RSA: - this.tlsSigner = new TlsRSASigner(); - break; - case KeyExchangeAlgorithm.ECDHE_ECDSA: - this.tlsSigner = new TlsECDSASigner(); - break; - case KeyExchangeAlgorithm.ECDH_anon: - case KeyExchangeAlgorithm.ECDH_RSA: - case KeyExchangeAlgorithm.ECDH_ECDSA: - this.tlsSigner = null; - break; - default: - throw new IllegalArgumentException("unsupported key exchange algorithm"); - } - - this.namedCurves = namedCurves; - this.clientECPointFormats = clientECPointFormats; - this.serverECPointFormats = serverECPointFormats; - } - - public void init(TlsContext context) - { - super.init(context); - - if (this.tlsSigner != null) - { - this.tlsSigner.init(context); - } - } - - public void skipServerCredentials() throws IOException - { - if (keyExchange != KeyExchangeAlgorithm.ECDH_anon) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - - public void processServerCertificate(Certificate serverCertificate) throws IOException - { - if (keyExchange == KeyExchangeAlgorithm.ECDH_anon) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - if (serverCertificate.isEmpty()) - { - throw new TlsFatalAlert(AlertDescription.bad_certificate); - } - - com.fr.third.org.bouncycastle.asn1.x509.Certificate x509Cert = serverCertificate.getCertificateAt(0); - - SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo(); - try - { - this.serverPublicKey = PublicKeyFactory.createKey(keyInfo); - } - catch (RuntimeException e) - { - throw new TlsFatalAlert(AlertDescription.unsupported_certificate, e); - } - - if (tlsSigner == null) - { - try - { - this.ecAgreePublicKey = TlsECCUtils.validateECPublicKey((ECPublicKeyParameters) this.serverPublicKey); - } - catch (ClassCastException e) - { - throw new TlsFatalAlert(AlertDescription.certificate_unknown, e); - } - - TlsUtils.validateKeyUsage(x509Cert, KeyUsage.keyAgreement); - } - else - { - if (!tlsSigner.isValidPublicKey(this.serverPublicKey)) - { - throw new TlsFatalAlert(AlertDescription.certificate_unknown); - } - - TlsUtils.validateKeyUsage(x509Cert, KeyUsage.digitalSignature); - } - - super.processServerCertificate(serverCertificate); - } - - public boolean requiresServerKeyExchange() - { - switch (keyExchange) - { - case KeyExchangeAlgorithm.ECDH_anon: - case KeyExchangeAlgorithm.ECDHE_ECDSA: - case KeyExchangeAlgorithm.ECDHE_RSA: - return true; - default: - return false; - } - } - - public byte[] generateServerKeyExchange() - throws IOException - { - if (!requiresServerKeyExchange()) - { - return null; - } - - // ECDH_anon is handled here, ECDHE_* in a subclass - - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - this.ecAgreePrivateKey = TlsECCUtils.generateEphemeralServerKeyExchange(context.getSecureRandom(), namedCurves, - clientECPointFormats, buf); - return buf.toByteArray(); - } - - public void processServerKeyExchange(InputStream input) - throws IOException - { - if (!requiresServerKeyExchange()) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - // ECDH_anon is handled here, ECDHE_* in a subclass - - ECDomainParameters curve_params = TlsECCUtils.readECParameters(namedCurves, clientECPointFormats, input); - - byte[] point = TlsUtils.readOpaque8(input); - - this.ecAgreePublicKey = TlsECCUtils.validateECPublicKey(TlsECCUtils.deserializeECPublicKey( - clientECPointFormats, curve_params, point)); - } - - public void validateCertificateRequest(CertificateRequest certificateRequest) throws IOException - { - if (keyExchange == KeyExchangeAlgorithm.ECDH_anon) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - /* - * RFC 4492 3. [...] The ECDSA_fixed_ECDH and RSA_fixed_ECDH mechanisms are usable with - * ECDH_ECDSA and ECDH_RSA. Their use with ECDHE_ECDSA and ECDHE_RSA is prohibited because - * the use of a long-term ECDH client key would jeopardize the forward secrecy property of - * these algorithms. - */ - short[] types = certificateRequest.getCertificateTypes(); - for (int i = 0; i < types.length; ++i) - { - switch (types[i]) - { - case ClientCertificateType.rsa_sign: - case ClientCertificateType.dss_sign: - case ClientCertificateType.ecdsa_sign: - case ClientCertificateType.rsa_fixed_ecdh: - case ClientCertificateType.ecdsa_fixed_ecdh: - break; - default: - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - } - - public void processClientCredentials(TlsCredentials clientCredentials) throws IOException - { - if (keyExchange == KeyExchangeAlgorithm.ECDH_anon) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - if (clientCredentials instanceof TlsAgreementCredentials) - { - // TODO Validate client cert has matching parameters (see 'TlsECCUtils.areOnSameCurve')? - - this.agreementCredentials = (TlsAgreementCredentials)clientCredentials; - } - else if (clientCredentials instanceof TlsSignerCredentials) - { - // OK - } - else - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public void generateClientKeyExchange(OutputStream output) throws IOException - { - if (agreementCredentials == null) - { - this.ecAgreePrivateKey = TlsECCUtils.generateEphemeralClientKeyExchange(context.getSecureRandom(), - serverECPointFormats, ecAgreePublicKey.getParameters(), output); - } - } - - public void processClientCertificate(Certificate clientCertificate) throws IOException - { - if (keyExchange == KeyExchangeAlgorithm.ECDH_anon) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - // TODO Extract the public key - // TODO If the certificate is 'fixed', take the public key as ecAgreeClientPublicKey - } - - public void processClientKeyExchange(InputStream input) throws IOException - { - if (ecAgreePublicKey != null) - { - // For ecdsa_fixed_ecdh and rsa_fixed_ecdh, the key arrived in the client certificate - return; - } - - byte[] point = TlsUtils.readOpaque8(input); - - ECDomainParameters curve_params = this.ecAgreePrivateKey.getParameters(); - - this.ecAgreePublicKey = TlsECCUtils.validateECPublicKey(TlsECCUtils.deserializeECPublicKey( - serverECPointFormats, curve_params, point)); - } - - public byte[] generatePremasterSecret() throws IOException - { - if (agreementCredentials != null) - { - return agreementCredentials.generateAgreement(ecAgreePublicKey); - } - - if (ecAgreePrivateKey != null) - { - return TlsECCUtils.calculateECDHBasicAgreement(ecAgreePublicKey, ecAgreePrivateKey); - } - - throw new TlsFatalAlert(AlertDescription.internal_error); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsECDSASigner.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsECDSASigner.java deleted file mode 100644 index 66a5feff2..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsECDSASigner.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.crypto.DSA; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.signers.ECDSASigner; -import com.fr.third.org.bouncycastle.crypto.signers.HMacDSAKCalculator; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsECDSASigner - extends TlsDSASigner -{ - public boolean isValidPublicKey(AsymmetricKeyParameter publicKey) - { - return publicKey instanceof ECPublicKeyParameters; - } - - protected DSA createDSAImpl(short hashAlgorithm) - { - return new ECDSASigner(new HMacDSAKCalculator(TlsUtils.createHash(hashAlgorithm))); - } - - protected short getSignatureAlgorithm() - { - return SignatureAlgorithm.ecdsa; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsEncryptionCredentials.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsEncryptionCredentials.java deleted file mode 100644 index 3105946cd..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsEncryptionCredentials.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsEncryptionCredentials extends TlsCredentials -{ - byte[] decryptPreMasterSecret(byte[] encryptedPreMasterSecret) - throws IOException; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsException.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsException.java deleted file mode 100644 index 4939ed9df..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsException.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsException - extends IOException -{ - // TODO Some day we might be able to just pass this down to IOException (1.6+) - protected Throwable cause; - - public TlsException(String message, Throwable cause) - { - super(message); - - this.cause = cause; - } - - public Throwable getCause() - { - return cause; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsExtensionsUtils.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsExtensionsUtils.java deleted file mode 100644 index 79b3d253d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsExtensionsUtils.java +++ /dev/null @@ -1,322 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.util.Integers; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsExtensionsUtils -{ - public static final Integer EXT_encrypt_then_mac = Integers.valueOf(ExtensionType.encrypt_then_mac); - public static final Integer EXT_extended_master_secret = Integers.valueOf(ExtensionType.extended_master_secret); - public static final Integer EXT_heartbeat = Integers.valueOf(ExtensionType.heartbeat); - public static final Integer EXT_max_fragment_length = Integers.valueOf(ExtensionType.max_fragment_length); - public static final Integer EXT_padding = Integers.valueOf(ExtensionType.padding); - public static final Integer EXT_server_name = Integers.valueOf(ExtensionType.server_name); - public static final Integer EXT_status_request = Integers.valueOf(ExtensionType.status_request); - public static final Integer EXT_truncated_hmac = Integers.valueOf(ExtensionType.truncated_hmac); - - public static Hashtable ensureExtensionsInitialised(Hashtable extensions) - { - return extensions == null ? new Hashtable() : extensions; - } - - public static void addEncryptThenMACExtension(Hashtable extensions) - { - extensions.put(EXT_encrypt_then_mac, createEncryptThenMACExtension()); - } - - public static void addExtendedMasterSecretExtension(Hashtable extensions) - { - extensions.put(EXT_extended_master_secret, createExtendedMasterSecretExtension()); - } - - public static void addHeartbeatExtension(Hashtable extensions, HeartbeatExtension heartbeatExtension) - throws IOException - { - extensions.put(EXT_heartbeat, createHeartbeatExtension(heartbeatExtension)); - } - - public static void addMaxFragmentLengthExtension(Hashtable extensions, short maxFragmentLength) - throws IOException - { - extensions.put(EXT_max_fragment_length, createMaxFragmentLengthExtension(maxFragmentLength)); - } - - public static void addPaddingExtension(Hashtable extensions, int dataLength) - throws IOException - { - extensions.put(EXT_padding, createPaddingExtension(dataLength)); - } - - public static void addServerNameExtension(Hashtable extensions, ServerNameList serverNameList) - throws IOException - { - extensions.put(EXT_server_name, createServerNameExtension(serverNameList)); - } - - public static void addStatusRequestExtension(Hashtable extensions, CertificateStatusRequest statusRequest) - throws IOException - { - extensions.put(EXT_status_request, createStatusRequestExtension(statusRequest)); - } - - public static void addTruncatedHMacExtension(Hashtable extensions) - { - extensions.put(EXT_truncated_hmac, createTruncatedHMacExtension()); - } - - public static HeartbeatExtension getHeartbeatExtension(Hashtable extensions) - throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_heartbeat); - return extensionData == null ? null : readHeartbeatExtension(extensionData); - } - - public static short getMaxFragmentLengthExtension(Hashtable extensions) - throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_max_fragment_length); - return extensionData == null ? -1 : readMaxFragmentLengthExtension(extensionData); - } - - public static int getPaddingExtension(Hashtable extensions) - throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_padding); - return extensionData == null ? -1 : readPaddingExtension(extensionData); - } - - public static ServerNameList getServerNameExtension(Hashtable extensions) - throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_server_name); - return extensionData == null ? null : readServerNameExtension(extensionData); - } - - public static CertificateStatusRequest getStatusRequestExtension(Hashtable extensions) - throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_status_request); - return extensionData == null ? null : readStatusRequestExtension(extensionData); - } - - public static boolean hasEncryptThenMACExtension(Hashtable extensions) throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_encrypt_then_mac); - return extensionData == null ? false : readEncryptThenMACExtension(extensionData); - } - - public static boolean hasExtendedMasterSecretExtension(Hashtable extensions) throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_extended_master_secret); - return extensionData == null ? false : readExtendedMasterSecretExtension(extensionData); - } - - public static boolean hasTruncatedHMacExtension(Hashtable extensions) throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_truncated_hmac); - return extensionData == null ? false : readTruncatedHMacExtension(extensionData); - } - - public static byte[] createEmptyExtensionData() - { - return TlsUtils.EMPTY_BYTES; - } - - public static byte[] createEncryptThenMACExtension() - { - return createEmptyExtensionData(); - } - - public static byte[] createExtendedMasterSecretExtension() - { - return createEmptyExtensionData(); - } - - public static byte[] createHeartbeatExtension(HeartbeatExtension heartbeatExtension) - throws IOException - { - if (heartbeatExtension == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - heartbeatExtension.encode(buf); - - return buf.toByteArray(); - } - - public static byte[] createMaxFragmentLengthExtension(short maxFragmentLength) - throws IOException - { - TlsUtils.checkUint8(maxFragmentLength); - - byte[] extensionData = new byte[1]; - TlsUtils.writeUint8(maxFragmentLength, extensionData, 0); - return extensionData; - } - - public static byte[] createPaddingExtension(int dataLength) - throws IOException - { - TlsUtils.checkUint16(dataLength); - return new byte[dataLength]; - } - - public static byte[] createServerNameExtension(ServerNameList serverNameList) - throws IOException - { - if (serverNameList == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - serverNameList.encode(buf); - - return buf.toByteArray(); - } - - public static byte[] createStatusRequestExtension(CertificateStatusRequest statusRequest) - throws IOException - { - if (statusRequest == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - statusRequest.encode(buf); - - return buf.toByteArray(); - } - - public static byte[] createTruncatedHMacExtension() - { - return createEmptyExtensionData(); - } - - private static boolean readEmptyExtensionData(byte[] extensionData) throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - - if (extensionData.length != 0) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - return true; - } - - public static boolean readEncryptThenMACExtension(byte[] extensionData) throws IOException - { - return readEmptyExtensionData(extensionData); - } - - public static boolean readExtendedMasterSecretExtension(byte[] extensionData) throws IOException - { - return readEmptyExtensionData(extensionData); - } - - public static HeartbeatExtension readHeartbeatExtension(byte[] extensionData) - throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - - ByteArrayInputStream buf = new ByteArrayInputStream(extensionData); - - HeartbeatExtension heartbeatExtension = HeartbeatExtension.parse(buf); - - TlsProtocol.assertEmpty(buf); - - return heartbeatExtension; - } - - public static short readMaxFragmentLengthExtension(byte[] extensionData) - throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - - if (extensionData.length != 1) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - return TlsUtils.readUint8(extensionData, 0); - } - - public static int readPaddingExtension(byte[] extensionData) - throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - for (int i = 0; i < extensionData.length; ++i) - { - if (extensionData[i] != 0) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - return extensionData.length; - } - - public static ServerNameList readServerNameExtension(byte[] extensionData) - throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - - ByteArrayInputStream buf = new ByteArrayInputStream(extensionData); - - ServerNameList serverNameList = ServerNameList.parse(buf); - - TlsProtocol.assertEmpty(buf); - - return serverNameList; - } - - public static CertificateStatusRequest readStatusRequestExtension(byte[] extensionData) - throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - - ByteArrayInputStream buf = new ByteArrayInputStream(extensionData); - - CertificateStatusRequest statusRequest = CertificateStatusRequest.parse(buf); - - TlsProtocol.assertEmpty(buf); - - return statusRequest; - } - - public static boolean readTruncatedHMacExtension(byte[] extensionData) throws IOException - { - return readEmptyExtensionData(extensionData); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsFatalAlert.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsFatalAlert.java deleted file mode 100644 index 8cdd673a4..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsFatalAlert.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsFatalAlert - extends TlsException -{ - protected short alertDescription; - - public TlsFatalAlert(short alertDescription) - { - this(alertDescription, null); - } - - public TlsFatalAlert(short alertDescription, Throwable alertCause) - { - super(AlertDescription.getText(alertDescription), alertCause); - - this.alertDescription = alertDescription; - } - - public short getAlertDescription() - { - return alertDescription; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsFatalAlertReceived.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsFatalAlertReceived.java deleted file mode 100644 index e3bdbc8ea..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsFatalAlertReceived.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsFatalAlertReceived - extends TlsException -{ - protected short alertDescription; - - public TlsFatalAlertReceived(short alertDescription) - { - super(AlertDescription.getText(alertDescription), null); - - this.alertDescription = alertDescription; - } - - public short getAlertDescription() - { - return alertDescription; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsHandshakeHash.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsHandshakeHash.java deleted file mode 100644 index b18b0ea03..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsHandshakeHash.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.crypto.Digest; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsHandshakeHash - extends Digest -{ - void init(TlsContext context); - - TlsHandshakeHash notifyPRFDetermined(); - - void trackHashAlgorithm(short hashAlgorithm); - - void sealHashAlgorithms(); - - TlsHandshakeHash stopTracking(); - - Digest forkPRFHash(); - - byte[] getFinalHash(short hashAlgorithm); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsInputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsInputStream.java deleted file mode 100644 index b3bb0fb79..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsInputStream.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; - -/** - * An InputStream for an TLS 1.0 connection. - */ -class TlsInputStream - extends InputStream -{ - private byte[] buf = new byte[1]; - private TlsProtocol handler = null; - - TlsInputStream(TlsProtocol handler) - { - this.handler = handler; - } - - public int available() - throws IOException - { - return this.handler.applicationDataAvailable(); - } - - public int read(byte[] buf, int offset, int len) - throws IOException - { - return this.handler.readApplicationData(buf, offset, len); - } - - public int read() - throws IOException - { - if (this.read(buf) < 0) - { - return -1; - } - return buf[0] & 0xff; - } - - public void close() - throws IOException - { - handler.close(); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsKeyExchange.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsKeyExchange.java deleted file mode 100644 index 6db8f0438..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsKeyExchange.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * A generic interface for key exchange implementations in (D)TLS. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsKeyExchange -{ - void init(TlsContext context); - - void skipServerCredentials() - throws IOException; - - void processServerCredentials(TlsCredentials serverCredentials) - throws IOException; - - void processServerCertificate(Certificate serverCertificate) - throws IOException; - - boolean requiresServerKeyExchange(); - - byte[] generateServerKeyExchange() - throws IOException; - - void skipServerKeyExchange() - throws IOException; - - void processServerKeyExchange(InputStream input) - throws IOException; - - void validateCertificateRequest(CertificateRequest certificateRequest) - throws IOException; - - void skipClientCredentials() - throws IOException; - - void processClientCredentials(TlsCredentials clientCredentials) - throws IOException; - - void processClientCertificate(Certificate clientCertificate) - throws IOException; - - void generateClientKeyExchange(OutputStream output) - throws IOException; - - void processClientKeyExchange(InputStream input) - throws IOException; - - byte[] generatePremasterSecret() - throws IOException; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsMac.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsMac.java deleted file mode 100644 index 01d1d0455..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsMac.java +++ /dev/null @@ -1,174 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.Mac; -import com.fr.third.org.bouncycastle.crypto.digests.LongDigest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * A generic TLS MAC implementation, acting as an HMAC based on some underlying Digest. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsMac -{ - protected TlsContext context; - protected byte[] secret; - protected Mac mac; - protected int digestBlockSize; - protected int digestOverhead; - protected int macLength; - - /** - * Generate a new instance of an TlsMac. - * - * @param context the TLS client context - * @param digest The digest to use. - * @param key A byte-array where the key for this MAC is located. - * @param keyOff The number of bytes to skip, before the key starts in the buffer. - * @param keyLen The length of the key. - */ - public TlsMac(TlsContext context, Digest digest, byte[] key, int keyOff, int keyLen) - { - this.context = context; - - KeyParameter keyParameter = new KeyParameter(key, keyOff, keyLen); - - this.secret = Arrays.clone(keyParameter.getKey()); - - // TODO This should check the actual algorithm, not rely on the engine type - if (digest instanceof LongDigest) - { - this.digestBlockSize = 128; - this.digestOverhead = 16; - } - else - { - this.digestBlockSize = 64; - this.digestOverhead = 8; - } - - if (TlsUtils.isSSL(context)) - { - this.mac = new SSL3Mac(digest); - - // TODO This should check the actual algorithm, not assume based on the digest size - if (digest.getDigestSize() == 20) - { - /* - * NOTE: When SHA-1 is used with the SSL 3.0 MAC, the secret + input pad is not - * digest block-aligned. - */ - this.digestOverhead = 4; - } - } - else - { - this.mac = new HMac(digest); - - // NOTE: The input pad for HMAC is always a full digest block - } - - this.mac.init(keyParameter); - - this.macLength = mac.getMacSize(); - if (context.getSecurityParameters().truncatedHMac) - { - this.macLength = Math.min(this.macLength, 10); - } - } - - /** - * @return the MAC write secret - */ - public byte[] getMACSecret() - { - return this.secret; - } - - /** - * @return The output length of this MAC. - */ - public int getSize() - { - return macLength; - } - - /** - * Calculate the MAC for some given data. - * - * @param type The message type of the message. - * @param message A byte-buffer containing the message. - * @param offset The number of bytes to skip, before the message starts. - * @param length The length of the message. - * @return A new byte-buffer containing the MAC value. - */ - public byte[] calculateMac(long seqNo, short type, byte[] message, int offset, int length) - { - ProtocolVersion serverVersion = context.getServerVersion(); - boolean isSSL = serverVersion.isSSL(); - - byte[] macHeader = new byte[isSSL ? 11 : 13]; - TlsUtils.writeUint64(seqNo, macHeader, 0); - TlsUtils.writeUint8(type, macHeader, 8); - if (!isSSL) - { - TlsUtils.writeVersion(serverVersion, macHeader, 9); - } - TlsUtils.writeUint16(length, macHeader, macHeader.length - 2); - - mac.update(macHeader, 0, macHeader.length); - mac.update(message, offset, length); - - byte[] result = new byte[mac.getMacSize()]; - mac.doFinal(result, 0); - return truncate(result); - } - - public byte[] calculateMacConstantTime(long seqNo, short type, byte[] message, int offset, int length, - int fullLength, byte[] dummyData) - { - /* - * Actual MAC only calculated on 'length' bytes... - */ - byte[] result = calculateMac(seqNo, type, message, offset, length); - - /* - * ...but ensure a constant number of complete digest blocks are processed (as many as would - * be needed for 'fullLength' bytes of input). - */ - int headerLength = TlsUtils.isSSL(context) ? 11 : 13; - - // How many extra full blocks do we need to calculate? - int extra = getDigestBlockCount(headerLength + fullLength) - getDigestBlockCount(headerLength + length); - - while (--extra >= 0) - { - mac.update(dummyData, 0, digestBlockSize); - } - - // One more byte in case the implementation is "lazy" about processing blocks - mac.update(dummyData[0]); - mac.reset(); - - return result; - } - - protected int getDigestBlockCount(int inputLength) - { - // NOTE: This calculation assumes a minimum of 1 pad byte - return (inputLength + digestOverhead) / digestBlockSize; - } - - protected byte[] truncate(byte[] bs) - { - if (bs.length <= macLength) - { - return bs; - } - - return Arrays.copyOf(bs, macLength); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsNoCloseNotifyException.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsNoCloseNotifyException.java deleted file mode 100644 index 731431d96..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsNoCloseNotifyException.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.EOFException; - -/** - * This exception will be thrown (only) when the connection is closed by the peer without sending a - * {@link AlertDescription#close_notify close_notify} warning alert. If this happens, the TLS - * protocol cannot rule out truncation of the connection data (potentially malicious). It may be - * possible to check for truncation via some property of a higher level protocol built upon TLS, - * e.g. the Content-Length header for HTTPS. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsNoCloseNotifyException - extends EOFException -{ - public TlsNoCloseNotifyException() - { - super("No close_notify alert received before connection closed"); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsNullCipher.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsNullCipher.java deleted file mode 100644 index ecb4634f7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsNullCipher.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * A NULL CipherSuite with optional MAC - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsNullCipher - implements TlsCipher -{ - protected TlsContext context; - - protected TlsMac writeMac; - protected TlsMac readMac; - - public TlsNullCipher(TlsContext context) - { - this.context = context; - this.writeMac = null; - this.readMac = null; - } - - public TlsNullCipher(TlsContext context, Digest clientWriteDigest, Digest serverWriteDigest) - throws IOException - { - if ((clientWriteDigest == null) != (serverWriteDigest == null)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - this.context = context; - - TlsMac clientWriteMac = null, serverWriteMac = null; - - if (clientWriteDigest != null) - { - int key_block_size = clientWriteDigest.getDigestSize() - + serverWriteDigest.getDigestSize(); - byte[] key_block = TlsUtils.calculateKeyBlock(context, key_block_size); - - int offset = 0; - - clientWriteMac = new TlsMac(context, clientWriteDigest, key_block, offset, - clientWriteDigest.getDigestSize()); - offset += clientWriteDigest.getDigestSize(); - - serverWriteMac = new TlsMac(context, serverWriteDigest, key_block, offset, - serverWriteDigest.getDigestSize()); - offset += serverWriteDigest.getDigestSize(); - - if (offset != key_block_size) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - if (context.isServer()) - { - writeMac = serverWriteMac; - readMac = clientWriteMac; - } - else - { - writeMac = clientWriteMac; - readMac = serverWriteMac; - } - } - - public int getPlaintextLimit(int ciphertextLimit) - { - int result = ciphertextLimit; - if (writeMac != null) - { - result -= writeMac.getSize(); - } - return result; - } - - public byte[] encodePlaintext(long seqNo, short type, byte[] plaintext, int offset, int len) - throws IOException - { - if (writeMac == null) - { - return Arrays.copyOfRange(plaintext, offset, offset + len); - } - - byte[] mac = writeMac.calculateMac(seqNo, type, plaintext, offset, len); - byte[] ciphertext = new byte[len + mac.length]; - System.arraycopy(plaintext, offset, ciphertext, 0, len); - System.arraycopy(mac, 0, ciphertext, len, mac.length); - return ciphertext; - } - - public byte[] decodeCiphertext(long seqNo, short type, byte[] ciphertext, int offset, int len) - throws IOException - { - if (readMac == null) - { - return Arrays.copyOfRange(ciphertext, offset, offset + len); - } - - int macSize = readMac.getSize(); - if (len < macSize) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - int macInputLen = len - macSize; - - byte[] receivedMac = Arrays.copyOfRange(ciphertext, offset + macInputLen, offset + len); - byte[] computedMac = readMac.calculateMac(seqNo, type, ciphertext, offset, macInputLen); - - if (!Arrays.constantTimeAreEqual(receivedMac, computedMac)) - { - throw new TlsFatalAlert(AlertDescription.bad_record_mac); - } - - return Arrays.copyOfRange(ciphertext, offset, offset + macInputLen); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsNullCompression.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsNullCompression.java deleted file mode 100644 index 3392f19ef..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsNullCompression.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.OutputStream; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsNullCompression - implements TlsCompression -{ - public OutputStream compress(OutputStream output) - { - return output; - } - - public OutputStream decompress(OutputStream output) - { - return output; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsOutputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsOutputStream.java deleted file mode 100644 index 77c539805..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsOutputStream.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * An OutputStream for an TLS connection. - */ -class TlsOutputStream - extends OutputStream -{ - private byte[] buf = new byte[1]; - private TlsProtocol handler; - - TlsOutputStream(TlsProtocol handler) - { - this.handler = handler; - } - - public void write(byte buf[], int offset, int len) - throws IOException - { - this.handler.writeData(buf, offset, len); - } - - public void write(int arg0) - throws IOException - { - buf[0] = (byte)arg0; - this.write(buf, 0, 1); - } - - public void close() - throws IOException - { - handler.close(); - } - - public void flush() - throws IOException - { - handler.flush(); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsPSKIdentity.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsPSKIdentity.java deleted file mode 100644 index a4c6db896..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsPSKIdentity.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsPSKIdentity -{ - void skipIdentityHint(); - - void notifyIdentityHint(byte[] psk_identity_hint); - - byte[] getPSKIdentity(); - - byte[] getPSK(); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsPSKIdentityManager.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsPSKIdentityManager.java deleted file mode 100644 index c38d69b62..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsPSKIdentityManager.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsPSKIdentityManager -{ - byte[] getHint(); - - byte[] getPSK(byte[] identity); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsPSKKeyExchange.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsPSKKeyExchange.java deleted file mode 100644 index 186573826..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsPSKKeyExchange.java +++ /dev/null @@ -1,370 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.math.BigInteger; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.x509.KeyUsage; -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.DHParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.DHPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.util.PublicKeyFactory; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.io.Streams; - -/** - * (D)TLS PSK key exchange (RFC 4279). - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsPSKKeyExchange - extends AbstractTlsKeyExchange -{ - protected TlsPSKIdentity pskIdentity; - protected TlsPSKIdentityManager pskIdentityManager; - - protected TlsDHVerifier dhVerifier; - protected DHParameters dhParameters; - protected int[] namedCurves; - protected short[] clientECPointFormats, serverECPointFormats; - - protected byte[] psk_identity_hint = null; - protected byte[] psk = null; - - protected DHPrivateKeyParameters dhAgreePrivateKey = null; - protected DHPublicKeyParameters dhAgreePublicKey = null; - - protected ECPrivateKeyParameters ecAgreePrivateKey = null; - protected ECPublicKeyParameters ecAgreePublicKey = null; - - protected AsymmetricKeyParameter serverPublicKey = null; - protected RSAKeyParameters rsaServerPublicKey = null; - protected TlsEncryptionCredentials serverCredentials = null; - protected byte[] premasterSecret; - - /** - * @deprecated Use constructor that takes a TlsDHVerifier - */ - public TlsPSKKeyExchange(int keyExchange, Vector supportedSignatureAlgorithms, TlsPSKIdentity pskIdentity, - TlsPSKIdentityManager pskIdentityManager, DHParameters dhParameters, int[] namedCurves, - short[] clientECPointFormats, short[] serverECPointFormats) - { - this(keyExchange, supportedSignatureAlgorithms, pskIdentity, pskIdentityManager, new DefaultTlsDHVerifier(), - dhParameters, namedCurves, clientECPointFormats, serverECPointFormats); - } - - public TlsPSKKeyExchange(int keyExchange, Vector supportedSignatureAlgorithms, TlsPSKIdentity pskIdentity, - TlsPSKIdentityManager pskIdentityManager, TlsDHVerifier dhVerifier, DHParameters dhParameters, int[] namedCurves, - short[] clientECPointFormats, short[] serverECPointFormats) - { - super(keyExchange, supportedSignatureAlgorithms); - - switch (keyExchange) - { - case KeyExchangeAlgorithm.DHE_PSK: - case KeyExchangeAlgorithm.ECDHE_PSK: - case KeyExchangeAlgorithm.PSK: - case KeyExchangeAlgorithm.RSA_PSK: - break; - default: - throw new IllegalArgumentException("unsupported key exchange algorithm"); - } - - this.pskIdentity = pskIdentity; - this.pskIdentityManager = pskIdentityManager; - this.dhVerifier = dhVerifier; - this.dhParameters = dhParameters; - this.namedCurves = namedCurves; - this.clientECPointFormats = clientECPointFormats; - this.serverECPointFormats = serverECPointFormats; - } - - public void skipServerCredentials() throws IOException - { - if (keyExchange == KeyExchangeAlgorithm.RSA_PSK) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - - public void processServerCredentials(TlsCredentials serverCredentials) throws IOException - { - if (!(serverCredentials instanceof TlsEncryptionCredentials)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - processServerCertificate(serverCredentials.getCertificate()); - - this.serverCredentials = (TlsEncryptionCredentials)serverCredentials; - } - - public byte[] generateServerKeyExchange() throws IOException - { - this.psk_identity_hint = pskIdentityManager.getHint(); - - if (this.psk_identity_hint == null && !requiresServerKeyExchange()) - { - return null; - } - - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - if (this.psk_identity_hint == null) - { - TlsUtils.writeOpaque16(TlsUtils.EMPTY_BYTES, buf); - } - else - { - TlsUtils.writeOpaque16(this.psk_identity_hint, buf); - } - - if (this.keyExchange == KeyExchangeAlgorithm.DHE_PSK) - { - if (this.dhParameters == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - this.dhAgreePrivateKey = TlsDHUtils.generateEphemeralServerKeyExchange(context.getSecureRandom(), - this.dhParameters, buf); - } - else if (this.keyExchange == KeyExchangeAlgorithm.ECDHE_PSK) - { - this.ecAgreePrivateKey = TlsECCUtils.generateEphemeralServerKeyExchange(context.getSecureRandom(), - namedCurves, clientECPointFormats, buf); - } - - return buf.toByteArray(); - } - - public void processServerCertificate(Certificate serverCertificate) throws IOException - { - if (keyExchange != KeyExchangeAlgorithm.RSA_PSK) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - if (serverCertificate.isEmpty()) - { - throw new TlsFatalAlert(AlertDescription.bad_certificate); - } - - com.fr.third.org.bouncycastle.asn1.x509.Certificate x509Cert = serverCertificate.getCertificateAt(0); - - SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo(); - try - { - this.serverPublicKey = PublicKeyFactory.createKey(keyInfo); - } - catch (RuntimeException e) - { - throw new TlsFatalAlert(AlertDescription.unsupported_certificate, e); - } - - // Sanity check the PublicKeyFactory - if (this.serverPublicKey.isPrivate()) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - this.rsaServerPublicKey = validateRSAPublicKey((RSAKeyParameters)this.serverPublicKey); - - TlsUtils.validateKeyUsage(x509Cert, KeyUsage.keyEncipherment); - - super.processServerCertificate(serverCertificate); - } - - public boolean requiresServerKeyExchange() - { - switch (keyExchange) - { - case KeyExchangeAlgorithm.DHE_PSK: - case KeyExchangeAlgorithm.ECDHE_PSK: - return true; - default: - return false; - } - } - - public void processServerKeyExchange(InputStream input) throws IOException - { - this.psk_identity_hint = TlsUtils.readOpaque16(input); - - if (this.keyExchange == KeyExchangeAlgorithm.DHE_PSK) - { - this.dhParameters = TlsDHUtils.receiveDHParameters(dhVerifier, input); - this.dhAgreePublicKey = new DHPublicKeyParameters(TlsDHUtils.readDHParameter(input), dhParameters); - } - else if (this.keyExchange == KeyExchangeAlgorithm.ECDHE_PSK) - { - ECDomainParameters ecParams = TlsECCUtils.readECParameters(namedCurves, clientECPointFormats, input); - - byte[] point = TlsUtils.readOpaque8(input); - - this.ecAgreePublicKey = TlsECCUtils.validateECPublicKey(TlsECCUtils.deserializeECPublicKey( - clientECPointFormats, ecParams, point)); - } - } - - public void validateCertificateRequest(CertificateRequest certificateRequest) throws IOException - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - public void processClientCredentials(TlsCredentials clientCredentials) throws IOException - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - public void generateClientKeyExchange(OutputStream output) throws IOException - { - if (psk_identity_hint == null) - { - pskIdentity.skipIdentityHint(); - } - else - { - pskIdentity.notifyIdentityHint(psk_identity_hint); - } - - byte[] psk_identity = pskIdentity.getPSKIdentity(); - if (psk_identity == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - this.psk = pskIdentity.getPSK(); - if (psk == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - TlsUtils.writeOpaque16(psk_identity, output); - - context.getSecurityParameters().pskIdentity = Arrays.clone(psk_identity); - - if (this.keyExchange == KeyExchangeAlgorithm.DHE_PSK) - { - this.dhAgreePrivateKey = TlsDHUtils.generateEphemeralClientKeyExchange(context.getSecureRandom(), - dhParameters, output); - } - else if (this.keyExchange == KeyExchangeAlgorithm.ECDHE_PSK) - { - this.ecAgreePrivateKey = TlsECCUtils.generateEphemeralClientKeyExchange(context.getSecureRandom(), - serverECPointFormats, ecAgreePublicKey.getParameters(), output); - } - else if (this.keyExchange == KeyExchangeAlgorithm.RSA_PSK) - { - this.premasterSecret = TlsRSAUtils.generateEncryptedPreMasterSecret(context, this.rsaServerPublicKey, - output); - } - } - - public void processClientKeyExchange(InputStream input) throws IOException - { - byte[] psk_identity = TlsUtils.readOpaque16(input); - - this.psk = pskIdentityManager.getPSK(psk_identity); - if (psk == null) - { - throw new TlsFatalAlert(AlertDescription.unknown_psk_identity); - } - - context.getSecurityParameters().pskIdentity = psk_identity; - - if (this.keyExchange == KeyExchangeAlgorithm.DHE_PSK) - { - this.dhAgreePublicKey = new DHPublicKeyParameters(TlsDHUtils.readDHParameter(input), dhParameters); - } - else if (this.keyExchange == KeyExchangeAlgorithm.ECDHE_PSK) - { - byte[] point = TlsUtils.readOpaque8(input); - - ECDomainParameters curve_params = this.ecAgreePrivateKey.getParameters(); - - this.ecAgreePublicKey = TlsECCUtils.validateECPublicKey(TlsECCUtils.deserializeECPublicKey( - serverECPointFormats, curve_params, point)); - } - else if (this.keyExchange == KeyExchangeAlgorithm.RSA_PSK) - { - byte[] encryptedPreMasterSecret; - if (TlsUtils.isSSL(context)) - { - // TODO Do any SSLv3 clients actually include the length? - encryptedPreMasterSecret = Streams.readAll(input); - } - else - { - encryptedPreMasterSecret = TlsUtils.readOpaque16(input); - } - - this.premasterSecret = serverCredentials.decryptPreMasterSecret(encryptedPreMasterSecret); - } - } - - public byte[] generatePremasterSecret() throws IOException - { - byte[] other_secret = generateOtherSecret(psk.length); - - ByteArrayOutputStream buf = new ByteArrayOutputStream(4 + other_secret.length + psk.length); - TlsUtils.writeOpaque16(other_secret, buf); - TlsUtils.writeOpaque16(psk, buf); - - Arrays.fill(psk, (byte)0); - this.psk = null; - - return buf.toByteArray(); - } - - protected byte[] generateOtherSecret(int pskLength) throws IOException - { - if (this.keyExchange == KeyExchangeAlgorithm.DHE_PSK) - { - if (dhAgreePrivateKey != null) - { - return TlsDHUtils.calculateDHBasicAgreement(dhAgreePublicKey, dhAgreePrivateKey); - } - - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - if (this.keyExchange == KeyExchangeAlgorithm.ECDHE_PSK) - { - if (ecAgreePrivateKey != null) - { - return TlsECCUtils.calculateECDHBasicAgreement(ecAgreePublicKey, ecAgreePrivateKey); - } - - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - if (this.keyExchange == KeyExchangeAlgorithm.RSA_PSK) - { - return this.premasterSecret; - } - - return new byte[pskLength]; - } - - protected RSAKeyParameters validateRSAPublicKey(RSAKeyParameters key) throws IOException - { - // TODO What is the minimum bit length required? - // key.getModulus().bitLength(); - - if (!key.getExponent().isProbablePrime(2)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - return key; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsPeer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsPeer.java deleted file mode 100644 index ddea87ab4..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsPeer.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsPeer -{ - void notifyCloseHandle(TlsCloseable closehandle); - - void cancel() throws IOException; - - /** - * This implementation supports RFC 7627 and will always negotiate the extended_master_secret - * extension where possible. When connecting to a peer that does not offer/accept this - * extension, it is recommended to abort the handshake. This option is provided for - * interoperability with legacy peers, although some TLS features will be disabled in that case - * (see RFC 7627 5.4). - * - * @returntrue
if the handshake should be aborted when the peer does not negotiate - * the extended_master_secret extension, orfalse
to support legacy - * interoperability. - */ - boolean requiresExtendedMasterSecret(); - - /** - * draft-mathewson-no-gmtunixtime-00 2. "If existing users of a TLS implementation may rely on - * gmt_unix_time containing the current time, we recommend that implementors MAY provide the - * ability to set gmt_unix_time as an option only, off by default." - * - * @returntrue
if the current time should be used in the gmt_unix_time field of - * Random, orfalse
if gmt_unix_time should contain a cryptographically - * random value. - */ - boolean shouldUseGMTUnixTime(); - - void notifySecureRenegotiation(boolean secureNegotiation) throws IOException; - - TlsCompression getCompression() throws IOException; - - TlsCipher getCipher() throws IOException; - - /** - * This method will be called when an alert is raised by the protocol. - * - * @param alertLevel {@link AlertLevel} - * @param alertDescription {@link AlertDescription} - * @param message A human-readable message explaining what caused this alert. May be null. - * @param cause The {@link Throwable} that caused this alert to be raised. May be null. - */ - void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause); - - /** - * This method will be called when an alert is received from the remote peer. - * - * @param alertLevel {@link AlertLevel} - * @param alertDescription {@link AlertDescription} - */ - void notifyAlertReceived(short alertLevel, short alertDescription); - - /** - * Notifies the peer that the handshake has been successfully completed. - */ - void notifyHandshakeComplete() throws IOException; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsProtocol.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsProtocol.java deleted file mode 100644 index 5ede6d39c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsProtocol.java +++ /dev/null @@ -1,1578 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.security.SecureRandom; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.prng.RandomGenerator; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Integers; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public abstract class TlsProtocol - implements TlsCloseable -{ - protected static final Integer EXT_RenegotiationInfo = Integers.valueOf(ExtensionType.renegotiation_info); - protected static final Integer EXT_SessionTicket = Integers.valueOf(ExtensionType.session_ticket); - - /* - * Our Connection states - */ - protected static final short CS_START = 0; - protected static final short CS_CLIENT_HELLO = 1; - protected static final short CS_SERVER_HELLO = 2; - protected static final short CS_SERVER_SUPPLEMENTAL_DATA = 3; - protected static final short CS_SERVER_CERTIFICATE = 4; - protected static final short CS_CERTIFICATE_STATUS = 5; - protected static final short CS_SERVER_KEY_EXCHANGE = 6; - protected static final short CS_CERTIFICATE_REQUEST = 7; - protected static final short CS_SERVER_HELLO_DONE = 8; - protected static final short CS_CLIENT_SUPPLEMENTAL_DATA = 9; - protected static final short CS_CLIENT_CERTIFICATE = 10; - protected static final short CS_CLIENT_KEY_EXCHANGE = 11; - protected static final short CS_CERTIFICATE_VERIFY = 12; - protected static final short CS_CLIENT_FINISHED = 13; - protected static final short CS_SERVER_SESSION_TICKET = 14; - protected static final short CS_SERVER_FINISHED = 15; - protected static final short CS_END = 16; - - /* - * Different modes to handle the known IV weakness - */ - protected static final short ADS_MODE_1_Nsub1 = 0; // 1/n-1 record splitting - protected static final short ADS_MODE_0_N = 1; // 0/n record splitting - protected static final short ADS_MODE_0_N_FIRSTONLY = 2; // 0/n record splitting on first data fragment only - - /* - * Queues for data from some protocols. - */ - private ByteQueue applicationDataQueue = new ByteQueue(0); - private ByteQueue alertQueue = new ByteQueue(2); - private ByteQueue handshakeQueue = new ByteQueue(0); -// private ByteQueue heartbeatQueue = new ByteQueue(); - - /* - * The Record Stream we use - */ - RecordStream recordStream; - protected SecureRandom secureRandom; - - private TlsInputStream tlsInputStream = null; - private TlsOutputStream tlsOutputStream = null; - - private volatile boolean closed = false; - private volatile boolean failedWithError = false; - private volatile boolean appDataReady = false; - private volatile boolean appDataSplitEnabled = true; - private volatile int appDataSplitMode = ADS_MODE_1_Nsub1; - private byte[] expected_verify_data = null; - - protected TlsSession tlsSession = null; - protected SessionParameters sessionParameters = null; - protected SecurityParameters securityParameters = null; - protected Certificate peerCertificate = null; - - protected int[] offeredCipherSuites = null; - protected short[] offeredCompressionMethods = null; - protected Hashtable clientExtensions = null; - protected Hashtable serverExtensions = null; - - protected short connection_state = CS_START; - protected boolean resumedSession = false; - protected boolean receivedChangeCipherSpec = false; - protected boolean secure_renegotiation = false; - protected boolean allowCertificateStatus = false; - protected boolean expectSessionTicket = false; - - protected boolean blocking; - protected ByteQueueInputStream inputBuffers; - protected ByteQueueOutputStream outputBuffer; - - public TlsProtocol(InputStream input, OutputStream output, SecureRandom secureRandom) - { - this.blocking = true; - this.recordStream = new RecordStream(this, input, output); - this.secureRandom = secureRandom; - } - - public TlsProtocol(SecureRandom secureRandom) - { - this.blocking = false; - this.inputBuffers = new ByteQueueInputStream(); - this.outputBuffer = new ByteQueueOutputStream(); - this.recordStream = new RecordStream(this, inputBuffers, outputBuffer); - this.secureRandom = secureRandom; - } - - protected abstract TlsContext getContext(); - - abstract AbstractTlsContext getContextAdmin(); - - protected abstract TlsPeer getPeer(); - - protected void handleAlertMessage(short alertLevel, short alertDescription) - throws IOException - { - getPeer().notifyAlertReceived(alertLevel, alertDescription); - - if (alertLevel == AlertLevel.warning) - { - handleAlertWarningMessage(alertDescription); - } - else - { - handleFailure(); - - throw new TlsFatalAlertReceived(alertDescription); - } - } - - protected void handleAlertWarningMessage(short alertDescription) - throws IOException - { - /* - * RFC 5246 7.2.1. The other party MUST respond with a close_notify alert of its own - * and close down the connection immediately, discarding any pending writes. - */ - if (alertDescription == AlertDescription.close_notify) - { - if (!appDataReady) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - handleClose(false); - } - } - - protected void handleChangeCipherSpecMessage() throws IOException - { - } - - protected void handleClose(boolean user_canceled) - throws IOException - { - if (!closed) - { - this.closed = true; - - if (user_canceled && !appDataReady) - { - raiseAlertWarning(AlertDescription.user_canceled, "User canceled handshake"); - } - - raiseAlertWarning(AlertDescription.close_notify, "Connection closed"); - - recordStream.safeClose(); - - if (!appDataReady) - { - cleanupHandshake(); - } - } - } - - protected void handleException(short alertDescription, String message, Throwable cause) - throws IOException - { - if (!closed) - { - raiseAlertFatal(alertDescription, message, cause); - - handleFailure(); - } - } - - protected void handleFailure() - { - this.closed = true; - this.failedWithError = true; - - /* - * RFC 2246 7.2.1. The session becomes unresumable if any connection is terminated - * without proper close_notify messages with level equal to warning. - */ - // TODO This isn't quite in the right place. Also, as of TLS 1.1 the above is obsolete. - invalidateSession(); - - recordStream.safeClose(); - - if (!appDataReady) - { - cleanupHandshake(); - } - } - - protected abstract void handleHandshakeMessage(short type, ByteArrayInputStream buf) - throws IOException; - - protected void applyMaxFragmentLengthExtension() - throws IOException - { - if (securityParameters.maxFragmentLength >= 0) - { - if (!MaxFragmentLength.isValid(securityParameters.maxFragmentLength)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - int plainTextLimit = 1 << (8 + securityParameters.maxFragmentLength); - recordStream.setPlaintextLimit(plainTextLimit); - } - } - - protected void checkReceivedChangeCipherSpec(boolean expected) - throws IOException - { - if (expected != receivedChangeCipherSpec) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - - protected void cleanupHandshake() - { - if (this.expected_verify_data != null) - { - Arrays.fill(this.expected_verify_data, (byte)0); - this.expected_verify_data = null; - } - - this.securityParameters.clear(); - this.peerCertificate = null; - - this.offeredCipherSuites = null; - this.offeredCompressionMethods = null; - this.clientExtensions = null; - this.serverExtensions = null; - - this.resumedSession = false; - this.receivedChangeCipherSpec = false; - this.secure_renegotiation = false; - this.allowCertificateStatus = false; - this.expectSessionTicket = false; - } - - protected void blockForHandshake() throws IOException - { - if (blocking) - { - while (this.connection_state != CS_END) - { - if (this.closed) - { - // NOTE: Any close during the handshake should have raised an exception. - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - safeReadRecord(); - } - } - } - - protected void completeHandshake() - throws IOException - { - try - { - this.connection_state = CS_END; - - this.alertQueue.shrink(); - this.handshakeQueue.shrink(); - - this.recordStream.finaliseHandshake(); - - this.appDataSplitEnabled = !TlsUtils.isTLSv11(getContext()); - - /* - * If this was an initial handshake, we are now ready to send and receive application data. - */ - if (!appDataReady) - { - this.appDataReady = true; - - if (blocking) - { - this.tlsInputStream = new TlsInputStream(this); - this.tlsOutputStream = new TlsOutputStream(this); - } - } - - if (this.tlsSession != null) - { - if (this.sessionParameters == null) - { - this.sessionParameters = new SessionParameters.Builder() - .setCipherSuite(this.securityParameters.getCipherSuite()) - .setCompressionAlgorithm(this.securityParameters.getCompressionAlgorithm()) - .setExtendedMasterSecret(securityParameters.isExtendedMasterSecret()) - .setMasterSecret(this.securityParameters.getMasterSecret()) - .setPeerCertificate(this.peerCertificate) - .setPSKIdentity(this.securityParameters.getPSKIdentity()) - .setSRPIdentity(this.securityParameters.getSRPIdentity()) - // TODO Consider filtering extensions that aren't relevant to resumed sessions - .setServerExtensions(this.serverExtensions) - .build(); - - this.tlsSession = new TlsSessionImpl(this.tlsSession.getSessionID(), this.sessionParameters); - } - - getContextAdmin().setResumableSession(this.tlsSession); - } - - getPeer().notifyHandshakeComplete(); - } - finally - { - cleanupHandshake(); - } - } - - protected void processRecord(short protocol, byte[] buf, int off, int len) - throws IOException - { - /* - * Have a look at the protocol type, and add it to the correct queue. - */ - switch (protocol) - { - case ContentType.alert: - { - alertQueue.addData(buf, off, len); - processAlertQueue(); - break; - } - case ContentType.application_data: - { - if (!appDataReady) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - applicationDataQueue.addData(buf, off, len); - processApplicationDataQueue(); - break; - } - case ContentType.change_cipher_spec: - { - processChangeCipherSpec(buf, off, len); - break; - } - case ContentType.handshake: - { - if (handshakeQueue.available() > 0) - { - handshakeQueue.addData(buf, off, len); - processHandshakeQueue(handshakeQueue); - } - else - { - ByteQueue tmpQueue = new ByteQueue(buf, off, len); - processHandshakeQueue(tmpQueue); - int remaining = tmpQueue.available(); - if (remaining > 0) - { - handshakeQueue.addData(buf, off + len - remaining, remaining); - } - } - break; - } -// case ContentType.heartbeat: -// { -// if (!appDataReady) -// { -// throw new TlsFatalAlert(AlertDescription.unexpected_message); -// } -// // TODO[RFC 6520] -//// heartbeatQueue.addData(buf, offset, len); -//// processHeartbeat(); -// break; -// } - default: - // Record type should already have been checked - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - private void processHandshakeQueue(ByteQueue queue) - throws IOException - { - while (queue.available() >= 4) - { - /* - * We need the first 4 bytes, they contain type and length of the message. - */ - byte[] beginning = new byte[4]; - queue.read(beginning, 0, 4, 0); - short type = TlsUtils.readUint8(beginning, 0); - int length = TlsUtils.readUint24(beginning, 1); - int totalLength = 4 + length; - - /* - * Check if we have enough bytes in the buffer to read the full message. - */ - if (queue.available() < totalLength) - { - break; - } - - /* - * RFC 2246 7.4.9. The value handshake_messages includes all handshake messages - * starting at client hello up to, but not including, this finished message. - * [..] Note: [Also,] Hello Request messages are omitted from handshake hashes. - */ - if (HandshakeType.hello_request != type) - { - if (HandshakeType.finished == type) - { - checkReceivedChangeCipherSpec(true); - - TlsContext ctx = getContext(); - if (this.expected_verify_data == null - && ctx.getSecurityParameters().getMasterSecret() != null) - { - this.expected_verify_data = createVerifyData(!ctx.isServer()); - } - } - else - { - checkReceivedChangeCipherSpec(connection_state == CS_END); - } - - queue.copyTo(recordStream.getHandshakeHashUpdater(), totalLength); - } - - queue.removeData(4); - - ByteArrayInputStream buf = queue.readFrom(length); - - /* - * Now, parse the message. - */ - handleHandshakeMessage(type, buf); - } - } - - private void processApplicationDataQueue() - { - /* - * There is nothing we need to do here. - * - * This function could be used for callbacks when application data arrives in the future. - */ - } - - private void processAlertQueue() - throws IOException - { - while (alertQueue.available() >= 2) - { - /* - * An alert is always 2 bytes. Read the alert. - */ - byte[] alert = alertQueue.removeData(2, 0); - short alertLevel = alert[0]; - short alertDescription = alert[1]; - - handleAlertMessage(alertLevel, alertDescription); - } - } - - /** - * This method is called, when a change cipher spec message is received. - * - * @throws IOException If the message has an invalid content or the handshake is not in the correct - * state. - */ - private void processChangeCipherSpec(byte[] buf, int off, int len) - throws IOException - { - for (int i = 0; i < len; ++i) - { - short message = TlsUtils.readUint8(buf, off + i); - - if (message != ChangeCipherSpec.change_cipher_spec) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - if (this.receivedChangeCipherSpec - || alertQueue.available() > 0 - || handshakeQueue.available() > 0) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - recordStream.receivedReadCipherSpec(); - - this.receivedChangeCipherSpec = true; - - handleChangeCipherSpecMessage(); - } - } - - protected int applicationDataAvailable() - { - return applicationDataQueue.available(); - } - - /** - * Read data from the network. The method will return immediately, if there is still some data - * left in the buffer, or block until some application data has been read from the network. - * - * @param buf The buffer where the data will be copied to. - * @param offset The position where the data will be placed in the buffer. - * @param len The maximum number of bytes to read. - * @return The number of bytes read. - * @throws IOException If something goes wrong during reading data. - */ - protected int readApplicationData(byte[] buf, int offset, int len) - throws IOException - { - if (len < 1) - { - return 0; - } - - while (applicationDataQueue.available() == 0) - { - if (this.closed) - { - if (this.failedWithError) - { - throw new IOException("Cannot read application data on failed TLS connection"); - } - if (!appDataReady) - { - throw new IllegalStateException("Cannot read application data until initial handshake completed."); - } - - return -1; - } - - safeReadRecord(); - } - - len = Math.min(len, applicationDataQueue.available()); - applicationDataQueue.removeData(buf, offset, len, 0); - return len; - } - - protected void safeCheckRecordHeader(byte[] recordHeader) - throws IOException - { - try - { - recordStream.checkRecordHeader(recordHeader); - } - catch (TlsFatalAlert e) - { - handleException(e.getAlertDescription(), "Failed to read record", e); - throw e; - } - catch (IOException e) - { - handleException(AlertDescription.internal_error, "Failed to read record", e); - throw e; - } - catch (RuntimeException e) - { - handleException(AlertDescription.internal_error, "Failed to read record", e); - throw new TlsFatalAlert(AlertDescription.internal_error, e); - } - } - - protected void safeReadRecord() - throws IOException - { - try - { - if (recordStream.readRecord()) - { - return; - } - - if (!appDataReady) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - } - catch (TlsFatalAlertReceived e) - { - // Connection failure already handled at source - throw e; - } - catch (TlsFatalAlert e) - { - handleException(e.getAlertDescription(), "Failed to read record", e); - throw e; - } - catch (IOException e) - { - handleException(AlertDescription.internal_error, "Failed to read record", e); - throw e; - } - catch (RuntimeException e) - { - handleException(AlertDescription.internal_error, "Failed to read record", e); - throw new TlsFatalAlert(AlertDescription.internal_error, e); - } - - handleFailure(); - - throw new TlsNoCloseNotifyException(); - } - - protected void safeWriteRecord(short type, byte[] buf, int offset, int len) - throws IOException - { - try - { - recordStream.writeRecord(type, buf, offset, len); - } - catch (TlsFatalAlert e) - { - handleException(e.getAlertDescription(), "Failed to write record", e); - throw e; - } - catch (IOException e) - { - handleException(AlertDescription.internal_error, "Failed to write record", e); - throw e; - } - catch (RuntimeException e) - { - handleException(AlertDescription.internal_error, "Failed to write record", e); - throw new TlsFatalAlert(AlertDescription.internal_error, e); - } - } - - /** - * Send some application data to the remote system. - *- * The method will handle fragmentation internally. - *
- * @param buf The buffer with the data. - * @param offset The position in the buffer where the data is placed. - * @param len The length of the data. - * @throws IOException If something goes wrong during sending. - */ - protected void writeData(byte[] buf, int offset, int len) - throws IOException - { - if (this.closed) - { - throw new IOException("Cannot write application data on closed/failed TLS connection"); - } - - while (len > 0) - { - /* - * RFC 5246 6.2.1. Zero-length fragments of Application data MAY be sent as they are - * potentially useful as a traffic analysis countermeasure. - * - * NOTE: Actually, implementations appear to have settled on 1/n-1 record splitting. - */ - - if (this.appDataSplitEnabled) - { - /* - * Protect against known IV attack! - * - * DO NOT REMOVE THIS CODE, EXCEPT YOU KNOW EXACTLY WHAT YOU ARE DOING HERE. - */ - switch (appDataSplitMode) { - case ADS_MODE_0_N_FIRSTONLY: - this.appDataSplitEnabled = false; - // fall through intended! - case ADS_MODE_0_N: - safeWriteRecord(ContentType.application_data, TlsUtils.EMPTY_BYTES, 0, 0); - break; - case ADS_MODE_1_Nsub1: - default: - safeWriteRecord(ContentType.application_data, buf, offset, 1); - ++offset; - --len; - break; - } - } - - if (len > 0) - { - // Fragment data according to the current fragment limit. - int toWrite = Math.min(len, recordStream.getPlaintextLimit()); - safeWriteRecord(ContentType.application_data, buf, offset, toWrite); - offset += toWrite; - len -= toWrite; - } - } - } - - protected void setAppDataSplitMode(int appDataSplitMode) { - if (appDataSplitMode < ADS_MODE_1_Nsub1 || - appDataSplitMode > ADS_MODE_0_N_FIRSTONLY) - { - throw new IllegalArgumentException("Illegal appDataSplitMode mode: " + appDataSplitMode); - } - this.appDataSplitMode = appDataSplitMode; - } - - protected void writeHandshakeMessage(byte[] buf, int off, int len) throws IOException - { - if (len < 4) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - short type = TlsUtils.readUint8(buf, off); - if (type != HandshakeType.hello_request) - { - recordStream.getHandshakeHashUpdater().write(buf, off, len); - } - - int total = 0; - do - { - // Fragment data according to the current fragment limit. - int toWrite = Math.min(len - total, recordStream.getPlaintextLimit()); - safeWriteRecord(ContentType.handshake, buf, off + total, toWrite); - total += toWrite; - } - while (total < len); - } - - /** - * @return An OutputStream which can be used to send data. Only allowed in blocking mode. - */ - public OutputStream getOutputStream() - { - if (!blocking) - { - throw new IllegalStateException("Cannot use OutputStream in non-blocking mode! Use offerOutput() instead."); - } - return this.tlsOutputStream; - } - - /** - * @return An InputStream which can be used to read data. Only allowed in blocking mode. - */ - public InputStream getInputStream() - { - if (!blocking) - { - throw new IllegalStateException("Cannot use InputStream in non-blocking mode! Use offerInput() instead."); - } - return this.tlsInputStream; - } - - /** - * Should be called in non-blocking mode when the input data reaches EOF. - */ - public void closeInput() throws IOException - { - if (blocking) - { - throw new IllegalStateException("Cannot use closeInput() in blocking mode!"); - } - - if (closed) - { - return; - } - - if (inputBuffers.available() > 0) - { - throw new EOFException(); - } - - if (!appDataReady) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - throw new TlsNoCloseNotifyException(); - } - - /** - * Equivalent toofferInput(input, 0, input.length)
- * @see TlsProtocol#offerInput(byte[], int, int) - * @param input The input buffer to offer - * @throws IOException If an error occurs while decrypting or processing a record - */ - public void offerInput(byte[] input) throws IOException - { - offerInput(input, 0, input.length); - } - - /** - * Offer input from an arbitrary source. Only allowed in non-blocking mode.
- *
- * This method will decrypt and process all records that are fully available. - * If only part of a record is available, the buffer will be retained until the - * remainder of the record is offered.
- *
- * If any records containing application data were processed, the decrypted data - * can be obtained using {@link #readInput(byte[], int, int)}. If any records - * containing protocol data were processed, a response may have been generated. - * You should always check to see if there is any available output after calling - * this method by calling {@link #getAvailableOutputBytes()}. - * @param input The input buffer to offer - * @param inputOff The offset within the input buffer that input begins - * @param inputLen The number of bytes of input being offered - * @throws IOException If an error occurs while decrypting or processing a record - */ - public void offerInput(byte[] input, int inputOff, int inputLen) throws IOException - { - if (blocking) - { - throw new IllegalStateException("Cannot use offerInput() in blocking mode! Use getInputStream() instead."); - } - - if (closed) - { - throw new IOException("Connection is closed, cannot accept any more input"); - } - - inputBuffers.addBytes(input, inputOff, inputLen); - - // loop while there are enough bytes to read the length of the next record - while (inputBuffers.available() >= RecordStream.TLS_HEADER_SIZE) - { - byte[] recordHeader = new byte[RecordStream.TLS_HEADER_SIZE]; - inputBuffers.peek(recordHeader); - - int totalLength = TlsUtils.readUint16(recordHeader, RecordStream.TLS_HEADER_LENGTH_OFFSET) + RecordStream.TLS_HEADER_SIZE; - if (inputBuffers.available() < totalLength) - { - // not enough bytes to read a whole record - safeCheckRecordHeader(recordHeader); - break; - } - - safeReadRecord(); - - if (closed) - { - if (connection_state != CS_END) - { - // NOTE: Any close during the handshake should have raised an exception. - throw new TlsFatalAlert(AlertDescription.internal_error); - } - break; - } - } - } - - /** - * Gets the amount of received application data. A call to {@link #readInput(byte[], int, int)} - * is guaranteed to be able to return at least this much data.
- *
- * Only allowed in non-blocking mode. - * @return The number of bytes of available application data - */ - public int getAvailableInputBytes() - { - if (blocking) - { - throw new IllegalStateException("Cannot use getAvailableInputBytes() in blocking mode! Use getInputStream().available() instead."); - } - return applicationDataAvailable(); - } - - /** - * Retrieves received application data. Use {@link #getAvailableInputBytes()} to check - * how much application data is currently available. This method functions similarly to - * {@link InputStream#read(byte[], int, int)}, except that it never blocks. If no data - * is available, nothing will be copied and zero will be returned.
- *
- * Only allowed in non-blocking mode. - * @param buffer The buffer to hold the application data - * @param offset The start offset in the buffer at which the data is written - * @param length The maximum number of bytes to read - * @return The total number of bytes copied to the buffer. May be less than the - * length specified if the length was greater than the amount of available data. - */ - public int readInput(byte[] buffer, int offset, int length) - { - if (blocking) - { - throw new IllegalStateException("Cannot use readInput() in blocking mode! Use getInputStream() instead."); - } - - try - { - return readApplicationData(buffer, offset, Math.min(length, applicationDataAvailable())); - } - catch (IOException e) - { - // readApplicationData() only throws if there is no data available, so this should never happen - throw new RuntimeException(e.toString()); // early JDK fix. - } - } - - /** - * Offer output from an arbitrary source. Only allowed in non-blocking mode.
- *
- * After this method returns, the specified section of the buffer will have been - * processed. Use {@link #readOutput(byte[], int, int)} to get the bytes to - * transmit to the other peer.
- *
- * This method must not be called until after the handshake is complete! Attempting - * to call it before the handshake is complete will result in an exception. - * @param buffer The buffer containing application data to encrypt - * @param offset The offset at which to begin reading data - * @param length The number of bytes of data to read - * @throws IOException If an error occurs encrypting the data, or the handshake is not complete - */ - public void offerOutput(byte[] buffer, int offset, int length) - throws IOException - { - if (blocking) - { - throw new IllegalStateException("Cannot use offerOutput() in blocking mode! Use getOutputStream() instead."); - } - - if (!appDataReady) - { - throw new IOException("Application data cannot be sent until the handshake is complete!"); - } - - writeData(buffer, offset, length); - } - - /** - * Gets the amount of encrypted data available to be sent. A call to - * {@link #readOutput(byte[], int, int)} is guaranteed to be able to return at - * least this much data.
- *
- * Only allowed in non-blocking mode. - * @return The number of bytes of available encrypted data - */ - public int getAvailableOutputBytes() - { - if (blocking) - { - throw new IllegalStateException("Cannot use getAvailableOutputBytes() in blocking mode! Use getOutputStream() instead."); - } - - return outputBuffer.getBuffer().available(); - } - - /** - * Retrieves encrypted data to be sent. Use {@link #getAvailableOutputBytes()} to check - * how much encrypted data is currently available. This method functions similarly to - * {@link InputStream#read(byte[], int, int)}, except that it never blocks. If no data - * is available, nothing will be copied and zero will be returned.
- *
- * Only allowed in non-blocking mode. - * @param buffer The buffer to hold the encrypted data - * @param offset The start offset in the buffer at which the data is written - * @param length The maximum number of bytes to read - * @return The total number of bytes copied to the buffer. May be less than the - * length specified if the length was greater than the amount of available data. - */ - public int readOutput(byte[] buffer, int offset, int length) - { - if (blocking) - { - throw new IllegalStateException("Cannot use readOutput() in blocking mode! Use getOutputStream() instead."); - } - - int bytesToRead = Math.min(getAvailableOutputBytes(), length); - outputBuffer.getBuffer().removeData(buffer, offset, bytesToRead, 0); - return bytesToRead; - } - - protected void invalidateSession() - { - if (this.sessionParameters != null) - { - this.sessionParameters.clear(); - this.sessionParameters = null; - } - - if (this.tlsSession != null) - { - this.tlsSession.invalidate(); - this.tlsSession = null; - } - } - - protected void processFinishedMessage(ByteArrayInputStream buf) - throws IOException - { - if (expected_verify_data == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - byte[] verify_data = TlsUtils.readFully(expected_verify_data.length, buf); - - assertEmpty(buf); - - /* - * Compare both checksums. - */ - if (!Arrays.constantTimeAreEqual(expected_verify_data, verify_data)) - { - /* - * Wrong checksum in the finished message. - */ - throw new TlsFatalAlert(AlertDescription.decrypt_error); - } - } - - protected void raiseAlertFatal(short alertDescription, String message, Throwable cause) - throws IOException - { - getPeer().notifyAlertRaised(AlertLevel.fatal, alertDescription, message, cause); - - byte[] alert = new byte[]{ (byte)AlertLevel.fatal, (byte)alertDescription }; - - try - { - recordStream.writeRecord(ContentType.alert, alert, 0, 2); - } - catch (Exception e) - { - // We are already processing an exception, so just ignore this - } - } - - protected void raiseAlertWarning(short alertDescription, String message) - throws IOException - { - getPeer().notifyAlertRaised(AlertLevel.warning, alertDescription, message, null); - - byte[] alert = new byte[]{ (byte)AlertLevel.warning, (byte)alertDescription }; - - safeWriteRecord(ContentType.alert, alert, 0, 2); - } - - protected void sendCertificateMessage(Certificate certificate) - throws IOException - { - if (certificate == null) - { - certificate = Certificate.EMPTY_CHAIN; - } - - if (certificate.isEmpty()) - { - TlsContext context = getContext(); - if (!context.isServer()) - { - ProtocolVersion serverVersion = getContext().getServerVersion(); - if (serverVersion.isSSL()) - { - String errorMessage = serverVersion.toString() + " client didn't provide credentials"; - raiseAlertWarning(AlertDescription.no_certificate, errorMessage); - return; - } - } - } - - HandshakeMessage message = new HandshakeMessage(HandshakeType.certificate); - - certificate.encode(message); - - message.writeToRecordStream(); - } - - protected void sendChangeCipherSpecMessage() - throws IOException - { - byte[] message = new byte[]{ 1 }; - safeWriteRecord(ContentType.change_cipher_spec, message, 0, message.length); - recordStream.sentWriteCipherSpec(); - } - - protected void sendFinishedMessage() - throws IOException - { - byte[] verify_data = createVerifyData(getContext().isServer()); - - HandshakeMessage message = new HandshakeMessage(HandshakeType.finished, verify_data.length); - - message.write(verify_data); - - message.writeToRecordStream(); - } - - protected void sendSupplementalDataMessage(Vector supplementalData) - throws IOException - { - HandshakeMessage message = new HandshakeMessage(HandshakeType.supplemental_data); - - writeSupplementalData(message, supplementalData); - - message.writeToRecordStream(); - } - - protected byte[] createVerifyData(boolean isServer) - { - TlsContext context = getContext(); - String asciiLabel = isServer ? ExporterLabel.server_finished : ExporterLabel.client_finished; - byte[] sslSender = isServer ? TlsUtils.SSL_SERVER : TlsUtils.SSL_CLIENT; - byte[] hash = getCurrentPRFHash(context, recordStream.getHandshakeHash(), sslSender); - return TlsUtils.calculateVerifyData(context, asciiLabel, hash); - } - - /** - * Closes this connection. - * - * @throws IOException If something goes wrong during closing. - */ - public void close() - throws IOException - { - handleClose(true); - } - - protected void flush() - throws IOException - { - recordStream.flush(); - } - - public boolean isClosed() - { - return closed; - } - - protected short processMaxFragmentLengthExtension(Hashtable clientExtensions, Hashtable serverExtensions, - short alertDescription) - throws IOException - { - short maxFragmentLength = TlsExtensionsUtils.getMaxFragmentLengthExtension(serverExtensions); - if (maxFragmentLength >= 0) - { - if (!MaxFragmentLength.isValid(maxFragmentLength) - || (!this.resumedSession && maxFragmentLength != TlsExtensionsUtils - .getMaxFragmentLengthExtension(clientExtensions))) - { - throw new TlsFatalAlert(alertDescription); - } - } - return maxFragmentLength; - } - - protected void refuseRenegotiation() throws IOException - { - /* - * RFC 5746 4.5 SSLv3 clients that refuse renegotiation SHOULD use a fatal - * handshake_failure alert. - */ - if (TlsUtils.isSSL(getContext())) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - raiseAlertWarning(AlertDescription.no_renegotiation, "Renegotiation not supported"); - } - - /** - * Make sure the InputStream 'buf' now empty. Fail otherwise. - * - * @param buf The InputStream to check. - * @throws IOException If 'buf' is not empty. - */ - protected static void assertEmpty(ByteArrayInputStream buf) - throws IOException - { - if (buf.available() > 0) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - } - - protected static byte[] createRandomBlock(boolean useGMTUnixTime, RandomGenerator randomGenerator) - { - byte[] result = new byte[32]; - randomGenerator.nextBytes(result); - - if (useGMTUnixTime) - { - TlsUtils.writeGMTUnixTime(result, 0); - } - - return result; - } - - protected static byte[] createRenegotiationInfo(byte[] renegotiated_connection) - throws IOException - { - return TlsUtils.encodeOpaque8(renegotiated_connection); - } - - protected static void establishMasterSecret(TlsContext context, TlsKeyExchange keyExchange) - throws IOException - { - byte[] pre_master_secret = keyExchange.generatePremasterSecret(); - - try - { - context.getSecurityParameters().masterSecret = TlsUtils.calculateMasterSecret(context, pre_master_secret); - } - finally - { - // TODO Is there a way to ensure the data is really overwritten? - /* - * RFC 2246 8.1. The pre_master_secret should be deleted from memory once the - * master_secret has been computed. - */ - if (pre_master_secret != null) - { - Arrays.fill(pre_master_secret, (byte)0); - } - } - } - - /** - * 'sender' only relevant to SSLv3 - */ - protected static byte[] getCurrentPRFHash(TlsContext context, TlsHandshakeHash handshakeHash, byte[] sslSender) - { - Digest d = handshakeHash.forkPRFHash(); - - if (sslSender != null && TlsUtils.isSSL(context)) - { - d.update(sslSender, 0, sslSender.length); - } - - byte[] bs = new byte[d.getDigestSize()]; - d.doFinal(bs, 0); - return bs; - } - - protected static Hashtable readExtensions(ByteArrayInputStream input) - throws IOException - { - if (input.available() < 1) - { - return null; - } - - byte[] extBytes = TlsUtils.readOpaque16(input); - - assertEmpty(input); - - ByteArrayInputStream buf = new ByteArrayInputStream(extBytes); - - // Integer -> byte[] - Hashtable extensions = new Hashtable(); - - while (buf.available() > 0) - { - Integer extension_type = Integers.valueOf(TlsUtils.readUint16(buf)); - byte[] extension_data = TlsUtils.readOpaque16(buf); - - /* - * RFC 3546 2.3 There MUST NOT be more than one extension of the same type. - */ - if (null != extensions.put(extension_type, extension_data)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - - return extensions; - } - - protected static Vector readSupplementalDataMessage(ByteArrayInputStream input) - throws IOException - { - byte[] supp_data = TlsUtils.readOpaque24(input); - - assertEmpty(input); - - ByteArrayInputStream buf = new ByteArrayInputStream(supp_data); - - Vector supplementalData = new Vector(); - - while (buf.available() > 0) - { - int supp_data_type = TlsUtils.readUint16(buf); - byte[] data = TlsUtils.readOpaque16(buf); - - supplementalData.addElement(new SupplementalDataEntry(supp_data_type, data)); - } - - return supplementalData; - } - - protected static void writeExtensions(OutputStream output, Hashtable extensions) - throws IOException - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - /* - * NOTE: There are reports of servers that don't accept a zero-length extension as the last - * one, so we write out any zero-length ones first as a best-effort workaround. - */ - writeSelectedExtensions(buf, extensions, true); - writeSelectedExtensions(buf, extensions, false); - - byte[] extBytes = buf.toByteArray(); - - TlsUtils.writeOpaque16(extBytes, output); - } - - protected static void writeSelectedExtensions(OutputStream output, Hashtable extensions, boolean selectEmpty) - throws IOException - { - Enumeration keys = extensions.keys(); - while (keys.hasMoreElements()) - { - Integer key = (Integer)keys.nextElement(); - int extension_type = key.intValue(); - byte[] extension_data = (byte[])extensions.get(key); - - if (selectEmpty == (extension_data.length == 0)) - { - TlsUtils.checkUint16(extension_type); - TlsUtils.writeUint16(extension_type, output); - TlsUtils.writeOpaque16(extension_data, output); - } - } - } - - protected static void writeSupplementalData(OutputStream output, Vector supplementalData) - throws IOException - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - for (int i = 0; i < supplementalData.size(); ++i) - { - SupplementalDataEntry entry = (SupplementalDataEntry)supplementalData.elementAt(i); - - int supp_data_type = entry.getDataType(); - TlsUtils.checkUint16(supp_data_type); - TlsUtils.writeUint16(supp_data_type, buf); - TlsUtils.writeOpaque16(entry.getData(), buf); - } - - byte[] supp_data = buf.toByteArray(); - - TlsUtils.writeOpaque24(supp_data, output); - } - - protected static int getPRFAlgorithm(TlsContext context, int ciphersuite) throws IOException - { - boolean isTLSv12 = TlsUtils.isTLSv12(context); - - switch (ciphersuite) - { - case CipherSuite.TLS_DH_anon_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CCM: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_AES_128_OCB: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CCM: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_AES_256_OCB: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_128_OCB: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CCM: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CCM_8: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_256_OCB: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_AES_128_OCB: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CCM: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_AES_256_OCB: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_AES_256_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_AES_256_OCB: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_PSK_DHE_WITH_AES_128_CCM_8: - case CipherSuite.TLS_PSK_DHE_WITH_AES_256_CCM_8: - case CipherSuite.TLS_PSK_WITH_AES_128_CCM: - case CipherSuite.TLS_PSK_WITH_AES_128_CCM_8: - case CipherSuite.TLS_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_PSK_WITH_AES_128_OCB: - case CipherSuite.TLS_PSK_WITH_AES_256_CCM: - case CipherSuite.TLS_PSK_WITH_AES_256_CCM_8: - case CipherSuite.DRAFT_TLS_PSK_WITH_AES_256_OCB: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_128_CCM: - case CipherSuite.TLS_RSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_256_CCM: - case CipherSuite.TLS_RSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_NULL_SHA256: - { - if (isTLSv12) - { - return PRFAlgorithm.tls_prf_sha256; - } - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - case CipherSuite.TLS_DH_anon_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384: - { - if (isTLSv12) - { - return PRFAlgorithm.tls_prf_sha384; - } - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_NULL_SHA384: - { - if (isTLSv12) - { - return PRFAlgorithm.tls_prf_sha384; - } - return PRFAlgorithm.tls_prf_legacy; - } - - default: - { - if (isTLSv12) - { - return PRFAlgorithm.tls_prf_sha256; - } - return PRFAlgorithm.tls_prf_legacy; - } - } - } - - class HandshakeMessage extends ByteArrayOutputStream - { - HandshakeMessage(short handshakeType) throws IOException - { - this(handshakeType, 60); - } - - HandshakeMessage(short handshakeType, int length) throws IOException - { - super(length + 4); - TlsUtils.writeUint8(handshakeType, this); - // Reserve space for length - count += 3; - } - - void writeToRecordStream() throws IOException - { - // Patch actual length back in - int length = count - 4; - TlsUtils.checkUint24(length); - TlsUtils.writeUint24(length, buf, 1); - writeHandshakeMessage(buf, 0, count); - buf = null; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsRSAKeyExchange.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsRSAKeyExchange.java deleted file mode 100644 index 5b701d273..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsRSAKeyExchange.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.x509.KeyUsage; -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.util.PublicKeyFactory; -import com.fr.third.org.bouncycastle.util.io.Streams; - -/** - * (D)TLS and SSLv3 RSA key exchange. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsRSAKeyExchange - extends AbstractTlsKeyExchange -{ - protected AsymmetricKeyParameter serverPublicKey = null; - - protected RSAKeyParameters rsaServerPublicKey = null; - - protected TlsEncryptionCredentials serverCredentials = null; - - protected byte[] premasterSecret; - - public TlsRSAKeyExchange(Vector supportedSignatureAlgorithms) - { - super(KeyExchangeAlgorithm.RSA, supportedSignatureAlgorithms); - } - - public void skipServerCredentials() - throws IOException - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - public void processServerCredentials(TlsCredentials serverCredentials) - throws IOException - { - if (!(serverCredentials instanceof TlsEncryptionCredentials)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - processServerCertificate(serverCredentials.getCertificate()); - - this.serverCredentials = (TlsEncryptionCredentials)serverCredentials; - } - - public void processServerCertificate(Certificate serverCertificate) - throws IOException - { - if (serverCertificate.isEmpty()) - { - throw new TlsFatalAlert(AlertDescription.bad_certificate); - } - - com.fr.third.org.bouncycastle.asn1.x509.Certificate x509Cert = serverCertificate.getCertificateAt(0); - - SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo(); - try - { - this.serverPublicKey = PublicKeyFactory.createKey(keyInfo); - } - catch (RuntimeException e) - { - throw new TlsFatalAlert(AlertDescription.unsupported_certificate, e); - } - - // Sanity check the PublicKeyFactory - if (this.serverPublicKey.isPrivate()) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - this.rsaServerPublicKey = validateRSAPublicKey((RSAKeyParameters)this.serverPublicKey); - - TlsUtils.validateKeyUsage(x509Cert, KeyUsage.keyEncipherment); - - super.processServerCertificate(serverCertificate); - } - - public void validateCertificateRequest(CertificateRequest certificateRequest) - throws IOException - { - short[] types = certificateRequest.getCertificateTypes(); - for (int i = 0; i < types.length; ++i) - { - switch (types[i]) - { - case ClientCertificateType.rsa_sign: - case ClientCertificateType.dss_sign: - case ClientCertificateType.ecdsa_sign: - break; - default: - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - } - } - - public void processClientCredentials(TlsCredentials clientCredentials) - throws IOException - { - if (!(clientCredentials instanceof TlsSignerCredentials)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public void generateClientKeyExchange(OutputStream output) - throws IOException - { - this.premasterSecret = TlsRSAUtils.generateEncryptedPreMasterSecret(context, rsaServerPublicKey, output); - } - - public void processClientKeyExchange(InputStream input) - throws IOException - { - byte[] encryptedPreMasterSecret; - if (TlsUtils.isSSL(context)) - { - // TODO Do any SSLv3 clients actually include the length? - encryptedPreMasterSecret = Streams.readAll(input); - } - else - { - encryptedPreMasterSecret = TlsUtils.readOpaque16(input); - } - - this.premasterSecret = serverCredentials.decryptPreMasterSecret(encryptedPreMasterSecret); - } - - public byte[] generatePremasterSecret() - throws IOException - { - if (this.premasterSecret == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - byte[] tmp = this.premasterSecret; - this.premasterSecret = null; - return tmp; - } - - // Would be needed to process RSA_EXPORT server key exchange - // protected void processRSAServerKeyExchange(InputStream is, Signer signer) throws IOException - // { - // InputStream sigIn = is; - // if (signer != null) - // { - // sigIn = new SignerInputStream(is, signer); - // } - // - // byte[] modulusBytes = TlsUtils.readOpaque16(sigIn); - // byte[] exponentBytes = TlsUtils.readOpaque16(sigIn); - // - // if (signer != null) - // { - // byte[] sigByte = TlsUtils.readOpaque16(is); - // - // if (!signer.verifySignature(sigByte)) - // { - // handler.failWithError(AlertLevel.fatal, AlertDescription.bad_certificate); - // } - // } - // - // BigInteger modulus = new BigInteger(1, modulusBytes); - // BigInteger exponent = new BigInteger(1, exponentBytes); - // - // this.rsaServerPublicKey = validateRSAPublicKey(new RSAKeyParameters(false, modulus, - // exponent)); - // } - - protected RSAKeyParameters validateRSAPublicKey(RSAKeyParameters key) - throws IOException - { - // TODO What is the minimum bit length required? - // key.getModulus().bitLength(); - - if (!key.getExponent().isProbablePrime(2)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - return key; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsRSASigner.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsRSASigner.java deleted file mode 100644 index b58c45d13..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsRSASigner.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.crypto.AsymmetricBlockCipher; -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.CryptoException; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.Signer; -import com.fr.third.org.bouncycastle.crypto.digests.NullDigest; -import com.fr.third.org.bouncycastle.crypto.encodings.PKCS1Encoding; -import com.fr.third.org.bouncycastle.crypto.engines.RSABlindedEngine; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.signers.GenericSigner; -import com.fr.third.org.bouncycastle.crypto.signers.RSADigestSigner; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsRSASigner - extends AbstractTlsSigner -{ - public byte[] generateRawSignature(SignatureAndHashAlgorithm algorithm, - AsymmetricKeyParameter privateKey, byte[] hash) - throws CryptoException - { - Signer signer = makeSigner(algorithm, true, true, - new ParametersWithRandom(privateKey, this.context.getSecureRandom())); - signer.update(hash, 0, hash.length); - return signer.generateSignature(); - } - - public boolean verifyRawSignature(SignatureAndHashAlgorithm algorithm, byte[] sigBytes, - AsymmetricKeyParameter publicKey, byte[] hash) - throws CryptoException - { - Signer signer = makeSigner(algorithm, true, false, publicKey); - signer.update(hash, 0, hash.length); - return signer.verifySignature(sigBytes); - } - - public Signer createSigner(SignatureAndHashAlgorithm algorithm, AsymmetricKeyParameter privateKey) - { - return makeSigner(algorithm, false, true, new ParametersWithRandom(privateKey, this.context.getSecureRandom())); - } - - public Signer createVerifyer(SignatureAndHashAlgorithm algorithm, AsymmetricKeyParameter publicKey) - { - return makeSigner(algorithm, false, false, publicKey); - } - - public boolean isValidPublicKey(AsymmetricKeyParameter publicKey) - { - return publicKey instanceof RSAKeyParameters && !publicKey.isPrivate(); - } - - protected Signer makeSigner(SignatureAndHashAlgorithm algorithm, boolean raw, boolean forSigning, - CipherParameters cp) - { - if ((algorithm != null) != TlsUtils.isTLSv12(context)) - { - throw new IllegalStateException(); - } - - if (algorithm != null && algorithm.getSignature() != SignatureAlgorithm.rsa) - { - throw new IllegalStateException(); - } - - Digest d; - if (raw) - { - d = new NullDigest(); - } - else if (algorithm == null) - { - d = new CombinedHash(); - } - else - { - d = TlsUtils.createHash(algorithm.getHash()); - } - - Signer s; - if (algorithm != null) - { - /* - * RFC 5246 4.7. In RSA signing, the opaque vector contains the signature generated - * using the RSASSA-PKCS1-v1_5 signature scheme defined in [PKCS1]. - */ - s = new RSADigestSigner(d, TlsUtils.getOIDForHashAlgorithm(algorithm.getHash())); - } - else - { - /* - * RFC 5246 4.7. Note that earlier versions of TLS used a different RSA signature scheme - * that did not include a DigestInfo encoding. - */ - s = new GenericSigner(createRSAImpl(), d); - } - s.init(forSigning, cp); - return s; - } - - protected AsymmetricBlockCipher createRSAImpl() - { - /* - * RFC 5246 7.4.7.1. Implementation note: It is now known that remote timing-based attacks - * on TLS are possible, at least when the client and server are on the same LAN. - * Accordingly, implementations that use static RSA keys MUST use RSA blinding or some other - * anti-timing technique, as described in [TIMING]. - */ - return new PKCS1Encoding(new RSABlindedEngine()); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsRSAUtils.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsRSAUtils.java deleted file mode 100644 index 78ed90545..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsRSAUtils.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.OutputStream; - -import com.fr.third.org.bouncycastle.crypto.InvalidCipherTextException; -import com.fr.third.org.bouncycastle.crypto.encodings.PKCS1Encoding; -import com.fr.third.org.bouncycastle.crypto.engines.RSABlindedEngine; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithRandom; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsRSAUtils -{ - public static byte[] generateEncryptedPreMasterSecret(TlsContext context, RSAKeyParameters rsaServerPublicKey, - OutputStream output) throws IOException - { - /* - * Choose a PremasterSecret and send it encrypted to the server - */ - byte[] premasterSecret = new byte[48]; - context.getSecureRandom().nextBytes(premasterSecret); - TlsUtils.writeVersion(context.getClientVersion(), premasterSecret, 0); - - PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine()); - encoding.init(true, new ParametersWithRandom(rsaServerPublicKey, context.getSecureRandom())); - - try - { - byte[] encryptedPreMasterSecret = encoding.processBlock(premasterSecret, 0, premasterSecret.length); - - if (TlsUtils.isSSL(context)) - { - // TODO Do any SSLv3 servers actually expect the length? - output.write(encryptedPreMasterSecret); - } - else - { - TlsUtils.writeOpaque16(encryptedPreMasterSecret, output); - } - } - catch (InvalidCipherTextException e) - { - /* - * This should never happen, only during decryption. - */ - throw new TlsFatalAlert(AlertDescription.internal_error, e); - } - - return premasterSecret; - } - - public static byte[] safeDecryptPreMasterSecret(TlsContext context, RSAKeyParameters rsaServerPrivateKey, - byte[] encryptedPreMasterSecret) - { - /* - * RFC 5246 7.4.7.1. - */ - ProtocolVersion clientVersion = context.getClientVersion(); - - // TODO Provide as configuration option? - boolean versionNumberCheckDisabled = false; - - /* - * Generate 48 random bytes we can use as a Pre-Master-Secret, if the - * PKCS1 padding check should fail. - */ - byte[] fallback = new byte[48]; - context.getSecureRandom().nextBytes(fallback); - - byte[] M = Arrays.clone(fallback); - try - { - PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine(), fallback); - encoding.init(false, - new ParametersWithRandom(rsaServerPrivateKey, context.getSecureRandom())); - - M = encoding.processBlock(encryptedPreMasterSecret, 0, encryptedPreMasterSecret.length); - } - catch (Exception e) - { - /* - * This should never happen since the decryption should never throw an exception - * and return a random value instead. - * - * In any case, a TLS server MUST NOT generate an alert if processing an - * RSA-encrypted premaster secret message fails, or the version number is not as - * expected. Instead, it MUST continue the handshake with a randomly generated - * premaster secret. - */ - } - - /* - * If ClientHello.client_version is TLS 1.1 or higher, server implementations MUST - * check the version number [..]. - */ - if (versionNumberCheckDisabled && clientVersion.isEqualOrEarlierVersionOf(ProtocolVersion.TLSv10)) - { - /* - * If the version number is TLS 1.0 or earlier, server - * implementations SHOULD check the version number, but MAY have a - * configuration option to disable the check. - * - * So there is nothing to do here. - */ - } - else - { - /* - * OK, we need to compare the version number in the decrypted Pre-Master-Secret with the - * clientVersion received during the handshake. If they don't match, we replace the - * decrypted Pre-Master-Secret with a random one. - */ - int correct = (clientVersion.getMajorVersion() ^ (M[0] & 0xff)) - | (clientVersion.getMinorVersion() ^ (M[1] & 0xff)); - correct |= correct >> 1; - correct |= correct >> 2; - correct |= correct >> 4; - int mask = ~((correct & 1) - 1); - - /* - * mask will be all bits set to 0xff if the version number differed. - */ - for (int i = 0; i < 48; i++) - { - M[i] = (byte)((M[i] & (~mask)) | (fallback[i] & mask)); - } - } - return M; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPGroupVerifier.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPGroupVerifier.java deleted file mode 100644 index 242a026ca..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPGroupVerifier.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.crypto.params.SRP6GroupParameters; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsSRPGroupVerifier -{ - /** - * Check whether the given SRP group parameters are acceptable for use. - * - * @param group the {@link SRP6GroupParameters} to check - * @return true if (and only if) the specified group parameters are acceptable - */ - boolean accept(SRP6GroupParameters group); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPIdentityManager.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPIdentityManager.java deleted file mode 100644 index f65ef86b3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPIdentityManager.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsSRPIdentityManager -{ - /** - * Lookup the {@link TlsSRPLoginParameters} corresponding to the specified identity. - * - * NOTE: To avoid "identity probing", unknown identities SHOULD be handled as recommended in RFC - * 5054 2.5.1.3. {@link SimulatedTlsSRPIdentityManager} is provided for this purpose. - * - * @param identity - * the SRP identity sent by the connecting client - * @return the {@link TlsSRPLoginParameters} for the specified identity, or else 'simulated' - * parameters if the identity is not recognized. A null value is also allowed, but not - * recommended. - */ - TlsSRPLoginParameters getLoginParameters(byte[] identity); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPKeyExchange.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPKeyExchange.java deleted file mode 100644 index 734e0e512..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPKeyExchange.java +++ /dev/null @@ -1,314 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.math.BigInteger; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.x509.KeyUsage; -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.crypto.CryptoException; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.Signer; -import com.fr.third.org.bouncycastle.crypto.agreement.srp.SRP6Client; -import com.fr.third.org.bouncycastle.crypto.agreement.srp.SRP6Server; -import com.fr.third.org.bouncycastle.crypto.agreement.srp.SRP6Util; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.SRP6GroupParameters; -import com.fr.third.org.bouncycastle.crypto.util.PublicKeyFactory; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.BigIntegers; -import com.fr.third.org.bouncycastle.util.io.TeeInputStream; - -/** - * (D)TLS SRP key exchange (RFC 5054). - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsSRPKeyExchange extends AbstractTlsKeyExchange -{ - protected static TlsSigner createSigner(int keyExchange) - { - switch (keyExchange) - { - case KeyExchangeAlgorithm.SRP: - return null; - case KeyExchangeAlgorithm.SRP_RSA: - return new TlsRSASigner(); - case KeyExchangeAlgorithm.SRP_DSS: - return new TlsDSSSigner(); - default: - throw new IllegalArgumentException("unsupported key exchange algorithm"); - } - } - - protected TlsSigner tlsSigner; - protected TlsSRPGroupVerifier groupVerifier; - protected byte[] identity; - protected byte[] password; - - protected AsymmetricKeyParameter serverPublicKey = null; - - protected SRP6GroupParameters srpGroup = null; - protected SRP6Client srpClient = null; - protected SRP6Server srpServer = null; - protected BigInteger srpPeerCredentials = null; - protected BigInteger srpVerifier = null; - protected byte[] srpSalt = null; - - protected TlsSignerCredentials serverCredentials = null; - - /** - * @deprecated Use constructor taking an explicit 'groupVerifier' argument - */ - public TlsSRPKeyExchange(int keyExchange, Vector supportedSignatureAlgorithms, byte[] identity, byte[] password) - { - this(keyExchange, supportedSignatureAlgorithms, new DefaultTlsSRPGroupVerifier(), identity, password); - } - - public TlsSRPKeyExchange(int keyExchange, Vector supportedSignatureAlgorithms, TlsSRPGroupVerifier groupVerifier, - byte[] identity, byte[] password) - { - super(keyExchange, supportedSignatureAlgorithms); - - this.tlsSigner = createSigner(keyExchange); - this.groupVerifier = groupVerifier; - this.identity = identity; - this.password = password; - this.srpClient = new SRP6Client(); - } - - public TlsSRPKeyExchange(int keyExchange, Vector supportedSignatureAlgorithms, byte[] identity, - TlsSRPLoginParameters loginParameters) - { - super(keyExchange, supportedSignatureAlgorithms); - - this.tlsSigner = createSigner(keyExchange); - this.identity = identity; - this.srpServer = new SRP6Server(); - this.srpGroup = loginParameters.getGroup(); - this.srpVerifier = loginParameters.getVerifier(); - this.srpSalt = loginParameters.getSalt(); - } - - public void init(TlsContext context) - { - super.init(context); - - if (this.tlsSigner != null) - { - this.tlsSigner.init(context); - } - } - - public void skipServerCredentials() throws IOException - { - if (tlsSigner != null) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - - public void processServerCertificate(Certificate serverCertificate) throws IOException - { - if (tlsSigner == null) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - if (serverCertificate.isEmpty()) - { - throw new TlsFatalAlert(AlertDescription.bad_certificate); - } - - com.fr.third.org.bouncycastle.asn1.x509.Certificate x509Cert = serverCertificate.getCertificateAt(0); - - SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo(); - try - { - this.serverPublicKey = PublicKeyFactory.createKey(keyInfo); - } - catch (RuntimeException e) - { - throw new TlsFatalAlert(AlertDescription.unsupported_certificate, e); - } - - if (!tlsSigner.isValidPublicKey(this.serverPublicKey)) - { - throw new TlsFatalAlert(AlertDescription.certificate_unknown); - } - - TlsUtils.validateKeyUsage(x509Cert, KeyUsage.digitalSignature); - - super.processServerCertificate(serverCertificate); - } - - public void processServerCredentials(TlsCredentials serverCredentials) - throws IOException - { - if ((keyExchange == KeyExchangeAlgorithm.SRP) || !(serverCredentials instanceof TlsSignerCredentials)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - processServerCertificate(serverCredentials.getCertificate()); - - this.serverCredentials = (TlsSignerCredentials)serverCredentials; - } - - public boolean requiresServerKeyExchange() - { - return true; - } - - public byte[] generateServerKeyExchange() throws IOException - { - srpServer.init(srpGroup, srpVerifier, TlsUtils.createHash(HashAlgorithm.sha1), context.getSecureRandom()); - BigInteger B = srpServer.generateServerCredentials(); - - ServerSRPParams srpParams = new ServerSRPParams(srpGroup.getN(), srpGroup.getG(), srpSalt, B); - - DigestInputBuffer buf = new DigestInputBuffer(); - - srpParams.encode(buf); - - if (serverCredentials != null) - { - /* - * RFC 5246 4.7. digitally-signed element needs SignatureAndHashAlgorithm from TLS 1.2 - */ - SignatureAndHashAlgorithm signatureAndHashAlgorithm = TlsUtils.getSignatureAndHashAlgorithm( - context, serverCredentials); - - Digest d = TlsUtils.createHash(signatureAndHashAlgorithm); - - SecurityParameters securityParameters = context.getSecurityParameters(); - d.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length); - d.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length); - buf.updateDigest(d); - - byte[] hash = new byte[d.getDigestSize()]; - d.doFinal(hash, 0); - - byte[] signature = serverCredentials.generateCertificateSignature(hash); - - DigitallySigned signed_params = new DigitallySigned(signatureAndHashAlgorithm, signature); - signed_params.encode(buf); - } - - return buf.toByteArray(); - } - - public void processServerKeyExchange(InputStream input) throws IOException - { - SecurityParameters securityParameters = context.getSecurityParameters(); - - SignerInputBuffer buf = null; - InputStream teeIn = input; - - if (tlsSigner != null) - { - buf = new SignerInputBuffer(); - teeIn = new TeeInputStream(input, buf); - } - - ServerSRPParams srpParams = ServerSRPParams.parse(teeIn); - - if (buf != null) - { - DigitallySigned signed_params = parseSignature(input); - - Signer signer = initVerifyer(tlsSigner, signed_params.getAlgorithm(), securityParameters); - buf.updateSigner(signer); - if (!signer.verifySignature(signed_params.getSignature())) - { - throw new TlsFatalAlert(AlertDescription.decrypt_error); - } - } - - this.srpGroup = new SRP6GroupParameters(srpParams.getN(), srpParams.getG()); - - if (!groupVerifier.accept(srpGroup)) - { - throw new TlsFatalAlert(AlertDescription.insufficient_security); - } - - this.srpSalt = srpParams.getS(); - - /* - * RFC 5054 2.5.3: The client MUST abort the handshake with an "illegal_parameter" alert if - * B % N = 0. - */ - try - { - this.srpPeerCredentials = SRP6Util.validatePublicValue(srpGroup.getN(), srpParams.getB()); - } - catch (CryptoException e) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter, e); - } - - this.srpClient.init(srpGroup, TlsUtils.createHash(HashAlgorithm.sha1), context.getSecureRandom()); - } - - public void validateCertificateRequest(CertificateRequest certificateRequest) throws IOException - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - public void processClientCredentials(TlsCredentials clientCredentials) throws IOException - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - public void generateClientKeyExchange(OutputStream output) throws IOException - { - BigInteger A = srpClient.generateClientCredentials(srpSalt, identity, password); - TlsSRPUtils.writeSRPParameter(A, output); - - context.getSecurityParameters().srpIdentity = Arrays.clone(identity); - } - - public void processClientKeyExchange(InputStream input) throws IOException - { - /* - * RFC 5054 2.5.4: The server MUST abort the handshake with an "illegal_parameter" alert if - * A % N = 0. - */ - try - { - this.srpPeerCredentials = SRP6Util.validatePublicValue(srpGroup.getN(), TlsSRPUtils.readSRPParameter(input)); - } - catch (CryptoException e) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter, e); - } - - context.getSecurityParameters().srpIdentity = Arrays.clone(identity); - } - - public byte[] generatePremasterSecret() throws IOException - { - try - { - BigInteger S = srpServer != null - ? srpServer.calculateSecret(srpPeerCredentials) - : srpClient.calculateSecret(srpPeerCredentials); - - // TODO Check if this needs to be a fixed size - return BigIntegers.asUnsignedByteArray(S); - } - catch (CryptoException e) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter, e); - } - } - - protected Signer initVerifyer(TlsSigner tlsSigner, SignatureAndHashAlgorithm algorithm, SecurityParameters securityParameters) - { - Signer signer = tlsSigner.createVerifyer(algorithm, this.serverPublicKey); - signer.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length); - signer.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length); - return signer; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPLoginParameters.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPLoginParameters.java deleted file mode 100644 index 4083d97f1..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPLoginParameters.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.crypto.params.SRP6GroupParameters; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsSRPLoginParameters -{ - protected SRP6GroupParameters group; - protected BigInteger verifier; - protected byte[] salt; - - public TlsSRPLoginParameters(SRP6GroupParameters group, BigInteger verifier, byte[] salt) - { - this.group = group; - this.verifier = verifier; - this.salt = salt; - } - - public SRP6GroupParameters getGroup() - { - return group; - } - - public byte[] getSalt() - { - return salt; - } - - public BigInteger getVerifier() - { - return verifier; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPUtils.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPUtils.java deleted file mode 100644 index 26d7deffa..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRPUtils.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.math.BigInteger; -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.util.BigIntegers; -import com.fr.third.org.bouncycastle.util.Integers; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsSRPUtils -{ - public static final Integer EXT_SRP = Integers.valueOf(ExtensionType.srp); - - public static void addSRPExtension(Hashtable extensions, byte[] identity) throws IOException - { - extensions.put(EXT_SRP, createSRPExtension(identity)); - } - - public static byte[] getSRPExtension(Hashtable extensions) throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_SRP); - return extensionData == null ? null : readSRPExtension(extensionData); - } - - public static byte[] createSRPExtension(byte[] identity) throws IOException - { - if (identity == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - return TlsUtils.encodeOpaque8(identity); - } - - public static byte[] readSRPExtension(byte[] extensionData) throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - - ByteArrayInputStream buf = new ByteArrayInputStream(extensionData); - byte[] identity = TlsUtils.readOpaque8(buf); - - TlsProtocol.assertEmpty(buf); - - return identity; - } - - public static BigInteger readSRPParameter(InputStream input) throws IOException - { - return new BigInteger(1, TlsUtils.readOpaque16(input)); - } - - public static void writeSRPParameter(BigInteger x, OutputStream output) throws IOException - { - TlsUtils.writeOpaque16(BigIntegers.asUnsignedByteArray(x), output); - } - - public static boolean isSRPCipherSuite(int cipherSuite) - { - switch (cipherSuite) - { - case CipherSuite.TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_WITH_AES_256_CBC_SHA: - return true; - - default: - return false; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRTPUtils.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRTPUtils.java deleted file mode 100644 index 4252a4cc4..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSRTPUtils.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.util.Integers; - -/** - * RFC 5764 DTLS Extension to Establish Keys for SRTP. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsSRTPUtils -{ - public static final Integer EXT_use_srtp = Integers.valueOf(ExtensionType.use_srtp); - - public static void addUseSRTPExtension(Hashtable extensions, UseSRTPData useSRTPData) - throws IOException - { - extensions.put(EXT_use_srtp, createUseSRTPExtension(useSRTPData)); - } - - public static UseSRTPData getUseSRTPExtension(Hashtable extensions) - throws IOException - { - byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_use_srtp); - return extensionData == null ? null : readUseSRTPExtension(extensionData); - } - - public static byte[] createUseSRTPExtension(UseSRTPData useSRTPData) - throws IOException - { - if (useSRTPData == null) - { - throw new IllegalArgumentException("'useSRTPData' cannot be null"); - } - - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - // SRTPProtectionProfiles - TlsUtils.writeUint16ArrayWithUint16Length(useSRTPData.getProtectionProfiles(), buf); - - // srtp_mki - TlsUtils.writeOpaque8(useSRTPData.getMki(), buf); - - return buf.toByteArray(); - } - - public static UseSRTPData readUseSRTPExtension(byte[] extensionData) - throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - - ByteArrayInputStream buf = new ByteArrayInputStream(extensionData); - - // SRTPProtectionProfiles - int length = TlsUtils.readUint16(buf); - if (length < 2 || (length & 1) != 0) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - int[] protectionProfiles = TlsUtils.readUint16Array(length / 2, buf); - - // srtp_mki - byte[] mki = TlsUtils.readOpaque8(buf); - - TlsProtocol.assertEmpty(buf); - - return new UseSRTPData(protectionProfiles, mki); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsServer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsServer.java deleted file mode 100644 index 5017481fc..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsServer.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.util.Hashtable; -import java.util.Vector; - -/** - * Interface describing a TLS server endpoint. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsServer - extends TlsPeer -{ - void init(TlsServerContext context); - - void notifyClientVersion(ProtocolVersion clientVersion) throws IOException; - - void notifyFallback(boolean isFallback) throws IOException; - - void notifyOfferedCipherSuites(int[] offeredCipherSuites) - throws IOException; - - void notifyOfferedCompressionMethods(short[] offeredCompressionMethods) - throws IOException; - - // Hashtable is (Integer -> byte[]) - void processClientExtensions(Hashtable clientExtensions) - throws IOException; - - ProtocolVersion getServerVersion() - throws IOException; - - int getSelectedCipherSuite() - throws IOException; - - short getSelectedCompressionMethod() - throws IOException; - - // Hashtable is (Integer -> byte[]) - Hashtable getServerExtensions() - throws IOException; - - // Vector is (SupplementalDataEntry) - Vector getServerSupplementalData() - throws IOException; - - TlsCredentials getCredentials() - throws IOException; - - /** - * This method will be called (only) if the server included an extension of type - * "status_request" with empty "extension_data" in the extended server hello. See RFC 3546 - * 3.6. Certificate Status Request. If a non-null {@link CertificateStatus} is returned, it - * is sent to the client as a handshake message of type "certificate_status". - * - * @return A {@link CertificateStatus} to be sent to the client (or null for none). - * @throws IOException - */ - CertificateStatus getCertificateStatus() - throws IOException; - - TlsKeyExchange getKeyExchange() - throws IOException; - - CertificateRequest getCertificateRequest() - throws IOException; - - // Vector is (SupplementalDataEntry) - void processClientSupplementalData(Vector clientSupplementalData) - throws IOException; - - /** - * Called by the protocol handler to report the client certificate, only if - * {@link #getCertificateRequest()} returned non-null. - * - * Note: this method is responsible for certificate verification and validation. - * - * @param clientCertificate - * the effective client certificate (may be an empty chain). - * @throws IOException - */ - void notifyClientCertificate(Certificate clientCertificate) - throws IOException; - - /** - * RFC 5077 3.3. NewSessionTicket Handshake Message. - *- * This method will be called (only) if a NewSessionTicket extension was sent by the server. See - * RFC 5077 4. Recommended Ticket Construction for recommended format and protection. - * - * @return The ticket. - * @throws IOException - */ - NewSessionTicket getNewSessionTicket() - throws IOException; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsServerContext.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsServerContext.java deleted file mode 100644 index 4f011aa35..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsServerContext.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * Marker interface to distinguish a TLS server context. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsServerContext - extends TlsContext -{ -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsServerContextImpl.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsServerContextImpl.java deleted file mode 100644 index 5012373f0..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsServerContextImpl.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.security.SecureRandom; - -class TlsServerContextImpl - extends AbstractTlsContext - implements TlsServerContext -{ - TlsServerContextImpl(SecureRandom secureRandom, SecurityParameters securityParameters) - { - super(secureRandom, securityParameters); - } - - public boolean isServer() - { - return true; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsServerProtocol.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsServerProtocol.java deleted file mode 100644 index 9a426fa2e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsServerProtocol.java +++ /dev/null @@ -1,876 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.security.SecureRandom; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.util.PublicKeyFactory; -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsServerProtocol - extends TlsProtocol -{ - protected TlsServer tlsServer = null; - TlsServerContextImpl tlsServerContext = null; - - protected TlsKeyExchange keyExchange = null; - protected TlsCredentials serverCredentials = null; - protected CertificateRequest certificateRequest = null; - - protected short clientCertificateType = -1; - protected TlsHandshakeHash prepareFinishHash = null; - - /** - * Constructor for blocking mode. - * @param input The stream of data from the client - * @param output The stream of data to the client - * @param secureRandom Random number generator for various cryptographic functions - */ - public TlsServerProtocol(InputStream input, OutputStream output, SecureRandom secureRandom) - { - super(input, output, secureRandom); - } - - /** - * Constructor for non-blocking mode.
-A lightweight TLS API. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/DTLSClientTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/DTLSClientTest.java deleted file mode 100644 index b1b36af83..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/DTLSClientTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.net.DatagramSocket; -import java.net.InetAddress; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.tls.DTLSClientProtocol; -import com.fr.third.org.bouncycastle.crypto.tls.DTLSTransport; -import com.fr.third.org.bouncycastle.crypto.tls.DatagramTransport; -import com.fr.third.org.bouncycastle.crypto.tls.TlsClient; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSession; -import com.fr.third.org.bouncycastle.crypto.tls.UDPTransport; - -/** - * A simple test designed to conduct a DTLS handshake with an external DTLS server. - *
- *
- * When data is received, use {@link #offerInput(byte[])} to provide the received ciphertext, - * then use {@link #readInput(byte[], int, int)} to read the corresponding cleartext.
- *
- * Similarly, when data needs to be sent, use {@link #offerOutput(byte[], int, int)} to provide - * the cleartext, then use {@link #readOutput(byte[], int, int)} to get the corresponding - * ciphertext. - * - * @param secureRandom - * Random number generator for various cryptographic functions - */ - public TlsServerProtocol(SecureRandom secureRandom) - { - super(secureRandom); - } - - /** - * Receives a TLS handshake in the role of server.
- *
- * In blocking mode, this will not return until the handshake is complete. - * In non-blocking mode, use {@link TlsPeer#notifyHandshakeComplete()} to - * receive a callback when the handshake is complete. - * - * @param tlsServer - * @throws IOException If in blocking mode and handshake was not successful. - */ - public void accept(TlsServer tlsServer) - throws IOException - { - if (tlsServer == null) - { - throw new IllegalArgumentException("'tlsServer' cannot be null"); - } - if (this.tlsServer != null) - { - throw new IllegalStateException("'accept' can only be called once"); - } - - this.tlsServer = tlsServer; - - this.securityParameters = new SecurityParameters(); - this.securityParameters.entity = ConnectionEnd.server; - - this.tlsServerContext = new TlsServerContextImpl(secureRandom, securityParameters); - - this.securityParameters.serverRandom = createRandomBlock(tlsServer.shouldUseGMTUnixTime(), - tlsServerContext.getNonceRandomGenerator()); - - this.tlsServer.init(tlsServerContext); - this.recordStream.init(tlsServerContext); - - tlsServer.notifyCloseHandle(this); - - this.recordStream.setRestrictReadVersion(false); - - blockForHandshake(); - } - - protected void cleanupHandshake() - { - super.cleanupHandshake(); - - this.keyExchange = null; - this.serverCredentials = null; - this.certificateRequest = null; - this.prepareFinishHash = null; - } - - protected TlsContext getContext() - { - return tlsServerContext; - } - - AbstractTlsContext getContextAdmin() - { - return tlsServerContext; - } - - protected TlsPeer getPeer() - { - return tlsServer; - } - - protected void handleHandshakeMessage(short type, ByteArrayInputStream buf) - throws IOException - { - switch (type) - { - case HandshakeType.client_hello: - { - switch (this.connection_state) - { - case CS_START: - { - receiveClientHelloMessage(buf); - this.connection_state = CS_CLIENT_HELLO; - - sendServerHelloMessage(); - this.connection_state = CS_SERVER_HELLO; - - recordStream.notifyHelloComplete(); - - Vector serverSupplementalData = tlsServer.getServerSupplementalData(); - if (serverSupplementalData != null) - { - sendSupplementalDataMessage(serverSupplementalData); - } - this.connection_state = CS_SERVER_SUPPLEMENTAL_DATA; - - this.keyExchange = tlsServer.getKeyExchange(); - this.keyExchange.init(getContext()); - - this.serverCredentials = tlsServer.getCredentials(); - - Certificate serverCertificate = null; - - if (this.serverCredentials == null) - { - this.keyExchange.skipServerCredentials(); - } - else - { - this.keyExchange.processServerCredentials(this.serverCredentials); - - serverCertificate = this.serverCredentials.getCertificate(); - sendCertificateMessage(serverCertificate); - } - this.connection_state = CS_SERVER_CERTIFICATE; - - // TODO[RFC 3546] Check whether empty certificates is possible, allowed, or excludes CertificateStatus - if (serverCertificate == null || serverCertificate.isEmpty()) - { - this.allowCertificateStatus = false; - } - - if (this.allowCertificateStatus) - { - CertificateStatus certificateStatus = tlsServer.getCertificateStatus(); - if (certificateStatus != null) - { - sendCertificateStatusMessage(certificateStatus); - } - } - - this.connection_state = CS_CERTIFICATE_STATUS; - - byte[] serverKeyExchange = this.keyExchange.generateServerKeyExchange(); - if (serverKeyExchange != null) - { - sendServerKeyExchangeMessage(serverKeyExchange); - } - this.connection_state = CS_SERVER_KEY_EXCHANGE; - - if (this.serverCredentials != null) - { - this.certificateRequest = tlsServer.getCertificateRequest(); - if (this.certificateRequest != null) - { - if (TlsUtils.isTLSv12(getContext()) != (certificateRequest.getSupportedSignatureAlgorithms() != null)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - this.keyExchange.validateCertificateRequest(certificateRequest); - - sendCertificateRequestMessage(certificateRequest); - - TlsUtils.trackHashAlgorithms(this.recordStream.getHandshakeHash(), - this.certificateRequest.getSupportedSignatureAlgorithms()); - } - } - this.connection_state = CS_CERTIFICATE_REQUEST; - - sendServerHelloDoneMessage(); - this.connection_state = CS_SERVER_HELLO_DONE; - - this.recordStream.getHandshakeHash().sealHashAlgorithms(); - - break; - } - case CS_END: - { - refuseRenegotiation(); - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - break; - } - case HandshakeType.supplemental_data: - { - switch (this.connection_state) - { - case CS_SERVER_HELLO_DONE: - { - tlsServer.processClientSupplementalData(readSupplementalDataMessage(buf)); - this.connection_state = CS_CLIENT_SUPPLEMENTAL_DATA; - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - break; - } - case HandshakeType.certificate: - { - switch (this.connection_state) - { - case CS_SERVER_HELLO_DONE: - { - tlsServer.processClientSupplementalData(null); - // NB: Fall through to next case label - } - case CS_CLIENT_SUPPLEMENTAL_DATA: - { - if (this.certificateRequest == null) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - receiveCertificateMessage(buf); - this.connection_state = CS_CLIENT_CERTIFICATE; - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - break; - } - case HandshakeType.client_key_exchange: - { - switch (this.connection_state) - { - case CS_SERVER_HELLO_DONE: - { - tlsServer.processClientSupplementalData(null); - // NB: Fall through to next case label - } - case CS_CLIENT_SUPPLEMENTAL_DATA: - { - if (this.certificateRequest == null) - { - this.keyExchange.skipClientCredentials(); - } - else - { - if (TlsUtils.isTLSv12(getContext())) - { - /* - * RFC 5246 If no suitable certificate is available, the client MUST send a - * certificate message containing no certificates. - * - * NOTE: In previous RFCs, this was SHOULD instead of MUST. - */ - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - else if (TlsUtils.isSSL(getContext())) - { - if (this.peerCertificate == null) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - else - { - notifyClientCertificate(Certificate.EMPTY_CHAIN); - } - } - // NB: Fall through to next case label - } - case CS_CLIENT_CERTIFICATE: - { - receiveClientKeyExchangeMessage(buf); - this.connection_state = CS_CLIENT_KEY_EXCHANGE; - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - break; - } - case HandshakeType.certificate_verify: - { - switch (this.connection_state) - { - case CS_CLIENT_KEY_EXCHANGE: - { - /* - * RFC 5246 7.4.8 This message is only sent following a client certificate that has - * signing capability (i.e., all certificates except those containing fixed - * Diffie-Hellman parameters). - */ - if (!expectCertificateVerifyMessage()) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - receiveCertificateVerifyMessage(buf); - this.connection_state = CS_CERTIFICATE_VERIFY; - - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - break; - } - case HandshakeType.finished: - { - switch (this.connection_state) - { - case CS_CLIENT_KEY_EXCHANGE: - { - if (expectCertificateVerifyMessage()) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - // NB: Fall through to next case label - } - case CS_CERTIFICATE_VERIFY: - { - processFinishedMessage(buf); - this.connection_state = CS_CLIENT_FINISHED; - - if (this.expectSessionTicket) - { - sendNewSessionTicketMessage(tlsServer.getNewSessionTicket()); - } - this.connection_state = CS_SERVER_SESSION_TICKET; - - sendChangeCipherSpecMessage(); - sendFinishedMessage(); - this.connection_state = CS_SERVER_FINISHED; - - completeHandshake(); - break; - } - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - break; - } - case HandshakeType.hello_request: - case HandshakeType.hello_verify_request: - case HandshakeType.server_hello: - case HandshakeType.server_key_exchange: - case HandshakeType.certificate_request: - case HandshakeType.server_hello_done: - case HandshakeType.session_ticket: - default: - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - - protected void handleAlertWarningMessage(short alertDescription) - throws IOException - { - super.handleAlertWarningMessage(alertDescription); - - switch (alertDescription) - { - case AlertDescription.no_certificate: - { - /* - * SSL 3.0 If the server has sent a certificate request Message, the client must send - * either the certificate message or a no_certificate alert. - */ - if (TlsUtils.isSSL(getContext()) && this.certificateRequest != null) - { - switch (this.connection_state) - { - case CS_SERVER_HELLO_DONE: - { - tlsServer.processClientSupplementalData(null); - // NB: Fall through to next case label - } - case CS_CLIENT_SUPPLEMENTAL_DATA: - { - notifyClientCertificate(Certificate.EMPTY_CHAIN); - this.connection_state = CS_CLIENT_CERTIFICATE; - return; - } - } - } - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - } - } - - protected void notifyClientCertificate(Certificate clientCertificate) - throws IOException - { - if (certificateRequest == null) - { - throw new IllegalStateException(); - } - - if (peerCertificate != null) - { - throw new TlsFatalAlert(AlertDescription.unexpected_message); - } - - this.peerCertificate = clientCertificate; - - if (clientCertificate.isEmpty()) - { - this.keyExchange.skipClientCredentials(); - } - else - { - - /* - * TODO RFC 5246 7.4.6. If the certificate_authorities list in the certificate request - * message was non-empty, one of the certificates in the certificate chain SHOULD be - * issued by one of the listed CAs. - */ - - this.clientCertificateType = TlsUtils.getClientCertificateType(clientCertificate, - this.serverCredentials.getCertificate()); - - this.keyExchange.processClientCertificate(clientCertificate); - } - - /* - * RFC 5246 7.4.6. If the client does not send any certificates, the server MAY at its - * discretion either continue the handshake without client authentication, or respond with a - * fatal handshake_failure alert. Also, if some aspect of the certificate chain was - * unacceptable (e.g., it was not signed by a known, trusted CA), the server MAY at its - * discretion either continue the handshake (considering the client unauthenticated) or send - * a fatal alert. - */ - this.tlsServer.notifyClientCertificate(clientCertificate); - } - - protected void receiveCertificateMessage(ByteArrayInputStream buf) - throws IOException - { - Certificate clientCertificate = Certificate.parse(buf); - - assertEmpty(buf); - - notifyClientCertificate(clientCertificate); - } - - protected void receiveCertificateVerifyMessage(ByteArrayInputStream buf) - throws IOException - { - if (certificateRequest == null) - { - throw new IllegalStateException(); - } - - DigitallySigned clientCertificateVerify = DigitallySigned.parse(getContext(), buf); - - assertEmpty(buf); - - // Verify the CertificateVerify message contains a correct signature. - try - { - SignatureAndHashAlgorithm signatureAlgorithm = clientCertificateVerify.getAlgorithm(); - - byte[] hash; - if (TlsUtils.isTLSv12(getContext())) - { - TlsUtils.verifySupportedSignatureAlgorithm(certificateRequest.getSupportedSignatureAlgorithms(), signatureAlgorithm); - hash = prepareFinishHash.getFinalHash(signatureAlgorithm.getHash()); - } - else - { - hash = securityParameters.getSessionHash(); - } - - com.fr.third.org.bouncycastle.asn1.x509.Certificate x509Cert = peerCertificate.getCertificateAt(0); - SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo(); - AsymmetricKeyParameter publicKey = PublicKeyFactory.createKey(keyInfo); - - TlsSigner tlsSigner = TlsUtils.createTlsSigner(clientCertificateType); - tlsSigner.init(getContext()); - if (!tlsSigner.verifyRawSignature(signatureAlgorithm, clientCertificateVerify.getSignature(), publicKey, hash)) - { - throw new TlsFatalAlert(AlertDescription.decrypt_error); - } - } - catch (TlsFatalAlert e) - { - throw e; - } - catch (Exception e) - { - throw new TlsFatalAlert(AlertDescription.decrypt_error, e); - } - } - - protected void receiveClientHelloMessage(ByteArrayInputStream buf) - throws IOException - { - ProtocolVersion client_version = TlsUtils.readVersion(buf); - recordStream.setWriteVersion(client_version); - - if (client_version.isDTLS()) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - byte[] client_random = TlsUtils.readFully(32, buf); - - /* - * TODO RFC 5077 3.4. If a ticket is presented by the client, the server MUST NOT attempt to - * use the Session ID in the ClientHello for stateful session resumption. - */ - byte[] sessionID = TlsUtils.readOpaque8(buf); - if (sessionID.length > 32) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - /* - * TODO RFC 5246 7.4.1.2. If the session_id field is not empty (implying a session - * resumption request), this vector MUST include at least the cipher_suite from that - * session. - */ - int cipher_suites_length = TlsUtils.readUint16(buf); - if (cipher_suites_length < 2 || (cipher_suites_length & 1) != 0) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - this.offeredCipherSuites = TlsUtils.readUint16Array(cipher_suites_length / 2, buf); - - /* - * TODO RFC 5246 7.4.1.2. If the session_id field is not empty (implying a session - * resumption request), it MUST include the compression_method from that session. - */ - int compression_methods_length = TlsUtils.readUint8(buf); - if (compression_methods_length < 1) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - this.offeredCompressionMethods = TlsUtils.readUint8Array(compression_methods_length, buf); - - /* - * TODO RFC 3546 2.3 If [...] the older session is resumed, then the server MUST ignore - * extensions appearing in the client hello, and send a server hello containing no - * extensions. - */ - this.clientExtensions = readExtensions(buf); - - /* - * TODO[resumption] Check RFC 7627 5.4. for required behaviour - */ - - /* - * RFC 7627 4. Clients and servers SHOULD NOT accept handshakes that do not use the extended - * master secret [..]. (and see 5.2, 5.3) - */ - this.securityParameters.extendedMasterSecret = TlsExtensionsUtils.hasExtendedMasterSecretExtension(clientExtensions); - if (!securityParameters.isExtendedMasterSecret() && tlsServer.requiresExtendedMasterSecret()) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - getContextAdmin().setClientVersion(client_version); - - tlsServer.notifyClientVersion(client_version); - tlsServer.notifyFallback(Arrays.contains(offeredCipherSuites, CipherSuite.TLS_FALLBACK_SCSV)); - - securityParameters.clientRandom = client_random; - - tlsServer.notifyOfferedCipherSuites(offeredCipherSuites); - tlsServer.notifyOfferedCompressionMethods(offeredCompressionMethods); - - /* - * RFC 5746 3.6. Server Behavior: Initial Handshake - */ - { - /* - * RFC 5746 3.4. The client MUST include either an empty "renegotiation_info" extension, - * or the TLS_EMPTY_RENEGOTIATION_INFO_SCSV signaling cipher suite value in the - * ClientHello. Including both is NOT RECOMMENDED. - */ - - /* - * When a ClientHello is received, the server MUST check if it includes the - * TLS_EMPTY_RENEGOTIATION_INFO_SCSV SCSV. If it does, set the secure_renegotiation flag - * to TRUE. - */ - if (Arrays.contains(offeredCipherSuites, CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV)) - { - this.secure_renegotiation = true; - } - - /* - * The server MUST check if the "renegotiation_info" extension is included in the - * ClientHello. - */ - byte[] renegExtData = TlsUtils.getExtensionData(clientExtensions, EXT_RenegotiationInfo); - if (renegExtData != null) - { - /* - * If the extension is present, set secure_renegotiation flag to TRUE. The - * server MUST then verify that the length of the "renegotiated_connection" - * field is zero, and if it is not, MUST abort the handshake. - */ - this.secure_renegotiation = true; - - if (!Arrays.constantTimeAreEqual(renegExtData, createRenegotiationInfo(TlsUtils.EMPTY_BYTES))) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - } - } - - tlsServer.notifySecureRenegotiation(this.secure_renegotiation); - - if (clientExtensions != null) - { - // NOTE: Validates the padding extension data, if present - TlsExtensionsUtils.getPaddingExtension(clientExtensions); - - tlsServer.processClientExtensions(clientExtensions); - } - } - - protected void receiveClientKeyExchangeMessage(ByteArrayInputStream buf) - throws IOException - { - keyExchange.processClientKeyExchange(buf); - - assertEmpty(buf); - - if (TlsUtils.isSSL(getContext())) - { - establishMasterSecret(getContext(), keyExchange); - } - - this.prepareFinishHash = recordStream.prepareToFinish(); - this.securityParameters.sessionHash = getCurrentPRFHash(getContext(), prepareFinishHash, null); - - if (!TlsUtils.isSSL(getContext())) - { - establishMasterSecret(getContext(), keyExchange); - } - - recordStream.setPendingConnectionState(getPeer().getCompression(), getPeer().getCipher()); - } - - protected void sendCertificateRequestMessage(CertificateRequest certificateRequest) - throws IOException - { - HandshakeMessage message = new HandshakeMessage(HandshakeType.certificate_request); - - certificateRequest.encode(message); - - message.writeToRecordStream(); - } - - protected void sendCertificateStatusMessage(CertificateStatus certificateStatus) - throws IOException - { - HandshakeMessage message = new HandshakeMessage(HandshakeType.certificate_status); - - certificateStatus.encode(message); - - message.writeToRecordStream(); - } - - protected void sendNewSessionTicketMessage(NewSessionTicket newSessionTicket) - throws IOException - { - if (newSessionTicket == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - HandshakeMessage message = new HandshakeMessage(HandshakeType.session_ticket); - - newSessionTicket.encode(message); - - message.writeToRecordStream(); - } - - protected void sendServerHelloMessage() - throws IOException - { - HandshakeMessage message = new HandshakeMessage(HandshakeType.server_hello); - - { - ProtocolVersion server_version = tlsServer.getServerVersion(); - if (!server_version.isEqualOrEarlierVersionOf(getContext().getClientVersion())) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - recordStream.setReadVersion(server_version); - recordStream.setWriteVersion(server_version); - recordStream.setRestrictReadVersion(true); - getContextAdmin().setServerVersion(server_version); - - TlsUtils.writeVersion(server_version, message); - } - - message.write(this.securityParameters.serverRandom); - - /* - * The server may return an empty session_id to indicate that the session will not be cached - * and therefore cannot be resumed. - */ - TlsUtils.writeOpaque8(TlsUtils.EMPTY_BYTES, message); - - int selectedCipherSuite = tlsServer.getSelectedCipherSuite(); - if (!Arrays.contains(offeredCipherSuites, selectedCipherSuite) - || selectedCipherSuite == CipherSuite.TLS_NULL_WITH_NULL_NULL - || CipherSuite.isSCSV(selectedCipherSuite) - || !TlsUtils.isValidCipherSuiteForVersion(selectedCipherSuite, getContext().getServerVersion())) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - securityParameters.cipherSuite = selectedCipherSuite; - - short selectedCompressionMethod = tlsServer.getSelectedCompressionMethod(); - if (!Arrays.contains(offeredCompressionMethods, selectedCompressionMethod)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - securityParameters.compressionAlgorithm = selectedCompressionMethod; - - TlsUtils.writeUint16(selectedCipherSuite, message); - TlsUtils.writeUint8(selectedCompressionMethod, message); - - this.serverExtensions = TlsExtensionsUtils.ensureExtensionsInitialised(tlsServer.getServerExtensions()); - - /* - * RFC 5746 3.6. Server Behavior: Initial Handshake - */ - if (this.secure_renegotiation) - { - byte[] renegExtData = TlsUtils.getExtensionData(this.serverExtensions, EXT_RenegotiationInfo); - boolean noRenegExt = (null == renegExtData); - - if (noRenegExt) - { - /* - * Note that sending a "renegotiation_info" extension in response to a ClientHello - * containing only the SCSV is an explicit exception to the prohibition in RFC 5246, - * Section 7.4.1.4, on the server sending unsolicited extensions and is only allowed - * because the client is signaling its willingness to receive the extension via the - * TLS_EMPTY_RENEGOTIATION_INFO_SCSV SCSV. - */ - - /* - * If the secure_renegotiation flag is set to TRUE, the server MUST include an empty - * "renegotiation_info" extension in the ServerHello message. - */ - this.serverExtensions.put(EXT_RenegotiationInfo, createRenegotiationInfo(TlsUtils.EMPTY_BYTES)); - } - } - - if (TlsUtils.isSSL(tlsServerContext)) - { - securityParameters.extendedMasterSecret = false; - } - else if (securityParameters.isExtendedMasterSecret()) - { - TlsExtensionsUtils.addExtendedMasterSecretExtension(serverExtensions); - } - - /* - * TODO RFC 3546 2.3 If [...] the older session is resumed, then the server MUST ignore - * extensions appearing in the client hello, and send a server hello containing no - * extensions. - */ - - if (!this.serverExtensions.isEmpty()) - { - this.securityParameters.encryptThenMAC = TlsExtensionsUtils.hasEncryptThenMACExtension(serverExtensions); - - this.securityParameters.maxFragmentLength = processMaxFragmentLengthExtension(clientExtensions, - serverExtensions, AlertDescription.internal_error); - - this.securityParameters.truncatedHMac = TlsExtensionsUtils.hasTruncatedHMacExtension(serverExtensions); - - /* - * TODO It's surprising that there's no provision to allow a 'fresh' CertificateStatus to be sent in - * a session resumption handshake. - */ - this.allowCertificateStatus = !resumedSession - && TlsUtils.hasExpectedEmptyExtensionData(serverExtensions, TlsExtensionsUtils.EXT_status_request, - AlertDescription.internal_error); - - this.expectSessionTicket = !resumedSession - && TlsUtils.hasExpectedEmptyExtensionData(serverExtensions, TlsProtocol.EXT_SessionTicket, - AlertDescription.internal_error); - - writeExtensions(message, serverExtensions); - } - - securityParameters.prfAlgorithm = getPRFAlgorithm(getContext(), securityParameters.getCipherSuite()); - - /* - * RFC 5246 7.4.9. Any cipher suite which does not explicitly specify verify_data_length has - * a verify_data_length equal to 12. This includes all existing cipher suites. - */ - securityParameters.verifyDataLength = 12; - - applyMaxFragmentLengthExtension(); - - message.writeToRecordStream(); - } - - protected void sendServerHelloDoneMessage() - throws IOException - { - byte[] message = new byte[4]; - TlsUtils.writeUint8(HandshakeType.server_hello_done, message, 0); - TlsUtils.writeUint24(0, message, 1); - - writeHandshakeMessage(message, 0, message.length); - } - - protected void sendServerKeyExchangeMessage(byte[] serverKeyExchange) - throws IOException - { - HandshakeMessage message = new HandshakeMessage(HandshakeType.server_key_exchange, serverKeyExchange.length); - - message.write(serverKeyExchange); - - message.writeToRecordStream(); - } - - protected boolean expectCertificateVerifyMessage() - { - return clientCertificateType >= 0 && TlsUtils.hasSigningCapability(clientCertificateType); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSession.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSession.java deleted file mode 100644 index a9a7bbe7c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSession.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsSession -{ - SessionParameters exportSessionParameters(); - - byte[] getSessionID(); - - void invalidate(); - - boolean isResumable(); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSessionImpl.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSessionImpl.java deleted file mode 100644 index 417c1a4da..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSessionImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.util.Arrays; - -class TlsSessionImpl implements TlsSession -{ - final byte[] sessionID; - final SessionParameters sessionParameters; - boolean resumable; - - TlsSessionImpl(byte[] sessionID, SessionParameters sessionParameters) - { - if (sessionID == null) - { - throw new IllegalArgumentException("'sessionID' cannot be null"); - } - if (sessionID.length > 32) - { - throw new IllegalArgumentException("'sessionID' cannot be longer than 32 bytes"); - } - - this.sessionID = Arrays.clone(sessionID); - this.sessionParameters = sessionParameters; - this.resumable = sessionID.length > 0 - && null != sessionParameters - && sessionParameters.isExtendedMasterSecret(); - } - - public synchronized SessionParameters exportSessionParameters() - { - return this.sessionParameters == null ? null : this.sessionParameters.copy(); - } - - public synchronized byte[] getSessionID() - { - return sessionID; - } - - public synchronized void invalidate() - { - this.resumable = false; - } - - public synchronized boolean isResumable() - { - return resumable; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSigner.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSigner.java deleted file mode 100644 index 950454011..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSigner.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import com.fr.third.org.bouncycastle.crypto.CryptoException; -import com.fr.third.org.bouncycastle.crypto.Signer; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsSigner -{ - void init(TlsContext context); - - byte[] generateRawSignature(AsymmetricKeyParameter privateKey, byte[] md5AndSha1) - throws CryptoException; - - byte[] generateRawSignature(SignatureAndHashAlgorithm algorithm, - AsymmetricKeyParameter privateKey, byte[] hash) - throws CryptoException; - - boolean verifyRawSignature(byte[] sigBytes, AsymmetricKeyParameter publicKey, byte[] md5AndSha1) - throws CryptoException; - - boolean verifyRawSignature(SignatureAndHashAlgorithm algorithm, byte[] sigBytes, - AsymmetricKeyParameter publicKey, byte[] hash) - throws CryptoException; - - Signer createSigner(AsymmetricKeyParameter privateKey); - - Signer createSigner(SignatureAndHashAlgorithm algorithm, AsymmetricKeyParameter privateKey); - - Signer createVerifyer(AsymmetricKeyParameter publicKey); - - Signer createVerifyer(SignatureAndHashAlgorithm algorithm, AsymmetricKeyParameter publicKey); - - boolean isValidPublicKey(AsymmetricKeyParameter publicKey); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSignerCredentials.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSignerCredentials.java deleted file mode 100644 index 381608d89..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsSignerCredentials.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public interface TlsSignerCredentials - extends TlsCredentials -{ - byte[] generateCertificateSignature(byte[] hash) - throws IOException; - - SignatureAndHashAlgorithm getSignatureAndHashAlgorithm(); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsStreamCipher.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsStreamCipher.java deleted file mode 100644 index 8ad63e04f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsStreamCipher.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; - -import com.fr.third.org.bouncycastle.crypto.CipherParameters; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.StreamCipher; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.ParametersWithIV; -import com.fr.third.org.bouncycastle.util.Arrays; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsStreamCipher - implements TlsCipher -{ - protected TlsContext context; - - protected StreamCipher encryptCipher; - protected StreamCipher decryptCipher; - - protected TlsMac writeMac; - protected TlsMac readMac; - - protected boolean usesNonce; - - public TlsStreamCipher(TlsContext context, StreamCipher clientWriteCipher, - StreamCipher serverWriteCipher, Digest clientWriteDigest, Digest serverWriteDigest, - int cipherKeySize, boolean usesNonce) throws IOException - { - boolean isServer = context.isServer(); - - this.context = context; - this.usesNonce = usesNonce; - - this.encryptCipher = clientWriteCipher; - this.decryptCipher = serverWriteCipher; - - int key_block_size = (2 * cipherKeySize) + clientWriteDigest.getDigestSize() - + serverWriteDigest.getDigestSize(); - - byte[] key_block = TlsUtils.calculateKeyBlock(context, key_block_size); - - int offset = 0; - - // Init MACs - TlsMac clientWriteMac = new TlsMac(context, clientWriteDigest, key_block, offset, - clientWriteDigest.getDigestSize()); - offset += clientWriteDigest.getDigestSize(); - TlsMac serverWriteMac = new TlsMac(context, serverWriteDigest, key_block, offset, - serverWriteDigest.getDigestSize()); - offset += serverWriteDigest.getDigestSize(); - - // Build keys - KeyParameter clientWriteKey = new KeyParameter(key_block, offset, cipherKeySize); - offset += cipherKeySize; - KeyParameter serverWriteKey = new KeyParameter(key_block, offset, cipherKeySize); - offset += cipherKeySize; - - if (offset != key_block_size) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - CipherParameters encryptParams, decryptParams; - if (isServer) - { - this.writeMac = serverWriteMac; - this.readMac = clientWriteMac; - this.encryptCipher = serverWriteCipher; - this.decryptCipher = clientWriteCipher; - encryptParams = serverWriteKey; - decryptParams = clientWriteKey; - } - else - { - this.writeMac = clientWriteMac; - this.readMac = serverWriteMac; - this.encryptCipher = clientWriteCipher; - this.decryptCipher = serverWriteCipher; - encryptParams = clientWriteKey; - decryptParams = serverWriteKey; - } - - if (usesNonce) - { - byte[] dummyNonce = new byte[8]; - encryptParams = new ParametersWithIV(encryptParams, dummyNonce); - decryptParams = new ParametersWithIV(decryptParams, dummyNonce); - } - - this.encryptCipher.init(true, encryptParams); - this.decryptCipher.init(false, decryptParams); - } - - public int getPlaintextLimit(int ciphertextLimit) - { - return ciphertextLimit - writeMac.getSize(); - } - - public byte[] encodePlaintext(long seqNo, short type, byte[] plaintext, int offset, int len) - { - if (usesNonce) - { - updateIV(encryptCipher, true, seqNo); - } - - byte[] outBuf = new byte[len + writeMac.getSize()]; - - encryptCipher.processBytes(plaintext, offset, len, outBuf, 0); - - byte[] mac = writeMac.calculateMac(seqNo, type, plaintext, offset, len); - encryptCipher.processBytes(mac, 0, mac.length, outBuf, len); - - return outBuf; - } - - public byte[] decodeCiphertext(long seqNo, short type, byte[] ciphertext, int offset, int len) - throws IOException - { - if (usesNonce) - { - updateIV(decryptCipher, false, seqNo); - } - - int macSize = readMac.getSize(); - if (len < macSize) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - - int plaintextLength = len - macSize; - - byte[] deciphered = new byte[len]; - decryptCipher.processBytes(ciphertext, offset, len, deciphered, 0); - checkMAC(seqNo, type, deciphered, plaintextLength, len, deciphered, 0, plaintextLength); - return Arrays.copyOfRange(deciphered, 0, plaintextLength); - } - - protected void checkMAC(long seqNo, short type, byte[] recBuf, int recStart, int recEnd, byte[] calcBuf, int calcOff, int calcLen) - throws IOException - { - byte[] receivedMac = Arrays.copyOfRange(recBuf, recStart, recEnd); - byte[] computedMac = readMac.calculateMac(seqNo, type, calcBuf, calcOff, calcLen); - - if (!Arrays.constantTimeAreEqual(receivedMac, computedMac)) - { - throw new TlsFatalAlert(AlertDescription.bad_record_mac); - } - } - - protected void updateIV(StreamCipher cipher, boolean forEncryption, long seqNo) - { - byte[] nonce = new byte[8]; - TlsUtils.writeUint64(seqNo, nonce, 0); - cipher.init(forEncryption, new ParametersWithIV(null, nonce)); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsUtils.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsUtils.java deleted file mode 100644 index 5cb3f5624..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/TlsUtils.java +++ /dev/null @@ -1,2558 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Hashtable; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.ASN1Encoding; -import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; -import com.fr.third.org.bouncycastle.asn1.ASN1Primitive; -import com.fr.third.org.bouncycastle.asn1.nist.NISTObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import com.fr.third.org.bouncycastle.asn1.x509.Extensions; -import com.fr.third.org.bouncycastle.asn1.x509.KeyUsage; -import com.fr.third.org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import com.fr.third.org.bouncycastle.asn1.x509.X509ObjectIdentifiers; -import com.fr.third.org.bouncycastle.crypto.Digest; -import com.fr.third.org.bouncycastle.crypto.digests.MD5Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA1Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA224Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA384Digest; -import com.fr.third.org.bouncycastle.crypto.digests.SHA512Digest; -import com.fr.third.org.bouncycastle.crypto.macs.HMac; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.DSAPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.KeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; -import com.fr.third.org.bouncycastle.crypto.util.PublicKeyFactory; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Integers; -import com.fr.third.org.bouncycastle.util.Shorts; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.io.Streams; - -/** - * Some helper functions for MicroTLS. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class TlsUtils -{ - public static final byte[] EMPTY_BYTES = new byte[0]; - public static final short[] EMPTY_SHORTS = new short[0]; - public static final int[] EMPTY_INTS = new int[0]; - public static final long[] EMPTY_LONGS = new long[0]; - - public static final Integer EXT_signature_algorithms = Integers.valueOf(ExtensionType.signature_algorithms); - - public static void checkUint8(short i) throws IOException - { - if (!isValidUint8(i)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static void checkUint8(int i) throws IOException - { - if (!isValidUint8(i)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static void checkUint8(long i) throws IOException - { - if (!isValidUint8(i)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static void checkUint16(int i) throws IOException - { - if (!isValidUint16(i)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static void checkUint16(long i) throws IOException - { - if (!isValidUint16(i)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static void checkUint24(int i) throws IOException - { - if (!isValidUint24(i)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static void checkUint24(long i) throws IOException - { - if (!isValidUint24(i)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static void checkUint32(long i) throws IOException - { - if (!isValidUint32(i)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static void checkUint48(long i) throws IOException - { - if (!isValidUint48(i)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static void checkUint64(long i) throws IOException - { - if (!isValidUint64(i)) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static boolean isValidUint8(short i) - { - return (i & 0xFF) == i; - } - - public static boolean isValidUint8(int i) - { - return (i & 0xFF) == i; - } - - public static boolean isValidUint8(long i) - { - return (i & 0xFFL) == i; - } - - public static boolean isValidUint16(int i) - { - return (i & 0xFFFF) == i; - } - - public static boolean isValidUint16(long i) - { - return (i & 0xFFFFL) == i; - } - - public static boolean isValidUint24(int i) - { - return (i & 0xFFFFFF) == i; - } - - public static boolean isValidUint24(long i) - { - return (i & 0xFFFFFFL) == i; - } - - public static boolean isValidUint32(long i) - { - return (i & 0xFFFFFFFFL) == i; - } - - public static boolean isValidUint48(long i) - { - return (i & 0xFFFFFFFFFFFFL) == i; - } - - public static boolean isValidUint64(long i) - { - return true; - } - - public static boolean isSSL(TlsContext context) - { - return context.getServerVersion().isSSL(); - } - - public static boolean isTLSv11(ProtocolVersion version) - { - return ProtocolVersion.TLSv11.isEqualOrEarlierVersionOf(version.getEquivalentTLSVersion()); - } - - public static boolean isTLSv11(TlsContext context) - { - return isTLSv11(context.getServerVersion()); - } - - public static boolean isTLSv12(ProtocolVersion version) - { - return ProtocolVersion.TLSv12.isEqualOrEarlierVersionOf(version.getEquivalentTLSVersion()); - } - - public static boolean isTLSv12(TlsContext context) - { - return isTLSv12(context.getServerVersion()); - } - - public static void writeUint8(short i, OutputStream output) - throws IOException - { - output.write(i); - } - - public static void writeUint8(int i, OutputStream output) - throws IOException - { - output.write(i); - } - - public static void writeUint8(short i, byte[] buf, int offset) - { - buf[offset] = (byte)i; - } - - public static void writeUint8(int i, byte[] buf, int offset) - { - buf[offset] = (byte)i; - } - - public static void writeUint16(int i, OutputStream output) - throws IOException - { - output.write(i >>> 8); - output.write(i); - } - - public static void writeUint16(int i, byte[] buf, int offset) - { - buf[offset] = (byte)(i >>> 8); - buf[offset + 1] = (byte)i; - } - - public static void writeUint24(int i, OutputStream output) - throws IOException - { - output.write((byte)(i >>> 16)); - output.write((byte)(i >>> 8)); - output.write((byte)i); - } - - public static void writeUint24(int i, byte[] buf, int offset) - { - buf[offset] = (byte)(i >>> 16); - buf[offset + 1] = (byte)(i >>> 8); - buf[offset + 2] = (byte)i; - } - - public static void writeUint32(long i, OutputStream output) - throws IOException - { - output.write((byte)(i >>> 24)); - output.write((byte)(i >>> 16)); - output.write((byte)(i >>> 8)); - output.write((byte)i); - } - - public static void writeUint32(long i, byte[] buf, int offset) - { - buf[offset] = (byte)(i >>> 24); - buf[offset + 1] = (byte)(i >>> 16); - buf[offset + 2] = (byte)(i >>> 8); - buf[offset + 3] = (byte)i; - } - - public static void writeUint48(long i, OutputStream output) - throws IOException - { - output.write((byte)(i >>> 40)); - output.write((byte)(i >>> 32)); - output.write((byte)(i >>> 24)); - output.write((byte)(i >>> 16)); - output.write((byte)(i >>> 8)); - output.write((byte)i); - } - - public static void writeUint48(long i, byte[] buf, int offset) - { - buf[offset] = (byte)(i >>> 40); - buf[offset + 1] = (byte)(i >>> 32); - buf[offset + 2] = (byte)(i >>> 24); - buf[offset + 3] = (byte)(i >>> 16); - buf[offset + 4] = (byte)(i >>> 8); - buf[offset + 5] = (byte)i; - } - - public static void writeUint64(long i, OutputStream output) - throws IOException - { - output.write((byte)(i >>> 56)); - output.write((byte)(i >>> 48)); - output.write((byte)(i >>> 40)); - output.write((byte)(i >>> 32)); - output.write((byte)(i >>> 24)); - output.write((byte)(i >>> 16)); - output.write((byte)(i >>> 8)); - output.write((byte)i); - } - - public static void writeUint64(long i, byte[] buf, int offset) - { - buf[offset] = (byte)(i >>> 56); - buf[offset + 1] = (byte)(i >>> 48); - buf[offset + 2] = (byte)(i >>> 40); - buf[offset + 3] = (byte)(i >>> 32); - buf[offset + 4] = (byte)(i >>> 24); - buf[offset + 5] = (byte)(i >>> 16); - buf[offset + 6] = (byte)(i >>> 8); - buf[offset + 7] = (byte)i; - } - - public static void writeOpaque8(byte[] buf, OutputStream output) - throws IOException - { - checkUint8(buf.length); - writeUint8(buf.length, output); - output.write(buf); - } - - public static void writeOpaque16(byte[] buf, OutputStream output) - throws IOException - { - checkUint16(buf.length); - writeUint16(buf.length, output); - output.write(buf); - } - - public static void writeOpaque24(byte[] buf, OutputStream output) - throws IOException - { - checkUint24(buf.length); - writeUint24(buf.length, output); - output.write(buf); - } - - public static void writeUint8Array(short[] uints, OutputStream output) - throws IOException - { - for (int i = 0; i < uints.length; ++i) - { - writeUint8(uints[i], output); - } - } - - public static void writeUint8Array(short[] uints, byte[] buf, int offset) - throws IOException - { - for (int i = 0; i < uints.length; ++i) - { - writeUint8(uints[i], buf, offset); - ++offset; - } - } - - public static void writeUint8ArrayWithUint8Length(short[] uints, OutputStream output) - throws IOException - { - checkUint8(uints.length); - writeUint8(uints.length, output); - writeUint8Array(uints, output); - } - - public static void writeUint8ArrayWithUint8Length(short[] uints, byte[] buf, int offset) - throws IOException - { - checkUint8(uints.length); - writeUint8(uints.length, buf, offset); - writeUint8Array(uints, buf, offset + 1); - } - - public static void writeUint16Array(int[] uints, OutputStream output) - throws IOException - { - for (int i = 0; i < uints.length; ++i) - { - writeUint16(uints[i], output); - } - } - - public static void writeUint16Array(int[] uints, byte[] buf, int offset) - throws IOException - { - for (int i = 0; i < uints.length; ++i) - { - writeUint16(uints[i], buf, offset); - offset += 2; - } - } - - public static void writeUint16ArrayWithUint16Length(int[] uints, OutputStream output) - throws IOException - { - int length = 2 * uints.length; - checkUint16(length); - writeUint16(length, output); - writeUint16Array(uints, output); - } - - public static void writeUint16ArrayWithUint16Length(int[] uints, byte[] buf, int offset) - throws IOException - { - int length = 2 * uints.length; - checkUint16(length); - writeUint16(length, buf, offset); - writeUint16Array(uints, buf, offset + 2); - } - - public static byte[] encodeOpaque8(byte[] buf) - throws IOException - { - checkUint8(buf.length); - return Arrays.prepend(buf, (byte)buf.length); - } - - public static byte[] encodeUint8ArrayWithUint8Length(short[] uints) throws IOException - { - byte[] result = new byte[1 + uints.length]; - writeUint8ArrayWithUint8Length(uints, result, 0); - return result; - } - - public static byte[] encodeUint16ArrayWithUint16Length(int[] uints) throws IOException - { - int length = 2 * uints.length; - byte[] result = new byte[2 + length]; - writeUint16ArrayWithUint16Length(uints, result, 0); - return result; - } - - public static short readUint8(InputStream input) - throws IOException - { - int i = input.read(); - if (i < 0) - { - throw new EOFException(); - } - return (short)i; - } - - public static short readUint8(byte[] buf, int offset) - { - return (short)(buf[offset] & 0xff); - } - - public static int readUint16(InputStream input) - throws IOException - { - int i1 = input.read(); - int i2 = input.read(); - if (i2 < 0) - { - throw new EOFException(); - } - return (i1 << 8) | i2; - } - - public static int readUint16(byte[] buf, int offset) - { - int n = (buf[offset] & 0xff) << 8; - n |= (buf[++offset] & 0xff); - return n; - } - - public static int readUint24(InputStream input) - throws IOException - { - int i1 = input.read(); - int i2 = input.read(); - int i3 = input.read(); - if (i3 < 0) - { - throw new EOFException(); - } - return (i1 << 16) | (i2 << 8) | i3; - } - - public static int readUint24(byte[] buf, int offset) - { - int n = (buf[offset] & 0xff) << 16; - n |= (buf[++offset] & 0xff) << 8; - n |= (buf[++offset] & 0xff); - return n; - } - - public static long readUint32(InputStream input) - throws IOException - { - int i1 = input.read(); - int i2 = input.read(); - int i3 = input.read(); - int i4 = input.read(); - if (i4 < 0) - { - throw new EOFException(); - } - return ((i1 << 24) | (i2 << 16) | (i3 << 8) | i4) & 0xFFFFFFFFL; - } - - public static long readUint32(byte[] buf, int offset) - { - int n = (buf[offset] & 0xff) << 24; - n |= (buf[++offset] & 0xff) << 16; - n |= (buf[++offset] & 0xff) << 8; - n |= (buf[++offset] & 0xff); - return n & 0xFFFFFFFFL; - } - - public static long readUint48(InputStream input) - throws IOException - { - int hi = readUint24(input); - int lo = readUint24(input); - return ((long)(hi & 0xffffffffL) << 24) | (long)(lo & 0xffffffffL); - } - - public static long readUint48(byte[] buf, int offset) - { - int hi = readUint24(buf, offset); - int lo = readUint24(buf, offset + 3); - return ((long)(hi & 0xffffffffL) << 24) | (long)(lo & 0xffffffffL); - } - - public static byte[] readAllOrNothing(int length, InputStream input) - throws IOException - { - if (length < 1) - { - return EMPTY_BYTES; - } - byte[] buf = new byte[length]; - int read = Streams.readFully(input, buf); - if (read == 0) - { - return null; - } - if (read != length) - { - throw new EOFException(); - } - return buf; - } - - public static byte[] readFully(int length, InputStream input) - throws IOException - { - if (length < 1) - { - return EMPTY_BYTES; - } - byte[] buf = new byte[length]; - if (length != Streams.readFully(input, buf)) - { - throw new EOFException(); - } - return buf; - } - - public static void readFully(byte[] buf, InputStream input) - throws IOException - { - int length = buf.length; - if (length > 0 && length != Streams.readFully(input, buf)) - { - throw new EOFException(); - } - } - - public static byte[] readOpaque8(InputStream input) - throws IOException - { - short length = readUint8(input); - return readFully(length, input); - } - - public static byte[] readOpaque16(InputStream input) - throws IOException - { - int length = readUint16(input); - return readFully(length, input); - } - - public static byte[] readOpaque24(InputStream input) - throws IOException - { - int length = readUint24(input); - return readFully(length, input); - } - - public static short[] readUint8Array(int count, InputStream input) - throws IOException - { - short[] uints = new short[count]; - for (int i = 0; i < count; ++i) - { - uints[i] = readUint8(input); - } - return uints; - } - - public static int[] readUint16Array(int count, InputStream input) - throws IOException - { - int[] uints = new int[count]; - for (int i = 0; i < count; ++i) - { - uints[i] = readUint16(input); - } - return uints; - } - - public static ProtocolVersion readVersion(byte[] buf, int offset) - throws IOException - { - return ProtocolVersion.get(buf[offset] & 0xFF, buf[offset + 1] & 0xFF); - } - - public static ProtocolVersion readVersion(InputStream input) - throws IOException - { - int i1 = input.read(); - int i2 = input.read(); - if (i2 < 0) - { - throw new EOFException(); - } - return ProtocolVersion.get(i1, i2); - } - - public static int readVersionRaw(byte[] buf, int offset) - throws IOException - { - return (buf[offset] << 8) | buf[offset + 1]; - } - - public static int readVersionRaw(InputStream input) - throws IOException - { - int i1 = input.read(); - int i2 = input.read(); - if (i2 < 0) - { - throw new EOFException(); - } - return (i1 << 8) | i2; - } - - public static ASN1Primitive readASN1Object(byte[] encoding) throws IOException - { - ASN1InputStream asn1 = new ASN1InputStream(encoding); - ASN1Primitive result = asn1.readObject(); - if (null == result) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - if (null != asn1.readObject()) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - return result; - } - - public static ASN1Primitive readDERObject(byte[] encoding) throws IOException - { - /* - * NOTE: The current ASN.1 parsing code can't enforce DER-only parsing, but since DER is - * canonical, we can check it by re-encoding the result and comparing to the original. - */ - ASN1Primitive result = readASN1Object(encoding); - byte[] check = result.getEncoded(ASN1Encoding.DER); - if (!Arrays.areEqual(check, encoding)) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - return result; - } - - public static void writeGMTUnixTime(byte[] buf, int offset) - { - int t = (int)(System.currentTimeMillis() / 1000L); - buf[offset] = (byte)(t >>> 24); - buf[offset + 1] = (byte)(t >>> 16); - buf[offset + 2] = (byte)(t >>> 8); - buf[offset + 3] = (byte)t; - } - - public static void writeVersion(ProtocolVersion version, OutputStream output) - throws IOException - { - output.write(version.getMajorVersion()); - output.write(version.getMinorVersion()); - } - - public static void writeVersion(ProtocolVersion version, byte[] buf, int offset) - { - buf[offset] = (byte)version.getMajorVersion(); - buf[offset + 1] = (byte)version.getMinorVersion(); - } - - public static Vector getAllSignatureAlgorithms() - { - Vector v = new Vector(4); - v.addElement(Shorts.valueOf(SignatureAlgorithm.anonymous)); - v.addElement(Shorts.valueOf(SignatureAlgorithm.rsa)); - v.addElement(Shorts.valueOf(SignatureAlgorithm.dsa)); - v.addElement(Shorts.valueOf(SignatureAlgorithm.ecdsa)); - return v; - } - - public static Vector getDefaultDSSSignatureAlgorithms() - { - return vectorOfOne(new SignatureAndHashAlgorithm(HashAlgorithm.sha1, SignatureAlgorithm.dsa)); - } - - public static Vector getDefaultECDSASignatureAlgorithms() - { - return vectorOfOne(new SignatureAndHashAlgorithm(HashAlgorithm.sha1, SignatureAlgorithm.ecdsa)); - } - - public static Vector getDefaultRSASignatureAlgorithms() - { - return vectorOfOne(new SignatureAndHashAlgorithm(HashAlgorithm.sha1, SignatureAlgorithm.rsa)); - } - - public static Vector getDefaultSupportedSignatureAlgorithms() - { - short[] hashAlgorithms = new short[]{ HashAlgorithm.sha1, HashAlgorithm.sha224, HashAlgorithm.sha256, - HashAlgorithm.sha384, HashAlgorithm.sha512 }; - short[] signatureAlgorithms = new short[]{ SignatureAlgorithm.rsa, SignatureAlgorithm.dsa, - SignatureAlgorithm.ecdsa }; - - Vector result = new Vector(); - for (int i = 0; i < signatureAlgorithms.length; ++i) - { - for (int j = 0; j < hashAlgorithms.length; ++j) - { - result.addElement(new SignatureAndHashAlgorithm(hashAlgorithms[j], signatureAlgorithms[i])); - } - } - return result; - } - - public static SignatureAndHashAlgorithm getSignatureAndHashAlgorithm(TlsContext context, - TlsSignerCredentials signerCredentials) - throws IOException - { - SignatureAndHashAlgorithm signatureAndHashAlgorithm = null; - if (isTLSv12(context)) - { - signatureAndHashAlgorithm = signerCredentials.getSignatureAndHashAlgorithm(); - if (signatureAndHashAlgorithm == null) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - return signatureAndHashAlgorithm; - } - - public static byte[] getExtensionData(Hashtable extensions, Integer extensionType) - { - return extensions == null ? null : (byte[])extensions.get(extensionType); - } - - public static boolean hasExpectedEmptyExtensionData(Hashtable extensions, Integer extensionType, - short alertDescription) throws IOException - { - byte[] extension_data = getExtensionData(extensions, extensionType); - if (extension_data == null) - { - return false; - } - if (extension_data.length != 0) - { - throw new TlsFatalAlert(alertDescription); - } - return true; - } - - public static TlsSession importSession(byte[] sessionID, SessionParameters sessionParameters) - { - return new TlsSessionImpl(sessionID, sessionParameters); - } - - public static boolean isSignatureAlgorithmsExtensionAllowed(ProtocolVersion clientVersion) - { - return ProtocolVersion.TLSv12.isEqualOrEarlierVersionOf(clientVersion.getEquivalentTLSVersion()); - } - - /** - * Add a 'signature_algorithms' extension to existing extensions. - * - * @param extensions A {@link Hashtable} to add the extension to. - * @param supportedSignatureAlgorithms {@link Vector} containing at least 1 {@link SignatureAndHashAlgorithm}. - * @throws IOException - */ - public static void addSignatureAlgorithmsExtension(Hashtable extensions, Vector supportedSignatureAlgorithms) - throws IOException - { - extensions.put(EXT_signature_algorithms, createSignatureAlgorithmsExtension(supportedSignatureAlgorithms)); - } - - /** - * Get a 'signature_algorithms' extension from extensions. - * - * @param extensions A {@link Hashtable} to get the extension from, if it is present. - * @return A {@link Vector} containing at least 1 {@link SignatureAndHashAlgorithm}, or null. - * @throws IOException - */ - public static Vector getSignatureAlgorithmsExtension(Hashtable extensions) - throws IOException - { - byte[] extensionData = getExtensionData(extensions, EXT_signature_algorithms); - return extensionData == null ? null : readSignatureAlgorithmsExtension(extensionData); - } - - /** - * Create a 'signature_algorithms' extension value. - * - * @param supportedSignatureAlgorithms A {@link Vector} containing at least 1 {@link SignatureAndHashAlgorithm}. - * @return A byte array suitable for use as an extension value. - * @throws IOException - */ - public static byte[] createSignatureAlgorithmsExtension(Vector supportedSignatureAlgorithms) - throws IOException - { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - // supported_signature_algorithms - encodeSupportedSignatureAlgorithms(supportedSignatureAlgorithms, false, buf); - - return buf.toByteArray(); - } - - /** - * Read 'signature_algorithms' extension data. - * - * @param extensionData The extension data. - * @return A {@link Vector} containing at least 1 {@link SignatureAndHashAlgorithm}. - * @throws IOException - */ - public static Vector readSignatureAlgorithmsExtension(byte[] extensionData) - throws IOException - { - if (extensionData == null) - { - throw new IllegalArgumentException("'extensionData' cannot be null"); - } - - ByteArrayInputStream buf = new ByteArrayInputStream(extensionData); - - // supported_signature_algorithms - Vector supported_signature_algorithms = parseSupportedSignatureAlgorithms(false, buf); - - TlsProtocol.assertEmpty(buf); - - return supported_signature_algorithms; - } - - public static void encodeSupportedSignatureAlgorithms(Vector supportedSignatureAlgorithms, boolean allowAnonymous, - OutputStream output) throws IOException - { - if (supportedSignatureAlgorithms == null || supportedSignatureAlgorithms.size() < 1 - || supportedSignatureAlgorithms.size() >= (1 << 15)) - { - throw new IllegalArgumentException( - "'supportedSignatureAlgorithms' must have length from 1 to (2^15 - 1)"); - } - - // supported_signature_algorithms - int length = 2 * supportedSignatureAlgorithms.size(); - checkUint16(length); - writeUint16(length, output); - for (int i = 0; i < supportedSignatureAlgorithms.size(); ++i) - { - SignatureAndHashAlgorithm entry = (SignatureAndHashAlgorithm)supportedSignatureAlgorithms.elementAt(i); - if (!allowAnonymous && entry.getSignature() == SignatureAlgorithm.anonymous) - { - /* - * RFC 5246 7.4.1.4.1 The "anonymous" value is meaningless in this context but used - * in Section 7.4.3. It MUST NOT appear in this extension. - */ - throw new IllegalArgumentException( - "SignatureAlgorithm.anonymous MUST NOT appear in the signature_algorithms extension"); - } - entry.encode(output); - } - } - - public static Vector parseSupportedSignatureAlgorithms(boolean allowAnonymous, InputStream input) - throws IOException - { - // supported_signature_algorithms - int length = readUint16(input); - if (length < 2 || (length & 1) != 0) - { - throw new TlsFatalAlert(AlertDescription.decode_error); - } - int count = length / 2; - Vector supportedSignatureAlgorithms = new Vector(count); - for (int i = 0; i < count; ++i) - { - SignatureAndHashAlgorithm entry = SignatureAndHashAlgorithm.parse(input); - if (!allowAnonymous && entry.getSignature() == SignatureAlgorithm.anonymous) - { - /* - * RFC 5246 7.4.1.4.1 The "anonymous" value is meaningless in this context but used - * in Section 7.4.3. It MUST NOT appear in this extension. - */ - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - supportedSignatureAlgorithms.addElement(entry); - } - return supportedSignatureAlgorithms; - } - - public static void verifySupportedSignatureAlgorithm(Vector supportedSignatureAlgorithms, SignatureAndHashAlgorithm signatureAlgorithm) - throws IOException - { - if (supportedSignatureAlgorithms == null || supportedSignatureAlgorithms.size() < 1 - || supportedSignatureAlgorithms.size() >= (1 << 15)) - { - throw new IllegalArgumentException( - "'supportedSignatureAlgorithms' must have length from 1 to (2^15 - 1)"); - } - if (signatureAlgorithm == null) - { - throw new IllegalArgumentException("'signatureAlgorithm' cannot be null"); - } - - if (signatureAlgorithm.getSignature() != SignatureAlgorithm.anonymous) - { - for (int i = 0; i < supportedSignatureAlgorithms.size(); ++i) - { - SignatureAndHashAlgorithm entry = (SignatureAndHashAlgorithm)supportedSignatureAlgorithms.elementAt(i); - if (entry.getHash() == signatureAlgorithm.getHash() && entry.getSignature() == signatureAlgorithm.getSignature()) - { - return; - } - } - } - - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - public static byte[] PRF(TlsContext context, byte[] secret, String asciiLabel, byte[] seed, int size) - { - ProtocolVersion version = context.getServerVersion(); - - if (version.isSSL()) - { - throw new IllegalStateException("No PRF available for SSLv3 session"); - } - - byte[] label = Strings.toByteArray(asciiLabel); - byte[] labelSeed = concat(label, seed); - - int prfAlgorithm = context.getSecurityParameters().getPrfAlgorithm(); - - if (prfAlgorithm == PRFAlgorithm.tls_prf_legacy) - { - return PRF_legacy(secret, label, labelSeed, size); - } - - Digest prfDigest = createPRFHash(prfAlgorithm); - byte[] buf = new byte[size]; - hmac_hash(prfDigest, secret, labelSeed, buf); - return buf; - } - - public static byte[] PRF_legacy(byte[] secret, String asciiLabel, byte[] seed, int size) - { - byte[] label = Strings.toByteArray(asciiLabel); - byte[] labelSeed = concat(label, seed); - - return PRF_legacy(secret, label, labelSeed, size); - } - - static byte[] PRF_legacy(byte[] secret, byte[] label, byte[] labelSeed, int size) - { - int s_half = (secret.length + 1) / 2; - byte[] s1 = new byte[s_half]; - byte[] s2 = new byte[s_half]; - System.arraycopy(secret, 0, s1, 0, s_half); - System.arraycopy(secret, secret.length - s_half, s2, 0, s_half); - - byte[] b1 = new byte[size]; - byte[] b2 = new byte[size]; - hmac_hash(createHash(HashAlgorithm.md5), s1, labelSeed, b1); - hmac_hash(createHash(HashAlgorithm.sha1), s2, labelSeed, b2); - for (int i = 0; i < size; i++) - { - b1[i] ^= b2[i]; - } - return b1; - } - - static byte[] concat(byte[] a, byte[] b) - { - byte[] c = new byte[a.length + b.length]; - System.arraycopy(a, 0, c, 0, a.length); - System.arraycopy(b, 0, c, a.length, b.length); - return c; - } - - static void hmac_hash(Digest digest, byte[] secret, byte[] seed, byte[] out) - { - HMac mac = new HMac(digest); - mac.init(new KeyParameter(secret)); - byte[] a = seed; - int size = digest.getDigestSize(); - int iterations = (out.length + size - 1) / size; - byte[] buf = new byte[mac.getMacSize()]; - byte[] buf2 = new byte[mac.getMacSize()]; - for (int i = 0; i < iterations; i++) - { - mac.update(a, 0, a.length); - mac.doFinal(buf, 0); - a = buf; - mac.update(a, 0, a.length); - mac.update(seed, 0, seed.length); - mac.doFinal(buf2, 0); - System.arraycopy(buf2, 0, out, (size * i), Math.min(size, out.length - (size * i))); - } - } - - static void validateKeyUsage(com.fr.third.org.bouncycastle.asn1.x509.Certificate c, int keyUsageBits) - throws IOException - { - Extensions exts = c.getTBSCertificate().getExtensions(); - if (exts != null) - { - KeyUsage ku = KeyUsage.fromExtensions(exts); - if (ku != null) - { - int bits = ku.getBytes()[0] & 0xff; - if ((bits & keyUsageBits) != keyUsageBits) - { - throw new TlsFatalAlert(AlertDescription.certificate_unknown); - } - } - } - } - - static byte[] calculateKeyBlock(TlsContext context, int size) - { - SecurityParameters securityParameters = context.getSecurityParameters(); - byte[] master_secret = securityParameters.getMasterSecret(); - byte[] seed = concat(securityParameters.getServerRandom(), - securityParameters.getClientRandom()); - - if (isSSL(context)) - { - return calculateKeyBlock_SSL(master_secret, seed, size); - } - - return PRF(context, master_secret, ExporterLabel.key_expansion, seed, size); - } - - static byte[] calculateKeyBlock_SSL(byte[] master_secret, byte[] random, int size) - { - Digest md5 = createHash(HashAlgorithm.md5); - Digest sha1 = createHash(HashAlgorithm.sha1); - int md5Size = md5.getDigestSize(); - byte[] shatmp = new byte[sha1.getDigestSize()]; - byte[] tmp = new byte[size + md5Size]; - - int i = 0, pos = 0; - while (pos < size) - { - byte[] ssl3Const = SSL3_CONST[i]; - - sha1.update(ssl3Const, 0, ssl3Const.length); - sha1.update(master_secret, 0, master_secret.length); - sha1.update(random, 0, random.length); - sha1.doFinal(shatmp, 0); - - md5.update(master_secret, 0, master_secret.length); - md5.update(shatmp, 0, shatmp.length); - md5.doFinal(tmp, pos); - - pos += md5Size; - ++i; - } - - return Arrays.copyOfRange(tmp, 0, size); - } - - static byte[] calculateMasterSecret(TlsContext context, byte[] pre_master_secret) - { - SecurityParameters securityParameters = context.getSecurityParameters(); - - byte[] seed; - if (securityParameters.isExtendedMasterSecret()) - { - seed = securityParameters.getSessionHash(); - } - else - { - seed = concat(securityParameters.getClientRandom(), securityParameters.getServerRandom()); - } - - if (isSSL(context)) - { - return calculateMasterSecret_SSL(pre_master_secret, seed); - } - - String asciiLabel = securityParameters.isExtendedMasterSecret() - ? ExporterLabel.extended_master_secret - : ExporterLabel.master_secret; - - return PRF(context, pre_master_secret, asciiLabel, seed, 48); - } - - static byte[] calculateMasterSecret_SSL(byte[] pre_master_secret, byte[] random) - { - Digest md5 = createHash(HashAlgorithm.md5); - Digest sha1 = createHash(HashAlgorithm.sha1); - int md5Size = md5.getDigestSize(); - byte[] shatmp = new byte[sha1.getDigestSize()]; - - byte[] rval = new byte[md5Size * 3]; - int pos = 0; - - for (int i = 0; i < 3; ++i) - { - byte[] ssl3Const = SSL3_CONST[i]; - - sha1.update(ssl3Const, 0, ssl3Const.length); - sha1.update(pre_master_secret, 0, pre_master_secret.length); - sha1.update(random, 0, random.length); - sha1.doFinal(shatmp, 0); - - md5.update(pre_master_secret, 0, pre_master_secret.length); - md5.update(shatmp, 0, shatmp.length); - md5.doFinal(rval, pos); - - pos += md5Size; - } - - return rval; - } - - static byte[] calculateVerifyData(TlsContext context, String asciiLabel, byte[] handshakeHash) - { - if (isSSL(context)) - { - return handshakeHash; - } - - SecurityParameters securityParameters = context.getSecurityParameters(); - byte[] master_secret = securityParameters.getMasterSecret(); - int verify_data_length = securityParameters.getVerifyDataLength(); - - return PRF(context, master_secret, asciiLabel, handshakeHash, verify_data_length); - } - - public static Digest createHash(short hashAlgorithm) - { - switch (hashAlgorithm) - { - case HashAlgorithm.md5: - return new MD5Digest(); - case HashAlgorithm.sha1: - return new SHA1Digest(); - case HashAlgorithm.sha224: - return new SHA224Digest(); - case HashAlgorithm.sha256: - return new SHA256Digest(); - case HashAlgorithm.sha384: - return new SHA384Digest(); - case HashAlgorithm.sha512: - return new SHA512Digest(); - default: - throw new IllegalArgumentException("unknown HashAlgorithm"); - } - } - - public static Digest createHash(SignatureAndHashAlgorithm signatureAndHashAlgorithm) - { - return signatureAndHashAlgorithm == null - ? new CombinedHash() - : createHash(signatureAndHashAlgorithm.getHash()); - } - - public static Digest cloneHash(short hashAlgorithm, Digest hash) - { - switch (hashAlgorithm) - { - case HashAlgorithm.md5: - return new MD5Digest((MD5Digest)hash); - case HashAlgorithm.sha1: - return new SHA1Digest((SHA1Digest)hash); - case HashAlgorithm.sha224: - return new SHA224Digest((SHA224Digest)hash); - case HashAlgorithm.sha256: - return new SHA256Digest((SHA256Digest)hash); - case HashAlgorithm.sha384: - return new SHA384Digest((SHA384Digest)hash); - case HashAlgorithm.sha512: - return new SHA512Digest((SHA512Digest)hash); - default: - throw new IllegalArgumentException("unknown HashAlgorithm"); - } - } - - public static Digest createPRFHash(int prfAlgorithm) - { - switch (prfAlgorithm) - { - case PRFAlgorithm.tls_prf_legacy: - return new CombinedHash(); - default: - return createHash(getHashAlgorithmForPRFAlgorithm(prfAlgorithm)); - } - } - - public static Digest clonePRFHash(int prfAlgorithm, Digest hash) - { - switch (prfAlgorithm) - { - case PRFAlgorithm.tls_prf_legacy: - return new CombinedHash((CombinedHash)hash); - default: - return cloneHash(getHashAlgorithmForPRFAlgorithm(prfAlgorithm), hash); - } - } - - public static short getHashAlgorithmForPRFAlgorithm(int prfAlgorithm) - { - switch (prfAlgorithm) - { - case PRFAlgorithm.tls_prf_legacy: - throw new IllegalArgumentException("legacy PRF not a valid algorithm"); - case PRFAlgorithm.tls_prf_sha256: - return HashAlgorithm.sha256; - case PRFAlgorithm.tls_prf_sha384: - return HashAlgorithm.sha384; - default: - throw new IllegalArgumentException("unknown PRFAlgorithm"); - } - } - - public static ASN1ObjectIdentifier getOIDForHashAlgorithm(short hashAlgorithm) - { - switch (hashAlgorithm) - { - case HashAlgorithm.md5: - return PKCSObjectIdentifiers.md5; - case HashAlgorithm.sha1: - return X509ObjectIdentifiers.id_SHA1; - case HashAlgorithm.sha224: - return NISTObjectIdentifiers.id_sha224; - case HashAlgorithm.sha256: - return NISTObjectIdentifiers.id_sha256; - case HashAlgorithm.sha384: - return NISTObjectIdentifiers.id_sha384; - case HashAlgorithm.sha512: - return NISTObjectIdentifiers.id_sha512; - default: - throw new IllegalArgumentException("unknown HashAlgorithm"); - } - } - - static short getClientCertificateType(Certificate clientCertificate, Certificate serverCertificate) - throws IOException - { - if (clientCertificate.isEmpty()) - { - return -1; - } - - com.fr.third.org.bouncycastle.asn1.x509.Certificate x509Cert = clientCertificate.getCertificateAt(0); - SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo(); - try - { - AsymmetricKeyParameter publicKey = PublicKeyFactory.createKey(keyInfo); - if (publicKey.isPrivate()) - { - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - /* - * TODO RFC 5246 7.4.6. The certificates MUST be signed using an acceptable hash/ - * signature algorithm pair, as described in Section 7.4.4. Note that this relaxes the - * constraints on certificate-signing algorithms found in prior versions of TLS. - */ - - /* - * RFC 5246 7.4.6. Client Certificate - */ - - /* - * RSA public key; the certificate MUST allow the key to be used for signing with the - * signature scheme and hash algorithm that will be employed in the certificate verify - * message. - */ - if (publicKey instanceof RSAKeyParameters) - { - validateKeyUsage(x509Cert, KeyUsage.digitalSignature); - return ClientCertificateType.rsa_sign; - } - - /* - * DSA public key; the certificate MUST allow the key to be used for signing with the - * hash algorithm that will be employed in the certificate verify message. - */ - if (publicKey instanceof DSAPublicKeyParameters) - { - validateKeyUsage(x509Cert, KeyUsage.digitalSignature); - return ClientCertificateType.dss_sign; - } - - /* - * ECDSA-capable public key; the certificate MUST allow the key to be used for signing - * with the hash algorithm that will be employed in the certificate verify message; the - * public key MUST use a curve and point format supported by the server. - */ - if (publicKey instanceof ECPublicKeyParameters) - { - validateKeyUsage(x509Cert, KeyUsage.digitalSignature); - // TODO Check the curve and point format - return ClientCertificateType.ecdsa_sign; - } - - // TODO Add support for ClientCertificateType.*_fixed_* - - throw new TlsFatalAlert(AlertDescription.unsupported_certificate); - } - catch (Exception e) - { - throw new TlsFatalAlert(AlertDescription.unsupported_certificate, e); - } - } - - static void trackHashAlgorithms(TlsHandshakeHash handshakeHash, Vector supportedSignatureAlgorithms) - { - if (supportedSignatureAlgorithms != null) - { - for (int i = 0; i < supportedSignatureAlgorithms.size(); ++i) - { - SignatureAndHashAlgorithm signatureAndHashAlgorithm = (SignatureAndHashAlgorithm) - supportedSignatureAlgorithms.elementAt(i); - short hashAlgorithm = signatureAndHashAlgorithm.getHash(); - - if (HashAlgorithm.isRecognized(hashAlgorithm)) - { - handshakeHash.trackHashAlgorithm(hashAlgorithm); - } - else //if (HashAlgorithm.isPrivate(hashAlgorithm)) - { - // TODO Support values in the "Reserved for Private Use" range - } - } - } - } - - public static boolean hasSigningCapability(short clientCertificateType) - { - switch (clientCertificateType) - { - case ClientCertificateType.dss_sign: - case ClientCertificateType.ecdsa_sign: - case ClientCertificateType.rsa_sign: - return true; - default: - return false; - } - } - - public static TlsSigner createTlsSigner(short clientCertificateType) - { - switch (clientCertificateType) - { - case ClientCertificateType.dss_sign: - return new TlsDSSSigner(); - case ClientCertificateType.ecdsa_sign: - return new TlsECDSASigner(); - case ClientCertificateType.rsa_sign: - return new TlsRSASigner(); - default: - throw new IllegalArgumentException("'clientCertificateType' is not a type with signing capability"); - } - } - - static final byte[] SSL_CLIENT = {0x43, 0x4C, 0x4E, 0x54}; - static final byte[] SSL_SERVER = {0x53, 0x52, 0x56, 0x52}; - - // SSL3 magic mix constants ("A", "BB", "CCC", ...) - static final byte[][] SSL3_CONST = genSSL3Const(); - - private static byte[][] genSSL3Const() - { - int n = 10; - byte[][] arr = new byte[n][]; - for (int i = 0; i < n; i++) - { - byte[] b = new byte[i + 1]; - Arrays.fill(b, (byte)('A' + i)); - arr[i] = b; - } - return arr; - } - - private static Vector vectorOfOne(Object obj) - { - Vector v = new Vector(1); - v.addElement(obj); - return v; - } - - public static int getCipherType(int ciphersuite) throws IOException - { - switch (getEncryptionAlgorithm(ciphersuite)) - { - case EncryptionAlgorithm.AES_128_CCM: - case EncryptionAlgorithm.AES_128_CCM_8: - case EncryptionAlgorithm.AES_128_GCM: - case EncryptionAlgorithm.AES_128_OCB_TAGLEN96: - case EncryptionAlgorithm.AES_256_CCM: - case EncryptionAlgorithm.AES_256_CCM_8: - case EncryptionAlgorithm.AES_256_GCM: - case EncryptionAlgorithm.AES_256_OCB_TAGLEN96: - case EncryptionAlgorithm.CAMELLIA_128_GCM: - case EncryptionAlgorithm.CAMELLIA_256_GCM: - case EncryptionAlgorithm.CHACHA20_POLY1305: - return CipherType.aead; - - case EncryptionAlgorithm.RC2_CBC_40: - case EncryptionAlgorithm.IDEA_CBC: - case EncryptionAlgorithm.DES40_CBC: - case EncryptionAlgorithm.DES_CBC: - case EncryptionAlgorithm._3DES_EDE_CBC: - case EncryptionAlgorithm.AES_128_CBC: - case EncryptionAlgorithm.AES_256_CBC: - case EncryptionAlgorithm.CAMELLIA_128_CBC: - case EncryptionAlgorithm.CAMELLIA_256_CBC: - case EncryptionAlgorithm.SEED_CBC: - return CipherType.block; - - case EncryptionAlgorithm.NULL: - case EncryptionAlgorithm.RC4_40: - case EncryptionAlgorithm.RC4_128: - return CipherType.stream; - - default: - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static int getEncryptionAlgorithm(int ciphersuite) throws IOException - { - switch (ciphersuite) - { - case CipherSuite.TLS_DH_anon_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA: - return EncryptionAlgorithm._3DES_EDE_CBC; - - case CipherSuite.TLS_DH_anon_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_anon_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_WITH_AES_128_CBC_SHA: - return EncryptionAlgorithm.AES_128_CBC; - - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CCM: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM: - case CipherSuite.TLS_PSK_WITH_AES_128_CCM: - case CipherSuite.TLS_RSA_WITH_AES_128_CCM: - return EncryptionAlgorithm.AES_128_CCM; - - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_PSK_DHE_WITH_AES_128_CCM_8: - case CipherSuite.TLS_PSK_WITH_AES_128_CCM_8: - case CipherSuite.TLS_RSA_WITH_AES_128_CCM_8: - return EncryptionAlgorithm.AES_128_CCM_8; - - case CipherSuite.TLS_DH_anon_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256: - return EncryptionAlgorithm.AES_128_GCM; - - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_PSK_WITH_AES_128_OCB: - return EncryptionAlgorithm.AES_128_OCB_TAGLEN96; - - case CipherSuite.TLS_DH_anon_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_ECDH_anon_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_WITH_AES_256_CBC_SHA: - return EncryptionAlgorithm.AES_256_CBC; - - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CCM: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CCM: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CCM: - case CipherSuite.TLS_PSK_WITH_AES_256_CCM: - case CipherSuite.TLS_RSA_WITH_AES_256_CCM: - return EncryptionAlgorithm.AES_256_CCM; - - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_PSK_DHE_WITH_AES_256_CCM_8: - case CipherSuite.TLS_PSK_WITH_AES_256_CCM_8: - case CipherSuite.TLS_RSA_WITH_AES_256_CCM_8: - return EncryptionAlgorithm.AES_256_CCM_8; - - case CipherSuite.TLS_DH_anon_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_RSA_WITH_AES_256_GCM_SHA384: - return EncryptionAlgorithm.AES_256_GCM; - - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_AES_256_OCB: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_256_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_AES_256_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_AES_256_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_AES_256_OCB: - case CipherSuite.DRAFT_TLS_PSK_WITH_AES_256_OCB: - return EncryptionAlgorithm.AES_256_OCB_TAGLEN96; - - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256: - return EncryptionAlgorithm.CAMELLIA_128_CBC; - - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256: - return EncryptionAlgorithm.CAMELLIA_128_GCM; - - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384: - return EncryptionAlgorithm.CAMELLIA_256_CBC; - - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384: - return EncryptionAlgorithm.CAMELLIA_256_GCM; - - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256: - return EncryptionAlgorithm.CHACHA20_POLY1305; - - case CipherSuite.TLS_RSA_WITH_NULL_MD5: - return EncryptionAlgorithm.NULL; - - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_NULL_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_NULL_SHA: - case CipherSuite.TLS_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_RSA_WITH_NULL_SHA: - return EncryptionAlgorithm.NULL; - - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_RSA_WITH_NULL_SHA256: - return EncryptionAlgorithm.NULL; - - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_NULL_SHA384: - return EncryptionAlgorithm.NULL; - - case CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5: - case CipherSuite.TLS_RSA_WITH_RC4_128_MD5: - return EncryptionAlgorithm.RC4_128; - - case CipherSuite.TLS_DHE_PSK_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_PSK_WITH_RC4_128_SHA: - case CipherSuite.TLS_RSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_RC4_128_SHA: - return EncryptionAlgorithm.RC4_128; - - case CipherSuite.TLS_DH_anon_WITH_SEED_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_SEED_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_SEED_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_SEED_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_SEED_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_SEED_CBC_SHA: - return EncryptionAlgorithm.SEED_CBC; - - default: - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static int getKeyExchangeAlgorithm(int ciphersuite) throws IOException - { - switch (ciphersuite) - { - case CipherSuite.TLS_DH_anon_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5: - case CipherSuite.TLS_DH_anon_WITH_SEED_CBC_SHA: - return KeyExchangeAlgorithm.DH_anon; - - case CipherSuite.TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DH_DSS_WITH_SEED_CBC_SHA: - return KeyExchangeAlgorithm.DH_DSS; - - case CipherSuite.TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DH_RSA_WITH_SEED_CBC_SHA: - return KeyExchangeAlgorithm.DH_RSA; - - case CipherSuite.TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_DSS_WITH_SEED_CBC_SHA: - return KeyExchangeAlgorithm.DHE_DSS; - - case CipherSuite.TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CCM: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_AES_128_OCB: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CCM: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_AES_256_OCB: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_RC4_128_SHA: - case CipherSuite.TLS_PSK_DHE_WITH_AES_128_CCM_8: - case CipherSuite.TLS_PSK_DHE_WITH_AES_256_CCM_8: - return KeyExchangeAlgorithm.DHE_PSK; - - case CipherSuite.TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_128_OCB: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CCM: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_256_OCB: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_SEED_CBC_SHA: - return KeyExchangeAlgorithm.DHE_RSA; - - case CipherSuite.TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_NULL_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_RC4_128_SHA: - return KeyExchangeAlgorithm.ECDH_anon; - - case CipherSuite.TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_RC4_128_SHA: - return KeyExchangeAlgorithm.ECDH_ECDSA; - - case CipherSuite.TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_RC4_128_SHA: - return KeyExchangeAlgorithm.ECDH_RSA; - - case CipherSuite.TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_AES_128_OCB: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CCM: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_AES_256_OCB: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA: - return KeyExchangeAlgorithm.ECDHE_ECDSA; - - case CipherSuite.TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_AES_128_OCB: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_AES_256_OCB: - case CipherSuite.TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_ECDHE_PSK_WITH_RC4_128_SHA: - return KeyExchangeAlgorithm.ECDHE_PSK; - - case CipherSuite.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_AES_128_OCB: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_AES_256_OCB: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_RC4_128_SHA: - return KeyExchangeAlgorithm.ECDHE_RSA; - - case CipherSuite.TLS_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_PSK_WITH_AES_128_CCM: - case CipherSuite.TLS_PSK_WITH_AES_128_CCM_8: - case CipherSuite.TLS_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_PSK_WITH_AES_128_OCB: - case CipherSuite.TLS_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_PSK_WITH_AES_256_CCM: - case CipherSuite.TLS_PSK_WITH_AES_256_CCM_8: - case CipherSuite.TLS_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_PSK_WITH_AES_256_OCB: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_PSK_WITH_RC4_128_SHA: - return KeyExchangeAlgorithm.PSK; - - case CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_128_CCM: - case CipherSuite.TLS_RSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_256_CCM: - case CipherSuite.TLS_RSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_RSA_WITH_NULL_MD5: - case CipherSuite.TLS_RSA_WITH_NULL_SHA: - case CipherSuite.TLS_RSA_WITH_NULL_SHA256: - case CipherSuite.TLS_RSA_WITH_RC4_128_MD5: - case CipherSuite.TLS_RSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_RSA_WITH_SEED_CBC_SHA: - return KeyExchangeAlgorithm.RSA; - - case CipherSuite.TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_RC4_128_SHA: - return KeyExchangeAlgorithm.RSA_PSK; - - case CipherSuite.TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_WITH_AES_256_CBC_SHA: - return KeyExchangeAlgorithm.SRP; - - case CipherSuite.TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA: - return KeyExchangeAlgorithm.SRP_DSS; - - case CipherSuite.TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA: - return KeyExchangeAlgorithm.SRP_RSA; - - default: - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static int getMACAlgorithm(int ciphersuite) throws IOException - { - switch (ciphersuite) - { - case CipherSuite.TLS_DH_anon_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CCM: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_AES_128_OCB: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CCM: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_AES_256_OCB: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_128_OCB: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CCM: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_256_OCB: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_AES_128_OCB: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CCM: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_AES_256_OCB: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_AES_256_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_AES_128_OCB: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_AES_256_OCB: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_PSK_DHE_WITH_AES_128_CCM_8: - case CipherSuite.TLS_PSK_DHE_WITH_AES_256_CCM_8: - case CipherSuite.TLS_PSK_WITH_AES_128_CCM: - case CipherSuite.TLS_PSK_WITH_AES_128_CCM_8: - case CipherSuite.TLS_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_PSK_WITH_AES_128_OCB: - case CipherSuite.TLS_PSK_WITH_AES_256_CCM: - case CipherSuite.TLS_PSK_WITH_AES_256_CCM_8: - case CipherSuite.TLS_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_PSK_WITH_AES_256_OCB: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_128_CCM: - case CipherSuite.TLS_RSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_256_CCM: - case CipherSuite.TLS_RSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384: - return MACAlgorithm._null; - - case CipherSuite.TLS_DH_anon_WITH_RC4_128_MD5: - case CipherSuite.TLS_RSA_WITH_NULL_MD5: - case CipherSuite.TLS_RSA_WITH_RC4_128_MD5: - return MACAlgorithm.hmac_md5; - - case CipherSuite.TLS_DH_anon_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DH_anon_WITH_SEED_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DH_DSS_WITH_SEED_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DH_RSA_WITH_SEED_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DHE_DSS_WITH_SEED_CBC_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_DHE_PSK_WITH_RC4_128_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_DHE_RSA_WITH_SEED_CBC_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_NULL_SHA: - case CipherSuite.TLS_ECDH_anon_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDH_ECDSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDH_RSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_ECDHE_PSK_WITH_RC4_128_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_NULL_SHA: - case CipherSuite.TLS_ECDHE_RSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_PSK_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_PSK_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_PSK_WITH_RC4_128_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_NULL_SHA: - case CipherSuite.TLS_RSA_PSK_WITH_RC4_128_SHA: - case CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_CBC_SHA: - case CipherSuite.TLS_RSA_WITH_NULL_SHA: - case CipherSuite.TLS_RSA_WITH_RC4_128_SHA: - case CipherSuite.TLS_RSA_WITH_SEED_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_WITH_AES_128_CBC_SHA: - case CipherSuite.TLS_SRP_SHA_WITH_AES_256_CBC_SHA: - return MACAlgorithm.hmac_sha1; - - case CipherSuite.TLS_DH_anon_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_NULL_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_NULL_SHA256: - return MACAlgorithm.hmac_sha256; - - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_PSK_WITH_NULL_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_NULL_SHA384: - return MACAlgorithm.hmac_sha384; - - default: - throw new TlsFatalAlert(AlertDescription.internal_error); - } - } - - public static ProtocolVersion getMinimumVersion(int ciphersuite) - { - switch (ciphersuite) - { - case CipherSuite.TLS_DH_anon_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_CCM: - case CipherSuite.TLS_DHE_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_AES_128_OCB: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_CCM: - case CipherSuite.TLS_DHE_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_AES_256_OCB: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_128_OCB: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CCM: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_256_OCB: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_AES_128_OCB: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CCM: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_AES_256_OCB: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_AES_128_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_AES_256_OCB: - case CipherSuite.DRAFT_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_AES_128_OCB: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_AES_256_OCB: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384: - case CipherSuite.TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_PSK_DHE_WITH_AES_128_CCM_8: - case CipherSuite.TLS_PSK_DHE_WITH_AES_256_CCM_8: - case CipherSuite.TLS_PSK_WITH_AES_128_CCM: - case CipherSuite.TLS_PSK_WITH_AES_128_CCM_8: - case CipherSuite.TLS_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.DRAFT_TLS_PSK_WITH_AES_128_OCB: - case CipherSuite.TLS_PSK_WITH_AES_256_CCM: - case CipherSuite.TLS_PSK_WITH_AES_256_CCM_8: - case CipherSuite.TLS_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_PSK_WITH_AES_256_OCB: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.DRAFT_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_128_CCM: - case CipherSuite.TLS_RSA_WITH_AES_128_CCM_8: - case CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_AES_256_CCM: - case CipherSuite.TLS_RSA_WITH_AES_256_CCM_8: - case CipherSuite.TLS_RSA_WITH_AES_256_GCM_SHA384: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256: - case CipherSuite.TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384: - case CipherSuite.TLS_RSA_WITH_NULL_SHA256: - return ProtocolVersion.TLSv12; - - default: - return ProtocolVersion.SSLv3; - } - } - - public static boolean isAEADCipherSuite(int ciphersuite) throws IOException - { - return CipherType.aead == getCipherType(ciphersuite); - } - - public static boolean isBlockCipherSuite(int ciphersuite) throws IOException - { - return CipherType.block == getCipherType(ciphersuite); - } - - public static boolean isStreamCipherSuite(int ciphersuite) throws IOException - { - return CipherType.stream == getCipherType(ciphersuite); - } - - public static boolean isValidCipherSuiteForSignatureAlgorithms(int cipherSuite, Vector sigAlgs) - { - int keyExchangeAlgorithm; - try - { - keyExchangeAlgorithm = getKeyExchangeAlgorithm(cipherSuite); - } - catch (IOException e) - { - return true; - } - - switch (keyExchangeAlgorithm) - { - case KeyExchangeAlgorithm.DH_anon: - case KeyExchangeAlgorithm.DH_anon_EXPORT: - case KeyExchangeAlgorithm.ECDH_anon: - return sigAlgs.contains(Shorts.valueOf(SignatureAlgorithm.anonymous)); - - case KeyExchangeAlgorithm.DHE_RSA: - case KeyExchangeAlgorithm.DHE_RSA_EXPORT: - case KeyExchangeAlgorithm.ECDHE_RSA: - case KeyExchangeAlgorithm.SRP_RSA: - return sigAlgs.contains(Shorts.valueOf(SignatureAlgorithm.rsa)); - - case KeyExchangeAlgorithm.DHE_DSS: - case KeyExchangeAlgorithm.DHE_DSS_EXPORT: - case KeyExchangeAlgorithm.SRP_DSS: - return sigAlgs.contains(Shorts.valueOf(SignatureAlgorithm.dsa)); - - case KeyExchangeAlgorithm.ECDHE_ECDSA: - return sigAlgs.contains(Shorts.valueOf(SignatureAlgorithm.ecdsa)); - - default: - return true; - } - } - - public static boolean isValidCipherSuiteForVersion(int cipherSuite, ProtocolVersion serverVersion) - { - return getMinimumVersion(cipherSuite).isEqualOrEarlierVersionOf(serverVersion.getEquivalentTLSVersion()); - } - - public static Vector getUsableSignatureAlgorithms(Vector sigHashAlgs) - { - if (sigHashAlgs == null) - { - return getAllSignatureAlgorithms(); - } - - Vector v = new Vector(4); - v.addElement(Shorts.valueOf(SignatureAlgorithm.anonymous)); - for (int i = 0; i < sigHashAlgs.size(); ++i) - { - SignatureAndHashAlgorithm sigHashAlg = (SignatureAndHashAlgorithm)sigHashAlgs.elementAt(i); -// if (sigHashAlg.getHash() >= MINIMUM_HASH_STRICT) - { - Short sigAlg = Shorts.valueOf(sigHashAlg.getSignature()); - if (!v.contains(sigAlg)) - { - v.addElement(sigAlg); - } - } - } - return v; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/UDPTransport.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/UDPTransport.java deleted file mode 100644 index c6ae2fdac..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/UDPTransport.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; - -/** - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class UDPTransport - implements DatagramTransport -{ - protected final static int MIN_IP_OVERHEAD = 20; - protected final static int MAX_IP_OVERHEAD = MIN_IP_OVERHEAD + 64; - protected final static int UDP_OVERHEAD = 8; - - protected final DatagramSocket socket; - protected final int receiveLimit, sendLimit; - - public UDPTransport(DatagramSocket socket, int mtu) - throws IOException - { - if (!socket.isBound() || !socket.isConnected()) - { - throw new IllegalArgumentException("'socket' must be bound and connected"); - } - - this.socket = socket; - - // NOTE: As of JDK 1.6, can use NetworkInterface.getMTU - - this.receiveLimit = mtu - MIN_IP_OVERHEAD - UDP_OVERHEAD; - this.sendLimit = mtu - MAX_IP_OVERHEAD - UDP_OVERHEAD; - } - - public int getReceiveLimit() - { - return receiveLimit; - } - - public int getSendLimit() - { - // TODO[DTLS] Implement Path-MTU discovery? - return sendLimit; - } - - public int receive(byte[] buf, int off, int len, int waitMillis) - throws IOException - { - socket.setSoTimeout(waitMillis); - DatagramPacket packet = new DatagramPacket(buf, off, len); - socket.receive(packet); - return packet.getLength(); - } - - public void send(byte[] buf, int off, int len) - throws IOException - { - if (len > getSendLimit()) - { - /* - * RFC 4347 4.1.1. "If the application attempts to send a record larger than the MTU, - * the DTLS implementation SHOULD generate an error, thus avoiding sending a packet - * which will be fragmented." - */ - throw new TlsFatalAlert(AlertDescription.internal_error); - } - - DatagramPacket packet = new DatagramPacket(buf, off, len); - socket.send(packet); - } - - public void close() - throws IOException - { - socket.close(); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/URLAndHash.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/URLAndHash.java deleted file mode 100644 index 071b9b6b3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/URLAndHash.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import com.fr.third.org.bouncycastle.util.Strings; - -/** - * RFC 6066 5. - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class URLAndHash -{ - protected String url; - protected byte[] sha1Hash; - - public URLAndHash(String url, byte[] sha1Hash) - { - if (url == null || url.length() < 1 || url.length() >= (1 << 16)) - { - throw new IllegalArgumentException("'url' must have length from 1 to (2^16 - 1)"); - } - if (sha1Hash != null && sha1Hash.length != 20) - { - throw new IllegalArgumentException("'sha1Hash' must have length == 20, if present"); - } - - this.url = url; - this.sha1Hash = sha1Hash; - } - - public String getURL() - { - return url; - } - - public byte[] getSHA1Hash() - { - return sha1Hash; - } - - /** - * Encode this {@link URLAndHash} to an {@link OutputStream}. - * - * @param output the {@link OutputStream} to encode to. - * @throws IOException - */ - public void encode(OutputStream output) - throws IOException - { - byte[] urlEncoding = Strings.toByteArray(this.url); - TlsUtils.writeOpaque16(urlEncoding, output); - - if (this.sha1Hash == null) - { - TlsUtils.writeUint8(0, output); - } - else - { - TlsUtils.writeUint8(1, output); - output.write(this.sha1Hash); - } - } - - /** - * Parse a {@link URLAndHash} from an {@link InputStream}. - * - * @param context - * the {@link TlsContext} of the current connection. - * @param input - * the {@link InputStream} to parse from. - * @return a {@link URLAndHash} object. - * @throws IOException - */ - public static URLAndHash parse(TlsContext context, InputStream input) - throws IOException - { - byte[] urlEncoding = TlsUtils.readOpaque16(input); - if (urlEncoding.length < 1) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - String url = Strings.fromByteArray(urlEncoding); - - byte[] sha1Hash = null; - short padding = TlsUtils.readUint8(input); - switch (padding) - { - case 0: - if (TlsUtils.isTLSv12(context)) - { - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - break; - case 1: - sha1Hash = TlsUtils.readFully(20, input); - break; - default: - throw new TlsFatalAlert(AlertDescription.illegal_parameter); - } - - return new URLAndHash(url, sha1Hash); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/UseSRTPData.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/UseSRTPData.java deleted file mode 100644 index d9e9da849..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/UseSRTPData.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 5764 4.1.1 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class UseSRTPData -{ - protected int[] protectionProfiles; - protected byte[] mki; - - /** - * @param protectionProfiles see {@link SRTPProtectionProfile} for valid constants. - * @param mki valid lengths from 0 to 255. - */ - public UseSRTPData(int[] protectionProfiles, byte[] mki) - { - if (protectionProfiles == null || protectionProfiles.length < 1 - || protectionProfiles.length >= (1 << 15)) - { - throw new IllegalArgumentException( - "'protectionProfiles' must have length from 1 to (2^15 - 1)"); - } - - if (mki == null) - { - mki = TlsUtils.EMPTY_BYTES; - } - else if (mki.length > 255) - { - throw new IllegalArgumentException("'mki' cannot be longer than 255 bytes"); - } - - this.protectionProfiles = protectionProfiles; - this.mki = mki; - } - - /** - * @return see {@link SRTPProtectionProfile} for valid constants. - */ - public int[] getProtectionProfiles() - { - return protectionProfiles; - } - - /** - * @return valid lengths from 0 to 255. - */ - public byte[] getMki() - { - return mki; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/UserMappingType.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/UserMappingType.java deleted file mode 100644 index ab9323268..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/UserMappingType.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls; - -/** - * RFC 4681 - * - * @deprecated Migrate to the (D)TLS API in com.fr.third.org.bouncycastle.tls (bctls jar). - */ -public class UserMappingType -{ - /* - * RFC 4681 - */ - public static final short upn_domain_hint = 64; -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/package.html deleted file mode 100644 index ee59f8afb..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/package.html +++ /dev/null @@ -1,5 +0,0 @@ - -- * Please refer to GnuTLSSetup.html or OpenSSLSetup.html (under 'docs'), and x509-*.pem files in - * this package (under 'src/test/resources') for help configuring an external DTLS server. - *
- */ -public class DTLSClientTest -{ - private static final SecureRandom secureRandom = new SecureRandom(); - - public static void main(String[] args) - throws Exception - { - InetAddress address = InetAddress.getLocalHost(); - int port = 5556; - - TlsSession session = createSession(address, port); - - MockDTLSClient client = new MockDTLSClient(session); - - DTLSTransport dtls = openDTLSConnection(address, port, client); - - System.out.println("Receive limit: " + dtls.getReceiveLimit()); - System.out.println("Send limit: " + dtls.getSendLimit()); - - // Send and hopefully receive a packet back - - byte[] request = "Hello World!\n".getBytes("UTF-8"); - dtls.send(request, 0, request.length); - - byte[] response = new byte[dtls.getReceiveLimit()]; - int received = dtls.receive(response, 0, response.length, 30000); - if (received >= 0) - { - System.out.println(new String(response, 0, received, "UTF-8")); - } - - dtls.close(); - } - - private static TlsSession createSession(InetAddress address, int port) - throws IOException - { - MockDTLSClient client = new MockDTLSClient(null); - DTLSTransport dtls = openDTLSConnection(address, port, client); - TlsSession session = client.getSessionToResume(); - dtls.close(); - return session; - } - - private static DTLSTransport openDTLSConnection(InetAddress address, int port, TlsClient client) - throws IOException - { - DatagramSocket socket = new DatagramSocket(); - socket.connect(address, port); - - int mtu = 1500; - DatagramTransport transport = new UDPTransport(socket, mtu); - transport = new UnreliableDatagramTransport(transport, secureRandom, 0, 0); - transport = new LoggingDatagramTransport(transport, System.out); - - DTLSClientProtocol protocol = new DTLSClientProtocol(secureRandom); - - return protocol.connect(client, transport); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/DTLSServerTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/DTLSServerTest.java deleted file mode 100644 index 8ba6576ab..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/DTLSServerTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.SocketTimeoutException; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.tls.DTLSServerProtocol; -import com.fr.third.org.bouncycastle.crypto.tls.DTLSTransport; -import com.fr.third.org.bouncycastle.crypto.tls.DatagramTransport; -import com.fr.third.org.bouncycastle.crypto.tls.UDPTransport; - -/** - * A simple test designed to conduct a DTLS handshake with an external DTLS client. - *- * Please refer to GnuTLSSetup.html or OpenSSLSetup.html (under 'docs'), and x509-*.pem files in - * this package (under 'src/test/resources') for help configuring an external DTLS client. - *
- */ -public class DTLSServerTest -{ - public static void main(String[] args) - throws Exception - { - int port = 5556; - - int mtu = 1500; - - SecureRandom secureRandom = new SecureRandom(); - - DTLSServerProtocol serverProtocol = new DTLSServerProtocol(secureRandom); - - byte[] data = new byte[mtu]; - DatagramPacket packet = new DatagramPacket(data, mtu); - - DatagramSocket socket = new DatagramSocket(port); - socket.receive(packet); - - System.out.println("Accepting connection from " + packet.getAddress().getHostAddress() + ":" + port); - socket.connect(packet.getAddress(), packet.getPort()); - - /* - * NOTE: For simplicity, and since we don't yet have HelloVerifyRequest support, we just - * discard the initial packet, which the client should re-send anyway. - */ - - DatagramTransport transport = new UDPTransport(socket, mtu); - - // Uncomment to see packets -// transport = new LoggingDatagramTransport(transport, System.out); - - MockDTLSServer server = new MockDTLSServer(); - DTLSTransport dtlsServer = serverProtocol.accept(server, transport); - - byte[] buf = new byte[dtlsServer.getReceiveLimit()]; - - while (!socket.isClosed()) - { - try - { - int length = dtlsServer.receive(buf, 0, buf.length, 60000); - if (length >= 0) - { - System.out.write(buf, 0, length); - dtlsServer.send(buf, 0, length); - } - } - catch (SocketTimeoutException ste) - { - } - } - - dtlsServer.close(); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/DTLSTestClientProtocol.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/DTLSTestClientProtocol.java deleted file mode 100644 index ee0b62bad..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/DTLSTestClientProtocol.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.tls.DTLSClientProtocol; -import com.fr.third.org.bouncycastle.crypto.tls.DigitallySigned; - -class DTLSTestClientProtocol extends DTLSClientProtocol -{ - protected final TlsTestConfig config; - - public DTLSTestClientProtocol(SecureRandom secureRandom, TlsTestConfig config) - { - super(secureRandom); - - this.config = config; - } - - protected byte[] generateCertificateVerify(ClientHandshakeState state, DigitallySigned certificateVerify) - throws IOException - { - if (certificateVerify.getAlgorithm() != null && config.clientAuthSigAlgClaimed != null) - { - certificateVerify = new DigitallySigned(config.clientAuthSigAlgClaimed, certificateVerify.getSignature()); - } - - return super.generateCertificateVerify(state, certificateVerify); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/DTLSTestServerProtocol.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/DTLSTestServerProtocol.java deleted file mode 100644 index 24ab142e9..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/DTLSTestServerProtocol.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.tls.DTLSServerProtocol; - -class DTLSTestServerProtocol extends DTLSServerProtocol -{ - protected final TlsTestConfig config; - - public DTLSTestServerProtocol(SecureRandom secureRandom, TlsTestConfig config) - { - super(secureRandom); - - this.config = config; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/HTTPSServerThread.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/HTTPSServerThread.java deleted file mode 100644 index 14af787e8..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/HTTPSServerThread.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.security.KeyStore; - -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLServerSocket; -import javax.net.ssl.SSLServerSocketFactory; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocket; -import javax.net.ssl.TrustManagerFactory; - -public class HTTPSServerThread - extends Thread -{ - private static final int PORT_NO = 8003; - private static final char[] SERVER_PASSWORD = "serverPassword".toCharArray(); - private static final char[] TRUST_STORE_PASSWORD = "trustPassword".toCharArray(); - - /** - * Read a HTTP request - */ - private void readRequest( - InputStream in) - throws IOException - { - int ch = 0; - int lastCh = 0; - while ((ch = in.read()) >= 0 && (ch != '\n' && lastCh != '\n')) - { - if (ch != '\r') - { - lastCh = ch; - } - } - } - - /** - * Send a response - */ - private void sendResponse( - OutputStream out) - { - PrintWriter pWrt = new PrintWriter(new OutputStreamWriter(out)); - pWrt.print("HTTP/1.1 200 OK\r\n"); - pWrt.print("Content-Type: text/html\r\n"); - pWrt.print("\r\n"); - pWrt.print("\r\n"); - pWrt.print("\r\n"); - pWrt.print("Hello World!\r\n"); - pWrt.print("\r\n"); - pWrt.print("\r\n"); - pWrt.flush(); - } - - SSLContext createSSLContext() - throws Exception - { - KeyManagerFactory mgrFact = KeyManagerFactory.getInstance("SunX509"); - KeyStore serverStore = KeyStore.getInstance("JKS"); - - serverStore.load(new ByteArrayInputStream(KeyStores.server), SERVER_PASSWORD); - - mgrFact.init(serverStore, SERVER_PASSWORD); - - // set up a trust manager so we can recognize the server - TrustManagerFactory trustFact = TrustManagerFactory.getInstance("SunX509"); - KeyStore trustStore = KeyStore.getInstance("JKS"); - - trustStore.load(new ByteArrayInputStream(KeyStores.trustStore), TRUST_STORE_PASSWORD); - - trustFact.init(trustStore); - - // create a context and set up a socket factory - SSLContext sslContext = SSLContext.getInstance("TLS"); - - sslContext.init(mgrFact.getKeyManagers(), trustFact.getTrustManagers(), null); - - return sslContext; - } - - public void run() - { - try - { - SSLContext sslContext = createSSLContext(); - SSLServerSocketFactory fact = sslContext.getServerSocketFactory(); - - SSLServerSocket sSock = (SSLServerSocket)fact.createServerSocket(PORT_NO); - SSLSocket sslSock = (SSLSocket)sSock.accept(); - - sslSock.startHandshake(); - - readRequest(sslSock.getInputStream()); - - SSLSession session = sslSock.getSession(); - - sendResponse(sslSock.getOutputStream()); - - sslSock.close(); - sSock.close(); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/KeyStores.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/KeyStores.java deleted file mode 100644 index 2eea83f45..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/KeyStores.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import com.fr.third.org.bouncycastle.util.encoders.Base64; - -public class KeyStores -{ - static final byte[] trustStore = Base64.decode( - "/u3+7QAAAAIAAAABAAAAAgAGc2VydmVyAAABD34zDJEABVguNTA5AAABrzCC" - + "AaswggEUAgEBMA0GCSqGSIb3DQEBBQUAMB4xHDAaBgNVBAMTE1Rlc3QgQ0Eg" - + "Q2VydGlmaWNhdGUwHhcNMDYxMjEzMjM0MzI5WhcNMDYxMjIwMjM0MzI5WjAe" - + "MRwwGgYDVQQDExNUZXN0IENBIENlcnRpZmljYXRlMIGfMA0GCSqGSIb3DQEB" - + "AQUAA4GNADCBiQKBgQCmOumCM46ehsdcrZMw6tj0hMl5D0xf21gcyBj/ByIv" - + "pe008ukaN3zCXIUUUlAu0GkbI1sCbTD1V4qVZuaHqtfa/FINJjyZJy5w7KEx" - + "93OOF2/gyPlnEPGs6RPdThAPliSBsWKBKqtOdmKpwYn/NKuUNFRkFXVLLUPn" - + "jyEKjIcNywIDAQABMA0GCSqGSIb3DQEBBQUAA4GBACi8J7raYqDFjXqAXXPJ" - + "ljZHqvzJNVaSWvBtK/oY7g0+sdGIjPR526fhSCxOZRr7G157ERqMnPjuFjcm" - + "cRlUOPsQtTl6KbUnxmKxa04UzDuNXzSx2oyGx5GCWx9u62hpO6vSpK69L9gH" - + "OUtM5dQXcoK4i3olScKaU8qaYb0mBAy8fnx5pen8B0bIg+pz47l5VxQ5NO8="); - - static final byte[] server = Base64.decode( - "/u3+7QAAAAIAAAABAAAAAQAGc2VydmVyAAABD34zDJIAAAK8MIICuDAOBgor" - + "BgEEASoCEQEBBQAEggKk9OXWj3aBr6rV9Grcsm2YL+/2ShVsxbJVGMSWll1f" - + "U8z/mjhv5K/skgleTIMoyE5FzDDxJIGEmSMCkcHsnseXzxyhLpKBaz3N1Tk7" - + "KVPzXfrNh0FJwzw3lPWyC2ayT+ObQfAtzuI9SUWNLBzzpWeolUJ8gkXnLshX" - + "5RqmR735NRZdjgQOtNYBBErX/NOhTyi009/CZDNxgJQzywFmQcXBLhNSA+0i" - + "cE+LwZ4sZV0NXshPZiyNnsfqN/XNOyhpKr8a3VyVtee2nhO9+FY5IDEviHmR" - + "WDvH5TmB6Os3L6xvwE1ZQCPElk/cK2G1q9+zDBe4JDeo8o7lPhiNpVfcivnr" - + "+tyK9m7PqlssR0+ohuZGwrFMyzLugkOWh+qZ3pk8/7AwJosMvvTvIg36nN7R" - + "pdnouQNKqTm1Sr/UUnKyWqfG7zqKIuF72IkDwwafwuQ9YRX5PAOuRfo6bCyb" - + "D4w1OWdfGFciKMc1BrT+8JzhiTkzNe+jWEA5Tw1zeazPGpp1RHPz2np50G2s" - + "v025uiOSUilBe13Qpx0mAyx7z8Gl6eOxai6rQ/eB/Fu++BMx0OX8vO/K4//Q" - + "w43IPVPklGlb/3Qt7eoNf4tichuxrYJjHu4XbwnzB29Vmsan0XZFER7epvFj" - + "cAZCSG+O6G/f6Ib+7d7xYjLdUaPI60tJ4/C+AuYwZn4jJwTnMnMmwIypz4Z8" - + "XPXW5SbHlV5OkkFC+eAuuN4b2YXZmifeWv4fx65Ioir921LMJrorMizH41RJ" - + "/rAO5wGSwjeDJ784QhhLGbEUMygraRtdaz6MRx26InnoHY7V58ET3Z5YGV39" - + "p+9AtVhYw/QQmTZiF7hqnEMf9AMVFfac9qFF2+IN3g9HAMC6QLxJ1VuPn5oo" - + "lS//axPfjckO7iZx9x59/gAAAAEABVguNTA5AAABrzCCAaswggEUAgEBMA0G" - + "CSqGSIb3DQEBBQUAMB4xHDAaBgNVBAMTE1Rlc3QgQ0EgQ2VydGlmaWNhdGUw" - + "HhcNMDYxMjEzMjM0MzI5WhcNMDYxMjIwMjM0MzI5WjAeMRwwGgYDVQQDExNU" - + "ZXN0IENBIENlcnRpZmljYXRlMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB" - + "gQCmOumCM46ehsdcrZMw6tj0hMl5D0xf21gcyBj/ByIvpe008ukaN3zCXIUU" - + "UlAu0GkbI1sCbTD1V4qVZuaHqtfa/FINJjyZJy5w7KEx93OOF2/gyPlnEPGs" - + "6RPdThAPliSBsWKBKqtOdmKpwYn/NKuUNFRkFXVLLUPnjyEKjIcNywIDAQAB" - + "MA0GCSqGSIb3DQEBBQUAA4GBACi8J7raYqDFjXqAXXPJljZHqvzJNVaSWvBt" - + "K/oY7g0+sdGIjPR526fhSCxOZRr7G157ERqMnPjuFjcmcRlUOPsQtTl6KbUn" - + "xmKxa04UzDuNXzSx2oyGx5GCWx9u62hpO6vSpK69L9gHOUtM5dQXcoK4i3ol" - + "ScKaU8qaYb0mBAy87VQaPfaiQqqxSgqifbSowlg+0fg="); - - static final byte[] client = Base64.decode( - "MIACAQMwgAYJKoZIhvcNAQcBoIAkgASCA+gwgDCABgkqhkiG9w0BBwGggCSA" - + "BIIDDzCCAwswggMHBgsqhkiG9w0BDAoBAqCCArIwggKuMCgGCiqGSIb3DQEM" - + "AQMwGgQUyeN8U+ViAJCk1WGo8wTnRVOaE1oCAgQABIICgH3yMWB+dfMBNa07" - + "hn3smUSBTF+LUauM+kx+12nZt0QazBYg09yM+aVcTznettlDwE/PTpKZnrFT" - + "22DSQf5GwABwiL6KW+xyM8wV5vZx1xtqrQoNf2oNHnF0lB7ddSYM8jHqennb" - + "bzcVOdrrCqewqAfUU/CDugpwwI8c8Iy9ECri6vBMbfeIIZQTug+1952TCCiA" - + "E1bEDFGqgAoDsqYi6uNtpjmL/DPX/qmkbHAXUKxOtjTtxacfat2HgN97Gb7z" - + "+ZBNI5aaCSRoYwl+K9biWGID3EqsNmg0+2ELmFhE4mQZ78i7vNLTG7e5mj6v" - + "Qt+QuqN+daCbVqVTKxsFpODRRweobUTRxwEun6p0p3w3SUhR6p7ug1Jttgyu" - + "vfZug3PIk2j9fb26wAs2ZreVYut8hXpp/09ulCUudtlsYb/FD+H11v/JyopG" - + "2vYy0hL/gkMr41sGoVdyvzXeZUa7A1wYask+g7torad9sT8CPb3zXBd0kU2r" - + "lbSJIXQ8wTpheeUKe47YF9JVCF8WRc1dokD7fgfn6197pwyZpDEVrVyz1pUq" - + "jyum3ctONU4BSkAUVr9pTyeRFUeOE7SLuVu+c67PzNWXEc/HMVD4Hgs/idVc" - + "mrONk3xe385wFJK1iPe1kfRX5OXk9UWr2/yjgrahbkonWhJHnIlvs+b5rRKN" - + "qauwUZ+agMJV98Eyc2Lz0Lp/pNDRNjmGXeJLzAaAy46STov8sxwAgj3bQ7xu" - + "uEzdhJPDynAY5sWd3WnBY2ZhpawnToEKnD4u+eiH2MjUL2q/R2IPSmoyg9i2" - + "Ictgh4/ylrhm+lJDzcDrLDhC0m/t9EdhytH4erk/uCPcmAK/jpzFn6ltxcsx" - + "QjAbBgkqhkiG9w0BCRQxDh4MAGMAbABpAGUAbgB0MCMGCSqGSIb3DQEJFTEW" - + "BBS2wDxw7yH2OhKIgkDoQrTlavLvxQAAAAAAADCABgkqhkiG9w0BBwaggDCA" - + "AgEAMIAGCSqGSIb3DQEHATAoBgoqhkiG9w0BDAEGMBoEFORdyeTIG2oXDQBl" - + "I3aFNozDAkC2AgIEAKCABIIHICsc3D8rxLiDlegyXFfIejto66RW4u6b+d0C" - + "uAAz0G+dIvhQ9g3s++vUsX7x+icO/vjpgdo09aqtIg7T3suzfcHtU8CGSgtQ" - + "Tvml25LDC3IK3qI6cRqO+sCdvg18aS04IDKvDPYH4ca5btwPBIID6CStk/jY" - + "QFpnSI6VNz9IERi/nwuvuBYk+A0Z7+nQdhF+QkW1rzN+uz0dkNJt6ZbG5lEK" - + "GayV+FDTQcREMihYa716RN9sq3cm0jXXdttj998oS/QrpZDEcPqd4AM6EIL+" - + "PTA1tEQYxXa8msAPp+tLvXOtiD6v/4FO77EA7E5oR36a9en+M1QQasFU3VBf" - + "V9os92QlbtVUTkspJV9gXL6s4CGNptc7lUH+nIw65j9MOoyOU9w1qjPRlN/Z" - + "MTuhFooglE6TPd29Udwufqp+hHkW/7z5tBKkhGlZEClzD3IWhcF9NVraE/IV" - + "S5qVmx2Up7SeLZAXJ+AAznq5IXwE1dOUTkwYLcIrH1FuVA5rtOkB8Xt1LJq0" - + "ERkjJ5MfpxTxbKXp5PejzD98v54+s4INekcrI0jzz4pLsann7ex0r6CPsQsH" - + "+F3rBVaT3oHSKqoIm2Nw57oDjLLp5lP2qcCqps3y2dcVzu5NIzCSkVlxUaBK" - + "IT3xv0gvVJI7wnP0QM35MCywKkToJX5ajQKrDc4iCAAzmxaQzdBycxJPYByq" - + "VHvH7BJldJlMw5NHbTHlNoYKndMdAsHp7sUqERkDEGl80R86TlB4nJaDrfsx" - + "vL+KluiCY9AD7o+MEYZ9VYoNDUzVGH4pTr4wnv1UFoRWix5IZuDnnYkyijKD" - + "VtU5+mc0YtsPQIpKCBJOYt05bgpX5aPQ3s2lviYw3bvP0TrclYs/rx4wKVgW" - + "2GYLzPh0OVMBduCbzW1E58ieBsgRyQ7+2MTl9Nj+nznjCAfLSvrVEcwxVUQA" - + "ofcEbiECEJss2JNQq8erwgo8dP3atwQ1KeqMc8acICcOrI2rNxwVOLzPuCsl" - + "l8gwZOoxLZXuKMQbQu4as1HNS309dfWIWppvc3K4nDWg51HUCPbsIo3wm3rR" - + "igc/W3bf4Ppg0pLAS5c1s0Xau43u9GmIjGiDqYaasfcXnCKy2LNuUpbhoOC1" - + "o/wMC9gT45aJQ5vsVGe5XvfhLV7Y815EdI756s9PIEOnG8HbAtCAjOIVpQfP" - + "eF8+cnZyGGdsbmu7lYzg3whCpZ/L2RrTI86nEn5eePs4m2hDV0Oi9r6e2CIf" - + "nGUa0TB9jf1OMhOSBD+h4jx7b6uT+XLmG8qUxvkoItMDZLrJ0f8czO5MyOZa" - + "nEJoG42Fy2p7zD/qO72OUQISNmt8C1rQFsg9dBDib4DMu69vBsVrIV028sal" - + "+tq1UH3vFMbEYyVfPH3WDgxyHwUQK2qrz3WBdD/BMyuAV4DPI3SPTweROh8n" - + "yWJN1ppY9qybmTyHFCs6TRjPB9cVcdKSc0qYxgzblJiXXb3s9ANOb89aA3Ah" - + "anWnAhcEggLZN2yFCtrRuvJXvDQhj8qmye9UkjB2fEpWXV7H0natE3hSoB+C" - + "2krt3eBV0xJ1tLEco7T4zsbQQJRmeu/essOsfwpRfE5ZPoIeThf+UmWTsfsw" - + "r4fxeePMTy6iCnkF5/ro8k5WKnOsaV+HWy/ulwW2r/DMT3aDBWfHX5Hk8DpU" - + "+PlQhbyGTSTIJ/OFmbcWjMPt469o7+KrrF9IBrzJ42KzMw6xtKwtVb0232AM" - + "pIwnLzCHIiNO2qDBZAIDdF68+GU3RsEkHfR6d5myZVxnH4mhSCFFtHxgqTOz" - + "Ouo/uvgu72miZ0OFAy1zcMtfGMS3Md54MJkhSZq4ZgUo/EyJCeEDLGn8pMF1" - + "jX1WsUj96qMRyc+p2KnKs6ZL95BVa76SdIFz6ts6uoIem3drTXYJHNbw29OW" - + "Y0am+FmXTWFZFnin8Qu5Xct5l7FYIGA9VLOHL9Vtp+SXomcFEZpjMaxvtf4R" - + "xoAI2Bc9Ka+MNiz35O0JXhI9/t5uOdiN6ZOJlfpEWOK7ou5lDkZuDcrHvLvQ" - + "PocP2Yemd36xEgjFssR/tFITlhRBXHDeHwpvmXM4iiwD1wOGMqybXx/1g1m1" - + "0UBbKqDsgSLQC7c0TaRFJjj71T74PBMiapiQgijv9WINfmTgxNUukbK3Kqp/" - + "G3BmThoIDCB8WD1kxXBpaG62dSsih7yhPQJVEV3Y0tdkdChOk+Y3Wf8crV/Q" - + "P08pQH7H9yCi04S5fSJtIDtYARWhr1yl8EQMnu2X8J6r/DWcDmXUK4Bv1vqe" - + "tcnT5EAYFPeOMz21nonM3kJgUMNsxCQjKaEMEcUu8ZRnGUAFdG4lULPJn5NQ" - + "LTvWg8Y3GrHRLjpnd9k+8gWWzRIbBiwCwEbClMZffRd6kcA5ZoOhVngdyvvj" - + "BhkgadB5jC+ZRzExHxoEhzPJx3mxIVTqLuw7QxHz9OTcysvY/cGKCvmgzgk/" - + "TjTJsqcEAAAAAAAAAAAAAAAAAAAAAAAAMD0wITAJBgUrDgMCGgUABBQWfGA6" - + "lI+TXQiuXaa1V+LlHodhXAQUAwMIAAUvBYY+a7sXNlQeVEPAGkMCAgQAAAA="); -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/LoggingDatagramTransport.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/LoggingDatagramTransport.java deleted file mode 100644 index 5ffa95726..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/LoggingDatagramTransport.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.PrintStream; - -import com.fr.third.org.bouncycastle.crypto.tls.DatagramTransport; -import com.fr.third.org.bouncycastle.util.Strings; - -public class LoggingDatagramTransport - implements DatagramTransport -{ - - private static final String HEX_CHARS = "0123456789ABCDEF"; - - private final DatagramTransport transport; - private final PrintStream output; - private final long launchTimestamp; - - public LoggingDatagramTransport(DatagramTransport transport, PrintStream output) - { - this.transport = transport; - this.output = output; - this.launchTimestamp = System.currentTimeMillis(); - } - - public int getReceiveLimit() - throws IOException - { - return transport.getReceiveLimit(); - } - - public int getSendLimit() - throws IOException - { - return transport.getSendLimit(); - } - - public int receive(byte[] buf, int off, int len, int waitMillis) - throws IOException - { - int length = transport.receive(buf, off, len, waitMillis); - if (length >= 0) - { - dumpDatagram("Received", buf, off, length); - } - return length; - } - - public void send(byte[] buf, int off, int len) - throws IOException - { - dumpDatagram("Sending", buf, off, len); - transport.send(buf, off, len); - } - - public void close() - throws IOException - { - } - - private void dumpDatagram(String verb, byte[] buf, int off, int len) - throws IOException - { - long timestamp = System.currentTimeMillis() - launchTimestamp; - StringBuffer sb = new StringBuffer("(+" + timestamp + "ms) " + verb + " " + len + " byte datagram:"); - for (int pos = 0; pos < len; ++pos) - { - if (pos % 16 == 0) - { - sb.append(Strings.lineSeparator()); - sb.append(" "); - } - else if (pos % 16 == 8) - { - sb.append('-'); - } - else - { - sb.append(' '); - } - int val = buf[off + pos] & 0xFF; - sb.append(HEX_CHARS.charAt(val >> 4)); - sb.append(HEX_CHARS.charAt(val & 0xF)); - } - dump(sb.toString()); - } - - private synchronized void dump(String s) - { - output.println(s); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockDTLSClient.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockDTLSClient.java deleted file mode 100644 index 54e229255..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockDTLSClient.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.asn1.x509.Certificate; -import com.fr.third.org.bouncycastle.crypto.tls.AlertDescription; -import com.fr.third.org.bouncycastle.crypto.tls.AlertLevel; -import com.fr.third.org.bouncycastle.crypto.tls.CertificateRequest; -import com.fr.third.org.bouncycastle.crypto.tls.ClientCertificateType; -import com.fr.third.org.bouncycastle.crypto.tls.DefaultTlsClient; -import com.fr.third.org.bouncycastle.crypto.tls.MaxFragmentLength; -import com.fr.third.org.bouncycastle.crypto.tls.ProtocolVersion; -import com.fr.third.org.bouncycastle.crypto.tls.SignatureAlgorithm; -import com.fr.third.org.bouncycastle.crypto.tls.TlsAuthentication; -import com.fr.third.org.bouncycastle.crypto.tls.TlsCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsExtensionsUtils; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSession; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - -public class MockDTLSClient - extends DefaultTlsClient -{ - protected TlsSession session; - - public MockDTLSClient(TlsSession session) - { - this.session = session; - } - - public TlsSession getSessionToResume() - { - return this.session; - } - - public void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("DTLS client raised alert: " + AlertLevel.getText(alertLevel) - + ", " + AlertDescription.getText(alertDescription)); - if (message != null) - { - out.println(message); - } - if (cause != null) - { - cause.printStackTrace(out); - } - } - - public void notifyAlertReceived(short alertLevel, short alertDescription) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("DTLS client received alert: " + AlertLevel.getText(alertLevel) - + ", " + AlertDescription.getText(alertDescription)); - } - - public ProtocolVersion getClientVersion() - { - return ProtocolVersion.DTLSv12; - } - - public ProtocolVersion getMinimumVersion() - { - return ProtocolVersion.DTLSv10; - } - -// public int[] getCipherSuites() -// { -// return Arrays.concatenate(super.getCipherSuites(), -// new int[] -// { -// CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, -// }); -// } - - public Hashtable getClientExtensions() throws IOException - { - Hashtable clientExtensions = TlsExtensionsUtils.ensureExtensionsInitialised(super.getClientExtensions()); - TlsExtensionsUtils.addEncryptThenMACExtension(clientExtensions); - { - /* - * NOTE: If you are copying test code, do not blindly set these extensions in your own client. - */ - TlsExtensionsUtils.addMaxFragmentLengthExtension(clientExtensions, MaxFragmentLength.pow2_9); - TlsExtensionsUtils.addPaddingExtension(clientExtensions, context.getSecureRandom().nextInt(16)); - TlsExtensionsUtils.addTruncatedHMacExtension(clientExtensions); - } - return clientExtensions; - } - - public void notifyServerVersion(ProtocolVersion serverVersion) throws IOException - { - super.notifyServerVersion(serverVersion); - - System.out.println("Negotiated " + serverVersion); - } - - public TlsAuthentication getAuthentication() - throws IOException - { - return new TlsAuthentication() - { - public void notifyServerCertificate(com.fr.third.org.bouncycastle.crypto.tls.Certificate serverCertificate) - throws IOException - { - Certificate[] chain = serverCertificate.getCertificateList(); - System.out.println("DTLS client received server certificate chain of length " + chain.length); - for (int i = 0; i != chain.length; i++) - { - Certificate entry = chain[i]; - // TODO Create fingerprint based on certificate signature algorithm digest - System.out.println(" fingerprint:SHA-256 " + TlsTestUtils.fingerprint(entry) + " (" - + entry.getSubject() + ")"); - } - } - - public TlsCredentials getClientCredentials(CertificateRequest certificateRequest) - throws IOException - { - short[] certificateTypes = certificateRequest.getCertificateTypes(); - if (certificateTypes == null || !Arrays.contains(certificateTypes, ClientCertificateType.rsa_sign)) - { - return null; - } - - return TlsTestUtils.loadSignerCredentials(context, certificateRequest.getSupportedSignatureAlgorithms(), - SignatureAlgorithm.rsa, "x509-client.pem", "x509-client-key.pem"); - } - }; - } - - public void notifyHandshakeComplete() throws IOException - { - super.notifyHandshakeComplete(); - - TlsSession newSession = context.getResumableSession(); - if (newSession != null) - { - byte[] newSessionID = newSession.getSessionID(); - String hex = Hex.toHexString(newSessionID); - - if (this.session != null && Arrays.areEqual(this.session.getSessionID(), newSessionID)) - { - System.out.println("Resumed session: " + hex); - } - else - { - System.out.println("Established session: " + hex); - } - - this.session = newSession; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockDTLSServer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockDTLSServer.java deleted file mode 100644 index 3f2157907..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockDTLSServer.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.x509.Certificate; -import com.fr.third.org.bouncycastle.crypto.tls.AlertDescription; -import com.fr.third.org.bouncycastle.crypto.tls.AlertLevel; -import com.fr.third.org.bouncycastle.crypto.tls.CertificateRequest; -import com.fr.third.org.bouncycastle.crypto.tls.CipherSuite; -import com.fr.third.org.bouncycastle.crypto.tls.ClientCertificateType; -import com.fr.third.org.bouncycastle.crypto.tls.DefaultTlsServer; -import com.fr.third.org.bouncycastle.crypto.tls.ProtocolVersion; -import com.fr.third.org.bouncycastle.crypto.tls.SignatureAlgorithm; -import com.fr.third.org.bouncycastle.crypto.tls.TlsEncryptionCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSignerCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsUtils; -import com.fr.third.org.bouncycastle.util.Arrays; - -public class MockDTLSServer - extends DefaultTlsServer -{ - public void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("DTLS server raised alert: " + AlertLevel.getText(alertLevel) - + ", " + AlertDescription.getText(alertDescription)); - if (message != null) - { - out.println(message); - } - if (cause != null) - { - cause.printStackTrace(out); - } - } - - public void notifyAlertReceived(short alertLevel, short alertDescription) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("DTLS server received alert: " + AlertLevel.getText(alertLevel) - + ", " + AlertDescription.getText(alertDescription)); - } - - protected int[] getCipherSuites() - { - return Arrays.concatenate(super.getCipherSuites(), - new int[] - { - CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, - }); - } - - public CertificateRequest getCertificateRequest() throws IOException - { - short[] certificateTypes = new short[]{ ClientCertificateType.rsa_sign, - ClientCertificateType.dss_sign, ClientCertificateType.ecdsa_sign }; - - Vector serverSigAlgs = null; - if (TlsUtils.isSignatureAlgorithmsExtensionAllowed(serverVersion)) - { - serverSigAlgs = TlsUtils.getDefaultSupportedSignatureAlgorithms(); - } - - Vector certificateAuthorities = new Vector(); - certificateAuthorities.addElement(TlsTestUtils.loadCertificateResource("x509-ca.pem").getSubject()); - - return new CertificateRequest(certificateTypes, serverSigAlgs, certificateAuthorities); - } - - public void notifyClientCertificate(com.fr.third.org.bouncycastle.crypto.tls.Certificate clientCertificate) - throws IOException - { - Certificate[] chain = clientCertificate.getCertificateList(); - System.out.println("DTLS server received client certificate chain of length " + chain.length); - for (int i = 0; i != chain.length; i++) - { - Certificate entry = chain[i]; - // TODO Create fingerprint based on certificate signature algorithm digest - System.out.println(" fingerprint:SHA-256 " + TlsTestUtils.fingerprint(entry) + " (" + entry.getSubject() - + ")"); - } - } - - protected ProtocolVersion getMaximumVersion() - { - return ProtocolVersion.DTLSv12; - } - - protected ProtocolVersion getMinimumVersion() - { - return ProtocolVersion.DTLSv10; - } - - protected TlsEncryptionCredentials getRSAEncryptionCredentials() - throws IOException - { - return TlsTestUtils.loadEncryptionCredentials(context, new String[]{"x509-server.pem", "x509-ca.pem"}, - "x509-server-key.pem"); - } - - protected TlsSignerCredentials getRSASignerCredentials() throws IOException - { - return TlsTestUtils.loadSignerCredentials(context, supportedSignatureAlgorithms, SignatureAlgorithm.rsa, - "x509-server.pem", "x509-server-key.pem"); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockDatagramAssociation.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockDatagramAssociation.java deleted file mode 100644 index 8eb339d1d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockDatagramAssociation.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.net.DatagramPacket; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.crypto.tls.DatagramTransport; - -public class MockDatagramAssociation -{ - private int mtu; - private MockDatagramTransport client, server; - - public MockDatagramAssociation(int mtu) - { - this.mtu = mtu; - - Vector clientQueue = new Vector(); - Vector serverQueue = new Vector(); - - this.client = new MockDatagramTransport(clientQueue, serverQueue); - this.server = new MockDatagramTransport(serverQueue, clientQueue); - } - - public DatagramTransport getClient() - { - return client; - } - - public DatagramTransport getServer() - { - return server; - } - - private class MockDatagramTransport - implements DatagramTransport - { - private Vector receiveQueue, sendQueue; - - MockDatagramTransport(Vector receiveQueue, Vector sendQueue) - { - this.receiveQueue = receiveQueue; - this.sendQueue = sendQueue; - } - - public int getReceiveLimit() - throws IOException - { - return mtu; - } - - public int getSendLimit() - throws IOException - { - return mtu; - } - - public int receive(byte[] buf, int off, int len, int waitMillis) - throws IOException - { - synchronized (receiveQueue) - { - if (receiveQueue.isEmpty()) - { - try - { - receiveQueue.wait(waitMillis); - } - catch (InterruptedException e) - { - // TODO Keep waiting until full wait expired? - } - if (receiveQueue.isEmpty()) - { - return -1; - } - } - DatagramPacket packet = (DatagramPacket)receiveQueue.remove(0); - int copyLength = Math.min(len, packet.getLength()); - System.arraycopy(packet.getData(), packet.getOffset(), buf, off, copyLength); - return copyLength; - } - } - - public void send(byte[] buf, int off, int len) - throws IOException - { - if (len > mtu) - { - // TODO Simulate rejection? - } - - byte[] copy = new byte[len]; - System.arraycopy(buf, off, copy, 0, len); - DatagramPacket packet = new DatagramPacket(copy, len); - - synchronized (sendQueue) - { - sendQueue.addElement(packet); - sendQueue.notify(); - } - } - - public void close() - throws IOException - { - // TODO? - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockPSKTlsClient.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockPSKTlsClient.java deleted file mode 100644 index da32a9358..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockPSKTlsClient.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.asn1.x509.Certificate; -import com.fr.third.org.bouncycastle.crypto.tls.AlertDescription; -import com.fr.third.org.bouncycastle.crypto.tls.AlertLevel; -import com.fr.third.org.bouncycastle.crypto.tls.BasicTlsPSKIdentity; -import com.fr.third.org.bouncycastle.crypto.tls.CipherSuite; -import com.fr.third.org.bouncycastle.crypto.tls.PSKTlsClient; -import com.fr.third.org.bouncycastle.crypto.tls.ProtocolVersion; -import com.fr.third.org.bouncycastle.crypto.tls.ServerOnlyTlsAuthentication; -import com.fr.third.org.bouncycastle.crypto.tls.TlsAuthentication; -import com.fr.third.org.bouncycastle.crypto.tls.TlsExtensionsUtils; -import com.fr.third.org.bouncycastle.crypto.tls.TlsPSKIdentity; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSession; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - -class MockPSKTlsClient - extends PSKTlsClient -{ - TlsSession session; - - MockPSKTlsClient(TlsSession session) - { - this(session, new BasicTlsPSKIdentity("client", Strings.toUTF8ByteArray("TLS_TEST_PSK"))); - } - - MockPSKTlsClient(TlsSession session, TlsPSKIdentity pskIdentity) - { - super(pskIdentity); - - this.session = session; - } - - public TlsSession getSessionToResume() - { - return this.session; - } - - public void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS-PSK client raised alert: " + AlertLevel.getText(alertLevel) + ", " - + AlertDescription.getText(alertDescription)); - if (message != null) - { - out.println("> " + message); - } - if (cause != null) - { - cause.printStackTrace(out); - } - } - - public void notifyAlertReceived(short alertLevel, short alertDescription) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS-PSK client received alert: " + AlertLevel.getText(alertLevel) + ", " - + AlertDescription.getText(alertDescription)); - } - - public void notifyHandshakeComplete() throws IOException - { - super.notifyHandshakeComplete(); - - TlsSession newSession = context.getResumableSession(); - if (newSession != null) - { - byte[] newSessionID = newSession.getSessionID(); - String hex = Hex.toHexString(newSessionID); - - if (this.session != null && Arrays.areEqual(this.session.getSessionID(), newSessionID)) - { - System.out.println("Resumed session: " + hex); - } - else - { - System.out.println("Established session: " + hex); - } - - this.session = newSession; - } - } - - public int[] getCipherSuites() - { - return new int[]{ CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384, - CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA384, CipherSuite.TLS_RSA_PSK_WITH_AES_256_CBC_SHA384, - CipherSuite.TLS_PSK_WITH_AES_256_CBC_SHA }; - } - - public ProtocolVersion getMinimumVersion() - { - return ProtocolVersion.TLSv12; - } - - public Hashtable getClientExtensions() throws IOException - { - Hashtable clientExtensions = TlsExtensionsUtils.ensureExtensionsInitialised(super.getClientExtensions()); - TlsExtensionsUtils.addEncryptThenMACExtension(clientExtensions); - return clientExtensions; - } - - public void notifyServerVersion(ProtocolVersion serverVersion) throws IOException - { - super.notifyServerVersion(serverVersion); - - System.out.println("TLS-PSK client negotiated " + serverVersion); - } - - public TlsAuthentication getAuthentication() throws IOException - { - return new ServerOnlyTlsAuthentication() - { - public void notifyServerCertificate(com.fr.third.org.bouncycastle.crypto.tls.Certificate serverCertificate) - throws IOException - { - Certificate[] chain = serverCertificate.getCertificateList(); - System.out.println("TLS-PSK client received server certificate chain of length " + chain.length); - for (int i = 0; i != chain.length; i++) - { - Certificate entry = chain[i]; - // TODO Create fingerprint based on certificate signature algorithm digest - System.out.println(" fingerprint:SHA-256 " + TlsTestUtils.fingerprint(entry) + " (" - + entry.getSubject() + ")"); - } - } - }; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockPSKTlsServer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockPSKTlsServer.java deleted file mode 100644 index 101a2c899..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockPSKTlsServer.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.PrintStream; - -import com.fr.third.org.bouncycastle.crypto.tls.AlertDescription; -import com.fr.third.org.bouncycastle.crypto.tls.AlertLevel; -import com.fr.third.org.bouncycastle.crypto.tls.CipherSuite; -import com.fr.third.org.bouncycastle.crypto.tls.PSKTlsServer; -import com.fr.third.org.bouncycastle.crypto.tls.ProtocolVersion; -import com.fr.third.org.bouncycastle.crypto.tls.TlsEncryptionCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsPSKIdentityManager; -import com.fr.third.org.bouncycastle.util.Strings; - -class MockPSKTlsServer - extends PSKTlsServer -{ - MockPSKTlsServer() - { - super(new MyIdentityManager()); - } - - public void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS-PSK server raised alert: " + AlertLevel.getText(alertLevel) + ", " - + AlertDescription.getText(alertDescription)); - if (message != null) - { - out.println("> " + message); - } - if (cause != null) - { - cause.printStackTrace(out); - } - } - - public void notifyAlertReceived(short alertLevel, short alertDescription) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS-PSK server received alert: " + AlertLevel.getText(alertLevel) + ", " - + AlertDescription.getText(alertDescription)); - } - - public void notifyHandshakeComplete() throws IOException - { - super.notifyHandshakeComplete(); - - byte[] pskIdentity = context.getSecurityParameters().getPSKIdentity(); - if (pskIdentity != null) - { - String name = Strings.fromUTF8ByteArray(pskIdentity); - System.out.println("TLS-PSK server completed handshake for PSK identity: " + name); - } - } - - protected int[] getCipherSuites() - { - return new int[]{ CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384, - CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA384, CipherSuite.TLS_RSA_PSK_WITH_AES_256_CBC_SHA384, - CipherSuite.TLS_PSK_WITH_AES_256_CBC_SHA }; - } - - protected ProtocolVersion getMaximumVersion() - { - return ProtocolVersion.TLSv12; - } - - protected ProtocolVersion getMinimumVersion() - { - return ProtocolVersion.TLSv12; - } - - public ProtocolVersion getServerVersion() throws IOException - { - ProtocolVersion serverVersion = super.getServerVersion(); - - System.out.println("TLS-PSK server negotiated " + serverVersion); - - return serverVersion; - } - - protected TlsEncryptionCredentials getRSAEncryptionCredentials() throws IOException - { - return TlsTestUtils.loadEncryptionCredentials(context, new String[]{ "x509-server.pem", "x509-ca.pem" }, - "x509-server-key.pem"); - } - - static class MyIdentityManager - implements TlsPSKIdentityManager - { - public byte[] getHint() - { - return Strings.toUTF8ByteArray("hint"); - } - - public byte[] getPSK(byte[] identity) - { - if (identity != null) - { - String name = Strings.fromUTF8ByteArray(identity); - if (name.equals("client")) - { - return Strings.toUTF8ByteArray("TLS_TEST_PSK"); - } - } - return null; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockSRPTlsClient.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockSRPTlsClient.java deleted file mode 100644 index 2fc2155c4..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockSRPTlsClient.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.asn1.x509.Certificate; -import com.fr.third.org.bouncycastle.crypto.tls.AlertDescription; -import com.fr.third.org.bouncycastle.crypto.tls.AlertLevel; -import com.fr.third.org.bouncycastle.crypto.tls.CipherSuite; -import com.fr.third.org.bouncycastle.crypto.tls.ProtocolVersion; -import com.fr.third.org.bouncycastle.crypto.tls.SRPTlsClient; -import com.fr.third.org.bouncycastle.crypto.tls.ServerOnlyTlsAuthentication; -import com.fr.third.org.bouncycastle.crypto.tls.TlsAuthentication; -import com.fr.third.org.bouncycastle.crypto.tls.TlsExtensionsUtils; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSession; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - -class MockSRPTlsClient - extends SRPTlsClient -{ - TlsSession session; - - MockSRPTlsClient(TlsSession session, byte[] identity, byte[] password) - { - super(identity, password); - - this.session = session; - } - - public TlsSession getSessionToResume() - { - return this.session; - } - - public void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS-SRP client raised alert: " + AlertLevel.getText(alertLevel) + ", " - + AlertDescription.getText(alertDescription)); - if (message != null) - { - out.println("> " + message); - } - if (cause != null) - { - cause.printStackTrace(out); - } - } - - public void notifyAlertReceived(short alertLevel, short alertDescription) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS-SRP client received alert: " + AlertLevel.getText(alertLevel) + ", " - + AlertDescription.getText(alertDescription)); - } - - public void notifyHandshakeComplete() throws IOException - { - super.notifyHandshakeComplete(); - - TlsSession newSession = context.getResumableSession(); - if (newSession != null) - { - byte[] newSessionID = newSession.getSessionID(); - String hex = Hex.toHexString(newSessionID); - - if (this.session != null && Arrays.areEqual(this.session.getSessionID(), newSessionID)) - { - System.out.println("Resumed session: " + hex); - } - else - { - System.out.println("Established session: " + hex); - } - - this.session = newSession; - } - } - - public ProtocolVersion getMinimumVersion() - { - return ProtocolVersion.TLSv12; - } - - public Hashtable getClientExtensions() throws IOException - { - Hashtable clientExtensions = TlsExtensionsUtils.ensureExtensionsInitialised(super.getClientExtensions()); - TlsExtensionsUtils.addEncryptThenMACExtension(clientExtensions); - return clientExtensions; - } - - public void notifyServerVersion(ProtocolVersion serverVersion) throws IOException - { - super.notifyServerVersion(serverVersion); - - System.out.println("TLS-SRP client negotiated " + serverVersion); - } - - public TlsAuthentication getAuthentication() throws IOException - { - return new ServerOnlyTlsAuthentication() - { - public void notifyServerCertificate(com.fr.third.org.bouncycastle.crypto.tls.Certificate serverCertificate) - throws IOException - { - Certificate[] chain = serverCertificate.getCertificateList(); - System.out.println("TLS-SRP client received server certificate chain of length " + chain.length); - for (int i = 0; i != chain.length; i++) - { - Certificate entry = chain[i]; - // TODO Create fingerprint based on certificate signature algorithm digest - System.out.println(" fingerprint:SHA-256 " + TlsTestUtils.fingerprint(entry) + " (" - + entry.getSubject() + ")"); - } - } - }; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockSRPTlsServer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockSRPTlsServer.java deleted file mode 100644 index ae395f395..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockSRPTlsServer.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.PrintStream; -import java.math.BigInteger; - -import com.fr.third.org.bouncycastle.crypto.agreement.srp.SRP6StandardGroups; -import com.fr.third.org.bouncycastle.crypto.agreement.srp.SRP6VerifierGenerator; -import com.fr.third.org.bouncycastle.crypto.params.SRP6GroupParameters; -import com.fr.third.org.bouncycastle.crypto.tls.AlertDescription; -import com.fr.third.org.bouncycastle.crypto.tls.AlertLevel; -import com.fr.third.org.bouncycastle.crypto.tls.HashAlgorithm; -import com.fr.third.org.bouncycastle.crypto.tls.ProtocolVersion; -import com.fr.third.org.bouncycastle.crypto.tls.SRPTlsServer; -import com.fr.third.org.bouncycastle.crypto.tls.SignatureAlgorithm; -import com.fr.third.org.bouncycastle.crypto.tls.SimulatedTlsSRPIdentityManager; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSRPIdentityManager; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSRPLoginParameters; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSignerCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsUtils; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.Strings; - -class MockSRPTlsServer - extends SRPTlsServer -{ - static final SRP6GroupParameters TEST_GROUP = SRP6StandardGroups.rfc5054_1024; - static final byte[] TEST_IDENTITY = Strings.toUTF8ByteArray("client"); - static final byte[] TEST_PASSWORD = Strings.toUTF8ByteArray("password"); - static final byte[] TEST_SALT = Strings.toUTF8ByteArray("salt"); - static final byte[] TEST_SEED_KEY = Strings.toUTF8ByteArray("seed_key"); - - MockSRPTlsServer() - { - super(new MyIdentityManager()); - } - - public void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS-SRP server raised alert: " + AlertLevel.getText(alertLevel) + ", " - + AlertDescription.getText(alertDescription)); - if (message != null) - { - out.println("> " + message); - } - if (cause != null) - { - cause.printStackTrace(out); - } - } - - public void notifyAlertReceived(short alertLevel, short alertDescription) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS-SRP server received alert: " + AlertLevel.getText(alertLevel) + ", " - + AlertDescription.getText(alertDescription)); - } - - public void notifyHandshakeComplete() throws IOException - { - super.notifyHandshakeComplete(); - - byte[] srpIdentity = context.getSecurityParameters().getSRPIdentity(); - if (srpIdentity != null) - { - String name = Strings.fromUTF8ByteArray(srpIdentity); - System.out.println("TLS-SRP server completed handshake for SRP identity: " + name); - } - } - - protected ProtocolVersion getMaximumVersion() - { - return ProtocolVersion.TLSv12; - } - - protected ProtocolVersion getMinimumVersion() - { - return ProtocolVersion.TLSv12; - } - - public ProtocolVersion getServerVersion() throws IOException - { - ProtocolVersion serverVersion = super.getServerVersion(); - - System.out.println("TLS-SRP server negotiated " + serverVersion); - - return serverVersion; - } - - protected TlsSignerCredentials getDSASignerCredentials() throws IOException - { - return TlsTestUtils.loadSignerCredentials(context, supportedSignatureAlgorithms, SignatureAlgorithm.dsa, - "x509-server-dsa.pem", "x509-server-key-dsa.pem"); - } - - protected TlsSignerCredentials getRSASignerCredentials() throws IOException - { - return TlsTestUtils.loadSignerCredentials(context, supportedSignatureAlgorithms, SignatureAlgorithm.rsa, - "x509-server.pem", "x509-server-key.pem"); - } - - static class MyIdentityManager - implements TlsSRPIdentityManager - { - protected SimulatedTlsSRPIdentityManager unknownIdentityManager = SimulatedTlsSRPIdentityManager.getRFC5054Default( - TEST_GROUP, TEST_SEED_KEY); - - public TlsSRPLoginParameters getLoginParameters(byte[] identity) - { - if (Arrays.areEqual(TEST_IDENTITY, identity)) - { - SRP6VerifierGenerator verifierGenerator = new SRP6VerifierGenerator(); - verifierGenerator.init(TEST_GROUP, TlsUtils.createHash(HashAlgorithm.sha1)); - - BigInteger verifier = verifierGenerator.generateVerifier(TEST_SALT, identity, TEST_PASSWORD); - - return new TlsSRPLoginParameters(TEST_GROUP, verifier, TEST_SALT); - } - - return unknownIdentityManager.getLoginParameters(identity); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockTlsClient.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockTlsClient.java deleted file mode 100644 index 26a6dd56d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockTlsClient.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Hashtable; - -import com.fr.third.org.bouncycastle.asn1.x509.Certificate; -import com.fr.third.org.bouncycastle.crypto.tls.AlertDescription; -import com.fr.third.org.bouncycastle.crypto.tls.AlertLevel; -import com.fr.third.org.bouncycastle.crypto.tls.CertificateRequest; -import com.fr.third.org.bouncycastle.crypto.tls.CipherSuite; -import com.fr.third.org.bouncycastle.crypto.tls.ClientCertificateType; -import com.fr.third.org.bouncycastle.crypto.tls.DefaultTlsClient; -import com.fr.third.org.bouncycastle.crypto.tls.MaxFragmentLength; -import com.fr.third.org.bouncycastle.crypto.tls.ProtocolVersion; -import com.fr.third.org.bouncycastle.crypto.tls.SignatureAlgorithm; -import com.fr.third.org.bouncycastle.crypto.tls.TlsAuthentication; -import com.fr.third.org.bouncycastle.crypto.tls.TlsCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsExtensionsUtils; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSession; -import com.fr.third.org.bouncycastle.util.Arrays; -import com.fr.third.org.bouncycastle.util.encoders.Hex; - -class MockTlsClient - extends DefaultTlsClient -{ - TlsSession session; - - MockTlsClient(TlsSession session) - { - this.session = session; - } - - public TlsSession getSessionToResume() - { - return this.session; - } - - public void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS client raised alert: " + AlertLevel.getText(alertLevel) - + ", " + AlertDescription.getText(alertDescription)); - if (message != null) - { - out.println("> " + message); - } - if (cause != null) - { - cause.printStackTrace(out); - } - } - - public void notifyAlertReceived(short alertLevel, short alertDescription) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS client received alert: " + AlertLevel.getText(alertLevel) - + ", " + AlertDescription.getText(alertDescription)); - } - -// public int[] getCipherSuites() -// { -// return Arrays.concatenate(super.getCipherSuites(), -// new int[] -// { -// CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, -// }); -// } - - public Hashtable getClientExtensions() throws IOException - { - Hashtable clientExtensions = TlsExtensionsUtils.ensureExtensionsInitialised(super.getClientExtensions()); - TlsExtensionsUtils.addEncryptThenMACExtension(clientExtensions); - { - /* - * NOTE: If you are copying test code, do not blindly set these extensions in your own client. - */ - TlsExtensionsUtils.addMaxFragmentLengthExtension(clientExtensions, MaxFragmentLength.pow2_9); - TlsExtensionsUtils.addPaddingExtension(clientExtensions, context.getSecureRandom().nextInt(16)); - TlsExtensionsUtils.addTruncatedHMacExtension(clientExtensions); - } - return clientExtensions; - } - - public void notifyServerVersion(ProtocolVersion serverVersion) throws IOException - { - super.notifyServerVersion(serverVersion); - - System.out.println("TLS client negotiated " + serverVersion); - } - - public TlsAuthentication getAuthentication() - throws IOException - { - return new TlsAuthentication() - { - public void notifyServerCertificate(com.fr.third.org.bouncycastle.crypto.tls.Certificate serverCertificate) - throws IOException - { - Certificate[] chain = serverCertificate.getCertificateList(); - System.out.println("TLS client received server certificate chain of length " + chain.length); - for (int i = 0; i != chain.length; i++) - { - Certificate entry = chain[i]; - // TODO Create fingerprint based on certificate signature algorithm digest - System.out.println(" fingerprint:SHA-256 " + TlsTestUtils.fingerprint(entry) + " (" - + entry.getSubject() + ")"); - } - } - - public TlsCredentials getClientCredentials(CertificateRequest certificateRequest) - throws IOException - { - short[] certificateTypes = certificateRequest.getCertificateTypes(); - if (certificateTypes == null || !Arrays.contains(certificateTypes, ClientCertificateType.rsa_sign)) - { - return null; - } - - return TlsTestUtils.loadSignerCredentials(context, certificateRequest.getSupportedSignatureAlgorithms(), - SignatureAlgorithm.rsa, "x509-client.pem", "x509-client-key.pem"); - } - }; - } - - public void notifyHandshakeComplete() throws IOException - { - super.notifyHandshakeComplete(); - - TlsSession newSession = context.getResumableSession(); - if (newSession != null) - { - byte[] newSessionID = newSession.getSessionID(); - String hex = Hex.toHexString(newSessionID); - - if (this.session != null && Arrays.areEqual(this.session.getSessionID(), newSessionID)) - { - System.out.println("Resumed session: " + hex); - } - else - { - System.out.println("Established session: " + hex); - } - - this.session = newSession; - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockTlsServer.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockTlsServer.java deleted file mode 100644 index c17855681..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/MockTlsServer.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.x509.Certificate; -import com.fr.third.org.bouncycastle.crypto.tls.AlertDescription; -import com.fr.third.org.bouncycastle.crypto.tls.AlertLevel; -import com.fr.third.org.bouncycastle.crypto.tls.CertificateRequest; -import com.fr.third.org.bouncycastle.crypto.tls.CipherSuite; -import com.fr.third.org.bouncycastle.crypto.tls.ClientCertificateType; -import com.fr.third.org.bouncycastle.crypto.tls.DefaultTlsServer; -import com.fr.third.org.bouncycastle.crypto.tls.ProtocolVersion; -import com.fr.third.org.bouncycastle.crypto.tls.SignatureAlgorithm; -import com.fr.third.org.bouncycastle.crypto.tls.TlsEncryptionCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSignerCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsUtils; -import com.fr.third.org.bouncycastle.util.Arrays; - -class MockTlsServer - extends DefaultTlsServer -{ - public void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS server raised alert: " + AlertLevel.getText(alertLevel) - + ", " + AlertDescription.getText(alertDescription)); - if (message != null) - { - out.println("> " + message); - } - if (cause != null) - { - cause.printStackTrace(out); - } - } - - public void notifyAlertReceived(short alertLevel, short alertDescription) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS server received alert: " + AlertLevel.getText(alertLevel) - + ", " + AlertDescription.getText(alertDescription)); - } - - protected int[] getCipherSuites() - { - return Arrays.concatenate(super.getCipherSuites(), - new int[] - { - CipherSuite.DRAFT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, - }); - } - - protected ProtocolVersion getMaximumVersion() - { - return ProtocolVersion.TLSv12; - } - - public ProtocolVersion getServerVersion() throws IOException - { - ProtocolVersion serverVersion = super.getServerVersion(); - - System.out.println("TLS server negotiated " + serverVersion); - - return serverVersion; - } - - public CertificateRequest getCertificateRequest() throws IOException - { - short[] certificateTypes = new short[]{ ClientCertificateType.rsa_sign, - ClientCertificateType.dss_sign, ClientCertificateType.ecdsa_sign }; - - Vector serverSigAlgs = null; - if (TlsUtils.isSignatureAlgorithmsExtensionAllowed(serverVersion)) - { - serverSigAlgs = TlsUtils.getDefaultSupportedSignatureAlgorithms(); - } - - Vector certificateAuthorities = new Vector(); - certificateAuthorities.addElement(TlsTestUtils.loadCertificateResource("x509-ca.pem").getSubject()); - - return new CertificateRequest(certificateTypes, serverSigAlgs, certificateAuthorities); - } - - public void notifyClientCertificate(com.fr.third.org.bouncycastle.crypto.tls.Certificate clientCertificate) - throws IOException - { - Certificate[] chain = clientCertificate.getCertificateList(); - System.out.println("TLS server received client certificate chain of length " + chain.length); - for (int i = 0; i != chain.length; i++) - { - Certificate entry = chain[i]; - // TODO Create fingerprint based on certificate signature algorithm digest - System.out.println(" fingerprint:SHA-256 " + TlsTestUtils.fingerprint(entry) + " (" - + entry.getSubject() + ")"); - } - } - - protected TlsEncryptionCredentials getRSAEncryptionCredentials() - throws IOException - { - return TlsTestUtils.loadEncryptionCredentials(context, new String[]{"x509-server.pem", "x509-ca.pem"}, - "x509-server-key.pem"); - } - - protected TlsSignerCredentials getRSASignerCredentials() throws IOException - { - return TlsTestUtils.loadSignerCredentials(context, supportedSignatureAlgorithms, SignatureAlgorithm.rsa, - "x509-server.pem", "x509-server-key.pem"); - } -} \ No newline at end of file diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/NetworkInputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/NetworkInputStream.java deleted file mode 100644 index b8186f2f3..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/NetworkInputStream.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * Tracks and enforces close() calls, without closing the underlying InputStream - */ -class NetworkInputStream extends FilterInputStream -{ - boolean closed = false; - - public NetworkInputStream(InputStream input) - { - super(input); - } - - synchronized boolean isClosed() - { - return closed; - } - - public int available() throws IOException - { - checkNotClosed(); - return in.available(); - } - - public synchronized void close() throws IOException - { - closed = true; - } - - public int read() throws IOException - { - checkNotClosed(); - return in.read(); - } - - public int read(byte[] b) throws IOException - { - checkNotClosed(); - return in.read(b); - } - - public int read(byte[] b, int off, int len) throws IOException - { - checkNotClosed(); - return in.read(b, off, len); - } - - protected synchronized void checkNotClosed() throws IOException - { - if (closed) - { - throw new IOException("NetworkInputStream closed"); - } - } -} \ No newline at end of file diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/NetworkOutputStream.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/NetworkOutputStream.java deleted file mode 100644 index a560d560e..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/NetworkOutputStream.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -/** - * Tracks and enforces close() calls, without closing the underlying OutputStream - */ -class NetworkOutputStream extends FilterOutputStream -{ - boolean closed = false; - - public NetworkOutputStream(OutputStream output) - { - super(output); - } - - synchronized boolean isClosed() - { - return closed; - } - - public synchronized void close() throws IOException - { - closed = true; - } - - public void write(int b) throws IOException - { - checkNotClosed(); - out.write(b); - } - - public void write(byte[] b) throws IOException - { - checkNotClosed(); - out.write(b); - } - - public void write(byte[] b, int off, int len) throws IOException - { - checkNotClosed(); - out.write(b, off, len); - } - - protected synchronized void checkNotClosed() throws IOException - { - if (closed) - { - throw new IOException("NetworkOutputStream closed"); - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/PSKTlsClientTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/PSKTlsClientTest.java deleted file mode 100644 index d104377df..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/PSKTlsClientTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.Socket; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.tls.BasicTlsPSKIdentity; -import com.fr.third.org.bouncycastle.crypto.tls.TlsClient; -import com.fr.third.org.bouncycastle.crypto.tls.TlsClientProtocol; -import com.fr.third.org.bouncycastle.util.Strings; - -/** - * A simple test designed to conduct a TLS handshake with an external TLS server. - *- * Please refer to GnuTLSSetup.html or OpenSSLSetup.html (under 'docs'), and x509-*.pem files in - * this package (under 'src/test/resources') for help configuring an external TLS server. - *
- * In both cases, extra options are required to enable PSK ciphersuites and configure identities/keys. - *
- */ -public class PSKTlsClientTest -{ - private static final SecureRandom secureRandom = new SecureRandom(); - - public static void main(String[] args) throws Exception - { - InetAddress address = InetAddress.getLocalHost(); - int port = 5556; - - long time1 = System.currentTimeMillis(); - - /* - * Note: This is the default PSK identity for 'openssl s_server' testing, the server must be - * started with "-psk 6161616161" to make the keys match, and possibly the "-psk_hint" - * option should be present. - */ -// String psk_identity = "Client_identity"; -// byte[] psk = new byte[]{ 0x61, 0x61, 0x61, 0x61, 0x61 }; - - // These correspond to the configuration of MockPSKTlsServer - String psk_identity = "client"; - byte[] psk = Strings.toUTF8ByteArray("TLS_TEST_PSK"); - - BasicTlsPSKIdentity pskIdentity = new BasicTlsPSKIdentity(psk_identity, psk); - - MockPSKTlsClient client = new MockPSKTlsClient(null, pskIdentity); - TlsClientProtocol protocol = openTlsConnection(address, port, client); - protocol.close(); - - long time2 = System.currentTimeMillis(); - System.out.println("Elapsed 1: " + (time2 - time1) + "ms"); - - client = new MockPSKTlsClient(client.getSessionToResume(), pskIdentity); - protocol = openTlsConnection(address, port, client); - - long time3 = System.currentTimeMillis(); - System.out.println("Elapsed 2: " + (time3 - time2) + "ms"); - - OutputStream output = protocol.getOutputStream(); - output.write("GET / HTTP/1.1\r\n\r\n".getBytes("UTF-8")); - output.flush(); - - InputStream input = protocol.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(input)); - - String line; - while ((line = reader.readLine()) != null) - { - System.out.println(">>> " + line); - } - - protocol.close(); - } - - static TlsClientProtocol openTlsConnection(InetAddress address, int port, TlsClient client) throws IOException - { - Socket s = new Socket(address, port); - TlsClientProtocol protocol = new TlsClientProtocol(s.getInputStream(), s.getOutputStream(), secureRandom); - protocol.connect(client); - return protocol; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/PSKTlsServerTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/PSKTlsServerTest.java deleted file mode 100644 index a29b57ff9..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/PSKTlsServerTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.tls.TlsServerProtocol; -import com.fr.third.org.bouncycastle.util.io.Streams; -import com.fr.third.org.bouncycastle.util.io.TeeOutputStream; - -/** - * A simple test designed to conduct a TLS handshake with an external TLS client. - *- * Please refer to GnuTLSSetup.html or OpenSSLSetup.html (under 'docs'), and x509-*.pem files in - * this package (under 'src/test/resources') for help configuring an external TLS client. - *
- */ -public class PSKTlsServerTest -{ - private static final SecureRandom secureRandom = new SecureRandom(); - - public static void main(String[] args) - throws Exception - { - InetAddress address = InetAddress.getLocalHost(); - int port = 5556; - - ServerSocket ss = new ServerSocket(port, 16, address); - try - { - while (true) - { - Socket s = ss.accept(); - System.out.println("--------------------------------------------------------------------------------"); - System.out.println("Accepted " + s); - ServerThread t = new ServerThread(s); - t.start(); - } - } - finally - { - ss.close(); - } - } - - static class ServerThread - extends Thread - { - private final Socket s; - - ServerThread(Socket s) - { - this.s = s; - } - - public void run() - { - try - { - MockPSKTlsServer server = new MockPSKTlsServer(); - TlsServerProtocol serverProtocol = new TlsServerProtocol(s.getInputStream(), s.getOutputStream(), secureRandom); - serverProtocol.accept(server); - OutputStream log = new TeeOutputStream(serverProtocol.getOutputStream(), System.out); - Streams.pipeAll(serverProtocol.getInputStream(), log); - serverProtocol.close(); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - finally - { - try - { - s.close(); - } - catch (IOException e) - { - } - finally - { - } - } - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsClientTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsClientTest.java deleted file mode 100644 index 81e0b098f..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsClientTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.Socket; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.tls.TlsClient; -import com.fr.third.org.bouncycastle.crypto.tls.TlsClientProtocol; - -/** - * A simple test designed to conduct a TLS handshake with an external TLS server. - *- * Please refer to GnuTLSSetup.html or OpenSSLSetup.html (under 'docs'), and x509-*.pem files in - * this package (under 'src/test/resources') for help configuring an external TLS server. - *
- */ -public class TlsClientTest -{ - private static final SecureRandom secureRandom = new SecureRandom(); - - public static void main(String[] args) - throws Exception - { - InetAddress address = InetAddress.getLocalHost(); - int port = 5556; - - long time1 = System.currentTimeMillis(); - - MockTlsClient client = new MockTlsClient(null); - TlsClientProtocol protocol = openTlsConnection(address, port, client); - protocol.close(); - - long time2 = System.currentTimeMillis(); - System.out.println("Elapsed 1: " + (time2 - time1) + "ms"); - - client = new MockTlsClient(client.getSessionToResume()); - protocol = openTlsConnection(address, port, client); - - long time3 = System.currentTimeMillis(); - System.out.println("Elapsed 2: " + (time3 - time2) + "ms"); - - OutputStream output = protocol.getOutputStream(); - output.write("GET / HTTP/1.1\r\n\r\n".getBytes("UTF-8")); - output.flush(); - - InputStream input = protocol.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(input)); - - String line; - while ((line = reader.readLine()) != null) - { - System.out.println(">>> " + line); - } - - protocol.close(); - } - - static TlsClientProtocol openTlsConnection(InetAddress address, int port, TlsClient client) throws IOException - { - Socket s = new Socket(address, port); - TlsClientProtocol protocol = new TlsClientProtocol(s.getInputStream(), s.getOutputStream(), secureRandom); - protocol.connect(client); - return protocol; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsServerTest.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsServerTest.java deleted file mode 100644 index 4a526eecc..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsServerTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.tls.TlsServerProtocol; -import com.fr.third.org.bouncycastle.util.io.Streams; -import com.fr.third.org.bouncycastle.util.io.TeeOutputStream; - -/** - * A simple test designed to conduct a TLS handshake with an external TLS client. - *- * Please refer to GnuTLSSetup.html or OpenSSLSetup.html (under 'docs'), and x509-*.pem files in - * this package (under 'src/test/resources') for help configuring an external TLS client. - *
- */ -public class TlsServerTest -{ - private static final SecureRandom secureRandom = new SecureRandom(); - - public static void main(String[] args) - throws Exception - { - InetAddress address = InetAddress.getLocalHost(); - int port = 5556; - - ServerSocket ss = new ServerSocket(port, 16, address); - try - { - while (true) - { - Socket s = ss.accept(); - System.out.println("--------------------------------------------------------------------------------"); - System.out.println("Accepted " + s); - ServerThread t = new ServerThread(s); - t.start(); - } - } - finally - { - ss.close(); - } - } - - static class ServerThread - extends Thread - { - private final Socket s; - - ServerThread(Socket s) - { - this.s = s; - } - - public void run() - { - try - { - MockTlsServer server = new MockTlsServer(); - TlsServerProtocol serverProtocol = new TlsServerProtocol(s.getInputStream(), s.getOutputStream(), secureRandom); - serverProtocol.accept(server); - OutputStream log = new TeeOutputStream(serverProtocol.getOutputStream(), System.out); - Streams.pipeAll(serverProtocol.getInputStream(), log); - serverProtocol.close(); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - finally - { - try - { - s.close(); - } - catch (IOException e) - { - } - finally - { - } - } - } - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestClientImpl.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestClientImpl.java deleted file mode 100644 index 3ea7c53a7..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestClientImpl.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Hashtable; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.ASN1EncodableVector; -import com.fr.third.org.bouncycastle.asn1.DERBitString; -import com.fr.third.org.bouncycastle.asn1.DERSequence; -import com.fr.third.org.bouncycastle.asn1.x509.Certificate; -import com.fr.third.org.bouncycastle.crypto.tls.AlertDescription; -import com.fr.third.org.bouncycastle.crypto.tls.AlertLevel; -import com.fr.third.org.bouncycastle.crypto.tls.CertificateRequest; -import com.fr.third.org.bouncycastle.crypto.tls.ClientCertificateType; -import com.fr.third.org.bouncycastle.crypto.tls.ConnectionEnd; -import com.fr.third.org.bouncycastle.crypto.tls.DefaultTlsClient; -import com.fr.third.org.bouncycastle.crypto.tls.ProtocolVersion; -import com.fr.third.org.bouncycastle.crypto.tls.SignatureAlgorithm; -import com.fr.third.org.bouncycastle.crypto.tls.SignatureAndHashAlgorithm; -import com.fr.third.org.bouncycastle.crypto.tls.TlsAuthentication; -import com.fr.third.org.bouncycastle.crypto.tls.TlsCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsFatalAlert; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSignerCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsUtils; -import com.fr.third.org.bouncycastle.util.Arrays; - -class TlsTestClientImpl - extends DefaultTlsClient -{ - protected final TlsTestConfig config; - - protected int firstFatalAlertConnectionEnd = -1; - protected short firstFatalAlertDescription = -1; - - TlsTestClientImpl(TlsTestConfig config) - { - this.config = config; - } - - int getFirstFatalAlertConnectionEnd() - { - return firstFatalAlertConnectionEnd; - } - - short getFirstFatalAlertDescription() - { - return firstFatalAlertDescription; - } - - public ProtocolVersion getClientVersion() - { - if (config.clientOfferVersion != null) - { - return config.clientOfferVersion; - } - - return super.getClientVersion(); - } - - public ProtocolVersion getMinimumVersion() - { - if (config.clientMinimumVersion != null) - { - return config.clientMinimumVersion; - } - - return super.getMinimumVersion(); - } - - public Hashtable getClientExtensions() throws IOException - { - Hashtable clientExtensions = super.getClientExtensions(); - if (clientExtensions != null && !config.clientSendSignatureAlgorithms) - { - clientExtensions.remove(TlsUtils.EXT_signature_algorithms); - this.supportedSignatureAlgorithms = null; - } - return clientExtensions; - } - - public boolean isFallback() - { - return config.clientFallback; - } - - public void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) - { - if (alertLevel == AlertLevel.fatal && firstFatalAlertConnectionEnd == -1) - { - firstFatalAlertConnectionEnd = ConnectionEnd.client; - firstFatalAlertDescription = alertDescription; - } - - if (TlsTestConfig.DEBUG) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS client raised alert: " + AlertLevel.getText(alertLevel) - + ", " + AlertDescription.getText(alertDescription)); - if (message != null) - { - out.println("> " + message); - } - if (cause != null) - { - cause.printStackTrace(out); - } - } - } - - public void notifyAlertReceived(short alertLevel, short alertDescription) - { - if (alertLevel == AlertLevel.fatal && firstFatalAlertConnectionEnd == -1) - { - firstFatalAlertConnectionEnd = ConnectionEnd.server; - firstFatalAlertDescription = alertDescription; - } - - if (TlsTestConfig.DEBUG) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS client received alert: " + AlertLevel.getText(alertLevel) - + ", " + AlertDescription.getText(alertDescription)); - } - } - - public void notifyServerVersion(ProtocolVersion serverVersion) throws IOException - { - super.notifyServerVersion(serverVersion); - - if (TlsTestConfig.DEBUG) - { - System.out.println("TLS client negotiated " + serverVersion); - } - } - - public TlsAuthentication getAuthentication() - throws IOException - { - return new TlsAuthentication() - { - public void notifyServerCertificate(com.fr.third.org.bouncycastle.crypto.tls.Certificate serverCertificate) - throws IOException - { - boolean isEmpty = serverCertificate == null || serverCertificate.isEmpty(); - - Certificate[] chain = serverCertificate.getCertificateList(); - - // TODO Cache test resources? - if (isEmpty || !(chain[0].equals(TlsTestUtils.loadCertificateResource("x509-server.pem")) - || chain[0].equals(TlsTestUtils.loadCertificateResource("x509-server-dsa.pem")) - || chain[0].equals(TlsTestUtils.loadCertificateResource("x509-server-ecdsa.pem")))) - { - throw new TlsFatalAlert(AlertDescription.bad_certificate); - } - - if (TlsTestConfig.DEBUG) - { - System.out.println("TLS client received server certificate chain of length " + chain.length); - for (int i = 0; i != chain.length; i++) - { - Certificate entry = chain[i]; - // TODO Create fingerprint based on certificate signature algorithm digest - System.out.println(" fingerprint:SHA-256 " + TlsTestUtils.fingerprint(entry) + " (" - + entry.getSubject() + ")"); - } - } - } - - public TlsCredentials getClientCredentials(CertificateRequest certificateRequest) - throws IOException - { - if (config.serverCertReq == TlsTestConfig.SERVER_CERT_REQ_NONE) - { - throw new IllegalStateException(); - } - if (config.clientAuth == TlsTestConfig.CLIENT_AUTH_NONE) - { - return null; - } - - short[] certificateTypes = certificateRequest.getCertificateTypes(); - if (certificateTypes == null || !Arrays.contains(certificateTypes, ClientCertificateType.rsa_sign)) - { - return null; - } - - Vector supportedSigAlgs = certificateRequest.getSupportedSignatureAlgorithms(); - if (supportedSigAlgs != null && config.clientAuthSigAlg != null) - { - supportedSigAlgs = new Vector(1); - supportedSigAlgs.addElement(config.clientAuthSigAlg); - } - - final TlsSignerCredentials signerCredentials = TlsTestUtils.loadSignerCredentials(context, - supportedSigAlgs, SignatureAlgorithm.rsa, "x509-client.pem", "x509-client-key.pem"); - - if (config.clientAuth == TlsTestConfig.CLIENT_AUTH_VALID) - { - return signerCredentials; - } - - return new TlsSignerCredentials() - { - public byte[] generateCertificateSignature(byte[] hash) throws IOException - { - byte[] sig = signerCredentials.generateCertificateSignature(hash); - - if (config.clientAuth == TlsTestConfig.CLIENT_AUTH_INVALID_VERIFY) - { - sig = corruptBit(sig); - } - - return sig; - } - - public com.fr.third.org.bouncycastle.crypto.tls.Certificate getCertificate() - { - com.fr.third.org.bouncycastle.crypto.tls.Certificate cert = signerCredentials.getCertificate(); - - if (config.clientAuth == TlsTestConfig.CLIENT_AUTH_INVALID_CERT) - { - cert = corruptCertificate(cert); - } - - return cert; - } - - public SignatureAndHashAlgorithm getSignatureAndHashAlgorithm() - { - return signerCredentials.getSignatureAndHashAlgorithm(); - } - }; - } - }; - } - - protected com.fr.third.org.bouncycastle.crypto.tls.Certificate corruptCertificate(com.fr.third.org.bouncycastle.crypto.tls.Certificate cert) - { - Certificate[] certList = cert.getCertificateList(); - certList[0] = corruptCertificateSignature(certList[0]); - return new com.fr.third.org.bouncycastle.crypto.tls.Certificate(certList); - } - - protected Certificate corruptCertificateSignature(Certificate cert) - { - ASN1EncodableVector v = new ASN1EncodableVector(); - v.add(cert.getTBSCertificate()); - v.add(cert.getSignatureAlgorithm()); - v.add(corruptSignature(cert.getSignature())); - - return Certificate.getInstance(new DERSequence(v)); - } - - protected DERBitString corruptSignature(DERBitString bs) - { - return new DERBitString(corruptBit(bs.getOctets())); - } - - protected byte[] corruptBit(byte[] bs) - { - bs = Arrays.clone(bs); - - // Flip a random bit - int bit = context.getSecureRandom().nextInt(bs.length << 3); - bs[bit >>> 3] ^= (1 << (bit & 7)); - - return bs; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestClientProtocol.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestClientProtocol.java deleted file mode 100644 index 64f1eac41..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestClientProtocol.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.tls.DigitallySigned; -import com.fr.third.org.bouncycastle.crypto.tls.TlsClientProtocol; - -class TlsTestClientProtocol extends TlsClientProtocol -{ - protected final TlsTestConfig config; - - public TlsTestClientProtocol(InputStream input, OutputStream output, SecureRandom secureRandom, TlsTestConfig config) - { - super(input, output, secureRandom); - - this.config = config; - } - - protected void sendCertificateVerifyMessage(DigitallySigned certificateVerify) throws IOException - { - if (certificateVerify.getAlgorithm() != null && config.clientAuthSigAlgClaimed != null) - { - certificateVerify = new DigitallySigned(config.clientAuthSigAlgClaimed, certificateVerify.getSignature()); - } - - super.sendCertificateVerifyMessage(certificateVerify); - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestConfig.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestConfig.java deleted file mode 100644 index d813fd709..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestConfig.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.util.Vector; - -import com.fr.third.org.bouncycastle.crypto.tls.ConnectionEnd; -import com.fr.third.org.bouncycastle.crypto.tls.ProtocolVersion; -import com.fr.third.org.bouncycastle.crypto.tls.SignatureAndHashAlgorithm; - -public class TlsTestConfig -{ - public static final boolean DEBUG = false; - - /** - * Client does not authenticate, ignores any certificate request - */ - public static final int CLIENT_AUTH_NONE = 0; - - /** - * Client will authenticate if it receives a certificate request - */ - public static final int CLIENT_AUTH_VALID = 1; - - /** - * Client will authenticate if it receives a certificate request, with an invalid certificate - */ - public static final int CLIENT_AUTH_INVALID_CERT = 2; - - /** - * Client will authenticate if it receives a certificate request, with an invalid CertificateVerify signature - */ - public static final int CLIENT_AUTH_INVALID_VERIFY = 3; - - /** - * Server will not request a client certificate - */ - public static final int SERVER_CERT_REQ_NONE = 0; - - /** - * Server will request a client certificate but receiving one is optional - */ - public static final int SERVER_CERT_REQ_OPTIONAL = 1; - - /** - * Server will request a client certificate and receiving one is mandatory - */ - public static final int SERVER_CERT_REQ_MANDATORY = 2; - - /** - * Configures the client authentication behaviour of the test client. Use CLIENT_AUTH_* constants. - */ - public int clientAuth = CLIENT_AUTH_VALID; - - /** - * If not null, and TLS 1.2 or higher is negotiated, selects a fixed signature/hash algorithm to - * be used for the CertificateVerify signature (if one is sent). - */ - public SignatureAndHashAlgorithm clientAuthSigAlg = null; - - /** - * If not null, and TLS 1.2 or higher is negotiated, selects a fixed signature/hash algorithm to - * be _claimed_ in the CertificateVerify (if one is sent), independently of what was actually used. - */ - public SignatureAndHashAlgorithm clientAuthSigAlgClaimed = null; - - /** - * Configures the minimum protocol version the client will accept. If null, uses the library's default. - */ - public ProtocolVersion clientMinimumVersion = null; - - /** - * Configures the protocol version the client will offer. If null, uses the library's default. - */ - public ProtocolVersion clientOfferVersion = null; - - /** - * Configures whether the client will indicate version fallback via TLS_FALLBACK_SCSV. - */ - public boolean clientFallback = false; - - /** - * Configures whether a (TLS 1.2+) client will send the signature_algorithms extension in ClientHello. - */ - public boolean clientSendSignatureAlgorithms = true; - - /** - * If not null, and TLS 1.2 or higher is negotiated, selects a fixed signature/hash algorithm to - * be used for the ServerKeyExchange signature (if one is sent). - */ - public SignatureAndHashAlgorithm serverAuthSigAlg = null; - - /** - * Configures whether the test server will send a certificate request. - */ - public int serverCertReq = SERVER_CERT_REQ_OPTIONAL; - - /** - * If TLS 1.2 or higher is negotiated, configures the set of supported signature algorithms in the - * CertificateRequest (if one is sent). If null, uses a default set. - */ - public Vector serverCertReqSigAlgs = null; - - /** - * Configures the maximum protocol version the server will accept. If null, uses the library's default. - */ - public ProtocolVersion serverMaximumVersion = null; - - /** - * Configures the minimum protocol version the server will accept. If null, uses the library's default. - */ - public ProtocolVersion serverMinimumVersion = null; - - /** - * Configures the connection end that a fatal alert is expected to be raised. Use ConnectionEnd.* constants. - */ - public int expectFatalAlertConnectionEnd = -1; - - /** - * Configures the type of fatal alert expected to be raised. Use AlertDescription.* constants. - */ - public short expectFatalAlertDescription = -1; - - public void expectClientFatalAlert(short alertDescription) - { - this.expectFatalAlertConnectionEnd = ConnectionEnd.client; - this.expectFatalAlertDescription = alertDescription; - } - - public void expectServerFatalAlert(short alertDescription) - { - this.expectFatalAlertConnectionEnd = ConnectionEnd.server; - this.expectFatalAlertDescription = alertDescription; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestServerImpl.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestServerImpl.java deleted file mode 100644 index 548b518ed..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestServerImpl.java +++ /dev/null @@ -1,214 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.PrintStream; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.x509.Certificate; -import com.fr.third.org.bouncycastle.crypto.tls.AlertDescription; -import com.fr.third.org.bouncycastle.crypto.tls.AlertLevel; -import com.fr.third.org.bouncycastle.crypto.tls.CertificateRequest; -import com.fr.third.org.bouncycastle.crypto.tls.ClientCertificateType; -import com.fr.third.org.bouncycastle.crypto.tls.ConnectionEnd; -import com.fr.third.org.bouncycastle.crypto.tls.DefaultTlsServer; -import com.fr.third.org.bouncycastle.crypto.tls.ProtocolVersion; -import com.fr.third.org.bouncycastle.crypto.tls.SignatureAlgorithm; -import com.fr.third.org.bouncycastle.crypto.tls.TlsEncryptionCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsFatalAlert; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSignerCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsUtils; - -class TlsTestServerImpl - extends DefaultTlsServer -{ - protected final TlsTestConfig config; - - protected int firstFatalAlertConnectionEnd = -1; - protected short firstFatalAlertDescription = -1; - - TlsTestServerImpl(TlsTestConfig config) - { - this.config = config; - } - - int getFirstFatalAlertConnectionEnd() - { - return firstFatalAlertConnectionEnd; - } - - short getFirstFatalAlertDescription() - { - return firstFatalAlertDescription; - } - - protected ProtocolVersion getMaximumVersion() - { - if (config.serverMaximumVersion != null) - { - return config.serverMaximumVersion; - } - - return super.getMaximumVersion(); - } - - protected ProtocolVersion getMinimumVersion() - { - if (config.serverMinimumVersion != null) - { - return config.serverMinimumVersion; - } - - return super.getMinimumVersion(); - } - - public void notifyAlertRaised(short alertLevel, short alertDescription, String message, Throwable cause) - { - if (alertLevel == AlertLevel.fatal && firstFatalAlertConnectionEnd == -1) - { - firstFatalAlertConnectionEnd = ConnectionEnd.server; - firstFatalAlertDescription = alertDescription; - } - - if (TlsTestConfig.DEBUG) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS server raised alert: " + AlertLevel.getText(alertLevel) - + ", " + AlertDescription.getText(alertDescription)); - if (message != null) - { - out.println("> " + message); - } - if (cause != null) - { - cause.printStackTrace(out); - } - } - } - - public void notifyAlertReceived(short alertLevel, short alertDescription) - { - if (alertLevel == AlertLevel.fatal && firstFatalAlertConnectionEnd == -1) - { - firstFatalAlertConnectionEnd = ConnectionEnd.client; - firstFatalAlertDescription = alertDescription; - } - - if (TlsTestConfig.DEBUG) - { - PrintStream out = (alertLevel == AlertLevel.fatal) ? System.err : System.out; - out.println("TLS server received alert: " + AlertLevel.getText(alertLevel) - + ", " + AlertDescription.getText(alertDescription)); - } - } - - public ProtocolVersion getServerVersion() throws IOException - { - ProtocolVersion serverVersion = super.getServerVersion(); - - if (TlsTestConfig.DEBUG) - { - System.out.println("TLS server negotiated " + serverVersion); - } - - return serverVersion; - } - - public CertificateRequest getCertificateRequest() throws IOException - { - if (config.serverCertReq == TlsTestConfig.SERVER_CERT_REQ_NONE) - { - return null; - } - - short[] certificateTypes = new short[]{ ClientCertificateType.rsa_sign, - ClientCertificateType.dss_sign, ClientCertificateType.ecdsa_sign }; - - Vector serverSigAlgs = null; - if (TlsUtils.isSignatureAlgorithmsExtensionAllowed(serverVersion)) - { - serverSigAlgs = config.serverCertReqSigAlgs; - if (serverSigAlgs == null) - { - serverSigAlgs = TlsUtils.getDefaultSupportedSignatureAlgorithms(); - } - } - - Vector certificateAuthorities = new Vector(); - certificateAuthorities.addElement(TlsTestUtils.loadCertificateResource("x509-ca.pem").getSubject()); - - return new CertificateRequest(certificateTypes, serverSigAlgs, certificateAuthorities); - } - - public void notifyClientCertificate(com.fr.third.org.bouncycastle.crypto.tls.Certificate clientCertificate) - throws IOException - { - boolean isEmpty = (clientCertificate == null || clientCertificate.isEmpty()); - - if (isEmpty != (config.clientAuth == TlsTestConfig.CLIENT_AUTH_NONE)) - { - throw new IllegalStateException(); - } - if (isEmpty && (config.serverCertReq == TlsTestConfig.SERVER_CERT_REQ_MANDATORY)) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - - Certificate[] chain = clientCertificate.getCertificateList(); - - // TODO Cache test resources? - if (!isEmpty && !(chain[0].equals(TlsTestUtils.loadCertificateResource("x509-client.pem")) - || chain[0].equals(TlsTestUtils.loadCertificateResource("x509-client-dsa.pem")) - || chain[0].equals(TlsTestUtils.loadCertificateResource("x509-client-ecdsa.pem")))) - { - throw new TlsFatalAlert(AlertDescription.bad_certificate); - } - - if (TlsTestConfig.DEBUG) - { - System.out.println("TLS server received client certificate chain of length " + chain.length); - for (int i = 0; i != chain.length; i++) - { - Certificate entry = chain[i]; - // TODO Create fingerprint based on certificate signature algorithm digest - System.out.println(" fingerprint:SHA-256 " + TlsTestUtils.fingerprint(entry) + " (" - + entry.getSubject() + ")"); - } - } - } - - protected Vector getSupportedSignatureAlgorithms() - { - if (TlsUtils.isTLSv12(context) && config.serverAuthSigAlg != null) - { - Vector signatureAlgorithms = new Vector(1); - signatureAlgorithms.addElement(config.serverAuthSigAlg); - return signatureAlgorithms; - } - - return supportedSignatureAlgorithms; - } - - protected TlsSignerCredentials getDSASignerCredentials() throws IOException - { - return TlsTestUtils.loadSignerCredentials(context, getSupportedSignatureAlgorithms(), SignatureAlgorithm.dsa, - "x509-server-dsa.pem", "x509-server-key-dsa.pem"); - } - - protected TlsSignerCredentials getECDSASignerCredentials() throws IOException - { - return TlsTestUtils.loadSignerCredentials(context, getSupportedSignatureAlgorithms(), SignatureAlgorithm.ecdsa, - "x509-server-ecdsa.pem", "x509-server-key-ecdsa.pem"); - } - - protected TlsEncryptionCredentials getRSAEncryptionCredentials() throws IOException - { - return TlsTestUtils.loadEncryptionCredentials(context, new String[]{ "x509-server.pem", "x509-ca.pem" }, - "x509-server-key.pem"); - } - - protected TlsSignerCredentials getRSASignerCredentials() throws IOException - { - return TlsTestUtils.loadSignerCredentials(context, getSupportedSignatureAlgorithms(), SignatureAlgorithm.rsa, - "x509-server.pem", "x509-server-key.pem"); - } -} \ No newline at end of file diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestServerProtocol.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestServerProtocol.java deleted file mode 100644 index 0844c310d..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestServerProtocol.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.InputStream; -import java.io.OutputStream; -import java.security.SecureRandom; - -import com.fr.third.org.bouncycastle.crypto.tls.TlsServerProtocol; - -class TlsTestServerProtocol extends TlsServerProtocol -{ - protected final TlsTestConfig config; - - public TlsTestServerProtocol(InputStream input, OutputStream output, SecureRandom secureRandom, TlsTestConfig config) - { - super(input, output, secureRandom); - - this.config = config; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestUtils.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestUtils.java deleted file mode 100644 index 2712f8bd6..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/TlsTestUtils.java +++ /dev/null @@ -1,191 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.Vector; - -import com.fr.third.org.bouncycastle.asn1.pkcs.RSAPrivateKey; -import com.fr.third.org.bouncycastle.crypto.digests.SHA256Digest; -import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import com.fr.third.org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters; -import com.fr.third.org.bouncycastle.crypto.tls.Certificate; -import com.fr.third.org.bouncycastle.crypto.tls.DefaultTlsAgreementCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.DefaultTlsEncryptionCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.DefaultTlsSignerCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.SignatureAndHashAlgorithm; -import com.fr.third.org.bouncycastle.crypto.tls.TlsAgreementCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsContext; -import com.fr.third.org.bouncycastle.crypto.tls.TlsEncryptionCredentials; -import com.fr.third.org.bouncycastle.crypto.tls.TlsSignerCredentials; -import com.fr.third.org.bouncycastle.crypto.util.PrivateKeyFactory; -import com.fr.third.org.bouncycastle.util.encoders.Base64; -import com.fr.third.org.bouncycastle.util.encoders.Hex; -import com.fr.third.org.bouncycastle.util.io.pem.PemObject; -import com.fr.third.org.bouncycastle.util.io.pem.PemReader; - -public class TlsTestUtils -{ - static final byte[] rsaCertData = Base64 - .decode("MIICUzCCAf2gAwIBAgIBATANBgkqhkiG9w0BAQQFADCBjzELMAkGA1UEBhMCQVUxKDAmBgNVBAoMH1RoZSBMZWdpb2" - + "4gb2YgdGhlIEJvdW5jeSBDYXN0bGUxEjAQBgNVBAcMCU1lbGJvdXJuZTERMA8GA1UECAwIVmljdG9yaWExLzAtBgkq" - + "hkiG9w0BCQEWIGZlZWRiYWNrLWNyeXB0b0Bib3VuY3ljYXN0bGUub3JnMB4XDTEzMDIyNTA2MDIwNVoXDTEzMDIyNT" - + "A2MDM0NVowgY8xCzAJBgNVBAYTAkFVMSgwJgYDVQQKDB9UaGUgTGVnaW9uIG9mIHRoZSBCb3VuY3kgQ2FzdGxlMRIw" - + "EAYDVQQHDAlNZWxib3VybmUxETAPBgNVBAgMCFZpY3RvcmlhMS8wLQYJKoZIhvcNAQkBFiBmZWVkYmFjay1jcnlwdG" - + "9AYm91bmN5Y2FzdGxlLm9yZzBaMA0GCSqGSIb3DQEBAQUAA0kAMEYCQQC0p+RhcFdPFqlwgrIr5YtqKmKXmEGb4Shy" - + "pL26Ymz66ZAPdqv7EhOdzl3lZWT6srZUMWWgQMYGiHQg4z2R7X7XAgERo0QwQjAOBgNVHQ8BAf8EBAMCBSAwEgYDVR" - + "0lAQH/BAgwBgYEVR0lADAcBgNVHREBAf8EEjAQgQ50ZXN0QHRlc3QudGVzdDANBgkqhkiG9w0BAQQFAANBAHU55Ncz" - + "eglREcTg54YLUlGWu2WOYWhit/iM1eeq8Kivro7q98eW52jTuMI3CI5ulqd0hYzshQKQaZ5GDzErMyM="); - - static final byte[] dudRsaCertData = Base64 - .decode("MIICUzCCAf2gAwIBAgIBATANBgkqhkiG9w0BAQQFADCBjzELMAkGA1UEBhMCQVUxKDAmBgNVBAoMH1RoZSBMZWdpb2" - + "4gb2YgdGhlIEJvdW5jeSBDYXN0bGUxEjAQBgNVBAcMCU1lbGJvdXJuZTERMA8GA1UECAwIVmljdG9yaWExLzAtBgkq" - + "hkiG9w0BCQEWIGZlZWRiYWNrLWNyeXB0b0Bib3VuY3ljYXN0bGUub3JnMB4XDTEzMDIyNTA1NDcyOFoXDTEzMDIyNT" - + "A1NDkwOFowgY8xCzAJBgNVBAYTAkFVMSgwJgYDVQQKDB9UaGUgTGVnaW9uIG9mIHRoZSBCb3VuY3kgQ2FzdGxlMRIw" - + "EAYDVQQHDAlNZWxib3VybmUxETAPBgNVBAgMCFZpY3RvcmlhMS8wLQYJKoZIhvcNAQkBFiBmZWVkYmFjay1jcnlwdG" - + "9AYm91bmN5Y2FzdGxlLm9yZzBaMA0GCSqGSIb3DQEBAQUAA0kAMEYCQQC0p+RhcFdPFqlwgrIr5YtqKmKXmEGb4Shy" - + "pL26Ymz66ZAPdqv7EhOdzl3lZWT6srZUMWWgQMYGiHQg4z2R7X7XAgERo0QwQjAOBgNVHQ8BAf8EBAMCAAEwEgYDVR" - + "0lAQH/BAgwBgYEVR0lADAcBgNVHREBAf8EEjAQgQ50ZXN0QHRlc3QudGVzdDANBgkqhkiG9w0BAQQFAANBAJg55PBS" - + "weg6obRUKF4FF6fCrWFi6oCYSQ99LWcAeupc5BofW5MstFMhCOaEucuGVqunwT5G7/DweazzCIrSzB0="); - - static String fingerprint(com.fr.third.org.bouncycastle.asn1.x509.Certificate c) - throws IOException - { - byte[] der = c.getEncoded(); - byte[] sha1 = sha256DigestOf(der); - byte[] hexBytes = Hex.encode(sha1); - String hex = new String(hexBytes, "ASCII").toUpperCase(); - - StringBuffer fp = new StringBuffer(); - int i = 0; - fp.append(hex.substring(i, i + 2)); - while ((i += 2) < hex.length()) - { - fp.append(':'); - fp.append(hex.substring(i, i + 2)); - } - return fp.toString(); - } - - static byte[] sha256DigestOf(byte[] input) - { - SHA256Digest d = new SHA256Digest(); - d.update(input, 0, input.length); - byte[] result = new byte[d.getDigestSize()]; - d.doFinal(result, 0); - return result; - } - - static TlsAgreementCredentials loadAgreementCredentials(TlsContext context, - String[] certResources, String keyResource) - throws IOException - { - Certificate certificate = loadCertificateChain(certResources); - AsymmetricKeyParameter privateKey = loadPrivateKeyResource(keyResource); - - return new DefaultTlsAgreementCredentials(certificate, privateKey); - } - - static TlsEncryptionCredentials loadEncryptionCredentials(TlsContext context, - String[] certResources, String keyResource) - throws IOException - { - Certificate certificate = loadCertificateChain(certResources); - AsymmetricKeyParameter privateKey = loadPrivateKeyResource(keyResource); - - return new DefaultTlsEncryptionCredentials(context, certificate, privateKey); - } - - static TlsSignerCredentials loadSignerCredentials(TlsContext context, String[] certResources, - String keyResource, SignatureAndHashAlgorithm signatureAndHashAlgorithm) - throws IOException - { - Certificate certificate = loadCertificateChain(certResources); - AsymmetricKeyParameter privateKey = loadPrivateKeyResource(keyResource); - - return new DefaultTlsSignerCredentials(context, certificate, privateKey, signatureAndHashAlgorithm); - } - - static TlsSignerCredentials loadSignerCredentials(TlsContext context, Vector supportedSignatureAlgorithms, - short signatureAlgorithm, String certResource, String keyResource) - throws IOException - { - /* - * TODO Note that this code fails to provide default value for the client supported - * algorithms if it wasn't sent. - */ - - SignatureAndHashAlgorithm signatureAndHashAlgorithm = null; - if (supportedSignatureAlgorithms != null) - { - for (int i = 0; i < supportedSignatureAlgorithms.size(); ++i) - { - SignatureAndHashAlgorithm alg = (SignatureAndHashAlgorithm) - supportedSignatureAlgorithms.elementAt(i); - if (alg.getSignature() == signatureAlgorithm) - { - signatureAndHashAlgorithm = alg; - break; - } - } - - if (signatureAndHashAlgorithm == null) - { - return null; - } - } - - return loadSignerCredentials(context, new String[]{ certResource, "x509-ca.pem" }, - keyResource, signatureAndHashAlgorithm); - } - - static Certificate loadCertificateChain(String[] resources) - throws IOException - { - com.fr.third.org.bouncycastle.asn1.x509.Certificate[] chain = new com.fr.third.org.bouncycastle.asn1.x509.Certificate[resources.length]; - for (int i = 0; i < resources.length; ++i) - { - chain[i] = loadCertificateResource(resources[i]); - } - return new Certificate(chain); - } - - static com.fr.third.org.bouncycastle.asn1.x509.Certificate loadCertificateResource(String resource) - throws IOException - { - PemObject pem = loadPemResource(resource); - if (pem.getType().endsWith("CERTIFICATE")) - { - return com.fr.third.org.bouncycastle.asn1.x509.Certificate.getInstance(pem.getContent()); - } - throw new IllegalArgumentException("'resource' doesn't specify a valid certificate"); - } - - static AsymmetricKeyParameter loadPrivateKeyResource(String resource) - throws IOException - { - PemObject pem = loadPemResource(resource); - if (pem.getType().endsWith("RSA PRIVATE KEY")) - { - RSAPrivateKey rsa = RSAPrivateKey.getInstance(pem.getContent()); - return new RSAPrivateCrtKeyParameters(rsa.getModulus(), rsa.getPublicExponent(), - rsa.getPrivateExponent(), rsa.getPrime1(), rsa.getPrime2(), rsa.getExponent1(), - rsa.getExponent2(), rsa.getCoefficient()); - } - if (pem.getType().endsWith("PRIVATE KEY")) - { - return PrivateKeyFactory.createKey(pem.getContent()); - } - throw new IllegalArgumentException("'resource' doesn't specify a valid private key"); - } - - static PemObject loadPemResource(String resource) - throws IOException - { - InputStream s = TlsTestUtils.class.getResourceAsStream(resource); - PemReader p = new PemReader(new InputStreamReader(s)); - PemObject o = p.readPemObject(); - p.close(); - return o; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/UnreliableDatagramTransport.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/UnreliableDatagramTransport.java deleted file mode 100644 index a7e1f2f1c..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/UnreliableDatagramTransport.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.fr.third.org.bouncycastle.crypto.tls.test; - -import java.io.IOException; -import java.util.Random; - -import com.fr.third.org.bouncycastle.crypto.tls.DatagramTransport; - -public class UnreliableDatagramTransport - implements DatagramTransport -{ - - private final DatagramTransport transport; - private final Random random; - private final int percentPacketLossReceiving, percentPacketLossSending; - - public UnreliableDatagramTransport(DatagramTransport transport, Random random, - int percentPacketLossReceiving, int percentPacketLossSending) - { - if (percentPacketLossReceiving < 0 || percentPacketLossReceiving > 100) - { - throw new IllegalArgumentException("'percentPacketLossReceiving' out of range"); - } - if (percentPacketLossSending < 0 || percentPacketLossSending > 100) - { - throw new IllegalArgumentException("'percentPacketLossSending' out of range"); - } - - this.transport = transport; - this.random = random; - this.percentPacketLossReceiving = percentPacketLossReceiving; - this.percentPacketLossSending = percentPacketLossSending; - } - - public int getReceiveLimit() - throws IOException - { - return transport.getReceiveLimit(); - } - - public int getSendLimit() - throws IOException - { - return transport.getSendLimit(); - } - - public int receive(byte[] buf, int off, int len, int waitMillis) - throws IOException - { - long endMillis = System.currentTimeMillis() + waitMillis; - for (; ; ) - { - int length = transport.receive(buf, off, len, waitMillis); - if (length < 0 || !lostPacket(percentPacketLossReceiving)) - { - return length; - } - - System.out.println("PACKET LOSS (" + length + " byte packet not received)"); - - long now = System.currentTimeMillis(); - if (now >= endMillis) - { - return -1; - } - - waitMillis = (int)(endMillis - now); - } - } - - public void send(byte[] buf, int off, int len) - throws IOException - { - if (lostPacket(percentPacketLossSending)) - { - System.out.println("PACKET LOSS (" + len + " byte packet not sent)"); - } - else - { - transport.send(buf, off, len); - } - } - - public void close() - throws IOException - { - transport.close(); - } - - private boolean lostPacket(int percentPacketLoss) - { - return percentPacketLoss > 0 && random.nextInt(100) < percentPacketLoss; - } -} diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/package.html b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/package.html deleted file mode 100644 index ec6dbbc86..000000000 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/tls/test/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -Example code and test classes for the lightweight TLS API. - - diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/OpenSSHPrivateKeyUtil.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/OpenSSHPrivateKeyUtil.java index 28e6f22e1..d4ecd1af1 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/OpenSSHPrivateKeyUtil.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/OpenSSHPrivateKeyUtil.java @@ -9,6 +9,7 @@ import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; import com.fr.third.org.bouncycastle.asn1.ASN1Sequence; import com.fr.third.org.bouncycastle.asn1.ASN1TaggedObject; import com.fr.third.org.bouncycastle.asn1.DERSequence; +import com.fr.third.org.bouncycastle.asn1.nist.NISTNamedCurves; import com.fr.third.org.bouncycastle.asn1.pkcs.PrivateKeyInfo; import com.fr.third.org.bouncycastle.asn1.pkcs.RSAPrivateKey; import com.fr.third.org.bouncycastle.asn1.sec.ECPrivateKey; @@ -156,7 +157,7 @@ public class OpenSSHPrivateKeyUtil { AsymmetricKeyParameter result = null; - if (blob[0] == 0x30) + if (blob[0] == 0x30) { ASN1Sequence sequence = ASN1Sequence.getInstance(blob); @@ -204,11 +205,7 @@ public class OpenSSHPrivateKeyUtil ecPrivateKey.getKey(), new ECNamedDomainParameters( curveOID, - x9Params.getCurve(), - x9Params.getG(), - x9Params.getN(), - x9Params.getH(), - x9Params.getSeed())); + x9Params)); } } } @@ -254,21 +251,43 @@ public class OpenSSHPrivateKeyUtil } String keyType = pkIn.readString(); - if (!"ssh-ed25519".equals(keyType)) + + if ("ssh-ed25519".equals(keyType)) { - throw new IllegalStateException("can not parse private key of type " + keyType); + // Public key + pkIn.readBlock(); + // Private key value.. + byte[] edPrivateKey = pkIn.readBlock(); + if (edPrivateKey.length != Ed25519PrivateKeyParameters.KEY_SIZE + Ed25519PublicKeyParameters.KEY_SIZE) + { + throw new IllegalStateException("private key value of wrong length"); + } + + result = new Ed25519PrivateKeyParameters(edPrivateKey, 0); } + else if (keyType.startsWith("ecdsa")) + { - // Skip public key - pkIn.skipBlock(); + ASN1ObjectIdentifier oid = SSHNamedCurves.getByName(Strings.fromByteArray(pkIn.readBlock())); + if (oid == null) + { + throw new IllegalStateException("OID not found for: " + keyType); + } - byte[] edPrivateKey = pkIn.readBlock(); - if (edPrivateKey.length != Ed25519PrivateKeyParameters.KEY_SIZE + Ed25519PublicKeyParameters.KEY_SIZE) - { - throw new IllegalStateException("private key value of wrong length"); + X9ECParameters curveParams = NISTNamedCurves.getByOID(oid); + if (curveParams == null) + { + throw new IllegalStateException("Curve not found for: " + oid); + } + + // Skip public key. + pkIn.readBlock(); + byte[] privKey = pkIn.readBlock(); + + result = new ECPrivateKeyParameters(new BigInteger(1, privKey), + new ECNamedDomainParameters(oid, curveParams)); } - result = new Ed25519PrivateKeyParameters(edPrivateKey, 0); // Comment for private key pkIn.skipBlock(); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/OpenSSHPublicKeyUtil.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/OpenSSHPublicKeyUtil.java index 9118f2f1b..27303bd4f 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/OpenSSHPublicKeyUtil.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/OpenSSHPublicKeyUtil.java @@ -3,17 +3,16 @@ package com.fr.third.org.bouncycastle.crypto.util; import java.io.IOException; import java.math.BigInteger; -import com.fr.third.org.bouncycastle.asn1.x9.ECNamedCurveTable; +import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; import com.fr.third.org.bouncycastle.crypto.params.AsymmetricKeyParameter; import com.fr.third.org.bouncycastle.crypto.params.DSAParameters; import com.fr.third.org.bouncycastle.crypto.params.DSAPublicKeyParameters; -import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; +import com.fr.third.org.bouncycastle.crypto.params.ECNamedDomainParameters; import com.fr.third.org.bouncycastle.crypto.params.ECPublicKeyParameters; import com.fr.third.org.bouncycastle.crypto.params.Ed25519PublicKeyParameters; import com.fr.third.org.bouncycastle.crypto.params.RSAKeyParameters; import com.fr.third.org.bouncycastle.math.ec.ECCurve; -import com.fr.third.org.bouncycastle.math.ec.custom.sec.SecP256R1Curve; /** @@ -81,12 +80,14 @@ public class OpenSSHPublicKeyUtil { SSHBuilder builder = new SSHBuilder(); - String name = null; - if (((ECPublicKeyParameters)cipherParameters).getParameters().getCurve() instanceof SecP256R1Curve) - { - name = "nistp256"; - } - else + // + // checked for named curve parameters.. + // + + + String name = SSHNamedCurves.getNameForParameters(((ECPublicKeyParameters)cipherParameters).getParameters()); + + if (name == null) { throw new IllegalArgumentException("unable to derive ssh curve name for " + ((ECPublicKeyParameters)cipherParameters).getParameters().getCurve().getClass().getName()); } @@ -149,35 +150,22 @@ public class OpenSSHPublicKeyUtil else if (magic.startsWith(ECDSA)) { String curveName = buffer.readString(); - String nameToFind = curveName; - if (curveName.startsWith("nist")) - { - // - // NIST names like P-256 are encoded in SSH as nistp256 - // - - nameToFind = curveName.substring(4); - nameToFind = nameToFind.substring(0, 1) + "-" + nameToFind.substring(1); - } - - X9ECParameters x9ECParameters = ECNamedCurveTable.getByName(nameToFind); + ASN1ObjectIdentifier oid = SSHNamedCurves.getByName(curveName); + X9ECParameters x9ECParameters = SSHNamedCurves.getParameters(oid); if (x9ECParameters == null) { - throw new IllegalStateException("unable to find curve for " + magic + " using curve name " + nameToFind); + throw new IllegalStateException("unable to find curve for " + magic + " using curve name " + curveName); } - // - // Extract name of digest from magic string value; - // - //String digest = magic.split("-")[1]; - ECCurve curve = x9ECParameters.getCurve(); byte[] pointRaw = buffer.readBlock(); - result = new ECPublicKeyParameters(curve.decodePoint(pointRaw), new ECDomainParameters(curve, x9ECParameters.getG(), x9ECParameters.getN(), x9ECParameters.getH(), x9ECParameters.getSeed())); + result = new ECPublicKeyParameters( + curve.decodePoint(pointRaw), + new ECNamedDomainParameters(oid, x9ECParameters)); } else if (ED_25519.equals(magic)) { diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/PrivateKeyFactory.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/PrivateKeyFactory.java index fa31ec720..bb8e57dd6 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/PrivateKeyFactory.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/PrivateKeyFactory.java @@ -156,8 +156,7 @@ public class PrivateKeyFactory { x9 = ECNamedCurveTable.getByOID(oid); } - dParams = new ECNamedDomainParameters( - oid, x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed()); + dParams = new ECNamedDomainParameters(oid, x9); } else { @@ -199,7 +198,7 @@ public class PrivateKeyFactory if (p instanceof ASN1Sequence && (ASN1Sequence.getInstance(p).size() == 2 || ASN1Sequence.getInstance(p).size() == 3)) { - ECDomainParameters ecP = ECGOST3410NamedCurves.getByOID(gostParams.getPublicKeyParamSet()); + X9ECParameters ecP = ECGOST3410NamedCurves.getByOIDX9(gostParams.getPublicKeyParamSet()); ecSpec = new ECGOST3410Parameters( new ECNamedDomainParameters( @@ -207,15 +206,24 @@ public class PrivateKeyFactory gostParams.getPublicKeyParamSet(), gostParams.getDigestParamSet(), gostParams.getEncryptionParamSet()); - ASN1Encodable privKey = keyInfo.parsePrivateKey(); - if (privKey instanceof ASN1Integer) + ASN1OctetString privEnc = keyInfo.getPrivateKey(); + + if (privEnc.getOctets().length == 32 || privEnc.getOctets().length == 64) { - d = ASN1Integer.getInstance(privKey).getPositiveValue(); + d = new BigInteger(1, Arrays.reverse(privEnc.getOctets())); } else { - byte[] dVal = Arrays.reverse(ASN1OctetString.getInstance(privKey).getOctets()); - d = new BigInteger(1, dVal); + ASN1Encodable privKey = keyInfo.parsePrivateKey(); + if (privKey instanceof ASN1Integer) + { + d = ASN1Integer.getInstance(privKey).getPositiveValue(); + } + else + { + byte[] dVal = Arrays.reverse(ASN1OctetString.getInstance(privKey).getOctets()); + d = new BigInteger(1, dVal); + } } } else @@ -226,27 +234,10 @@ public class PrivateKeyFactory { ASN1ObjectIdentifier oid = ASN1ObjectIdentifier.getInstance(params.getParameters()); X9ECParameters ecP = ECNamedCurveTable.getByOID(oid); - if (ecP == null) - { - ECDomainParameters gParam = ECGOST3410NamedCurves.getByOID(oid); - ecSpec = new ECGOST3410Parameters(new ECNamedDomainParameters( - oid, - gParam.getCurve(), - gParam.getG(), - gParam.getN(), - gParam.getH(), - gParam.getSeed()), gostParams.getPublicKeyParamSet(), gostParams.getDigestParamSet(), gostParams.getEncryptionParamSet()); - } - else - { - ecSpec = new ECGOST3410Parameters(new ECNamedDomainParameters( - oid, - ecP.getCurve(), - ecP.getG(), - ecP.getN(), - ecP.getH(), - ecP.getSeed()), gostParams.getPublicKeyParamSet(), gostParams.getDigestParamSet(), gostParams.getEncryptionParamSet()); - } + + ecSpec = new ECGOST3410Parameters(new ECNamedDomainParameters(oid, ecP), + gostParams.getPublicKeyParamSet(), gostParams.getDigestParamSet(), + gostParams.getEncryptionParamSet()); } else if (params.isImplicitlyCA()) { @@ -255,13 +246,9 @@ public class PrivateKeyFactory else { X9ECParameters ecP = X9ECParameters.getInstance(params.getParameters()); - ecSpec = new ECGOST3410Parameters(new ECNamedDomainParameters( - algOID, - ecP.getCurve(), - ecP.getG(), - ecP.getN(), - ecP.getH(), - ecP.getSeed()), gostParams.getPublicKeyParamSet(), gostParams.getDigestParamSet(), gostParams.getEncryptionParamSet()); + ecSpec = new ECGOST3410Parameters(new ECNamedDomainParameters(algOID, ecP), + gostParams.getPublicKeyParamSet(), gostParams.getDigestParamSet(), + gostParams.getEncryptionParamSet()); } ASN1Encodable privKey = keyInfo.parsePrivateKey(); @@ -273,7 +260,7 @@ public class PrivateKeyFactory } else { - com.fr.third.org.bouncycastle.asn1.sec.ECPrivateKey ec = com.fr.third.org.bouncycastle.asn1.sec.ECPrivateKey.getInstance(privKey); + ECPrivateKey ec = ECPrivateKey.getInstance(privKey); d = ec.getKey(); } diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/PublicKeyFactory.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/PublicKeyFactory.java index 60c644ebb..b43989379 100644 --- a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/PublicKeyFactory.java +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/PublicKeyFactory.java @@ -280,8 +280,7 @@ public class PublicKeyFactory { x9 = ECNamedCurveTable.getByOID(oid); } - dParams = new ECNamedDomainParameters( - oid, x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed()); + dParams = new ECNamedDomainParameters(oid, x9); } else if (params.isImplicitlyCA()) { @@ -290,8 +289,7 @@ public class PublicKeyFactory else { X9ECParameters x9 = X9ECParameters.getInstance(params.getParameters()); - dParams = new ECDomainParameters( - x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed()); + dParams = new ECDomainParameters(x9); } DERBitString bits = keyInfo.getPublicKeyData(); @@ -336,7 +334,7 @@ public class PublicKeyFactory ASN1ObjectIdentifier publicKeyParamSet = gostParams.getPublicKeyParamSet(); ECGOST3410Parameters ecDomainParameters = new ECGOST3410Parameters( - new ECNamedDomainParameters(publicKeyParamSet, ECGOST3410NamedCurves.getByOID(publicKeyParamSet)), + new ECNamedDomainParameters(publicKeyParamSet, ECGOST3410NamedCurves.getByOIDX9(publicKeyParamSet)), publicKeyParamSet, gostParams.getDigestParamSet(), gostParams.getEncryptionParamSet()); @@ -385,7 +383,7 @@ public class PublicKeyFactory ASN1ObjectIdentifier publicKeyParamSet = gostParams.getPublicKeyParamSet(); ECGOST3410Parameters ecDomainParameters = new ECGOST3410Parameters( - new ECNamedDomainParameters(publicKeyParamSet, ECGOST3410NamedCurves.getByOID(publicKeyParamSet)), + new ECNamedDomainParameters(publicKeyParamSet, ECGOST3410NamedCurves.getByOIDX9(publicKeyParamSet)), publicKeyParamSet, gostParams.getDigestParamSet(), gostParams.getEncryptionParamSet()); diff --git a/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/SSHNamedCurves.java b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/SSHNamedCurves.java new file mode 100644 index 000000000..dc30b93af --- /dev/null +++ b/fine-bouncycastle/src/main/java/com/fr/third/org/bouncycastle/crypto/util/SSHNamedCurves.java @@ -0,0 +1,130 @@ +package com.fr.third.org.bouncycastle.crypto.util; + +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; +import com.fr.third.org.bouncycastle.asn1.nist.NISTNamedCurves; +import com.fr.third.org.bouncycastle.asn1.sec.SECObjectIdentifiers; +import com.fr.third.org.bouncycastle.asn1.x9.X9ECParameters; +import com.fr.third.org.bouncycastle.crypto.ec.CustomNamedCurves; +import com.fr.third.org.bouncycastle.crypto.params.ECDomainParameters; +import com.fr.third.org.bouncycastle.crypto.params.ECNamedDomainParameters; +import com.fr.third.org.bouncycastle.math.ec.ECCurve; +import com.fr.third.org.bouncycastle.util.Strings; + +public class SSHNamedCurves +{ + private static final MapoidToName; + private static final Map oidMap = + Collections.unmodifiableMap(new HashMap () + { + { + put("nistp256", SECObjectIdentifiers.secp256r1); + put("nistp384", SECObjectIdentifiers.secp384r1); + put("nistp521", SECObjectIdentifiers.secp521r1); + put("nistk163", SECObjectIdentifiers.sect163k1); + put("nistp192", SECObjectIdentifiers.secp192r1); + put("nistp224", SECObjectIdentifiers.secp224r1); + put("nistk233", SECObjectIdentifiers.sect233k1); + put("nistb233", SECObjectIdentifiers.sect233r1); + put("nistk283", SECObjectIdentifiers.sect283k1); + put("nistk409", SECObjectIdentifiers.sect409k1); + put("nistb409", SECObjectIdentifiers.sect409r1); + put("nistt571", SECObjectIdentifiers.sect571k1); + } + }); + + private static final Map curveNameToSSHName = Collections.unmodifiableMap(new HashMap () + { + { + String[][] curves = { + {"secp256r1", "nistp256"}, + {"secp384r1", "nistp384"}, + {"secp521r1", "nistp521"}, + {"sect163k1", "nistk163"}, + {"secp192r1", "nistp192"}, + {"secp224r1", "nistp224"}, + {"sect233k1", "nistk233"}, + {"sect233r1", "nistb233"}, + {"sect283k1", "nistk283"}, + {"sect409k1", "nistk409"}, + {"sect409r1", "nistb409"}, + {"sect571k1", "nistt571"} + }; + for (int i = 0; i != curves.length; i++) + { + String[] item = curves[i]; + put(item[0], item[1]); + } + } + }); + private static HashMap curveMap = new HashMap () + { + { + Enumeration Note: if you're trying to be ultra orthodox, don't use this! It shouldn't be in here. */ - public static final DERObjectIdentifier EmailAddress = new DERObjectIdentifier("1.2.840.113549.1.9.1"); + public static final ASN1ObjectIdentifier EmailAddress = new ASN1ObjectIdentifier("1.2.840.113549.1.9.1"); /** * email address in Verisign certificates */ - public static final DERObjectIdentifier E = EmailAddress; + public static final ASN1ObjectIdentifier E = EmailAddress; - /** object identifier */ - public static final DERObjectIdentifier DC = new DERObjectIdentifier("0.9.2342.19200300.100.1.25"); + /** + * object identifier + */ + public static final ASN1ObjectIdentifier DC = new ASN1ObjectIdentifier("0.9.2342.19200300.100.1.25"); - /** LDAP User id. */ - public static final DERObjectIdentifier UID = new DERObjectIdentifier("0.9.2342.19200300.100.1.1"); + /** + * LDAP User id. + */ + public static final ASN1ObjectIdentifier UID = new ASN1ObjectIdentifier("0.9.2342.19200300.100.1.1"); - /** A HashMap with default symbols */ + /** + * A HashMap with default symbols + */ public static HashMap DefaultSymbols = new HashMap(); - + static { DefaultSymbols.put(C, "C"); DefaultSymbols.put(O, "O"); @@ -1552,83 +1580,91 @@ public class PdfPKCS7 { DefaultSymbols.put(INITIALS, "INITIALS"); DefaultSymbols.put(GENERATION, "GENERATION"); } - /** A HashMap with values */ + + /** + * A HashMap with values + */ public HashMap values = new HashMap(); /** * Constructs an X509 name + * * @param seq an ASN1 Sequence */ public X509Name(ASN1Sequence seq) { Enumeration e = seq.getObjects(); - + while (e.hasMoreElements()) { - ASN1Set set = (ASN1Set)e.nextElement(); - + ASN1Set set = (ASN1Set) e.nextElement(); + for (int i = 0; i < set.size(); i++) { - ASN1Sequence s = (ASN1Sequence)set.getObjectAt(i); - String id = (String)DefaultSymbols.get(s.getObjectAt(0)); + ASN1Sequence s = (ASN1Sequence) set.getObjectAt(i); + String id = (String) DefaultSymbols.get(s.getObjectAt(0)); if (id == null) continue; - ArrayList vs = (ArrayList)values.get(id); + ArrayList vs = (ArrayList) values.get(id); if (vs == null) { vs = new ArrayList(); values.put(id, vs); } - vs.add(((ASN1String)s.getObjectAt(1)).getString()); + vs.add(((ASN1String) s.getObjectAt(1)).getString()); } } } + /** * Constructs an X509 name + * * @param dirName a directory name */ public X509Name(String dirName) { - X509NameTokenizer nTok = new X509NameTokenizer(dirName); - + X509NameTokenizer nTok = new X509NameTokenizer(dirName); + while (nTok.hasMoreTokens()) { - String token = nTok.nextToken(); + String token = nTok.nextToken(); int index = token.indexOf('='); - + if (index == -1) { throw new IllegalArgumentException("badly formated directory string"); } - + String id = token.substring(0, index).toUpperCase(); String value = token.substring(index + 1); - ArrayList vs = (ArrayList)values.get(id); + ArrayList vs = (ArrayList) values.get(id); if (vs == null) { vs = new ArrayList(); values.put(id, vs); } vs.add(value); } - + } - + public String getField(String name) { - ArrayList vs = (ArrayList)values.get(name); - return vs == null ? null : (String)vs.get(0); + ArrayList vs = (ArrayList) values.get(name); + return vs == null ? null : (String) vs.get(0); } /** * gets a field array from the values Hashmap + * * @param name * @return an ArrayList */ public ArrayList getFieldArray(String name) { - ArrayList vs = (ArrayList)values.get(name); + ArrayList vs = (ArrayList) values.get(name); return vs == null ? null : vs; } - + /** * getter for values + * * @return a HashMap with the fields of the X509 name */ public HashMap getFields() { return values; } - + /** * @see java.lang.Object#toString() */ @@ -1636,7 +1672,7 @@ public class PdfPKCS7 { return values.toString(); } } - + /** * class for breaking up an X500 Name into it's component tokens, ala * java.util.StringTokenizer. We need this class as some of the @@ -1644,61 +1680,56 @@ public class PdfPKCS7 { * StringTokenizer. */ public static class X509NameTokenizer { - private String oid; - private int index; - private StringBuffer buf = new StringBuffer(); - + private String oid; + private int index; + private StringBuffer buf = new StringBuffer(); + public X509NameTokenizer( - String oid) { + String oid) { this.oid = oid; this.index = -1; } - + public boolean hasMoreTokens() { return (index != oid.length()); } - + public String nextToken() { if (index == oid.length()) { return null; } - - int end = index + 1; + + int end = index + 1; boolean quoted = false; boolean escaped = false; - + buf.setLength(0); - + while (end != oid.length()) { - char c = oid.charAt(end); - + char c = oid.charAt(end); + if (c == '"') { if (!escaped) { quoted = !quoted; - } - else { + } else { buf.append(c); } escaped = false; - } - else { + } else { if (escaped || quoted) { buf.append(c); escaped = false; - } - else if (c == '\\') { + } else if (c == '\\') { escaped = true; - } - else if (c == ',') { + } else if (c == ',') { break; - } - else { + } else { buf.append(c); } } end++; } - + index = end; return buf.toString().trim(); } diff --git a/fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/pdf/PdfPublicKeySecurityHandler.java b/fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/pdf/PdfPublicKeySecurityHandler.java index 1bd9ee366..6c483824e 100644 --- a/fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/pdf/PdfPublicKeySecurityHandler.java +++ b/fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/pdf/PdfPublicKeySecurityHandler.java @@ -48,12 +48,40 @@ */ /** - * The below 2 methods are from pdfbox. - * - * private DERObject createDERForRecipient(byte[] in, X509Certificate cert) ; - * private KeyTransRecipientInfo computeRecipientInfo(X509Certificate x509certificate, byte[] abyte0); - * - * 2006-11-22 Aiken Sam. + * The below 2 methods are from pdfbox. + *
+ * private DERObject createDERForRecipient(byte[] in, X509Certificate cert) ; + * private KeyTransRecipientInfo computeRecipientInfo(X509Certificate x509certificate, byte[] abyte0); + *
+ * 2006-11-22 Aiken Sam. + *
+ * Copyright (c) 2003-2006, www.pdfbox.org + * All rights reserved. + *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + *
+ * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *
+ * http://www.pdfbox.org */ /** @@ -90,7 +118,9 @@ package com.fr.third.com.lowagie.text.pdf; import com.fr.third.org.bouncycastle.asn1.ASN1Object; +import com.fr.third.org.bouncycastle.asn1.ASN1OutputStream; import com.fr.third.org.bouncycastle.asn1.ASN1Set; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -110,9 +140,8 @@ import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.DERObjectIdentifier; +import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.DEROutputStream; import com.fr.third.org.bouncycastle.asn1.DERSet; import com.fr.third.org.bouncycastle.asn1.cms.ContentInfo; import com.fr.third.org.bouncycastle.asn1.cms.EncryptedContentInfo; @@ -129,11 +158,11 @@ import com.fr.third.org.bouncycastle.asn1.x509.TBSCertificateStructure; * @author Aiken Sam (aikensam@ieee.org) */ public class PdfPublicKeySecurityHandler { - + static final int SEED_LENGTH = 20; - + private ArrayList recipients = null; - + private byte[] seed = new byte[SEED_LENGTH]; public PdfPublicKeySecurityHandler() { @@ -141,56 +170,57 @@ public class PdfPublicKeySecurityHandler { try { key = KeyGenerator.getInstance("AES"); key.init(192, new SecureRandom()); - SecretKey sk = key.generateKey(); + SecretKey sk = key.generateKey(); System.arraycopy(sk.getEncoded(), 0, seed, 0, SEED_LENGTH); // create the 20 bytes seed } catch (NoSuchAlgorithmException e) { - seed = SecureRandom.getSeed(SEED_LENGTH); + seed = SecureRandom.getSeed(SEED_LENGTH); } - + recipients = new ArrayList(); } - /* + /* * Routine for decode output of PdfContentByte.escapeString(byte[] bytes). - * It should be moved to PdfContentByte. + * It should be moved to PdfContentByte. */ - + static public byte[] unescapedString(byte[] bytes) throws BadPdfFormatException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - + int index = 0; - - if (bytes[0] != '(' && bytes[bytes.length-1] != ')') throw new BadPdfFormatException("Expect '(' and ')' at begin and end of the string."); - + + if (bytes[0] != '(' && bytes[bytes.length - 1] != ')') + throw new BadPdfFormatException("Expect '(' and ')' at begin and end of the string."); + while (index < bytes.length) { if (bytes[index] == '\\') { index++; switch (bytes[index]) { - case 'b': - baos.write('\b'); - break; - case 'f': - baos.write('\f'); - break; - case 't': - baos.write('\t'); - break; - case 'n': - baos.write('\n'); - break; - case 'r': - baos.write('\r'); - break; - case '(': + case 'b': + baos.write('\b'); + break; + case 'f': + baos.write('\f'); + break; + case 't': + baos.write('\t'); + break; + case 'n': + baos.write('\n'); + break; + case 'r': + baos.write('\r'); + break; + case '(': baos.write('('); break; - case ')': + case ')': baos.write(')'); - break; - case '\\': - baos.write('\\'); - break; + break; + case '\\': + baos.write('\\'); + break; } } else baos.write(bytes[index]); @@ -198,92 +228,91 @@ public class PdfPublicKeySecurityHandler { } return baos.toByteArray(); } - + public void addRecipient(PdfPublicKeyRecipient recipient) { recipients.add(recipient); } - + protected byte[] getSeed() { - return (byte[])seed.clone(); + return (byte[]) seed.clone(); } /* public PdfPublicKeyRecipient[] getRecipients() { recipients.toArray(); return (PdfPublicKeyRecipient[])recipients.toArray(); }*/ - + public int getRecipientsSize() { return recipients.size(); } - + public byte[] getEncodedRecipient(int index) throws IOException, GeneralSecurityException { //Certificate certificate = recipient.getX509(); - PdfPublicKeyRecipient recipient = (PdfPublicKeyRecipient)recipients.get(index); + PdfPublicKeyRecipient recipient = (PdfPublicKeyRecipient) recipients.get(index); byte[] cms = recipient.getCms(); - + if (cms != null) return cms; - - Certificate certificate = recipient.getCertificate(); - int permission = recipient.getPermission();//PdfWriter.AllowCopy | PdfWriter.AllowPrinting | PdfWriter.AllowScreenReaders | PdfWriter.AllowAssembly; + + Certificate certificate = recipient.getCertificate(); + int permission = recipient.getPermission();//PdfWriter.AllowCopy | PdfWriter.AllowPrinting | PdfWriter.AllowScreenReaders | PdfWriter.AllowAssembly; int revision = 3; - - permission |= revision==3 ? 0xfffff0c0 : 0xffffffc0; + + permission |= revision == 3 ? 0xfffff0c0 : 0xffffffc0; permission &= 0xfffffffc; permission += 1; - + byte[] pkcs7input = new byte[24]; - - byte one = (byte)(permission); - byte two = (byte)(permission >> 8); - byte three = (byte)(permission >> 16); - byte four = (byte)(permission >> 24); + + byte one = (byte) (permission); + byte two = (byte) (permission >> 8); + byte three = (byte) (permission >> 16); + byte four = (byte) (permission >> 24); System.arraycopy(seed, 0, pkcs7input, 0, 20); // put this seed in the pkcs7 input - + pkcs7input[20] = four; - pkcs7input[21] = three; + pkcs7input[21] = three; pkcs7input[22] = two; pkcs7input[23] = one; - - ASN1Object obj = createDERForRecipient(pkcs7input, (X509Certificate)certificate); - + + ASN1Object obj = createDERForRecipient(pkcs7input, (X509Certificate) certificate); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - DEROutputStream k = new DEROutputStream(baos); - - k.writeObject(obj); - + + ASN1OutputStream k = ASN1OutputStream.create(baos); + + k.writeObject(obj); + cms = baos.toByteArray(); recipient.setCms(cms); - - return cms; + + return cms; } - - public PdfArray getEncodedRecipients() throws IOException, - GeneralSecurityException { + + public PdfArray getEncodedRecipients() throws IOException, + GeneralSecurityException { PdfArray EncodedRecipients = new PdfArray(); byte[] cms = null; - for (int i=0; i
null for the default provider - */ + * @param certsKey the /Cert key + * @param provider the provider or null
for the default provider + */ public PdfPKCS7(byte[] contentsKey, byte[] certsKey, String provider) { try { this.provider = provider; @@ -304,73 +302,72 @@ public class PdfPKCS7 { cr.engineInit(new ByteArrayInputStream(certsKey)); certs = cr.engineReadAll(); signCerts = certs; - signCert = (X509Certificate)certs.iterator().next(); + signCert = (X509Certificate) certs.iterator().next(); crls = new ArrayList(); ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(contentsKey)); - digest = ((DEROctetString)in.readObject()).getOctets(); + digest = ((DEROctetString) in.readObject()).getOctets(); if (provider == null) sig = Signature.getInstance("SHA1withRSA"); else sig = Signature.getInstance("SHA1withRSA", provider); sig.initVerify(signCert.getPublicKey()); - } - catch (Exception e) { + } catch (Exception e) { throw new ExceptionConverter(e); } } - + // private BasicOCSPResp basicResp; - + /** * Gets the OCSP basic response if there is one. + * * @return the OCSP basic response or null - * @since 2.1.6 + * @since 2.1.6 */ // public BasicOCSPResp getOcsp() { // return basicResp; // } - private void findOcsp(ASN1Sequence seq) throws IOException { // basicResp = null; boolean ret = false; while (true) { - if ((seq.getObjectAt(0) instanceof DERObjectIdentifier) - && ((DERObjectIdentifier)seq.getObjectAt(0)).getId().equals(OCSPObjectIdentifiers.id_pkix_ocsp_basic.getId())) { + if ((seq.getObjectAt(0) instanceof ASN1ObjectIdentifier) + && ((ASN1ObjectIdentifier) seq.getObjectAt(0)).getId().equals(OCSPObjectIdentifiers.id_pkix_ocsp_basic.getId())) { break; } ret = true; for (int k = 0; k < seq.size(); ++k) { if (seq.getObjectAt(k) instanceof ASN1Sequence) { - seq = (ASN1Sequence)seq.getObjectAt(0); + seq = (ASN1Sequence) seq.getObjectAt(0); ret = false; break; } if (seq.getObjectAt(k) instanceof ASN1TaggedObject) { - ASN1TaggedObject tag = (ASN1TaggedObject)seq.getObjectAt(k); + ASN1TaggedObject tag = (ASN1TaggedObject) seq.getObjectAt(k); if (tag.getObject() instanceof ASN1Sequence) { - seq = (ASN1Sequence)tag.getObject(); + seq = (ASN1Sequence) tag.getObject(); ret = false; break; - } - else + } else return; } } if (ret) return; } - DEROctetString os = (DEROctetString)seq.getObjectAt(1); + DEROctetString os = (DEROctetString) seq.getObjectAt(1); ASN1InputStream inp = new ASN1InputStream(os.getOctets()); BasicOCSPResponse resp = BasicOCSPResponse.getInstance(inp.readObject()); // basicResp = new BasicOCSPResp(resp); } - + /** * Verifies a signature using the sub-filter adbe.pkcs7.detached or * adbe.pkcs7.sha1. + * * @param contentsKey the /Contents key - * @param provider the provider ornull
for the default provider - */ + * @param provider the provider ornull
for the default provider + */ public PdfPKCS7(byte[] contentsKey, String provider) { try { this.provider = provider; @@ -383,18 +380,17 @@ public class PdfPKCS7 { try { pkcs = din.readObject(); - } - catch (IOException e) { + } catch (IOException e) { throw new IllegalArgumentException("can't decode PKCS7SignedData object"); } if (!(pkcs instanceof ASN1Sequence)) { throw new IllegalArgumentException("Not a valid PKCS#7 object - not a sequence"); } - ASN1Sequence signedData = (ASN1Sequence)pkcs; - DERObjectIdentifier objId = (DERObjectIdentifier)signedData.getObjectAt(0); + ASN1Sequence signedData = (ASN1Sequence) pkcs; + ASN1ObjectIdentifier objId = (ASN1ObjectIdentifier) signedData.getObjectAt(0); if (!objId.getId().equals(ID_PKCS7_SIGNED_DATA)) throw new IllegalArgumentException("Not a valid PKCS#7 object - not signed data"); - ASN1Sequence content = (ASN1Sequence)((DERTaggedObject)signedData.getObjectAt(1)).getObject(); + ASN1Sequence content = (ASN1Sequence) ((DERTaggedObject) signedData.getObjectAt(1)).getObject(); // the positions that we care are: // 0 - version // 1 - digestAlgorithms @@ -403,15 +399,14 @@ public class PdfPKCS7 { // last - signerInfos // the version - version = ((DERInteger)content.getObjectAt(0)).getValue().intValue(); + version = ((ASN1Integer) content.getObjectAt(0)).getValue().intValue(); // the digestAlgorithms digestalgos = new HashSet(); - Enumeration e = ((ASN1Set)content.getObjectAt(1)).getObjects(); - while (e.hasMoreElements()) - { - ASN1Sequence s = (ASN1Sequence)e.nextElement(); - DERObjectIdentifier o = (DERObjectIdentifier)s.getObjectAt(0); + Enumeration e = ((ASN1Set) content.getObjectAt(1)).getObjects(); + while (e.hasMoreElements()) { + ASN1Sequence s = (ASN1Sequence) e.nextElement(); + ASN1ObjectIdentifier o = (ASN1ObjectIdentifier) s.getObjectAt(0); digestalgos.add(o.getId()); } @@ -424,9 +419,9 @@ public class PdfPKCS7 { crls = cl.engineReadAll(); // the possible ID_PKCS7_DATA - ASN1Sequence rsaData = (ASN1Sequence)content.getObjectAt(2); + ASN1Sequence rsaData = (ASN1Sequence) content.getObjectAt(2); if (rsaData.size() > 1) { - DEROctetString rsaDataContent = (DEROctetString)((DERTaggedObject)rsaData.getObjectAt(1)).getObject(); + DEROctetString rsaDataContent = (DEROctetString) ((DERTaggedObject) rsaData.getObjectAt(1)).getObject(); RSAdata = rsaDataContent.getOctets(); } @@ -434,22 +429,22 @@ public class PdfPKCS7 { int next = 3; while (content.getObjectAt(next) instanceof DERTaggedObject) ++next; - ASN1Set signerInfos = (ASN1Set)content.getObjectAt(next); + ASN1Set signerInfos = (ASN1Set) content.getObjectAt(next); if (signerInfos.size() != 1) throw new IllegalArgumentException("This PKCS#7 object has multiple SignerInfos - only one is supported at this time"); - ASN1Sequence signerInfo = (ASN1Sequence)signerInfos.getObjectAt(0); + ASN1Sequence signerInfo = (ASN1Sequence) signerInfos.getObjectAt(0); // the positions that we care are // 0 - version // 1 - the signing certificate serial number // 2 - the digest algorithm // 3 or 4 - digestEncryptionAlgorithm // 4 or 5 - encryptedDigest - signerversion = ((DERInteger)signerInfo.getObjectAt(0)).getValue().intValue(); + signerversion = ((ASN1Integer) signerInfo.getObjectAt(0)).getValue().intValue(); // Get the signing certificate - ASN1Sequence issuerAndSerialNumber = (ASN1Sequence)signerInfo.getObjectAt(1); - BigInteger serialNumber = ((DERInteger)issuerAndSerialNumber.getObjectAt(1)).getValue(); - for (Iterator i = certs.iterator(); i.hasNext();) { - X509Certificate cert = (X509Certificate)i.next(); + ASN1Sequence issuerAndSerialNumber = (ASN1Sequence) signerInfo.getObjectAt(1); + BigInteger serialNumber = ((ASN1Integer) issuerAndSerialNumber.getObjectAt(1)).getValue(); + for (Iterator i = certs.iterator(); i.hasNext(); ) { + X509Certificate cert = (X509Certificate) i.next(); if (serialNumber.equals(cert.getSerialNumber())) { signCert = cert; break; @@ -459,27 +454,26 @@ public class PdfPKCS7 { throw new IllegalArgumentException("Can't find signing certificate with serial " + serialNumber.toString(16)); } signCertificateChain(); - digestAlgorithm = ((DERObjectIdentifier)((ASN1Sequence)signerInfo.getObjectAt(2)).getObjectAt(0)).getId(); + digestAlgorithm = ((ASN1ObjectIdentifier) ((ASN1Sequence) signerInfo.getObjectAt(2)).getObjectAt(0)).getId(); next = 3; if (signerInfo.getObjectAt(next) instanceof ASN1TaggedObject) { - ASN1TaggedObject tagsig = (ASN1TaggedObject)signerInfo.getObjectAt(next); + ASN1TaggedObject tagsig = (ASN1TaggedObject) signerInfo.getObjectAt(next); ASN1Set sseq = ASN1Set.getInstance(tagsig, false); sigAttr = sseq.getEncoded("DER"); for (int k = 0; k < sseq.size(); ++k) { - ASN1Sequence seq2 = (ASN1Sequence)sseq.getObjectAt(k); - if (((DERObjectIdentifier)seq2.getObjectAt(0)).getId().equals(ID_MESSAGE_DIGEST)) { - ASN1Set set = (ASN1Set)seq2.getObjectAt(1); - digestAttr = ((DEROctetString)set.getObjectAt(0)).getOctets(); - } - else if (((DERObjectIdentifier)seq2.getObjectAt(0)).getId().equals(ID_ADBE_REVOCATION)) { - ASN1Set setout = (ASN1Set)seq2.getObjectAt(1); - ASN1Sequence seqout = (ASN1Sequence)setout.getObjectAt(0); + ASN1Sequence seq2 = (ASN1Sequence) sseq.getObjectAt(k); + if (((ASN1ObjectIdentifier) seq2.getObjectAt(0)).getId().equals(ID_MESSAGE_DIGEST)) { + ASN1Set set = (ASN1Set) seq2.getObjectAt(1); + digestAttr = ((DEROctetString) set.getObjectAt(0)).getOctets(); + } else if (((ASN1ObjectIdentifier) seq2.getObjectAt(0)).getId().equals(ID_ADBE_REVOCATION)) { + ASN1Set setout = (ASN1Set) seq2.getObjectAt(1); + ASN1Sequence seqout = (ASN1Sequence) setout.getObjectAt(0); for (int j = 0; j < seqout.size(); ++j) { - ASN1TaggedObject tg = (ASN1TaggedObject)seqout.getObjectAt(j); + ASN1TaggedObject tg = (ASN1TaggedObject) seqout.getObjectAt(j); if (tg.getTagNo() != 1) continue; - ASN1Sequence seqin = (ASN1Sequence)tg.getObject(); + ASN1Sequence seqin = (ASN1Sequence) tg.getObject(); findOcsp(seqin); } } @@ -488,8 +482,8 @@ public class PdfPKCS7 { throw new IllegalArgumentException("Authenticated attribute is missing the digest."); ++next; } - digestEncryptionAlgorithm = ((DERObjectIdentifier)((ASN1Sequence)signerInfo.getObjectAt(next++)).getObjectAt(0)).getId(); - digest = ((DEROctetString)signerInfo.getObjectAt(next++)).getOctets(); + digestEncryptionAlgorithm = ((ASN1ObjectIdentifier) ((ASN1Sequence) signerInfo.getObjectAt(next++)).getObjectAt(0)).getId(); + digest = ((DEROctetString) signerInfo.getObjectAt(next++)).getOctets(); if (next < signerInfo.size() && (signerInfo.getObjectAt(next) instanceof DERTaggedObject)) { DERTaggedObject taggedObject = (DERTaggedObject) signerInfo.getObjectAt(next); ASN1Set unat = ASN1Set.getInstance(taggedObject, false); @@ -513,56 +507,55 @@ public class PdfPKCS7 { else sig = Signature.getInstance(getDigestAlgorithm(), provider); sig.initVerify(signCert.getPublicKey()); - } - catch (Exception e) { + } catch (Exception e) { throw new ExceptionConverter(e); } } /** * Generates a signature. - * @param privKey the private key - * @param certChain the certificate chain - * @param crlList the certificate revocation list + * + * @param privKey the private key + * @param certChain the certificate chain + * @param crlList the certificate revocation list * @param hashAlgorithm the hash algorithm - * @param provider the provider ornull
for the default provider - * @param hasRSAdatatrue
if the sub-filter is adbe.pkcs7.sha1 - * @throws InvalidKeyException on error - * @throws NoSuchProviderException on error + * @param provider the provider ornull
for the default provider + * @param hasRSAdatatrue
if the sub-filter is adbe.pkcs7.sha1 + * @throws InvalidKeyException on error + * @throws NoSuchProviderException on error * @throws NoSuchAlgorithmException on error - */ + */ public PdfPKCS7(PrivateKey privKey, Certificate[] certChain, CRL[] crlList, String hashAlgorithm, String provider, boolean hasRSAdata) - throws InvalidKeyException, NoSuchProviderException, - NoSuchAlgorithmException - { + throws InvalidKeyException, NoSuchProviderException, + NoSuchAlgorithmException { this.privKey = privKey; this.provider = provider; - - digestAlgorithm = (String)allowedDigests.get(hashAlgorithm.toUpperCase()); + + digestAlgorithm = (String) allowedDigests.get(hashAlgorithm.toUpperCase()); if (digestAlgorithm == null) - throw new NoSuchAlgorithmException("Unknown Hash Algorithm "+hashAlgorithm); - + throw new NoSuchAlgorithmException("Unknown Hash Algorithm " + hashAlgorithm); + version = signerversion = 1; certs = new ArrayList(); crls = new ArrayList(); digestalgos = new HashSet(); digestalgos.add(digestAlgorithm); - + // // Copy in the certificates and crls used to sign the private key. // - signCert = (X509Certificate)certChain[0]; - for (int i = 0;i < certChain.length;i++) { + signCert = (X509Certificate) certChain[0]; + for (int i = 0; i < certChain.length; i++) { certs.add(certChain[i]); } - + if (crlList != null) { - for (int i = 0;i < crlList.length;i++) { + for (int i = 0; i < crlList.length; i++) { crls.add(crlList[i]); } } - + if (privKey != null) { // // Now we have private key, find out what the digestEncryptionAlgorithm is. @@ -570,12 +563,10 @@ public class PdfPKCS7 { digestEncryptionAlgorithm = privKey.getAlgorithm(); if (digestEncryptionAlgorithm.equals("RSA")) { digestEncryptionAlgorithm = ID_RSA; - } - else if (digestEncryptionAlgorithm.equals("DSA")) { + } else if (digestEncryptionAlgorithm.equals("DSA")) { digestEncryptionAlgorithm = ID_DSA; - } - else { - throw new NoSuchAlgorithmException("Unknown Key Algorithm "+digestEncryptionAlgorithm); + } else { + throw new NoSuchAlgorithmException("Unknown Key Algorithm " + digestEncryptionAlgorithm); } } if (hasRSAdata) { @@ -598,6 +589,7 @@ public class PdfPKCS7 { /** * Update the digest with the specified bytes. This method is used both for signing and verifying + * * @param buf the data buffer * @param off the offset in the data buffer * @param len the data length @@ -609,11 +601,12 @@ public class PdfPKCS7 { else sig.update(buf, off, len); } - + /** * Verify the digest. - * @throws SignatureException on error + * * @returntrue
if the signature checks out,false
otherwise + * @throws SignatureException on error */ public boolean verify() throws SignatureException { if (verified) @@ -625,8 +618,7 @@ public class PdfPKCS7 { messageDigest.update(msd); } verifyResult = (Arrays.equals(messageDigest.digest(), digestAttr) && sig.verify(digest)); - } - else { + } else { if (RSAdata != null) sig.update(messageDigest.digest()); verifyResult = sig.verify(digest); @@ -634,12 +626,12 @@ public class PdfPKCS7 { verified = true; return verifyResult; } - + /** * Checks if the timestamp refers to this document. * @throws java.security.NoSuchAlgorithmException on error * @return true if it checks false otherwise - * @since 2.1.6 + * @since 2.1.6 */ // public boolean verifyTimestampImprint() throws NoSuchAlgorithmException { // if (timeStampToken == null) @@ -650,33 +642,35 @@ public class PdfPKCS7 { // boolean res = Arrays.equals(md, imphashed); // return res; // } - + /** * Get all the X.509 certificates associated with this PKCS#7 object in no particular order. * Other certificates, from OCSP for example, will also be included. + * * @return the X.509 certificates associated with this PKCS#7 object */ public Certificate[] getCertificates() { - return (X509Certificate[])certs.toArray(new X509Certificate[certs.size()]); + return (X509Certificate[]) certs.toArray(new X509Certificate[certs.size()]); } - + /** * Get the X.509 sign certificate chain associated with this PKCS#7 object. * Only the certificates used for the main signature will be returned, with * the signing certificate first. + * * @return the X.509 certificates associated with this PKCS#7 object - * @since 2.1.6 + * @since 2.1.6 */ public Certificate[] getSignCertificateChain() { - return (X509Certificate[])signCerts.toArray(new X509Certificate[signCerts.size()]); + return (X509Certificate[]) signCerts.toArray(new X509Certificate[signCerts.size()]); } - + private void signCertificateChain() { ArrayList cc = new ArrayList(); cc.add(signCert); ArrayList oc = new ArrayList(certs); for (int k = 0; k < oc.size(); ++k) { - if (signCert.getSerialNumber().equals(((X509Certificate)oc.get(k)).getSerialNumber())) { + if (signCert.getSerialNumber().equals(((X509Certificate) oc.get(k)).getSerialNumber())) { oc.remove(k); --k; continue; @@ -684,72 +678,77 @@ public class PdfPKCS7 { } boolean found = true; while (found) { - X509Certificate v = (X509Certificate)cc.get(cc.size() - 1); + X509Certificate v = (X509Certificate) cc.get(cc.size() - 1); found = false; for (int k = 0; k < oc.size(); ++k) { try { if (provider == null) - v.verify(((X509Certificate)oc.get(k)).getPublicKey()); + v.verify(((X509Certificate) oc.get(k)).getPublicKey()); else - v.verify(((X509Certificate)oc.get(k)).getPublicKey(), provider); + v.verify(((X509Certificate) oc.get(k)).getPublicKey(), provider); found = true; cc.add(oc.get(k)); oc.remove(k); break; - } - catch (Exception e) { + } catch (Exception e) { } } } signCerts = cc; } - + /** * Get the X.509 certificate revocation lists associated with this PKCS#7 object + * * @return the X.509 certificate revocation lists associated with this PKCS#7 object */ public Collection getCRLs() { return crls; } - + /** * Get the X.509 certificate actually used to sign the digest. + * * @return the X.509 certificate actually used to sign the digest */ public X509Certificate getSigningCertificate() { return signCert; } - + /** * Get the version of the PKCS#7 object. Always 1 + * * @return the version of the PKCS#7 object. Always 1 */ public int getVersion() { return version; } - + /** * Get the version of the PKCS#7 "SignerInfo" object. Always 1 + * * @return the version of the PKCS#7 "SignerInfo" object. Always 1 */ public int getSigningInfoVersion() { return signerversion; } - + /** * Get the algorithm used to calculate the message digest + * * @return the algorithm used to calculate the message digest */ public String getDigestAlgorithm() { String dea = getAlgorithm(digestEncryptionAlgorithm); if (dea == null) dea = digestEncryptionAlgorithm; - + return getHashAlgorithm() + "with" + dea; } /** * Returns the algorithm. + * * @return the digest algorithm */ public String getHashAlgorithm() { @@ -759,17 +758,19 @@ public class PdfPKCS7 { /** * Loads the default root certificates at <java.home>/lib/security/cacerts * with the default provider. + * * @return aKeyStore
- */ + */ public static KeyStore loadCacertsKeyStore() { return loadCacertsKeyStore(null); } /** * Loads the default root certificates at <java.home>/lib/security/cacerts. + * * @param provider the provider ornull
for the default provider * @return aKeyStore
- */ + */ public static KeyStore loadCacertsKeyStore(String provider) { File file = new File(System.getProperty("java.home"), "lib"); file = new File(file, "security"); @@ -784,23 +785,27 @@ public class PdfPKCS7 { k = KeyStore.getInstance("JKS", provider); k.load(fin, null); return k; - } - catch (Exception e) { + } catch (Exception e) { throw new ExceptionConverter(e); - } - finally { - try{if (fin != null) {fin.close();}}catch(Exception ex){} + } finally { + try { + if (fin != null) { + fin.close(); + } + } catch (Exception ex) { + } } } - + /** * Verifies a single certificate. - * @param cert the certificate to verify - * @param crls the certificate revocation list ornull
+ * + * @param cert the certificate to verify + * @param crls the certificate revocation list ornull
* @param calendar the date ornull
for the current date * @return aString
with the error description ornull
* if no error - */ + */ public static String verifyCertificate(X509Certificate cert, Collection crls, Calendar calendar) { if (calendar == null) calendar = new GregorianCalendar(); @@ -808,70 +813,66 @@ public class PdfPKCS7 { return "Has unsupported critical extension"; try { cert.checkValidity(calendar.getTime()); - } - catch (Exception e) { + } catch (Exception e) { return e.getMessage(); } if (crls != null) { - for (Iterator it = crls.iterator(); it.hasNext();) { - if (((CRL)it.next()).isRevoked(cert)) + for (Iterator it = crls.iterator(); it.hasNext(); ) { + if (((CRL) it.next()).isRevoked(cert)) return "Certificate revoked"; } } return null; } - + /** * Verifies a certificate chain against a KeyStore. - * @param certs the certificate chain + * + * @param certs the certificate chain * @param keystore theKeyStore
- * @param crls the certificate revocation list ornull
+ * @param crls the certificate revocation list ornull
* @param calendar the date ornull
for the current date * @returnnull
if the certificate chain could be validated or a *Object[]{cert,error}
wherecert
is the * failed certificate anderror
is the error message - */ + */ public static Object[] verifyCertificates(Certificate certs[], KeyStore keystore, Collection crls, Calendar calendar) { if (calendar == null) calendar = new GregorianCalendar(); for (int k = 0; k < certs.length; ++k) { - X509Certificate cert = (X509Certificate)certs[k]; + X509Certificate cert = (X509Certificate) certs[k]; String err = verifyCertificate(cert, crls, calendar); if (err != null) return new Object[]{cert, err}; try { - for (Enumeration aliases = keystore.aliases(); aliases.hasMoreElements();) { + for (Enumeration aliases = keystore.aliases(); aliases.hasMoreElements(); ) { try { - String alias = (String)aliases.nextElement(); + String alias = (String) aliases.nextElement(); if (!keystore.isCertificateEntry(alias)) continue; - X509Certificate certStoreX509 = (X509Certificate)keystore.getCertificate(alias); + X509Certificate certStoreX509 = (X509Certificate) keystore.getCertificate(alias); if (verifyCertificate(certStoreX509, crls, calendar) != null) continue; try { cert.verify(certStoreX509.getPublicKey()); return null; - } - catch (Exception e) { + } catch (Exception e) { continue; } - } - catch (Exception ex) { + } catch (Exception ex) { } } - } - catch (Exception e) { + } catch (Exception e) { } int j; for (j = 0; j < certs.length; ++j) { if (j == k) continue; - X509Certificate certNext = (X509Certificate)certs[j]; + X509Certificate certNext = (X509Certificate) certs[j]; try { cert.verify(certNext.getPublicKey()); break; - } - catch (Exception e) { + } catch (Exception e) { } } if (j == certs.length) @@ -886,8 +887,8 @@ public class PdfPKCS7 { * @param keystore theKeyStore
* @param provider the provider ornull
to use the BouncyCastle provider * @returntrue
is a certificate was found - * @since 2.1.6 - */ + * @since 2.1.6 + */ // public static boolean verifyOcspCertificates(BasicOCSPResp ocsp, KeyStore keystore, String provider) { // if (provider == null) // provider = "BC"; @@ -909,15 +910,15 @@ public class PdfPKCS7 { // } // return false; // } - + /** * Verifies a timestamp against a KeyStore. * @param ts the timestamp * @param keystore theKeyStore
* @param provider the provider ornull
to use the BouncyCastle provider * @returntrue
is a certificate was found - * @since 2.1.6 - */ + * @since 2.1.6 + */ // public static boolean verifyTimestampCertificates(TimeStampToken ts, KeyStore keystore, String provider) { // if (provider == null) // provider = "BC"; @@ -939,13 +940,14 @@ public class PdfPKCS7 { // } // return false; // } - + /** * Retrieves the OCSP URL from the given certificate. + * * @param certificate the certificate * @return the URL or null * @throws CertificateParsingException on error - * @since 2.1.6 + * @since 2.1.6 */ public static String getOCSPURL(X509Certificate certificate) throws CertificateParsingException { try { @@ -953,32 +955,33 @@ public class PdfPKCS7 { if (obj == null) { return null; } - + ASN1Sequence AccessDescriptions = (ASN1Sequence) obj; for (int i = 0; i < AccessDescriptions.size(); i++) { ASN1Sequence AccessDescription = (ASN1Sequence) AccessDescriptions.getObjectAt(i); - if ( AccessDescription.size() != 2 ) { + if (AccessDescription.size() != 2) { continue; } else { - if ((AccessDescription.getObjectAt(0) instanceof DERObjectIdentifier) && ((DERObjectIdentifier)AccessDescription.getObjectAt(0)).getId().equals("1.3.6.1.5.5.7.48.1")) { - String AccessLocation = getStringFromGeneralName((ASN1Object)AccessDescription.getObjectAt(1)); - if ( AccessLocation == null ) { - return "" ; + if ((AccessDescription.getObjectAt(0) instanceof ASN1ObjectIdentifier) && ((ASN1ObjectIdentifier) AccessDescription.getObjectAt(0)).getId().equals("1.3.6.1.5.5.7.48.1")) { + String AccessLocation = getStringFromGeneralName((ASN1Object) AccessDescription.getObjectAt(1)); + if (AccessLocation == null) { + return ""; } else { - return AccessLocation ; + return AccessLocation; } } } } - } catch (Exception e) { + } catch (Exception e) { } return null; } - + /** * Checks if OCSP revocation refers to the document signing certificate. + * * @return true if it checks false otherwise - * @since 2.1.6 + * @since 2.1.6 */ // public boolean isRevocationValid() { // if (basicResp == null) @@ -998,7 +1001,6 @@ public class PdfPKCS7 { // } // return false; // } - private static ASN1Object getExtensionValue(X509Certificate cert, String oid) throws IOException { byte[] bytes = cert.getExtensionValue(oid); if (bytes == null) { @@ -1009,74 +1011,75 @@ public class PdfPKCS7 { aIn = new ASN1InputStream(new ByteArrayInputStream(octs.getOctets())); return aIn.readObject(); } - + private static String getStringFromGeneralName(ASN1Object names) throws IOException { - DERTaggedObject taggedObject = (DERTaggedObject) names ; + DERTaggedObject taggedObject = (DERTaggedObject) names; return new String(ASN1OctetString.getInstance(taggedObject, false).getOctets(), "ISO-8859-1"); } /** * Get the "issuer" from the TBSCertificate bytes that are passed in + * * @param enc a TBSCertificate in a byte array * @return a DERObject */ private static ASN1Object getIssuer(byte[] enc) { try { ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(enc)); - ASN1Sequence seq = (ASN1Sequence)in.readObject(); - return (ASN1Object)seq.getObjectAt(seq.getObjectAt(0) instanceof DERTaggedObject ? 3 : 2); - } - catch (IOException e) { + ASN1Sequence seq = (ASN1Sequence) in.readObject(); + return (ASN1Object) seq.getObjectAt(seq.getObjectAt(0) instanceof DERTaggedObject ? 3 : 2); + } catch (IOException e) { throw new ExceptionConverter(e); } } /** * Get the "subject" from the TBSCertificate bytes that are passed in + * * @param enc A TBSCertificate in a byte array * @return a DERObject */ private static ASN1Object getSubject(byte[] enc) { try { ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(enc)); - ASN1Sequence seq = (ASN1Sequence)in.readObject(); - return (ASN1Object)seq.getObjectAt(seq.getObjectAt(0) instanceof DERTaggedObject ? 5 : 4); - } - catch (IOException e) { + ASN1Sequence seq = (ASN1Sequence) in.readObject(); + return (ASN1Object) seq.getObjectAt(seq.getObjectAt(0) instanceof DERTaggedObject ? 5 : 4); + } catch (IOException e) { throw new ExceptionConverter(e); } } /** * Get the issuer fields from an X509 Certificate + * * @param cert an X509Certificate * @return an X509Name */ public static X509Name getIssuerFields(X509Certificate cert) { try { - return new X509Name((ASN1Sequence)getIssuer(cert.getTBSCertificate())); - } - catch (Exception e) { + return new X509Name((ASN1Sequence) getIssuer(cert.getTBSCertificate())); + } catch (Exception e) { throw new ExceptionConverter(e); } } /** * Get the subject fields from an X509 Certificate + * * @param cert an X509Certificate * @return an X509Name */ public static X509Name getSubjectFields(X509Certificate cert) { try { - return new X509Name((ASN1Sequence)getSubject(cert.getTBSCertificate())); - } - catch (Exception e) { + return new X509Name((ASN1Sequence) getSubject(cert.getTBSCertificate())); + } catch (Exception e) { throw new ExceptionConverter(e); } } - + /** * Gets the bytes for the PKCS#1 object. + * * @return a byte array */ public byte[] getEncodedPKCS1() { @@ -1085,55 +1088,55 @@ public class PdfPKCS7 { digest = externalDigest; else digest = sig.sign(); - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - + ByteArrayOutputStream bOut = new ByteArrayOutputStream(); + ASN1OutputStream dout = new ASN1OutputStream(bOut); dout.writeObject(new DEROctetString(digest)); dout.close(); - + return bOut.toByteArray(); - } - catch (Exception e) { + } catch (Exception e) { throw new ExceptionConverter(e); } } - + /** * Sets the digest/signature to an external calculated value. - * @param digest the digest. This is the actual signature - * @param RSAdata the extra data that goes into the data tag in PKCS#7 + * + * @param digest the digest. This is the actual signature + * @param RSAdata the extra data that goes into the data tag in PKCS#7 * @param digestEncryptionAlgorithm the encryption algorithm. It may must benull
if thedigest
- * is alsonull
. If thedigest
is notnull
- * then it may be "RSA" or "DSA" - */ + * is alsonull
. If thedigest
is notnull
+ * then it may be "RSA" or "DSA" + */ public void setExternalDigest(byte digest[], byte RSAdata[], String digestEncryptionAlgorithm) { externalDigest = digest; externalRSAdata = RSAdata; if (digestEncryptionAlgorithm != null) { if (digestEncryptionAlgorithm.equals("RSA")) { this.digestEncryptionAlgorithm = ID_RSA; - } - else if (digestEncryptionAlgorithm.equals("DSA")) { + } else if (digestEncryptionAlgorithm.equals("DSA")) { this.digestEncryptionAlgorithm = ID_DSA; - } - else - throw new ExceptionConverter(new NoSuchAlgorithmException("Unknown Key Algorithm "+digestEncryptionAlgorithm)); + } else + throw new ExceptionConverter(new NoSuchAlgorithmException("Unknown Key Algorithm " + digestEncryptionAlgorithm)); } } - + /** * Gets the bytes for the PKCS7SignedData object. + * * @return the bytes for the PKCS7SignedData object */ public byte[] getEncodedPKCS7() { return getEncodedPKCS7(null, null, null, null); } - + /** * Gets the bytes for the PKCS7SignedData object. Optionally the authenticatedAttributes * in the signerInfo can also be set. If either of the parameters isnull
, none will be used. + * * @param secondDigest the digest in the authenticatedAttributes - * @param signingTime the signing time in the authenticatedAttributes + * @param signingTime the signing time in the authenticatedAttributes * @return the bytes for the PKCS7SignedData object */ public byte[] getEncodedPKCS7(byte secondDigest[], Calendar signingTime) { @@ -1144,11 +1147,12 @@ public class PdfPKCS7 { * Gets the bytes for the PKCS7SignedData object. Optionally the authenticatedAttributes * in the signerInfo can also be set, OR a time-stamp-authority client * may be provided. + * * @param secondDigest the digest in the authenticatedAttributes - * @param signingTime the signing time in the authenticatedAttributes - * @param tsaClient TSAClient - null or an optional time stamp authority client + * @param signingTime the signing time in the authenticatedAttributes + * @param tsaClient TSAClient - null or an optional time stamp authority client * @return byte[] the bytes for the PKCS7SignedData object - * @since 2.1.6 + * @since 2.1.6 */ public byte[] getEncodedPKCS7(byte secondDigest[], Calendar signingTime, TSAClient tsaClient, byte[] ocsp) { try { @@ -1156,78 +1160,76 @@ public class PdfPKCS7 { digest = externalDigest; if (RSAdata != null) RSAdata = externalRSAdata; - } - else if (externalRSAdata != null && RSAdata != null) { + } else if (externalRSAdata != null && RSAdata != null) { RSAdata = externalRSAdata; sig.update(RSAdata); digest = sig.sign(); - } - else { + } else { if (RSAdata != null) { RSAdata = messageDigest.digest(); sig.update(RSAdata); } digest = sig.sign(); } - + // Create the set of Hash algorithms ASN1EncodableVector digestAlgorithms = new ASN1EncodableVector(); - for(Iterator it = digestalgos.iterator(); it.hasNext();) { + for (Iterator it = digestalgos.iterator(); it.hasNext(); ) { ASN1EncodableVector algos = new ASN1EncodableVector(); - algos.add(new DERObjectIdentifier((String)it.next())); + algos.add(new ASN1ObjectIdentifier((String) it.next())); algos.add(DERNull.INSTANCE); digestAlgorithms.add(new DERSequence(algos)); } - + // Create the contentInfo. ASN1EncodableVector v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(ID_PKCS7_DATA)); + v.add(new ASN1ObjectIdentifier(ID_PKCS7_DATA)); if (RSAdata != null) v.add(new DERTaggedObject(0, new DEROctetString(RSAdata))); DERSequence contentinfo = new DERSequence(v); - + // Get all the certificates // v = new ASN1EncodableVector(); - for (Iterator i = certs.iterator(); i.hasNext();) { - ASN1InputStream tempstream = new ASN1InputStream(new ByteArrayInputStream(((X509Certificate)i.next()).getEncoded())); + for (Iterator i = certs.iterator(); i.hasNext(); ) { + ASN1InputStream tempstream = new ASN1InputStream(new ByteArrayInputStream(((X509Certificate) i.next()).getEncoded())); v.add(tempstream.readObject()); } - + DERSet dercertificates = new DERSet(v); - + // Create signerinfo structure. // ASN1EncodableVector signerinfo = new ASN1EncodableVector(); - + // Add the signerInfo version // - signerinfo.add(new DERInteger(signerversion)); - + signerinfo.add(new ASN1Integer(signerversion)); + v = new ASN1EncodableVector(); v.add(getIssuer(signCert.getTBSCertificate())); - v.add(new DERInteger(signCert.getSerialNumber())); + v.add(new ASN1Integer(signCert.getSerialNumber())); signerinfo.add(new DERSequence(v)); - + // Add the digestAlgorithm v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(digestAlgorithm)); - v.add(new DERNull()); + v.add(new ASN1ObjectIdentifier(digestAlgorithm)); + v.add(DERNull.INSTANCE); signerinfo.add(new DERSequence(v)); - + // add the authenticated attribute if present if (secondDigest != null && signingTime != null) { signerinfo.add(new DERTaggedObject(false, 0, getAuthenticatedAttributeSet(secondDigest, signingTime, ocsp))); } // Add the digestEncryptionAlgorithm v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(digestEncryptionAlgorithm)); - v.add(new DERNull()); + v.add(new ASN1ObjectIdentifier(digestEncryptionAlgorithm)); + v.add(DERNull.INSTANCE); signerinfo.add(new DERSequence(v)); - + // Add the digest signerinfo.add(new DEROctetString(digest)); - + // When requested, go get and add the timestamp. May throw an exception. // Added by Martin Brunecky, 07/12/2007 folowing Aiken Sam, 2006-11-15 // Sam found Adobe expects time-stamped SHA1-1 of the encrypted digest @@ -1241,57 +1243,57 @@ public class PdfPKCS7 { } } } - + // Finally build the body out of all the components above ASN1EncodableVector body = new ASN1EncodableVector(); - body.add(new DERInteger(version)); + body.add(new ASN1Integer(version)); body.add(new DERSet(digestAlgorithms)); body.add(contentinfo); body.add(new DERTaggedObject(false, 0, dercertificates)); - - if (!crls.isEmpty()) { + + if (!crls.isEmpty()) { v = new ASN1EncodableVector(); - for (Iterator i = crls.iterator();i.hasNext();) { - ASN1InputStream t = new ASN1InputStream(new ByteArrayInputStream(((X509CRL)i.next()).getEncoded())); + for (Iterator i = crls.iterator(); i.hasNext(); ) { + ASN1InputStream t = new ASN1InputStream(new ByteArrayInputStream(((X509CRL) i.next()).getEncoded())); v.add(t.readObject()); } DERSet dercrls = new DERSet(v); body.add(new DERTaggedObject(false, 1, dercrls)); } - + // Only allow one signerInfo body.add(new DERSet(new DERSequence(signerinfo))); - + // Now we have the body, wrap it in it's PKCS7Signed shell // and return it // ASN1EncodableVector whole = new ASN1EncodableVector(); - whole.add(new DERObjectIdentifier(ID_PKCS7_SIGNED_DATA)); + whole.add(new ASN1ObjectIdentifier(ID_PKCS7_SIGNED_DATA)); whole.add(new DERTaggedObject(0, new DERSequence(body))); - - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - + + ByteArrayOutputStream bOut = new ByteArrayOutputStream(); + ASN1OutputStream dout = new ASN1OutputStream(bOut); dout.writeObject(new DERSequence(whole)); dout.close(); - + return bOut.toByteArray(); - } - catch (Exception e) { + } catch (Exception e) { throw new ExceptionConverter(e); } } - + /** * Added by Aiken Sam, 2006-11-15, modifed by Martin Brunecky 07/12/2007 * to start with the timeStampToken (signedData 1.2.840.113549.1.7.2). * Token is the TSA response without response status, which is usually * handled by the (vendor supplied) TSA request/response interface). + * * @param timeStampToken byte[] - time stamp token, DER encoded signedData * @return ASN1EncodableVector * @throws IOException */ - private ASN1EncodableVector buildUnauthenticatedAttributes(byte[] timeStampToken) throws IOException { + private ASN1EncodableVector buildUnauthenticatedAttributes(byte[] timeStampToken) throws IOException { if (timeStampToken == null) return null; @@ -1302,20 +1304,20 @@ public class PdfPKCS7 { ASN1EncodableVector unauthAttributes = new ASN1EncodableVector(); ASN1EncodableVector v = new ASN1EncodableVector(); - v.add(new DERObjectIdentifier(ID_TIME_STAMP_TOKEN)); // id-aa-timeStampToken + v.add(new ASN1ObjectIdentifier(ID_TIME_STAMP_TOKEN)); // id-aa-timeStampToken ASN1Sequence seq = (ASN1Sequence) tempstream.readObject(); v.add(new DERSet(seq)); unauthAttributes.add(new DERSequence(v)); return unauthAttributes; - } + } + - /** * When using authenticatedAttributes the authentication process is different. * The document digest is generated and put inside the attribute. The signing is done over the DER encoded * authenticatedAttributes. This method provides that encoding and the parameters must be - * exactly the same as in {@link #getEncodedPKCS7(byte[],Calendar)}. + * exactly the same as in {@link #getEncodedPKCS7(byte[], Calendar)}. ** A simple example: *
@@ -1334,132 +1336,138 @@ public class PdfPKCS7 { * pk7.update(sh, 0, sh.length); * byte sg[] = pk7.getEncodedPKCS7(hash, cal); *
Note: if you're trying to be ultra orthodox, don't use this! It shouldn't be in here. */ - public static final DERObjectIdentifier EmailAddress = new DERObjectIdentifier("1.2.840.113549.1.9.1"); + public static final ASN1ObjectIdentifier EmailAddress = new ASN1ObjectIdentifier("1.2.840.113549.1.9.1"); /** * email address in Verisign certificates */ - public static final DERObjectIdentifier E = EmailAddress; + public static final ASN1ObjectIdentifier E = EmailAddress; - /** object identifier */ - public static final DERObjectIdentifier DC = new DERObjectIdentifier("0.9.2342.19200300.100.1.25"); + /** + * object identifier + */ + public static final ASN1ObjectIdentifier DC = new ASN1ObjectIdentifier("0.9.2342.19200300.100.1.25"); - /** LDAP User id. */ - public static final DERObjectIdentifier UID = new DERObjectIdentifier("0.9.2342.19200300.100.1.1"); + /** + * LDAP User id. + */ + public static final ASN1ObjectIdentifier UID = new ASN1ObjectIdentifier("0.9.2342.19200300.100.1.1"); - /** A HashMap with default symbols */ + /** + * A HashMap with default symbols + */ public static HashMap DefaultSymbols = new HashMap(); - + static { DefaultSymbols.put(C, "C"); DefaultSymbols.put(O, "O"); @@ -1552,83 +1576,91 @@ public class PdfPKCS7 { DefaultSymbols.put(INITIALS, "INITIALS"); DefaultSymbols.put(GENERATION, "GENERATION"); } - /** A HashMap with values */ + + /** + * A HashMap with values + */ public HashMap values = new HashMap(); /** * Constructs an X509 name + * * @param seq an ASN1 Sequence */ public X509Name(ASN1Sequence seq) { Enumeration e = seq.getObjects(); - + while (e.hasMoreElements()) { - ASN1Set set = (ASN1Set)e.nextElement(); - + ASN1Set set = (ASN1Set) e.nextElement(); + for (int i = 0; i < set.size(); i++) { - ASN1Sequence s = (ASN1Sequence)set.getObjectAt(i); - String id = (String)DefaultSymbols.get(s.getObjectAt(0)); + ASN1Sequence s = (ASN1Sequence) set.getObjectAt(i); + String id = (String) DefaultSymbols.get(s.getObjectAt(0)); if (id == null) continue; - ArrayList vs = (ArrayList)values.get(id); + ArrayList vs = (ArrayList) values.get(id); if (vs == null) { vs = new ArrayList(); values.put(id, vs); } - vs.add(((ASN1String)s.getObjectAt(1)).getString()); + vs.add(((ASN1String) s.getObjectAt(1)).getString()); } } } + /** * Constructs an X509 name + * * @param dirName a directory name */ public X509Name(String dirName) { - X509NameTokenizer nTok = new X509NameTokenizer(dirName); - + X509NameTokenizer nTok = new X509NameTokenizer(dirName); + while (nTok.hasMoreTokens()) { - String token = nTok.nextToken(); + String token = nTok.nextToken(); int index = token.indexOf('='); - + if (index == -1) { throw new IllegalArgumentException("badly formated directory string"); } - + String id = token.substring(0, index).toUpperCase(); String value = token.substring(index + 1); - ArrayList vs = (ArrayList)values.get(id); + ArrayList vs = (ArrayList) values.get(id); if (vs == null) { vs = new ArrayList(); values.put(id, vs); } vs.add(value); } - + } - + public String getField(String name) { - ArrayList vs = (ArrayList)values.get(name); - return vs == null ? null : (String)vs.get(0); + ArrayList vs = (ArrayList) values.get(name); + return vs == null ? null : (String) vs.get(0); } /** * gets a field array from the values Hashmap + * * @param name * @return an ArrayList */ public ArrayList getFieldArray(String name) { - ArrayList vs = (ArrayList)values.get(name); + ArrayList vs = (ArrayList) values.get(name); return vs == null ? null : vs; } - + /** * getter for values + * * @return a HashMap with the fields of the X509 name */ public HashMap getFields() { return values; } - + /** * @see java.lang.Object#toString() */ @@ -1636,7 +1668,7 @@ public class PdfPKCS7 { return values.toString(); } } - + /** * class for breaking up an X500 Name into it's component tokens, ala * java.util.StringTokenizer. We need this class as some of the @@ -1644,61 +1676,56 @@ public class PdfPKCS7 { * StringTokenizer. */ public static class X509NameTokenizer { - private String oid; - private int index; - private StringBuffer buf = new StringBuffer(); - + private String oid; + private int index; + private StringBuffer buf = new StringBuffer(); + public X509NameTokenizer( - String oid) { + String oid) { this.oid = oid; this.index = -1; } - + public boolean hasMoreTokens() { return (index != oid.length()); } - + public String nextToken() { if (index == oid.length()) { return null; } - - int end = index + 1; + + int end = index + 1; boolean quoted = false; boolean escaped = false; - + buf.setLength(0); - + while (end != oid.length()) { - char c = oid.charAt(end); - + char c = oid.charAt(end); + if (c == '"') { if (!escaped) { quoted = !quoted; - } - else { + } else { buf.append(c); } escaped = false; - } - else { + } else { if (escaped || quoted) { buf.append(c); escaped = false; - } - else if (c == '\\') { + } else if (c == '\\') { escaped = true; - } - else if (c == ',') { + } else if (c == ',') { break; - } - else { + } else { buf.append(c); } } end++; } - + index = end; return buf.toString().trim(); } diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPublicKeySecurityHandler.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPublicKeySecurityHandler.java index 1c5fc76f1..99c47bac3 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPublicKeySecurityHandler.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPublicKeySecurityHandler.java @@ -48,12 +48,124 @@ */ /** - * The below 2 methods are from pdfbox. - * - * private DERObject createDERForRecipient(byte[] in, X509Certificate cert) ; - * private KeyTransRecipientInfo computeRecipientInfo(X509Certificate x509certificate, byte[] abyte0); - * - * 2006-11-22 Aiken Sam. + * The below 2 methods are from pdfbox. + *
+ * private DERObject createDERForRecipient(byte[] in, X509Certificate cert) ; + * private KeyTransRecipientInfo computeRecipientInfo(X509Certificate x509certificate, byte[] abyte0); + *
+ * 2006-11-22 Aiken Sam. + *
+ * Copyright (c) 2003-2006, www.pdfbox.org + * All rights reserved. + *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + *
+ * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *
+ * http://www.pdfbox.org + *
+ * Copyright (c) 2003-2006, www.pdfbox.org + * All rights reserved. + *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + *
+ * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *
+ * http://www.pdfbox.org + *
+ * Copyright (c) 2003-2006, www.pdfbox.org + * All rights reserved. + *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + *
+ * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *
+ * http://www.pdfbox.org + *
+ * Copyright (c) 2003-2006, www.pdfbox.org + * All rights reserved. + *
+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + *
+ * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *
+ * http://www.pdfbox.org */ /** @@ -90,7 +202,9 @@ package com.fr.third.v2.lowagie.text.pdf; import com.fr.third.org.bouncycastle.asn1.ASN1Object; +import com.fr.third.org.bouncycastle.asn1.ASN1OutputStream; import com.fr.third.org.bouncycastle.asn1.ASN1Set; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -110,9 +224,8 @@ import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import com.fr.third.org.bouncycastle.asn1.ASN1InputStream; -import com.fr.third.org.bouncycastle.asn1.DERObjectIdentifier; +import com.fr.third.org.bouncycastle.asn1.ASN1ObjectIdentifier; import com.fr.third.org.bouncycastle.asn1.DEROctetString; -import com.fr.third.org.bouncycastle.asn1.DEROutputStream; import com.fr.third.org.bouncycastle.asn1.DERSet; import com.fr.third.org.bouncycastle.asn1.cms.ContentInfo; import com.fr.third.org.bouncycastle.asn1.cms.EncryptedContentInfo; @@ -129,11 +242,11 @@ import com.fr.third.org.bouncycastle.asn1.x509.TBSCertificateStructure; * @author Aiken Sam (aikensam@ieee.org) */ public class PdfPublicKeySecurityHandler { - + static final int SEED_LENGTH = 20; - + private ArrayList recipients = null; - + private byte[] seed = new byte[SEED_LENGTH]; public PdfPublicKeySecurityHandler() { @@ -141,56 +254,57 @@ public class PdfPublicKeySecurityHandler { try { key = KeyGenerator.getInstance("AES"); key.init(192, new SecureRandom()); - SecretKey sk = key.generateKey(); + SecretKey sk = key.generateKey(); System.arraycopy(sk.getEncoded(), 0, seed, 0, SEED_LENGTH); // create the 20 bytes seed } catch (NoSuchAlgorithmException e) { - seed = SecureRandom.getSeed(SEED_LENGTH); + seed = SecureRandom.getSeed(SEED_LENGTH); } - + recipients = new ArrayList(); } - /* + /* * Routine for decode output of PdfContentByte.escapeString(byte[] bytes). - * It should be moved to PdfContentByte. + * It should be moved to PdfContentByte. */ - + static public byte[] unescapedString(byte[] bytes) throws BadPdfFormatException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - + int index = 0; - - if (bytes[0] != '(' && bytes[bytes.length-1] != ')') throw new BadPdfFormatException("Expect '(' and ')' at begin and end of the string."); - + + if (bytes[0] != '(' && bytes[bytes.length - 1] != ')') + throw new BadPdfFormatException("Expect '(' and ')' at begin and end of the string."); + while (index < bytes.length) { if (bytes[index] == '\\') { index++; switch (bytes[index]) { - case 'b': - baos.write('\b'); - break; - case 'f': - baos.write('\f'); - break; - case 't': - baos.write('\t'); - break; - case 'n': - baos.write('\n'); - break; - case 'r': - baos.write('\r'); - break; - case '(': + case 'b': + baos.write('\b'); + break; + case 'f': + baos.write('\f'); + break; + case 't': + baos.write('\t'); + break; + case 'n': + baos.write('\n'); + break; + case 'r': + baos.write('\r'); + break; + case '(': baos.write('('); break; - case ')': + case ')': baos.write(')'); - break; - case '\\': - baos.write('\\'); - break; + break; + case '\\': + baos.write('\\'); + break; } } else baos.write(bytes[index]); @@ -198,92 +312,91 @@ public class PdfPublicKeySecurityHandler { } return baos.toByteArray(); } - + public void addRecipient(PdfPublicKeyRecipient recipient) { recipients.add(recipient); } - + protected byte[] getSeed() { - return (byte[])seed.clone(); + return (byte[]) seed.clone(); } /* public PdfPublicKeyRecipient[] getRecipients() { recipients.toArray(); return (PdfPublicKeyRecipient[])recipients.toArray(); }*/ - + public int getRecipientsSize() { return recipients.size(); } - + public byte[] getEncodedRecipient(int index) throws IOException, GeneralSecurityException { //Certificate certificate = recipient.getX509(); - PdfPublicKeyRecipient recipient = (PdfPublicKeyRecipient)recipients.get(index); + PdfPublicKeyRecipient recipient = (PdfPublicKeyRecipient) recipients.get(index); byte[] cms = recipient.getCms(); - + if (cms != null) return cms; - - Certificate certificate = recipient.getCertificate(); - int permission = recipient.getPermission();//PdfWriter.AllowCopy | PdfWriter.AllowPrinting | PdfWriter.AllowScreenReaders | PdfWriter.AllowAssembly; + + Certificate certificate = recipient.getCertificate(); + int permission = recipient.getPermission();//PdfWriter.AllowCopy | PdfWriter.AllowPrinting | PdfWriter.AllowScreenReaders | PdfWriter.AllowAssembly; int revision = 3; - - permission |= revision==3 ? 0xfffff0c0 : 0xffffffc0; + + permission |= revision == 3 ? 0xfffff0c0 : 0xffffffc0; permission &= 0xfffffffc; permission += 1; - + byte[] pkcs7input = new byte[24]; - - byte one = (byte)(permission); - byte two = (byte)(permission >> 8); - byte three = (byte)(permission >> 16); - byte four = (byte)(permission >> 24); + + byte one = (byte) (permission); + byte two = (byte) (permission >> 8); + byte three = (byte) (permission >> 16); + byte four = (byte) (permission >> 24); System.arraycopy(seed, 0, pkcs7input, 0, 20); // put this seed in the pkcs7 input - + pkcs7input[20] = four; - pkcs7input[21] = three; + pkcs7input[21] = three; pkcs7input[22] = two; pkcs7input[23] = one; - - ASN1Object obj = createDERForRecipient(pkcs7input, (X509Certificate)certificate); - + + ASN1Object obj = createDERForRecipient(pkcs7input, (X509Certificate) certificate); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - DEROutputStream k = new DEROutputStream(baos); - - k.writeObject(obj); - + + ASN1OutputStream k = ASN1OutputStream.create(baos); + + k.writeObject(obj); + cms = baos.toByteArray(); recipient.setCms(cms); - - return cms; + + return cms; } - - public PdfArray getEncodedRecipients() throws IOException, - GeneralSecurityException { + + public PdfArray getEncodedRecipients() throws IOException, + GeneralSecurityException { PdfArray EncodedRecipients = new PdfArray(); byte[] cms = null; - for (int i=0; i
0) { byte b = value[sIdx0 - 1]; - byte b2 = (byte) (~(b & 0xff) >> sIdx1 << sIdx1 + ((b & 0xff) << (32 - sIdx1) >> (32 - sIdx1))); + byte b2 = (byte) (b ^ (0xff - (int) Math.pow(2, eIdx1) + 1)); value[sIdx0 - 1] = b2; lenDiff += countInByte(b2) - countInByte(b); } @@ -75,7 +75,7 @@ public class RoaringBitmap { } if (eIdx1 > 0) { byte b = value[eIdx0]; - byte b2 = (byte) (((b & 0xff) >> eIdx1 << eIdx1) + ~(b & 0xff) << (32 - eIdx1) >> (32 - eIdx1)); + byte b2 = (byte) (b ^ ((int) Math.pow(2, eIdx1) - 1)); value[eIdx0] = b2; lenDiff += countInByte(b2) - countInByte(b); }