Skip to content

Commit 9a83754

Browse files
committed
Fix Harakas XOF API compliance
1 parent fcccf29 commit 9a83754

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

core/src/main/java/org/bouncycastle/pqc/crypto/sphincsplus/HarakaSXof.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,27 @@ public void update(byte input)
5353
public int doFinal(byte[] out, int outOff, int len)
5454
{
5555
int outLen = len;
56+
5657
//Finalize
5758
buffer[off] ^= 0x1F;
5859
buffer[31] ^= 128;
59-
off = 0;
60+
6061
//Squeeze
61-
while (len > 0)
62+
while (len >= 32)
6263
{
6364
haraka512Perm(buffer);
64-
int i = 0;
65-
while (i < 32 && i + outOff < out.length)
66-
{
67-
out[i + outOff] = buffer[i];
68-
i++;
69-
}
70-
outOff += i;
71-
len -= i;
65+
System.arraycopy(buffer, 0, out, outOff, 32);
66+
outOff += 32;
67+
len -= 32;
7268
}
73-
if (len != 0)
69+
if (len > 0)
7470
{
75-
byte[] d = new byte[64];
76-
haraka512Perm(d);
77-
System.arraycopy(d, 0, out, outOff, -len);
71+
haraka512Perm(buffer);
72+
System.arraycopy(buffer, 0, out, outOff, len);
7873
}
7974

8075
reset();
81-
76+
8277
return outLen;
8378
}
8479
}

0 commit comments

Comments
 (0)