diff options
Diffstat (limited to 'crypto/src/crypto/digests/XofUtils.cs')
-rw-r--r-- | crypto/src/crypto/digests/XofUtils.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/crypto/src/crypto/digests/XofUtils.cs b/crypto/src/crypto/digests/XofUtils.cs new file mode 100644 index 000000000..e4c893e01 --- /dev/null +++ b/crypto/src/crypto/digests/XofUtils.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Org.BouncyCastle.Crypto.Digests +{ + public class XofUtils + { + public static byte[] leftEncode(long strLen) + { + byte n = 1; + + long v = strLen; + while ((v >>= 8) != 0) + { + n++; + } + + byte[] b = new byte[n + 1]; + + b[0] = n; + + for (int i = 1; i <= n; i++) + { + b[i] = (byte)(strLen >> (8 * (n - i))); + } + + return b; + } + + public static byte[] rightEncode(long strLen) + { + byte n = 1; + + long v = strLen; + while ((v >>= 8) != 0) + { + n++; + } + + byte[] b = new byte[n + 1]; + + b[n] = n; + + for (int i = 0; i < n; i++) + { + b[i] = (byte)(strLen >> (8 * (n - i - 1))); + } + + return b; + } + } +} |