Skip to content

Commit e998a59

Browse files
author
gefeili
committed
Merge remote-tracking branch 'origin/sm2-key-exchange' into sm2-key-exchange
2 parents 5bb9713 + b0c834d commit e998a59

File tree

113 files changed

+937
-855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+937
-855
lines changed

bc-build.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# intended to hold user-specific settings that are *not* committed to
44
# the repository.
55

6-
release.suffix: 1.83
7-
release.name: 1.83
8-
release.version: 1.83
6+
release.suffix: 1.84-SNAPSHOT
7+
release.name: 1.84-SNAPSHOT
8+
release.version: 1.83.99
99
release.debug: false
1010

1111
mail.jar.home: ./libs/javax.mail-1.4.7.jar

core/src/main/java/org/bouncycastle/asn1/BEROctetString.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.IOException;
44

5+
import org.bouncycastle.util.Arrays;
6+
57
/**
68
* ASN.1 OctetStrings, with indefinite length rules, and <i>constructed form</i> support.
79
* <p>
@@ -19,10 +21,37 @@
1921
public class BEROctetString
2022
extends ASN1OctetString
2123
{
22-
private static final int DEFAULT_SEGMENT_LIMIT = 1000;
24+
public static final BEROctetString EMPTY = new BEROctetString(EMPTY_OCTETS);
2325

24-
private final int segmentLimit;
25-
private final ASN1OctetString[] elements;
26+
public static BEROctetString fromContents(byte[] contents)
27+
{
28+
if (contents == null)
29+
{
30+
throw new NullPointerException("'contents' cannot be null");
31+
}
32+
33+
return internalFromContents(contents);
34+
}
35+
36+
public static BEROctetString fromContentsOptional(byte[] contents)
37+
{
38+
return contents == null ? null : internalFromContents(contents);
39+
}
40+
41+
public static BEROctetString withContents(byte[] contents)
42+
{
43+
if (contents == null)
44+
{
45+
throw new NullPointerException("'contents' cannot be null");
46+
}
47+
48+
return internalWithContents(contents);
49+
}
50+
51+
public static BEROctetString withContentsOptional(byte[] contents)
52+
{
53+
return contents == null ? null : internalWithContents(contents);
54+
}
2655

2756
/**
2857
* Convert a vector of octet strings into a single byte string
@@ -58,6 +87,21 @@ static byte[] flattenOctetStrings(ASN1OctetString[] octetStrings)
5887
}
5988
}
6089

90+
static BEROctetString internalFromContents(byte[] contents)
91+
{
92+
return contents.length < 1 ? EMPTY : new BEROctetString(Arrays.clone(contents));
93+
}
94+
95+
static BEROctetString internalWithContents(byte[] contents)
96+
{
97+
return contents.length < 1 ? EMPTY : new BEROctetString(contents);
98+
}
99+
100+
private static final int DEFAULT_SEGMENT_LIMIT = 1000;
101+
102+
private final int segmentLimit;
103+
private final ASN1OctetString[] elements;
104+
61105
/**
62106
* Create an OCTET-STRING object from a byte[]
63107
* @param string the octets making up the octet string.

core/src/main/java/org/bouncycastle/asn1/DEROctetString.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,56 @@
22

33
import java.io.IOException;
44

5+
import org.bouncycastle.util.Arrays;
6+
57
/**
68
* Carrier class for a DER encoding OCTET STRING
79
*/
810
public class DEROctetString
911
extends ASN1OctetString
1012
{
13+
public static final DEROctetString EMPTY = new DEROctetString(EMPTY_OCTETS);
14+
15+
public static DEROctetString fromContents(byte[] contents)
16+
{
17+
if (contents == null)
18+
{
19+
throw new NullPointerException("'contents' cannot be null");
20+
}
21+
22+
return internalFromContents(contents);
23+
}
24+
25+
public static DEROctetString fromContentsOptional(byte[] contents)
26+
{
27+
return contents == null ? null : internalFromContents(contents);
28+
}
29+
30+
public static DEROctetString withContents(byte[] contents)
31+
{
32+
if (contents == null)
33+
{
34+
throw new NullPointerException("'contents' cannot be null");
35+
}
36+
37+
return internalWithContents(contents);
38+
}
39+
40+
public static DEROctetString withContentsOptional(byte[] contents)
41+
{
42+
return contents == null ? null : internalWithContents(contents);
43+
}
44+
45+
static DEROctetString internalFromContents(byte[] contents)
46+
{
47+
return contents.length < 1 ? EMPTY : new DEROctetString(Arrays.clone(contents));
48+
}
49+
50+
static DEROctetString internalWithContents(byte[] contents)
51+
{
52+
return contents.length < 1 ? EMPTY : new DEROctetString(contents);
53+
}
54+
1155
/**
1256
* Base constructor.
1357
*

core/src/main/java/org/bouncycastle/asn1/sec/SECObjectIdentifiers.java

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
*/
1616
public interface SECObjectIdentifiers
1717
{
18-
/** Base OID: 1.3.132.0 */
19-
static final ASN1ObjectIdentifier ellipticCurve = new ASN1ObjectIdentifier("1.3.132.0");
18+
static final ASN1ObjectIdentifier certicom = new ASN1ObjectIdentifier("1.3.132");
19+
20+
static final ASN1ObjectIdentifier ellipticCurve = certicom.branch("0");
2021

2122
/** sect163k1 OID: 1.3.132.0.1 */
2223
static final ASN1ObjectIdentifier sect163k1 = ellipticCurve.branch("1");
@@ -86,25 +87,52 @@ public interface SECObjectIdentifiers
8687
/** secp256r1 OID: 1.3.132.0.prime256v1 */
8788
static final ASN1ObjectIdentifier secp256r1 = X9ObjectIdentifiers.prime256v1;
8889

89-
static final ASN1ObjectIdentifier secg_scheme = new ASN1ObjectIdentifier("1.3.132.1");
90+
static final ASN1ObjectIdentifier secg_scheme = certicom.branch("1");
91+
92+
static final ASN1ObjectIdentifier dhSinglePass_cofactorDH_recommendedKDF = secg_scheme.branch("1");
93+
static final ASN1ObjectIdentifier dhSinglePass_cofactorDH_specifiedKDF = secg_scheme.branch("2");
94+
static final ASN1ObjectIdentifier mqvSinglePass_recommendedKDF = secg_scheme.branch("3");
95+
static final ASN1ObjectIdentifier mqvSinglePass_specifiedKDF = secg_scheme.branch("4");
96+
static final ASN1ObjectIdentifier mqvFull_recommendedKDF = secg_scheme.branch("5");
97+
static final ASN1ObjectIdentifier mqvFull_specifiedKDF = secg_scheme.branch("6");
98+
static final ASN1ObjectIdentifier ecies_recommendedParameters = secg_scheme.branch("7");
99+
static final ASN1ObjectIdentifier ecies_specifiedParameters = secg_scheme.branch("8");
100+
101+
static final ASN1ObjectIdentifier dhSinglePass_stdDH_kdf_schemes = secg_scheme.branch("11");
102+
103+
static final ASN1ObjectIdentifier dhSinglePass_stdDH_sha224kdf_scheme = dhSinglePass_stdDH_kdf_schemes.branch("0");
104+
static final ASN1ObjectIdentifier dhSinglePass_stdDH_sha256kdf_scheme = dhSinglePass_stdDH_kdf_schemes.branch("1");
105+
static final ASN1ObjectIdentifier dhSinglePass_stdDH_sha384kdf_scheme = dhSinglePass_stdDH_kdf_schemes.branch("2");
106+
static final ASN1ObjectIdentifier dhSinglePass_stdDH_sha512kdf_scheme = dhSinglePass_stdDH_kdf_schemes.branch("3");
107+
108+
static final ASN1ObjectIdentifier ecdh = secg_scheme.branch("12");
109+
static final ASN1ObjectIdentifier ecmqv = secg_scheme.branch("13");
110+
111+
static final ASN1ObjectIdentifier dhSinglePass_cofactorDH_kdf_schemes = secg_scheme.branch("14");
112+
113+
static final ASN1ObjectIdentifier dhSinglePass_cofactorDH_sha224kdf_scheme = dhSinglePass_cofactorDH_kdf_schemes.branch("0");
114+
static final ASN1ObjectIdentifier dhSinglePass_cofactorDH_sha256kdf_scheme = dhSinglePass_cofactorDH_kdf_schemes.branch("1");
115+
static final ASN1ObjectIdentifier dhSinglePass_cofactorDH_sha384kdf_scheme = dhSinglePass_cofactorDH_kdf_schemes.branch("2");
116+
static final ASN1ObjectIdentifier dhSinglePass_cofactorDH_sha512kdf_scheme = dhSinglePass_cofactorDH_kdf_schemes.branch("3");
117+
118+
static final ASN1ObjectIdentifier mqvSinglePass_kdf_schemes = secg_scheme.branch("15");
119+
120+
static final ASN1ObjectIdentifier mqvSinglePass_sha224kdf_scheme = mqvSinglePass_kdf_schemes.branch("0");
121+
static final ASN1ObjectIdentifier mqvSinglePass_sha256kdf_scheme = mqvSinglePass_kdf_schemes.branch("1");
122+
static final ASN1ObjectIdentifier mqvSinglePass_sha384kdf_scheme = mqvSinglePass_kdf_schemes.branch("2");
123+
static final ASN1ObjectIdentifier mqvSinglePass_sha512kdf_scheme = mqvSinglePass_kdf_schemes.branch("3");
90124

91-
static final ASN1ObjectIdentifier dhSinglePass_stdDH_sha224kdf_scheme = secg_scheme.branch("11.0");
92-
static final ASN1ObjectIdentifier dhSinglePass_stdDH_sha256kdf_scheme = secg_scheme.branch("11.1");
93-
static final ASN1ObjectIdentifier dhSinglePass_stdDH_sha384kdf_scheme = secg_scheme.branch("11.2");
94-
static final ASN1ObjectIdentifier dhSinglePass_stdDH_sha512kdf_scheme = secg_scheme.branch("11.3");
125+
static final ASN1ObjectIdentifier mqvFull_kdf_schemes = secg_scheme.branch("16");
95126

96-
static final ASN1ObjectIdentifier dhSinglePass_cofactorDH_sha224kdf_scheme = secg_scheme.branch("14.0");
97-
static final ASN1ObjectIdentifier dhSinglePass_cofactorDH_sha256kdf_scheme = secg_scheme.branch("14.1");
98-
static final ASN1ObjectIdentifier dhSinglePass_cofactorDH_sha384kdf_scheme = secg_scheme.branch("14.2");
99-
static final ASN1ObjectIdentifier dhSinglePass_cofactorDH_sha512kdf_scheme = secg_scheme.branch("14.3");
127+
static final ASN1ObjectIdentifier mqvFull_sha224kdf_scheme = mqvFull_kdf_schemes.branch("0");
128+
static final ASN1ObjectIdentifier mqvFull_sha256kdf_scheme = mqvFull_kdf_schemes.branch("1");
129+
static final ASN1ObjectIdentifier mqvFull_sha384kdf_scheme = mqvFull_kdf_schemes.branch("2");
130+
static final ASN1ObjectIdentifier mqvFull_sha512kdf_scheme = mqvFull_kdf_schemes.branch("3");
100131

101-
static final ASN1ObjectIdentifier mqvSinglePass_sha224kdf_scheme = secg_scheme.branch("15.0");
102-
static final ASN1ObjectIdentifier mqvSinglePass_sha256kdf_scheme = secg_scheme.branch("15.1");
103-
static final ASN1ObjectIdentifier mqvSinglePass_sha384kdf_scheme = secg_scheme.branch("15.2");
104-
static final ASN1ObjectIdentifier mqvSinglePass_sha512kdf_scheme = secg_scheme.branch("15.3");
132+
static final ASN1ObjectIdentifier kdf_algorithms = secg_scheme.branch("17");
105133

106-
static final ASN1ObjectIdentifier mqvFull_sha224kdf_scheme = secg_scheme.branch("16.0");
107-
static final ASN1ObjectIdentifier mqvFull_sha256kdf_scheme = secg_scheme.branch("16.1");
108-
static final ASN1ObjectIdentifier mqvFull_sha384kdf_scheme = secg_scheme.branch("16.2");
109-
static final ASN1ObjectIdentifier mqvFull_sha512kdf_scheme = secg_scheme.branch("16.3");
134+
static final ASN1ObjectIdentifier x9_63_kdf = kdf_algorithms.branch("0");
135+
static final ASN1ObjectIdentifier nist_concatenation_kdf = kdf_algorithms.branch("1");
136+
static final ASN1ObjectIdentifier tls_kdf = kdf_algorithms.branch("2");
137+
static final ASN1ObjectIdentifier ikev2_kdf = kdf_algorithms.branch("3");
110138
}

core/src/main/java/org/bouncycastle/asn1/x9/KeySpecificInfo.java

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package org.bouncycastle.asn1.x9;
22

3-
import java.util.Enumeration;
4-
53
import org.bouncycastle.asn1.ASN1Object;
64
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
75
import org.bouncycastle.asn1.ASN1OctetString;
86
import org.bouncycastle.asn1.ASN1Primitive;
97
import org.bouncycastle.asn1.ASN1Sequence;
8+
import org.bouncycastle.asn1.ASN1TaggedObject;
109
import org.bouncycastle.asn1.DERSequence;
1110

1211
/**
@@ -22,23 +21,6 @@
2221
public class KeySpecificInfo
2322
extends ASN1Object
2423
{
25-
private ASN1ObjectIdentifier algorithm;
26-
private ASN1OctetString counter;
27-
28-
/**
29-
* Base constructor.
30-
*
31-
* @param algorithm algorithm identifier for the CEK.
32-
* @param counter initial counter value for key derivation.
33-
*/
34-
public KeySpecificInfo(
35-
ASN1ObjectIdentifier algorithm,
36-
ASN1OctetString counter)
37-
{
38-
this.algorithm = algorithm;
39-
this.counter = counter;
40-
}
41-
4224
/**
4325
* Return a KeySpecificInfo object from the passed in object.
4426
*
@@ -59,13 +41,50 @@ else if (obj != null)
5941
return null;
6042
}
6143

62-
private KeySpecificInfo(
63-
ASN1Sequence seq)
44+
public static KeySpecificInfo getInstance(ASN1TaggedObject taggedObject, boolean declaredExplicit)
45+
{
46+
return new KeySpecificInfo(ASN1Sequence.getInstance(taggedObject, declaredExplicit));
47+
}
48+
49+
public static KeySpecificInfo getTagged(ASN1TaggedObject taggedObject, boolean declaredExplicit)
50+
{
51+
return new KeySpecificInfo(ASN1Sequence.getTagged(taggedObject, declaredExplicit));
52+
}
53+
54+
private final ASN1ObjectIdentifier algorithm;
55+
private final ASN1OctetString counter;
56+
57+
private KeySpecificInfo(ASN1Sequence seq)
6458
{
65-
Enumeration e = seq.getObjects();
59+
int count = seq.size();
60+
if (count != 2)
61+
{
62+
throw new IllegalArgumentException("Bad sequence size: " + count);
63+
}
64+
65+
this.algorithm = ASN1ObjectIdentifier.getInstance(seq.getObjectAt(0));
66+
this.counter = ASN1OctetString.getInstance(seq.getObjectAt(1));
67+
}
6668

67-
algorithm = (ASN1ObjectIdentifier)e.nextElement();
68-
counter = (ASN1OctetString)e.nextElement();
69+
/**
70+
* Base constructor.
71+
*
72+
* @param algorithm algorithm identifier for the CEK.
73+
* @param counter initial counter value for key derivation.
74+
*/
75+
public KeySpecificInfo(ASN1ObjectIdentifier algorithm, ASN1OctetString counter)
76+
{
77+
if (algorithm == null)
78+
{
79+
throw new NullPointerException("'algorithm' cannot be null");
80+
}
81+
if (counter == null)
82+
{
83+
throw new NullPointerException("'counter' cannot be null");
84+
}
85+
86+
this.algorithm = algorithm;
87+
this.counter = counter;
6988
}
7089

7190
/**

0 commit comments

Comments
 (0)