From 6a948eb427afc513c0c12a054e9a2635cc66da3a Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Mon, 10 Oct 2022 14:55:00 +0700 Subject: Fix Harakas XOF API compliance --- crypto/src/pqc/crypto/sphincsplus/HarakaSXof.cs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/crypto/src/pqc/crypto/sphincsplus/HarakaSXof.cs b/crypto/src/pqc/crypto/sphincsplus/HarakaSXof.cs index 210ac35e1..86c2f8fbb 100644 --- a/crypto/src/pqc/crypto/sphincsplus/HarakaSXof.cs +++ b/crypto/src/pqc/crypto/sphincsplus/HarakaSXof.cs @@ -54,30 +54,27 @@ namespace Org.BouncyCastle.Pqc.Crypto.SphincsPlus public int DoFinal(byte[] output, int outOff, int len) { int outLen = len; + //Finalize buffer[off] ^= 0x1F; buffer[31] ^= 128; - off = 0; + //Squeeze - while (len > 0) + while (len >= 32) { Haraka512Perm(buffer); - int i = 0; - while (i < 32 && i + outOff < output.Length) - { - output[i + outOff] = buffer[i]; - i++; - } - outOff += i; - len -= i; + Array.Copy(buffer, 0, output, outOff, 32); + outOff += 32; + len -= 32; } - if (len != 0) + if (len > 0) { - byte[] d = new byte[64]; - Haraka512Perm(d); - Array.Copy(d, 0, output, outOff, -len); + Haraka512Perm(buffer); + Array.Copy(buffer, 0, output, outOff, len); } + Reset(); + return outLen; } } -- cgit 1.4.1