Skip to content

Commit 9dbad2d

Browse files
author
gefeili
committed
Add AsconPermutation.set
1 parent c2b0ed7 commit 9dbad2d

File tree

12 files changed

+31
-75
lines changed

12 files changed

+31
-75
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ abstract class AsconBaseDigest
99
public static class Friend
1010
{
1111
private static final Friend INSTANCE = new Friend();
12-
private Friend() {}
12+
13+
private Friend()
14+
{
15+
}
1316
}
1417

1518

@@ -49,8 +52,7 @@ protected void finish(byte[] output, int outOff)
4952

5053
protected void padAndAbsorb()
5154
{
52-
p.x0 ^= loadBytes(m_buf, 0, m_bufPos);
53-
p.x0 ^= pad(m_bufPos);
55+
p.x0 ^= loadBytes(m_buf, 0, m_bufPos) ^ pad(m_bufPos);
5456
p.p(12);
5557
}
5658

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,12 @@ public void reset()
131131
super.reset();
132132
m_squeezing = false;
133133
/* initialize */
134-
p.x0 = z0;
135-
p.x1 = z1;
136-
p.x2 = z2;
137-
p.x3 = z3;
138-
p.x4 = z4;
134+
p.set(z0, z1, z2, z3, z4);
139135
}
140136

141137
private void initState(byte[] z, int zOff, int zLen)
142138
{
143-
p.x0 = 7445901275803737603L;
144-
p.x1 = 4886737088792722364L;
145-
p.x2 = -1616759365661982283L;
146-
p.x3 = 3076320316797452470L;
147-
p.x4 = -8124743304765850554L;
139+
p.set(7445901275803737603L, 4886737088792722364L, -1616759365661982283L, 3076320316797452470L, -8124743304765850554L);
148140
long bitLength = ((long)zLen) << 3;
149141
Pack.longToLittleEndian(bitLength, m_buf, 0);
150142
p.p(12);

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,10 @@ public void reset()
7474
switch (asconParameters)
7575
{
7676
case AsconHashA:
77-
p.x0 = 92044056785660070L;
78-
p.x1 = 8326807761760157607L;
79-
p.x2 = 3371194088139667532L;
80-
p.x3 = -2956994353054992515L;
81-
p.x4 = -6828509670848688761L;
77+
p.set(92044056785660070L, 8326807761760157607L, 3371194088139667532L, -2956994353054992515L, -6828509670848688761L);
8278
break;
8379
case AsconHash:
84-
p.x0 = -1255492011513352131L;
85-
p.x1 = -8380609354527731710L;
86-
p.x2 = -5437372128236807582L;
87-
p.x3 = 4834782570098516968L;
88-
p.x4 = 3787428097924915520L;
80+
p.set(-1255492011513352131L, -8380609354527731710L, -5437372128236807582L, 4834782570098516968L, 3787428097924915520L);
8981
break;
9082
}
9183
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* <a href="https://csrc.nist.gov/pubs/sp/800/232/ipd">NIST SP 800-232 (Initial Public Draft)</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
13-
* ASM implementations of Ascon (NIST SP 800-232)</a>.
13+
* ASM implementations of Ascon (NIST SP 800-232)</a>.
1414
* </p>
1515
*/
1616
public class AsconHash256
@@ -52,10 +52,6 @@ public void reset()
5252
{
5353
super.reset();
5454
/* initialize */
55-
p.x0 = -7269279749984954751L;
56-
p.x1 = 5459383224871899602L;
57-
p.x2 = -5880230600644446182L;
58-
p.x3 = 4359436768738168243L;
59-
p.x4 = 1899470422303676269L;
55+
p.set(-7269279749984954751L, 5459383224871899602L, -5880230600644446182L, 4359436768738168243L, 1899470422303676269L);
6056
}
6157
}

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public enum AsconParameters
2626

2727
public AsconXof(AsconXof.AsconParameters parameters)
2828
{
29+
BlockSize = 8;
2930
this.asconParameters = parameters;
3031
switch (parameters)
3132
{
@@ -42,6 +43,7 @@ public AsconXof(AsconXof.AsconParameters parameters)
4243
}
4344
reset();
4445
}
46+
4547
private boolean m_squeezing = false;
4648

4749
@Override
@@ -109,12 +111,6 @@ public int doFinal(byte[] output, int outOff, int outLen)
109111
return rlt;
110112
}
111113

112-
@Override
113-
public int getByteLength()
114-
{
115-
return 8;
116-
}
117-
118114
@Override
119115
public void reset()
120116
{
@@ -124,18 +120,10 @@ public void reset()
124120
switch (asconParameters)
125121
{
126122
case AsconXof:
127-
p.x0 = -5368810569253202922L;
128-
p.x1 = 3121280575360345120L;
129-
p.x2 = 7395939140700676632L;
130-
p.x3 = 6533890155656471820L;
131-
p.x4 = 5710016986865767350L;
123+
p.set(-5368810569253202922L, 3121280575360345120L, 7395939140700676632L, 6533890155656471820L, 5710016986865767350L);
132124
break;
133125
case AsconXofA:
134-
p.x0 = 4940560291654768690L;
135-
p.x1 = -3635129828240960206L;
136-
p.x2 = -597534922722107095L;
137-
p.x3 = 2623493988082852443L;
138-
p.x4 = -6283826724160825537L;
126+
p.set(4940560291654768690L, -3635129828240960206L, -597534922722107095L, 2623493988082852443L, -6283826724160825537L);
139127
break;
140128
}
141129
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ public void reset()
9797
m_squeezing = false;
9898
super.reset();
9999
/* initialize */
100-
p.x0 = -2701369817892108309L;
101-
p.x1 = -3711838248891385495L;
102-
p.x2 = -1778763697082575311L;
103-
p.x3 = 1072114354614917324L;
104-
p.x4 = -2282070310009238562L;
100+
p.set(-2701369817892108309L, -3711838248891385495L, -1778763697082575311L, 1072114354614917324L, -2282070310009238562L);
105101
}
106102
}
107103

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ public void reset()
8383
{
8484
super.reset();
8585
/* init state */
86-
p.x0 = -1255492011513352131L;
87-
p.x1 = -8380609354527731710L;
88-
p.x2 = -5437372128236807582L;
89-
p.x3 = 4834782570098516968L;
90-
p.x4 = 3787428097924915520L;
86+
p.set(-1255492011513352131L, -8380609354527731710L, -5437372128236807582L, 4834782570098516968L, 3787428097924915520L);
9187
}
9288
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ protected void setBytes(long n, byte[] bs, int off)
4949
protected void ascon_aeadinit()
5050
{
5151
/* initialize */
52-
p.x0 = ASCON_IV;
53-
p.x1 = K0;
54-
p.x2 = K1;
55-
p.x3 = N0;
56-
p.x4 = N1;
52+
p.set(ASCON_IV, K0, K1, N0, N1);
5753
p.p(12);
5854
p.x3 ^= K0;
5955
p.x4 ^= K1;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class AsconBaseEngine
99
protected long N0;
1010
protected long N1;
1111
protected long ASCON_IV;
12-
AsconPermutationFriend.AsconPermutation p;
12+
AsconPermutationFriend.AsconPermutation p = new AsconPermutationFriend.AsconPermutation();
1313
protected long dsep; //domain separation
1414

1515
protected abstract long pad(int i);
@@ -98,7 +98,6 @@ protected void processBufferEncrypt(byte[] buffer, int bufOff, byte[] output, in
9898

9999
protected void reset(boolean clearMac)
100100
{
101-
p = new AsconPermutationFriend.AsconPermutation();
102101
bufferReset();
103102
ascon_aeadinit();
104103
super.reset(clearMac);

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,11 @@ protected void setBytes(long n, byte[] bs, int off)
8787
protected void ascon_aeadinit()
8888
{
8989
/* initialize */
90-
p.x0 = ASCON_IV;
90+
p.set(ASCON_IV, K1, K2, N0, N1);
9191
if (KEY_SIZE == 20)
9292
{
9393
p.x0 ^= K0;
9494
}
95-
p.x1 = K1;
96-
p.x2 = K2;
97-
p.x3 = N0;
98-
p.x4 = N1;
9995
p.p(12);
10096
if (KEY_SIZE == 20)
10197
{

0 commit comments

Comments
 (0)