Skip to content

Commit f6f4cf5

Browse files
author
gefeili
committed
Update java doc, update initState of AsconCXof128, set AsconAEAD128 mac size range 4-16 bytes.
1 parent 9ddc55d commit f6f4cf5

File tree

8 files changed

+51
-44
lines changed

8 files changed

+51
-44
lines changed

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

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
/**
77
* Ascon-CXOF128 was introduced in NIST Special Publication (SP) 800-232
8-
* (Initial Public Draft).
98
* <p>
109
* Additional details and the specification can be found in:
11-
* <a href="https://csrc.nist.gov/pubs/sp/800/232/ipd">NIST SP 800-232 (Initial Public Draft)</a>.
10+
* <a href="https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-232.pdf">NIST SP 800-232
11+
* Ascon-Based Lightweight Cryptography Standards for Constrained Devices</a>.
1212
* For reference source code and implementation details, please see:
1313
* <a href="https://github.com/ascon/ascon-c">Reference, highly optimized, masked C and
1414
* ASM implementations of Ascon (NIST SP 800-232)</a>.
@@ -81,26 +81,18 @@ public void reset()
8181

8282
private void initState(byte[] z, int zOff, int zLen)
8383
{
84-
// p.set(0x0000080000cc0004L, 0L, 0L, 0L, 0L);
85-
// p.p(12);
86-
87-
if (zLen == 0)
88-
{
89-
// p.p(12);
90-
// padAndAbsorb();
91-
92-
p.set(0x500cccc894e3c9e8L, 0x5bed06f28f71248dL, 0x3b03a0f930afd512L, 0x112ef093aa5c698bL, 0x00c8356340a347f0L);
93-
}
94-
else
95-
{
96-
p.set(0x675527c2a0e8de03L, 0x43d12d7dc0377bbcL, 0xe9901dec426e81b5L, 0x2ab14907720780b6L, 0x8f3f1d02d432bc46L);
97-
98-
p.x0 ^= ((long)zLen) << 3;
99-
p.p(12);
100-
update(z, zOff, zLen);
101-
padAndAbsorb();
102-
}
103-
84+
// if (zLen == 0)
85+
// {
86+
// p.set(0x500cccc894e3c9e8L, 0x5bed06f28f71248dL, 0x3b03a0f930afd512L, 0x112ef093aa5c698bL, 0x00c8356340a347f0L);
87+
// }
88+
// else
89+
// {
90+
p.set(0x675527c2a0e8de03L, 0x43d12d7dc0377bbcL, 0xe9901dec426e81b5L, 0x2ab14907720780b6L, 0x8f3f1d02d432bc46L);
91+
p.x0 ^= ((long)zLen) << 3;
92+
p.p(12);
93+
update(z, zOff, zLen);
94+
padAndAbsorb();
95+
// }
10496
super.reset();
10597
}
10698
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import org.bouncycastle.util.Pack;
44

55
/**
6-
* ASCON v1.2 Digest, https://ascon.iaik.tugraz.at/ .
6+
* ASCON v1.2 Digest, <a href="https://ascon.iaik.tugraz.at/">...</a> .
77
* <p>
8-
* https://csrc.nist.gov/CSRC/media/Projects/lightweight-cryptography/documents/finalist-round/updated-spec-doc/ascon-spec-final.pdf
8+
* <a href="https://csrc.nist.gov/CSRC/media/Projects/lightweight-cryptography/documents/finalist-round/updated-spec-doc/ascon-spec-final.pdf">...</a>
99
* <p>
10-
* ASCON v1.2 Digest with reference to C Reference Impl from: https://github.com/ascon/ascon-c .
10+
* ASCON v1.2 Digest with reference to C Reference Impl from: <a href="https://github.com/ascon/ascon-c">...</a> .
1111
*
1212
* @deprecated use Ascon Hash 256 Digest
1313
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
/**
66
* Ascon-Hash256 was introduced in NIST Special Publication (SP) 800-232
7-
* (Initial Public Draft).
87
* <p>
98
* Additional details and the specification can be found in:
10-
* <a href="https://csrc.nist.gov/pubs/sp/800/232/ipd">NIST SP 800-232 (Initial Public Draft)</a>.
9+
* <a href="https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-232.pdf">NIST SP 800-232
10+
* Ascon-Based Lightweight Cryptography Standards for Constrained Devices</a>.
1111
* For reference source code and implementation details, please see:
1212
* <a href="https://github.com/ascon/ascon-c">Reference, highly optimized, masked C and
1313
* ASM implementations of Ascon (NIST SP 800-232)</a>.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import org.bouncycastle.util.Pack;
44

55
/**
6-
* ASCON v1.2 XOF, https://ascon.iaik.tugraz.at/ .
6+
* ASCON v1.2 XOF, <a href="https://ascon.iaik.tugraz.at/">...</a> .
77
* <p>
8-
* https://csrc.nist.gov/CSRC/media/Projects/lightweight-cryptography/documents/finalist-round/updated-spec-doc/ascon-spec-final.pdf
8+
* <a href="https://csrc.nist.gov/CSRC/media/Projects/lightweight-cryptography/documents/finalist-round/updated-spec-doc/ascon-spec-final.pdf">...</a>
99
* <p>
10-
* ASCON v1.2 XOF with reference to C Reference Impl from: https://github.com/ascon/ascon-c .
10+
* ASCON v1.2 XOF with reference to C Reference Impl from: <a href="https://github.com/ascon/ascon-c">...</a> .
1111
*
1212
* @deprecated Now superseded - please use AsconXof128
1313
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
/**
66
* Ascon-XOF128 was introduced in NIST Special Publication (SP) 800-232
7-
* (Initial Public Draft).
87
* <p>
98
* Additional details and the specification can be found in:
10-
* <a href="https://csrc.nist.gov/pubs/sp/800/232/ipd">NIST SP 800-232 (Initial Public Draft)</a>.
9+
* <a href="https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-232.pdf">NIST SP 800-232
10+
* Ascon-Based Lightweight Cryptography Standards for Constrained Devices</a>.
1111
* For reference source code and implementation details, please see:
1212
* <a href="https://github.com/ascon/ascon-c">Reference, highly optimized, masked C and
1313
* ASM implementations of Ascon (NIST SP 800-232)</a>.

core/src/main/java/org/bouncycastle/crypto/engines/AEADBaseEngine.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ protected static class State
106106
protected int KEY_SIZE;
107107
protected int IV_SIZE;
108108
protected int MAC_SIZE;
109+
protected int macSizeLowerBound = 0;
109110
protected byte[] initialAssociatedText;
110111
protected byte[] mac;
111112
protected byte[] m_buf;
@@ -157,9 +158,22 @@ public void init(boolean forEncryption, CipherParameters params)
157158
initialAssociatedText = aeadParameters.getAssociatedText();
158159

159160
int macSizeBits = aeadParameters.getMacSize();
160-
if (macSizeBits != MAC_SIZE * 8)
161+
if (macSizeLowerBound == 0)
161162
{
162-
throw new IllegalArgumentException("Invalid value for MAC size: " + macSizeBits);
163+
if (macSizeBits != (MAC_SIZE << 3))
164+
{
165+
throw new IllegalArgumentException("Invalid value for MAC size: " + macSizeBits);
166+
}
167+
}
168+
else
169+
{
170+
//TODO: set macSizeUpperBound instead of 128 fix value if necessary
171+
if (macSizeBits > 128 || macSizeBits < (macSizeLowerBound << 3) || (macSizeBits & 7) != 0)
172+
{
173+
throw new IllegalArgumentException("MAC size must be between " + (macSizeLowerBound << 3) +
174+
" and 128 bits for " + algorithmName);
175+
}
176+
MAC_SIZE = macSizeBits >>> 3;
163177
}
164178
}
165179
else if (params instanceof ParametersWithIV)

core/src/main/java/org/bouncycastle/crypto/engines/AsconAEAD128.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import org.bouncycastle.util.Pack;
55

66
/**
7-
* Ascon-AEAD128 was introduced as part of the NIST Lightweight Cryptography
8-
* competition and described in the NIST Special Publication SP 800-232 (Initial
9-
* Public Draft).
10-
* For additional details, see:
11-
* <ul>
12-
* <li><a href="https://csrc.nist.gov/pubs/sp/800/232/ipd">NIST SP 800-232 (Initial Public Draft)</a></li>
13-
* <li><a href="https://github.com/ascon/ascon-c">Reference, highly optimized, masked C and
14-
* ASM implementations of Ascon (NIST SP 800-232)</a></li>
15-
* </ul>
7+
* Ascon-AEAD128 was introduced in NIST Special Publication (SP) 800-232
8+
* <p>
9+
* Additional details and the specification can be found in:
10+
* <a href="https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-232.pdf">NIST SP 800-232
11+
* Ascon-Based Lightweight Cryptography Standards for Constrained Devices</a>.
12+
* For reference source code and implementation details, please see:
13+
* <a href="https://github.com/ascon/ascon-c">Reference, highly optimized, masked C and
14+
* ASM implementations of Ascon (NIST SP 800-232)</a>.
15+
* </p>
1616
*
1717
* @version 1.3
1818
*/
@@ -26,6 +26,7 @@ public AsconAEAD128()
2626
algorithmName = "Ascon-AEAD128";
2727
nr = 8;
2828
dsep = -9223372036854775808L; //0x80L << 56
29+
macSizeLowerBound = 4;
2930
setInnerMembers(ProcessingBufferType.Immediate, AADOperatorType.Default, DataOperatorType.Default);
3031
}
3132

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static void checkAEADParemeter(SimpleTest test, int keySize, int ivSize, final i
362362
}
363363
len += cipher.doFinal(plaintext1, len);
364364

365-
test.testException("Invalid value for MAC size: ", "IllegalArgumentException", new TestExceptionOperation()
365+
test.testException("MAC size", "IllegalArgumentException", new TestExceptionOperation()
366366
{
367367
@Override
368368
public void operation()

0 commit comments

Comments
 (0)