Skip to content

Commit 3c400c9

Browse files
author
gefeili
committed
Refactor around Ascon digests
1 parent b75d857 commit 3c400c9

File tree

6 files changed

+14
-36
lines changed

6 files changed

+14
-36
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ public void update(byte[] input, int inOff, int len)
124124
m_bufPos = remaining;
125125
}
126126

127+
@Override
128+
public int doFinal(byte[] output, int outOff)
129+
{
130+
return hash(output, outOff, CRYPTO_BYTES);
131+
}
132+
127133
protected void finishAbsorbing()
128134
{
129135
x0 ^= loadBytes(m_buf, 0, m_bufPos);

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* <a href="https://csrc.nist.gov/pubs/sp/800/232/ipd">NIST SP 800-232 (Initial Public Draft)</a>.
1515
* For reference source code and implementation details, please see:
1616
* <a href="https://github.com/ascon/ascon-c">Reference, highly optimized, masked C and
17-
* ASM implementations of Ascon (NIST SP 800-232)</a>.
17+
* ASM implementations of Ascon (NIST SP 800-232)</a>.
1818
* </p>
1919
*/
2020
public class AsconCxof128
@@ -31,8 +31,6 @@ public AsconCxof128(byte[] s)
3131
}
3232
this.s = Arrays.clone(s);
3333
reset();
34-
update(s, 0, s.length);
35-
finishAbsorbing();
3634
}
3735

3836
public AsconCxof128(byte[] s, int off, int len)
@@ -47,8 +45,6 @@ public AsconCxof128(byte[] s, int off, int len)
4745
}
4846
this.s = Arrays.copyOfRange(s, off, off + len);
4947
reset();
50-
update(s, 0, s.length);
51-
finishAbsorbing();
5248
}
5349

5450
public AsconCxof128()
@@ -63,7 +59,7 @@ protected long pad(int i)
6359

6460
protected long loadBytes(final byte[] bytes, int inOff)
6561
{
66-
return Pack.littleEndianToLong(bytes, inOff);
62+
return Pack.littleEndianToLong(bytes, inOff);
6763
}
6864

6965
protected long loadBytes(final byte[] bytes, int inOff, int n)
@@ -100,11 +96,6 @@ public int doOutput(byte[] output, int outOff, int outLen)
10096
return outLen;
10197
}
10298

103-
@Override
104-
public int doFinal(byte[] output, int outOff)
105-
{
106-
return doOutput(output, outOff, getDigestSize());
107-
}
10899

109100
@Override
110101
public int doFinal(byte[] output, int outOff, int outLen)
@@ -122,8 +113,11 @@ public void reset()
122113
x2 = -1616759365661982283L;
123114
x3 = 3076320316797452470L;
124115
x4 = -8124743304765850554L;
125-
update(s, 0, s.length);
126-
finishAbsorbing();
116+
if (s != null)
117+
{
118+
update(s, 0, s.length);
119+
finishAbsorbing();
120+
}
127121
}
128122
}
129123

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ public String getAlgorithmName()
7272
return algorithmName;
7373
}
7474

75-
@Override
76-
public int doFinal(byte[] output, int outOff)
77-
{
78-
return hash(output, outOff, CRYPTO_BYTES);
79-
}
80-
8175
@Override
8276
public void reset()
8377
{

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ public String getAlgorithmName()
5252
return "Ascon-Hash256";
5353
}
5454

55-
@Override
56-
public int doFinal(byte[] output, int outOff)
57-
{
58-
return hash(output, outOff, CRYPTO_BYTES);
59-
}
55+
6056

6157
@Override
6258
public void reset()

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ public int doOutput(byte[] output, int outOff, int outLen)
8282
return hash(output, outOff, outLen);
8383
}
8484

85-
@Override
86-
public int doFinal(byte[] output, int outOff)
87-
{
88-
return doOutput(output, outOff, getDigestSize());
89-
}
90-
9185
@Override
9286
public int doFinal(byte[] output, int outOff, int outLen)
9387
{

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ public int doOutput(byte[] output, int outOff, int outLen)
6060
return hash(output, outOff, outLen);
6161
}
6262

63-
@Override
64-
public int doFinal(byte[] output, int outOff)
65-
{
66-
return doOutput(output, outOff, getDigestSize());
67-
}
68-
6963
@Override
7064
public int doFinal(byte[] output, int outOff, int outLen)
7165
{

0 commit comments

Comments
 (0)