Skip to content

Commit 49695cf

Browse files
author
gefeili
committed
Merge branch 'main' into ascon-update
2 parents 9544976 + 4a723e3 commit 49695cf

File tree

38 files changed

+2022
-516
lines changed

38 files changed

+2022
-516
lines changed

core/src/main/java/org/bouncycastle/asn1/bc/BCObjectIdentifiers.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,43 @@ public interface BCObjectIdentifiers
365365
/** 2.16.840.1.114027.80.8.1.13 OQS_OID_MLDSA87_ed448 */
366366
ASN1ObjectIdentifier mldsa87_ed448 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.8.1.13");
367367

368+
/** 2.16.840.1.114027.80.9.1.0 id-MLDSA44-RSA2048-PSS-SHA256 */
369+
ASN1ObjectIdentifier id_MLDSA44_RSA2048_PSS_SHA256 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.0");
370+
/** 2.16.840.1.114027.80.9.1.1 id-MLDSA44-RSA2048-PKCS15-SHA256 */
371+
ASN1ObjectIdentifier id_MLDSA44_RSA2048_PKCS15_SHA256 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.1");
372+
/** 2.16.840.1.114027.80.9.1.2 id-MLDSA44-Ed25519-SHA512 */
373+
ASN1ObjectIdentifier id_MLDSA44_Ed25519_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.2");
374+
/** 2.16.840.1.114027.80.9.1.3 id-MLDSA44-ECDSA-P256-SHA256 */
375+
ASN1ObjectIdentifier id_MLDSA44_ECDSA_P256_SHA256 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.3");
376+
/** 2.16.840.1.114027.80.9.1.4 id-MLDSA65-RSA3072-PSS-SHA512 */
377+
ASN1ObjectIdentifier id_MLDSA65_RSA3072_PSS_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.4");
378+
/** 2.16.840.1.114027.80.9.1.5 id-MLDSA65-RSA3072-PKCS15-SHA512 */
379+
ASN1ObjectIdentifier id_MLDSA65_RSA3072_PKCS15_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.5");
380+
/** 2.16.840.1.114027.80.9.1.6 id-MLDSA65-RSA4096-PSS-SHA512 */
381+
ASN1ObjectIdentifier id_MLDSA65_RSA4096_PSS_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.6");
382+
/** 2.16.840.1.114027.80.9.1.7 id-MLDSA65-RSA4096-PKCS15-SHA512 */
383+
ASN1ObjectIdentifier id_MLDSA65_RSA4096_PKCS15_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.7");
384+
/** 2.16.840.1.114027.80.9.1.8 id-MLDSA65-ECDSA-P256-SHA512 */
385+
ASN1ObjectIdentifier id_MLDSA65_ECDSA_P256_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.8");
386+
/** 2.16.840.1.114027.80.9.1.9 id-MLDSA65-ECDSA-P384-SHA512 */
387+
ASN1ObjectIdentifier id_MLDSA65_ECDSA_P384_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.9");
388+
/** 2.16.840.1.114027.80.9.1.10 id-MLDSA65-ECDSA-brainpoolP256r1-SHA512 */
389+
ASN1ObjectIdentifier id_MLDSA65_ECDSA_brainpoolP256r1_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.10");
390+
/** 2.16.840.1.114027.80.9.1.11 id-MLDSA65-Ed25519-SHA512 */
391+
ASN1ObjectIdentifier id_MLDSA65_Ed25519_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.11");
392+
/** 2.16.840.1.114027.80.9.1.12 id-MLDSA87-ECDSA-P384-SHA512 */
393+
ASN1ObjectIdentifier id_MLDSA87_ECDSA_P384_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.12");
394+
/** 2.16.840.1.114027.80.9.1.13 id-MLDSA87-ECDSA-brainpoolP384r1-SHA512 */
395+
ASN1ObjectIdentifier id_MLDSA87_ECDSA_brainpoolP384r1_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.13");
396+
/** 2.16.840.1.114027.80.9.1.14 id-MLDSA87-Ed448-SHAKE256 */
397+
ASN1ObjectIdentifier id_MLDSA87_Ed448_SHAKE256 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.14");
398+
/** 2.16.840.1.114027.80.9.1.15 id-MLDSA87-RSA3072-PSS-SHA512 */
399+
ASN1ObjectIdentifier id_MLDSA87_RSA3072_PSS_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.15");
400+
/** 2.16.840.1.114027.80.9.1.16 id-MLDSA87-RSA4096-PSS-SHA512 */
401+
ASN1ObjectIdentifier id_MLDSA87_RSA4096_PSS_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.16");
402+
/** 2.16.840.1.114027.80.9.1.17 id-MLDSA87-ECDSA-P521-SHA512 */
403+
ASN1ObjectIdentifier id_MLDSA87_ECDSA_P521_SHA512 = new ASN1ObjectIdentifier("2.16.840.1.114027.80.9.1.17");
404+
368405
/*
369406
* Rainbow
370407
*/

core/src/main/java/org/bouncycastle/asn1/gm/GMObjectIdentifiers.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ public interface GMObjectIdentifiers
5252
* <Information security technology — Cryptographic application identifier criterion specification>
5353
* <url>http://c.gb688.cn/bzgk/gb/showGb?type=online&hcno=252CF0F72A7BE339A56DEA7D774E8994</url>,
5454
* Page 21 only cover from 301.1 to 301.3
55-
* */
56-
ASN1ObjectIdentifier wapip192v1 = sm_scheme.branch("301.101");
55+
*/
56+
ASN1ObjectIdentifier wapip192v1 = sm_scheme.branch("301.101");
5757
/**
5858
* <WAPI certificate management—Part 5: Example of certificate format (draft)>
5959
* <url>http://www.chinabwips.org.cn/zqyjgs1.htm</url> and
6060
* <url>http://www.chinabwips.org.cn/doc/101.pdf</url>,
6161
* Page 9 and page 10 states the OID of ECDSA-192 algorithm based on SHA-256 is 1.2.156.11235.1.1.1
62-
* */
63-
ASN1ObjectIdentifier wapi192v1 = new ASN1ObjectIdentifier("1.2.156.11235.1.1.1");
64-
ASN1ObjectIdentifier wapi192v1_parameters = new ASN1ObjectIdentifier("1.2.156.11235.1.1.2.1");
62+
*/
63+
ASN1ObjectIdentifier wapi192v1 = new ASN1ObjectIdentifier("1.2.156.11235.1.1.1");
64+
ASN1ObjectIdentifier wapi192v1_parameters = new ASN1ObjectIdentifier("1.2.156.11235.1.1.2.1");
6565

6666
ASN1ObjectIdentifier sm2encrypt_recommendedParameters = sm2encrypt.branch("1");
6767
ASN1ObjectIdentifier sm2encrypt_specifiedParameters = sm2encrypt.branch("2");
@@ -71,8 +71,8 @@ public interface GMObjectIdentifiers
7171
ASN1ObjectIdentifier sm2encrypt_with_sha256 = sm2encrypt.branch("2.4");
7272
ASN1ObjectIdentifier sm2encrypt_with_sha384 = sm2encrypt.branch("2.5");
7373
ASN1ObjectIdentifier sm2encrypt_with_sha512 = sm2encrypt.branch("2.6");
74-
ASN1ObjectIdentifier sm2encrypt_with_rmd160 = sm2encrypt.branch("2.7");
75-
ASN1ObjectIdentifier sm2encrypt_with_whirlpool =sm2encrypt.branch("2.8");
74+
ASN1ObjectIdentifier sm2encrypt_with_rmd160 = sm2encrypt.branch("2.7");
75+
ASN1ObjectIdentifier sm2encrypt_with_whirlpool = sm2encrypt.branch("2.8");
7676
ASN1ObjectIdentifier sm2encrypt_with_blake2b512 = sm2encrypt.branch("2.9");
7777
ASN1ObjectIdentifier sm2encrypt_with_blake2s256 = sm2encrypt.branch("2.10");
7878
ASN1ObjectIdentifier sm2encrypt_with_md5 = sm2encrypt.branch("2.11");

core/src/main/java/org/bouncycastle/crypto/BufferedBlockCipher.java

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.bouncycastle.crypto;
22

3-
import org.bouncycastle.util.Arrays;
4-
53
/**
64
* A wrapper class that allows block ciphers to be used to process data in
75
* a piecemeal fashion. The BufferedBlockCipher outputs a block only when the
@@ -168,27 +166,26 @@ public int getOutputSize(
168166
/**
169167
* process a single byte, producing an output block if necessary.
170168
*
171-
* @param in the input byte.
172-
* @param out the space for any output that might be produced.
169+
* @param in the input byte.
170+
* @param out the space for any output that might be produced.
173171
* @param outOff the offset from which the output will be copied.
174172
* @return the number of output bytes copied to out.
175-
* @throws DataLengthException if there isn't enough space in out.
176-
* @throws IllegalStateException if the cipher isn't initialised.
173+
* @exception DataLengthException if there isn't enough space in out.
174+
* @exception IllegalStateException if the cipher isn't initialised.
177175
*/
178176
public int processByte(
179-
byte in,
180-
byte[] out,
181-
int outOff)
177+
byte in,
178+
byte[] out,
179+
int outOff)
182180
throws DataLengthException, IllegalStateException
183181
{
184-
int resultLen = 0;
182+
int resultLen = 0;
185183

186184
buf[bufOff++] = in;
187185

188186
if (bufOff == buf.length)
189187
{
190-
resultLen = cipher.processBlock(buf, 0, out, outOff);
191-
bufOff = 0;
188+
resultLen = processBuffer(out, outOff);
192189
}
193190

194191
return resultLen;
@@ -197,30 +194,30 @@ public int processByte(
197194
/**
198195
* process an array of bytes, producing output if necessary.
199196
*
200-
* @param in the input byte array.
201-
* @param inOff the offset at which the input data starts.
202-
* @param len the number of bytes to be copied out of the input array.
203-
* @param out the space for any output that might be produced.
197+
* @param in the input byte array.
198+
* @param inOff the offset at which the input data starts.
199+
* @param len the number of bytes to be copied out of the input array.
200+
* @param out the space for any output that might be produced.
204201
* @param outOff the offset from which the output will be copied.
205202
* @return the number of output bytes copied to out.
206-
* @throws DataLengthException if there isn't enough space in out.
207-
* @throws IllegalStateException if the cipher isn't initialised.
203+
* @exception DataLengthException if there isn't enough space in out.
204+
* @exception IllegalStateException if the cipher isn't initialised.
208205
*/
209206
public int processBytes(
210-
byte[] in,
211-
int inOff,
212-
int len,
213-
byte[] out,
214-
int outOff)
207+
byte[] in,
208+
int inOff,
209+
int len,
210+
byte[] out,
211+
int outOff)
215212
throws DataLengthException, IllegalStateException
216213
{
217214
if (len < 0)
218215
{
219216
throw new IllegalArgumentException("Can't have a negative input length!");
220217
}
221218

222-
int blockSize = getBlockSize();
223-
int length = getUpdateOutputSize(len);
219+
int blockSize = getBlockSize();
220+
int length = getUpdateOutputSize(len);
224221

225222
if (length > 0)
226223
{
@@ -235,29 +232,35 @@ public int processBytes(
235232

236233
if (len > gapLen)
237234
{
238-
System.arraycopy(in, inOff, buf, bufOff, gapLen);
239-
inOff += gapLen;
240-
len -= gapLen;
241-
if (in == out && Arrays.segmentsOverlap(inOff, len, outOff, length))
235+
if (bufOff != 0)
236+
{
237+
System.arraycopy(in, inOff, buf, bufOff, gapLen);
238+
inOff += gapLen;
239+
len -= gapLen;
240+
}
241+
242+
if (in == out)
242243
{
243244
in = new byte[len];
244245
System.arraycopy(out, inOff, in, 0, len);
245246
inOff = 0;
246247
}
247248

248-
resultLen += cipher.processBlock(buf, 0, out, outOff);
249-
250-
bufOff = 0;
249+
// if bufOff non-zero buffer must now be full
250+
if (bufOff != 0)
251+
{
252+
resultLen += processBuffer(out, outOff);
253+
}
251254

252255
if (mbCipher != null)
253256
{
254-
int blockCount = len / mbCipher.getMultiBlockSize();
257+
int blockCount = (len / mbCipher.getMultiBlockSize()) * (mbCipher.getMultiBlockSize() / blockSize);
255258

256259
if (blockCount > 0)
257260
{
258261
resultLen += mbCipher.processBlocks(in, inOff, blockCount, out, outOff + resultLen);
259262

260-
int processed = blockCount * mbCipher.getMultiBlockSize();
263+
int processed = blockCount * blockSize;
261264

262265
len -= processed;
263266
inOff += processed;
@@ -281,13 +284,25 @@ public int processBytes(
281284

282285
if (bufOff == buf.length)
283286
{
284-
resultLen += cipher.processBlock(buf, 0, out, outOff + resultLen);
285-
bufOff = 0;
287+
resultLen += processBuffer(out, outOff + resultLen);
286288
}
287289

288290
return resultLen;
289291
}
290292

293+
private int processBuffer(byte[] out, int outOff)
294+
{
295+
bufOff = 0;
296+
if (mbCipher != null)
297+
{
298+
return mbCipher.processBlocks(buf, 0, buf.length / mbCipher.getBlockSize(), out, outOff);
299+
}
300+
else
301+
{
302+
return cipher.processBlock(buf, 0, out, outOff);
303+
}
304+
}
305+
291306
/**
292307
* Process the last block in the buffer.
293308
*
@@ -318,15 +333,26 @@ public int doFinal(
318333

319334
if (bufOff != 0)
320335
{
321-
if (!partialBlockOkay)
336+
int index = 0;
337+
if (mbCipher != null)
322338
{
323-
throw new DataLengthException("data not block size aligned");
339+
int nBlocks = bufOff / mbCipher.getBlockSize();
340+
resultLen += mbCipher.processBlocks(buf, 0, nBlocks, out, outOff);
341+
index = nBlocks * mbCipher.getBlockSize();
324342
}
325343

326-
cipher.processBlock(buf, 0, buf, 0);
327-
resultLen = bufOff;
328-
bufOff = 0;
329-
System.arraycopy(buf, 0, out, outOff, resultLen);
344+
if (bufOff != index)
345+
{
346+
if (!partialBlockOkay)
347+
{
348+
throw new DataLengthException("data not block size aligned");
349+
}
350+
351+
cipher.processBlock(buf, index, buf, index);
352+
System.arraycopy(buf, index, out, outOff + resultLen, bufOff - index);
353+
resultLen += bufOff - index;
354+
bufOff = 0;
355+
}
330356
}
331357

332358
return resultLen;

0 commit comments

Comments
 (0)