Skip to content

Commit 7924ec4

Browse files
author
gefeili
committed
Merge branch 'main' into pqc-mayo
2 parents ad11e9b + 2c4f6f8 commit 7924ec4

File tree

80 files changed

+907
-2357
lines changed

Some content is hidden

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

80 files changed

+907
-2357
lines changed

ant/jdk14.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@
196196
<exclude name="**/TlsClientRawKeysTest.java"/>
197197
</fileset>
198198

199-
<fileset dir="tls/src/test/resources" includes="**/*.*"/>
200-
201199
<fileset dir="core/src/test/" includes="**/*.properties"/>
202200
<fileset dir="prov/src/main/resources" includes="**/*.properties"/>
203201
<fileset dir="pkix/src/test/resources" includes="**/*.*"/>

ant/jdk15+.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
<fileset dir="tls/src/main/java" includes="**/*.java" />
4444
<fileset dir="tls/src/main/javadoc" includes="**/*.html" />
4545
<fileset dir="tls/src/test/java" includes="**/*.java" />
46-
<fileset dir="tls/src/test/resources" includes="**/*.*" />
4746

4847
<fileset dir="pkix/src/main/java" includes="**/*.java" />
4948
<fileset dir="pkix/src/main/javadoc" includes="**/*.html" />

ant/jdk18+.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
<fileset dir="tls/src/main/jdk1.5" includes="**/*.java" />
4444
<fileset dir="tls/src/main/javadoc" includes="**/*.html" />
4545
<fileset dir="tls/src/test/java" includes="**/*.java" />
46-
<fileset dir="tls/src/test/resources" includes="**/*.*" />
4746

4847
<fileset dir="pkix/src/main/java" includes="**/*.java" />
4948
<fileset dir="pkix/src/main/javadoc" includes="**/*.html" />

ci/check_java.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ export JAVA_HOME=`openjdk_21`
1515
export PATH=$JAVA_HOME/bin:$PATH
1616

1717
# Checkstyle
18-
./gradlew check -x test;
18+
./gradlew clean build check -x test;
1919

2020

2121
# OSGI scanner only, no testing
22-
./gradlew clean build -x test
2322
./osgi_scan.sh
2423

24+
25+
# module tester
26+
./run_mtt.sh

core/src/main/java/org/bouncycastle/crypto/digests/ParallelHash.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class ParallelHash
3838
* Base constructor.
3939
*
4040
* @param bitLength security strength (bits) of the underlying SHAKE function, 128 or 256.
41-
* @param S the customization string - available for local use.
42-
* @param B the blocksize (in bytes) for hashing.
41+
* @param S the customization string - available for local use.
42+
* @param B the blocksize (in bytes) for hashing.
4343
*/
4444
public ParallelHash(int bitLength, byte[] S, int B)
4545
{
@@ -50,12 +50,18 @@ public ParallelHash(int bitLength, byte[] S, int B, int outputSize)
5050
{
5151
this(bitLength, S, B, outputSize, CryptoServicePurpose.ANY);
5252
}
53+
5354
public ParallelHash(int bitLength, byte[] S, int B, int outputSize, CryptoServicePurpose purpose)
5455
{
56+
if (B <= 0)
57+
{
58+
throw new IllegalArgumentException("block size should be greater than 0");
59+
}
5560
this.cshake = new CSHAKEDigest(bitLength, N_PARALLEL_HASH, S);
5661
this.compressor = new CSHAKEDigest(bitLength, new byte[0], new byte[0]);
5762
this.bitLength = bitLength;
5863
this.B = B;
64+
5965
this.outputLength = (outputSize + 7) / 8;
6066
this.buffer = new byte[B];
6167
this.compressorBuffer = new byte[bitLength * 2 / 8];
@@ -112,7 +118,7 @@ public void update(byte in)
112118
public void update(byte[] in, int inOff, int len)
113119
throws DataLengthException, IllegalStateException
114120
{
115-
len = Math.max(0, len);
121+
len = Math.max(0, len);
116122

117123
//
118124
// fill the current word
@@ -198,7 +204,7 @@ public int doFinal(byte[] out, int outOff, int outLen)
198204
{
199205
wrapUp(outputLength);
200206
}
201-
207+
202208
int rv = cshake.doFinal(out, outOff, outLen);
203209

204210
reset();

core/src/test/java/org/bouncycastle/crypto/test/PKCS12Test.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator;
77
import org.bouncycastle.crypto.params.KeyParameter;
88
import org.bouncycastle.crypto.params.ParametersWithIV;
9+
import org.bouncycastle.util.Arrays;
910
import org.bouncycastle.util.encoders.Hex;
1011
import org.bouncycastle.util.test.SimpleTestResult;
1112
import org.bouncycastle.util.test.Test;
@@ -22,26 +23,6 @@ public class PKCS12Test
2223
char[] password1 = { 's', 'm', 'e', 'g' };
2324
char[] password2 = { 'q', 'u', 'e', 'e', 'g' };
2425

25-
private boolean isEqual(
26-
byte[] a,
27-
byte[] b)
28-
{
29-
if (a.length != b.length)
30-
{
31-
return false;
32-
}
33-
34-
for (int i = 0; i != a.length; i++)
35-
{
36-
if (a[i] != b[i])
37-
{
38-
return false;
39-
}
40-
}
41-
42-
return true;
43-
}
44-
4526
private TestResult run1(
4627
int id,
4728
char[] password,
@@ -59,7 +40,7 @@ private TestResult run1(
5940

6041
CipherParameters key = generator.generateDerivedParameters(24 * 8);
6142

62-
if (isEqual(result, ((KeyParameter)key).getKey()))
43+
if (Arrays.areEqual(result, ((KeyParameter)key).getKey()))
6344
{
6445
return new SimpleTestResult(true, "PKCS12Test: Okay");
6546
}
@@ -87,7 +68,7 @@ private TestResult run2(
8768

8869
ParametersWithIV params = (ParametersWithIV)generator.generateDerivedParameters(64, 64);
8970

90-
if (isEqual(result, params.getIV()))
71+
if (Arrays.areEqual(result, params.getIV()))
9172
{
9273
return new SimpleTestResult(true, "PKCS12Test: Okay");
9374
}
@@ -115,7 +96,7 @@ private TestResult run3(
11596

11697
CipherParameters key = generator.generateDerivedMacParameters(160);
11798

118-
if (isEqual(result, ((KeyParameter)key).getKey()))
99+
if (Arrays.areEqual(result, ((KeyParameter)key).getKey()))
119100
{
120101
return new SimpleTestResult(true, "PKCS12Test: Okay");
121102
}

core/src/test/java/org/bouncycastle/crypto/test/ParallelHashTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.bouncycastle.crypto.test;
22

3+
34
import org.bouncycastle.crypto.Digest;
45
import org.bouncycastle.crypto.digests.ParallelHash;
56
import org.bouncycastle.util.Arrays;
@@ -23,6 +24,7 @@ public String getName()
2324
public void performTest()
2425
throws Exception
2526
{
27+
testException();
2628
ParallelHash pHash = new ParallelHash(128, new byte[0], 8);
2729

2830
byte[] data = Hex.decode("00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27");
@@ -164,6 +166,19 @@ private void testClone()
164166
}
165167
}
166168

169+
private void testException()
170+
{
171+
testException("block size should be greater than 0", "IllegalArgumentException", new TestExceptionOperation()
172+
{
173+
@Override
174+
public void operation()
175+
throws Exception
176+
{
177+
Digest digest = new ParallelHash(128, null, 0);
178+
}
179+
});
180+
}
181+
167182
public static void main(
168183
String[] args)
169184
{

pg/src/main/java/org/bouncycastle/openpgp/PGPSignatureSubpacketGenerator.java

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ public PGPSignatureSubpacketGenerator(PGPSignatureSubpacketVector sigSubV)
6969
*/
7070
public void setRevocable(boolean isCritical, boolean isRevocable)
7171
{
72-
if (contains(SignatureSubpacketTags.REVOCABLE))
73-
{
74-
throw new IllegalStateException("Revocable exists in the Signature Subpacket Generator");
75-
}
72+
removePacketsOfType(SignatureSubpacketTags.REVOCABLE);
7673
packets.add(new Revocable(isCritical, isRevocable));
7774
}
7875

@@ -97,21 +94,19 @@ public void setExportable(boolean isExportable)
9794
*/
9895
public void setExportable(boolean isCritical, boolean isExportable)
9996
{
100-
if (contains(SignatureSubpacketTags.EXPORTABLE))
101-
{
102-
throw new IllegalStateException("Exportable Certification exists in the Signature Subpacket Generator");
103-
}
97+
removePacketsOfType(SignatureSubpacketTags.EXPORTABLE);
10498
packets.add(new Exportable(isCritical, isExportable));
10599
}
106100

107101
/**
108102
* Specify the set of features of the key.
109103
*
110104
* @param isCritical true if should be treated as critical, false otherwise.
111-
* @param feature features
105+
* @param feature features bitmap
112106
*/
113107
public void setFeature(boolean isCritical, byte feature)
114108
{
109+
removePacketsOfType(SignatureSubpacketTags.FEATURES);
115110
packets.add(new Features(isCritical, feature));
116111
}
117112

@@ -126,6 +121,7 @@ public void setFeature(boolean isCritical, byte feature)
126121
*/
127122
public void setTrust(boolean isCritical, int depth, int trustAmount)
128123
{
124+
removePacketsOfType(SignatureSubpacketTags.TRUST_SIG);
129125
packets.add(new TrustSignature(isCritical, depth, trustAmount));
130126
}
131127

@@ -150,6 +146,7 @@ public void setKeyExpirationTime(long seconds)
150146
*/
151147
public void setKeyExpirationTime(boolean isCritical, long seconds)
152148
{
149+
removePacketsOfType(SignatureSubpacketTags.KEY_EXPIRE_TIME);
153150
packets.add(new KeyExpirationTime(isCritical, seconds));
154151
}
155152

@@ -175,6 +172,7 @@ public void setSignatureExpirationTime(long seconds)
175172
*/
176173
public void setSignatureExpirationTime(boolean isCritical, long seconds)
177174
{
175+
removePacketsOfType(SignatureSubpacketTags.EXPIRE_TIME);
178176
packets.add(new SignatureExpirationTime(isCritical, seconds));
179177
}
180178

@@ -200,6 +198,7 @@ public void setSignatureCreationTime(Date date)
200198
*/
201199
public void setSignatureCreationTime(boolean isCritical, Date date)
202200
{
201+
removePacketsOfType(SignatureSubpacketTags.CREATION_TIME);
203202
packets.add(new SignatureCreationTime(isCritical, date));
204203
}
205204

@@ -212,6 +211,7 @@ public void setSignatureCreationTime(boolean isCritical, Date date)
212211
*/
213212
public void setPreferredHashAlgorithms(boolean isCritical, int[] algorithms)
214213
{
214+
removePacketsOfType(SignatureSubpacketTags.PREFERRED_HASH_ALGS);
215215
packets.add(new PreferredAlgorithms(SignatureSubpacketTags.PREFERRED_HASH_ALGS, isCritical,
216216
algorithms));
217217
}
@@ -225,6 +225,7 @@ public void setPreferredHashAlgorithms(boolean isCritical, int[] algorithms)
225225
*/
226226
public void setPreferredSymmetricAlgorithms(boolean isCritical, int[] algorithms)
227227
{
228+
removePacketsOfType(SignatureSubpacketTags.PREFERRED_SYM_ALGS);
228229
packets.add(new PreferredAlgorithms(SignatureSubpacketTags.PREFERRED_SYM_ALGS, isCritical,
229230
algorithms));
230231
}
@@ -238,6 +239,7 @@ public void setPreferredSymmetricAlgorithms(boolean isCritical, int[] algorithms
238239
*/
239240
public void setPreferredCompressionAlgorithms(boolean isCritical, int[] algorithms)
240241
{
242+
removePacketsOfType(SignatureSubpacketTags.PREFERRED_COMP_ALGS);
241243
packets.add(new PreferredAlgorithms(SignatureSubpacketTags.PREFERRED_COMP_ALGS, isCritical,
242244
algorithms));
243245
}
@@ -254,6 +256,7 @@ public void setPreferredCompressionAlgorithms(boolean isCritical, int[] algorith
254256
@Deprecated
255257
public void setPreferredAEADAlgorithms(boolean isCritical, int[] algorithms)
256258
{
259+
removePacketsOfType(SignatureSubpacketTags.PREFERRED_AEAD_ALGORITHMS);
257260
packets.add(new PreferredAlgorithms(SignatureSubpacketTags.PREFERRED_AEAD_ALGORITHMS, isCritical,
258261
algorithms));
259262
}
@@ -268,6 +271,7 @@ public void setPreferredAEADAlgorithms(boolean isCritical, int[] algorithms)
268271
*/
269272
public void setPreferredAEADCiphersuites(boolean isCritical, PreferredAEADCiphersuites.Combination[] algorithms)
270273
{
274+
removePacketsOfType(SignatureSubpacketTags.PREFERRED_AEAD_ALGORITHMS);
271275
packets.add(new PreferredAEADCiphersuites(isCritical, algorithms));
272276
}
273277

@@ -280,6 +284,7 @@ public void setPreferredAEADCiphersuites(boolean isCritical, PreferredAEADCipher
280284
*/
281285
public void setPreferredAEADCiphersuites(PreferredAEADCiphersuites.Builder builder)
282286
{
287+
removePacketsOfType(SignatureSubpacketTags.PREFERRED_AEAD_ALGORITHMS);
283288
packets.add(builder.build());
284289
}
285290

@@ -300,6 +305,7 @@ public void setPreferredAEADCiphersuites(PreferredAEADCiphersuites.Builder build
300305
@Deprecated
301306
public void setPreferredLibrePgpEncryptionModes(boolean isCritical, int[] algorithms)
302307
{
308+
removePacketsOfType(SignatureSubpacketTags.LIBREPGP_PREFERRED_ENCRYPTION_MODES);
303309
packets.add(new LibrePGPPreferredEncryptionModes(isCritical, algorithms));
304310
}
305311

@@ -309,8 +315,22 @@ public void setPreferredLibrePgpEncryptionModes(boolean isCritical, int[] algori
309315
*
310316
* @param isCritical true if the subpacket should be treated as critical
311317
* @param uri key server URI
318+
* @deprecated use {@link #addPreferredKeyServer(boolean, String)} instead.
312319
*/
320+
@Deprecated
313321
public void setPreferredKeyServer(boolean isCritical, String uri)
322+
{
323+
addPreferredKeyServer(isCritical, uri);
324+
}
325+
326+
/**
327+
* Specify a preferred key server for the signed user-id / key.
328+
* Note, that the key server might also be a http/ftp etc. URI pointing to the key itself.
329+
*
330+
* @param isCritical true if the subpacket should be treated as critical
331+
* @param uri key server URI
332+
*/
333+
public void addPreferredKeyServer(boolean isCritical, String uri)
314334
{
315335
packets.add(new PreferredKeyServer(isCritical, uri));
316336
}
@@ -341,6 +361,7 @@ public void setKeyFlags(int flags)
341361
*/
342362
public void setKeyFlags(boolean isCritical, int flags)
343363
{
364+
removePacketsOfType(SignatureSubpacketTags.KEY_FLAGS);
344365
packets.add(new KeyFlags(isCritical, flags));
345366
}
346367

@@ -443,6 +464,7 @@ public void addEmbeddedSignature(boolean isCritical, PGPSignature pgpSignature)
443464

444465
public void setPrimaryUserID(boolean isCritical, boolean isPrimaryUserID)
445466
{
467+
removePacketsOfType(SignatureSubpacketTags.PRIMARY_USER_ID);
446468
packets.add(new PrimaryUserID(isCritical, isPrimaryUserID));
447469
}
448470

@@ -485,6 +507,7 @@ public void addNotationData(boolean isCritical, boolean isHumanReadable, String
485507
*/
486508
public void setRevocationReason(boolean isCritical, byte reason, String description)
487509
{
510+
removePacketsOfType(SignatureSubpacketTags.REVOCATION_REASON);
488511
packets.add(new RevocationReason(isCritical, reason, description));
489512
}
490513

@@ -523,6 +546,7 @@ public void addRevocationKey(boolean isCritical, int keyAlgorithm, byte[] finger
523546
*/
524547
public void setIssuerKeyID(boolean isCritical, long keyID)
525548
{
549+
removePacketsOfType(SignatureSubpacketTags.ISSUER_KEY_ID);
526550
packets.add(new IssuerKeyID(isCritical, keyID));
527551
}
528552

@@ -536,6 +560,7 @@ public void setIssuerKeyID(boolean isCritical, long keyID)
536560
*/
537561
public void setSignatureTarget(boolean isCritical, int publicKeyAlgorithm, int hashAlgorithm, byte[] hashData)
538562
{
563+
removePacketsOfType(SignatureSubpacketTags.SIGNATURE_TARGET);
539564
packets.add(new SignatureTarget(isCritical, publicKeyAlgorithm, hashAlgorithm, hashData));
540565
}
541566

@@ -558,6 +583,7 @@ public void setIssuerFingerprint(boolean isCritical, PGPSecretKey secretKey)
558583
*/
559584
public void setIssuerFingerprint(boolean isCritical, PGPPublicKey publicKey)
560585
{
586+
removePacketsOfType(SignatureSubpacketTags.ISSUER_FINGERPRINT);
561587
packets.add(new IssuerFingerprint(isCritical, publicKey.getVersion(), publicKey.getFingerprint()));
562588
}
563589

0 commit comments

Comments
 (0)