public int DoOutput(byte[] output, int outOff, int outLen) { if (firstOutput) { if (!initialised) { throw new InvalidOperationException("KMAC not initialized"); } byte[] encOut = XofUtilities.RightEncode(0); cshake.BlockUpdate(encOut, 0, encOut.Length); firstOutput = false; } return(cshake.DoOutput(output, outOff, outLen)); }
public int DoFinal(byte[] output, int outOff, int outLen) { if (firstOutput) { if (!initialised) { throw new InvalidOperationException("KMAC not initialized"); } byte[] encOut = XofUtilities.RightEncode(outLen * 8); cshake.BlockUpdate(encOut, 0, encOut.Length); } int rv = cshake.DoFinal(output, outOff, outLen); Reset(); return(rv); }
private void bytePad(byte[] X, int w) { byte[] bytes = XofUtilities.LeftEncode(w); BlockUpdate(bytes, 0, bytes.Length); byte[] encX = encode(X); BlockUpdate(encX, 0, encX.Length); int required = w - ((bytes.Length + encX.Length) % w); if (required > 0 && required != w) { while (required > padding.Length) { BlockUpdate(padding, 0, padding.Length); required -= padding.Length; } BlockUpdate(padding, 0, required); } }
private static byte[] encode(byte[] X) { return(Arrays.Concatenate(XofUtilities.LeftEncode(X.Length * 8), X)); }