Move message digests to new namespace

This commit is contained in:
Matt Nadareski
2024-11-09 20:51:38 -05:00
parent bb9d4155d2
commit d1b60f7951
8 changed files with 177 additions and 175 deletions

View File

@@ -55,13 +55,13 @@ namespace SabreTools.Hashing
return nchaArr;
#endif
case RipeMD.RipeMD128 r128:
case MessageDigest.RipeMD128 r128:
return r128.GetHash();
case RipeMD.RipeMD160 r160:
case MessageDigest.RipeMD160 r160:
return r160.GetHash();
case RipeMD.RipeMD256 r256:
case MessageDigest.RipeMD256 r256:
return r256.GetHash();
case RipeMD.RipeMD320 r320:
case MessageDigest.RipeMD320 r320:
return r320.GetHash();
#if NET8_0_OR_GREATER
@@ -71,7 +71,7 @@ namespace SabreTools.Hashing
return s256.GetCurrentHash(64);
#endif
case Tiger.TigerHash th:
case MessageDigest.TigerHash th:
return th.GetHash();
case XxHash.XxHash32 xxh32:
@@ -294,10 +294,10 @@ namespace SabreTools.Hashing
HashType.MD5 => MD5.Create(),
HashType.RIPEMD128 => new RipeMD.RipeMD128(),
HashType.RIPEMD160 => new RipeMD.RipeMD160(),
HashType.RIPEMD256 => new RipeMD.RipeMD256(),
HashType.RIPEMD320 => new RipeMD.RipeMD320(),
HashType.RIPEMD128 => new MessageDigest.RipeMD128(),
HashType.RIPEMD160 => new MessageDigest.RipeMD160(),
HashType.RIPEMD256 => new MessageDigest.RipeMD256(),
HashType.RIPEMD320 => new MessageDigest.RipeMD320(),
HashType.SHA1 => SHA1.Create(),
HashType.SHA256 => SHA256.Create(),
@@ -313,12 +313,12 @@ namespace SabreTools.Hashing
HashType.SpamSum => new SpamSumContext(),
HashType.Tiger128_3 => new Tiger.Tiger128_3(),
HashType.Tiger128_4 => new Tiger.Tiger128_4(),
HashType.Tiger160_3 => new Tiger.Tiger160_3(),
HashType.Tiger160_4 => new Tiger.Tiger160_4(),
HashType.Tiger192_3 => new Tiger.Tiger192_3(),
HashType.Tiger192_4 => new Tiger.Tiger192_4(),
HashType.Tiger128_3 => new MessageDigest.Tiger128_3(),
HashType.Tiger128_4 => new MessageDigest.Tiger128_4(),
HashType.Tiger160_3 => new MessageDigest.Tiger160_3(),
HashType.Tiger160_4 => new MessageDigest.Tiger160_4(),
HashType.Tiger192_3 => new MessageDigest.Tiger192_3(),
HashType.Tiger192_4 => new MessageDigest.Tiger192_4(),
HashType.XxHash32 => new XxHash.XxHash32(),
HashType.XxHash64 => new XxHash.XxHash64(),
@@ -369,16 +369,16 @@ namespace SabreTools.Hashing
break;
#endif
case RipeMD.RipeMD128 r128:
case MessageDigest.RipeMD128 r128:
r128.TransformBlock(buffer, offset, size);
break;
case RipeMD.RipeMD160 r160:
case MessageDigest.RipeMD160 r160:
r160.TransformBlock(buffer, offset, size);
break;
case RipeMD.RipeMD256 r256:
case MessageDigest.RipeMD256 r256:
r256.TransformBlock(buffer, offset, size);
break;
case RipeMD.RipeMD320 r320:
case MessageDigest.RipeMD320 r320:
r320.TransformBlock(buffer, offset, size);
break;
@@ -393,7 +393,7 @@ namespace SabreTools.Hashing
break;
#endif
case Tiger.TigerHash th:
case MessageDigest.TigerHash th:
th.TransformBlock(buffer, offset, size);
break;
@@ -419,20 +419,20 @@ namespace SabreTools.Hashing
ha.TransformFinalBlock(emptyBuffer, 0, 0);
break;
case RipeMD.RipeMD128 r128:
case MessageDigest.RipeMD128 r128:
r128.Terminate();
break;
case RipeMD.RipeMD160 r160:
case MessageDigest.RipeMD160 r160:
r160.Terminate();
break;
case RipeMD.RipeMD256 r256:
case MessageDigest.RipeMD256 r256:
r256.Terminate();
break;
case RipeMD.RipeMD320 r320:
case MessageDigest.RipeMD320 r320:
r320.Terminate();
break;
case Tiger.TigerHash th:
case MessageDigest.TigerHash th:
th.Terminate();
break;
}

View File

@@ -1,17 +1,141 @@
namespace SabreTools.Hashing.Tiger
namespace SabreTools.Hashing.MessageDigest
{
// <see href="https://cdn.standards.iteh.ai/samples/39876/10f9f9f4bb614eaaaeba7e157e183ca3/ISO-IEC-10118-3-2004.pdf"/>
internal static class Constants
{
public const ulong SeedA = 0x0123456789ABCDEF;
// <see href="https://cdn.standards.iteh.ai/samples/39876/10f9f9f4bb614eaaaeba7e157e183ca3/ISO-IEC-10118-3-2004.pdf"/>
#region RIPEMD-128 / RIPEMD-256
public const ulong SeedB = 0xFEDCBA9876543210;
public const uint RMD128Round00To15 = 0x00000000;
public const uint RMD128Round16To31 = 0x5A827999;
public const uint RMD128Round32To47 = 0x6ED9EBA1;
public const uint RMD128Round48To63 = 0x8F1BBCDC;
public const ulong SeedC = 0xF096A5B4C3B2E187;
public const uint RMD128RoundPrime00To15 = 0x50A28BE6;
public const uint RMD128RoundPrime16To31 = 0x5C4DD124;
public const uint RMD128RoundPrime32To47 = 0x6D703EF3;
public const uint RMD128RoundPrime48To63 = 0x00000000;
public const uint RMD128Y0 = 0x67452301;
public const uint RMD128Y1 = 0xEFCDAB89;
public const uint RMD128Y2 = 0x98BADCFE;
public const uint RMD128Y3 = 0x10325476;
public const uint RMD256Y4 = 0x76543210;
public const uint RMD256Y5 = 0xFEDCBA98;
public const uint RMD256Y6 = 0x89ABCDEF;
public const uint RMD256Y7 = 0x01234567;
#endregion
// <see href="https://cdn.standards.iteh.ai/samples/39876/10f9f9f4bb614eaaaeba7e157e183ca3/ISO-IEC-10118-3-2004.pdf"/>
#region RIPEMD-160 / RIPEMD-320
public const uint RMD160Round00To15 = 0x00000000;
public const uint RMD160Round16To31 = 0x5A827999;
public const uint RMD160Round32To47 = 0x6ED9EBA1;
public const uint RMD160Round48To63 = 0x8F1BBCDC;
public const uint RMD160Round64To79 = 0xA953FD4E;
public const uint RMD160RoundPrime00To15 = 0x50A28BE6;
public const uint RMD160RoundPrime16To31 = 0x5C4DD124;
public const uint RMD160RoundPrime32To47 = 0x6D703EF3;
public const uint RMD160RoundPrime48To63 = 0x7A6D76E9;
public const uint RMD160RoundPrime64To79 = 0x00000000;
public const uint RMD160Y0 = 0x67452301;
public const uint RMD160Y1 = 0xEFCDAB89;
public const uint RMD160Y2 = 0x98BADCFE;
public const uint RMD160Y3 = 0x10325476;
public const uint RMD160Y4 = 0xC3D2E1F0;
public const uint RMD320Y5 = 0x76543210;
public const uint RMD320Y6 = 0xFEDCBA98;
public const uint RMD320Y7 = 0x89ABCDEF;
public const uint RMD320Y8 = 0x01234567;
public const uint RMD320Y9 = 0x3C2D1E0F;
/// <summary>
/// t_i
/// </summary>
public static readonly byte[] RMD160Ti =
[
11, 14, 15, 12, 5, 8, 7, 9,
11, 13, 14, 15, 6, 7, 9, 8,
7, 6, 8, 13, 11, 9, 7, 15,
7, 12, 15, 9, 11, 7, 13, 12,
11, 13, 6, 7, 14, 9, 13, 15,
14, 8, 13, 6, 5, 12, 7, 5,
11, 12, 14, 15, 14, 15, 9, 8,
9, 14, 5, 6, 8, 6, 5, 12,
9, 15, 5, 11, 6, 8, 13, 12,
5, 12, 13, 14, 11, 8, 5, 6,
];
/// <summary>
/// t'_i
/// </summary>
public static readonly byte[] RMD160Tpi =
[
8, 9, 9, 11, 13, 15, 15, 5,
7, 7, 8, 11, 14, 14, 12, 6,
9, 13, 15, 7, 12, 8, 9, 11,
7, 7, 12, 7, 6, 15, 13, 11,
9, 7, 15, 11, 8, 6, 6, 14,
12, 13, 5, 14, 13, 13, 7, 5,
15, 5, 8, 11, 14, 14, 6, 14,
6, 9, 12, 9, 12, 5, 15, 8,
8, 5, 12, 9, 12, 5, 14, 6,
8, 13, 6, 5, 15, 13, 11, 11,
];
/// <summary>
/// a_i
/// </summary>
public static readonly byte[] RMD160Ai =
[
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
7, 4, 13, 1, 10, 6, 15, 3,
12, 0, 9, 5, 2, 14, 11, 8,
3, 10, 14, 4, 9, 15, 8, 1,
2, 7, 0, 6, 13, 11, 5, 12,
1, 9, 11, 10, 0, 8, 12, 4,
13, 3, 7, 15, 14, 5, 6, 2,
4, 0, 5, 9, 7, 12, 2, 10,
14, 1, 3, 8, 11, 6, 15, 13,
];
/// <summary>
/// a'_i
/// </summary>
public static readonly byte[] RMD160Api =
[
5, 14, 7, 0, 9, 2, 11, 4,
13, 6, 15, 8, 1, 10, 3, 12,
6, 11, 3, 7, 0, 13, 5, 10,
14, 15, 8, 12, 4, 9, 1, 2,
15, 5, 1, 3, 7, 14, 6, 9,
11, 8, 12, 2, 10, 0, 4, 13,
8, 6, 4, 1, 3, 11, 15, 0,
5, 12, 2, 13, 9, 7, 10, 14,
12, 15, 10, 4, 1, 5, 8, 7,
6, 2, 13, 14, 0, 3, 9, 11,
];
#endregion
/// <see href="https://biham.cs.technion.ac.il/Reports/Tiger//>
#region Tiger-128 / Tiger-160 / Tiger-192
public const ulong TigerSeedA = 0x0123456789ABCDEF;
public const ulong TigerSeedB = 0xFEDCBA9876543210;
public const ulong TigerSeedC = 0xF096A5B4C3B2E187;
/// <summary>
/// S-Boxes
/// </summary>
public static readonly ulong[] Table =
public static readonly ulong[] TigerSBox =
[
0x02AAB17CF7E90C5E /* 0 */, 0xAC424B03E243A8EC /* 1 */,
0x72CD5BE30DD5FCD3 /* 2 */, 0x6D019B93F6F97F3A /* 3 */,
@@ -526,5 +650,7 @@ namespace SabreTools.Hashing.Tiger
0xCD56D9430EA8280E /* 1020 */, 0xC12591D7535F5065 /* 1021 */,
0xC83223F1720AEF96 /* 1022 */, 0xC3A0396F7363A51F /* 1023 */
];
#endregion
}
}

View File

@@ -1,8 +1,8 @@
using System;
using static SabreTools.Hashing.HashOperations;
using static SabreTools.Hashing.RipeMD.Constants;
using static SabreTools.Hashing.MessageDigest.Constants;
namespace SabreTools.Hashing.RipeMD
namespace SabreTools.Hashing.MessageDigest
{
/// <see href="https://cdn.standards.iteh.ai/samples/39876/10f9f9f4bb614eaaaeba7e157e183ca3/ISO-IEC-10118-3-2004.pdf"/>
/// <see href="https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf"/>

View File

@@ -1,8 +1,8 @@
using System;
using static SabreTools.Hashing.HashOperations;
using static SabreTools.Hashing.RipeMD.Constants;
using static SabreTools.Hashing.MessageDigest.Constants;
namespace SabreTools.Hashing.RipeMD
namespace SabreTools.Hashing.MessageDigest
{
/// <see href="https://cdn.standards.iteh.ai/samples/39876/10f9f9f4bb614eaaaeba7e157e183ca3/ISO-IEC-10118-3-2004.pdf"/>
/// <see href="https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf"/>

View File

@@ -1,8 +1,8 @@
using System;
using static SabreTools.Hashing.HashOperations;
using static SabreTools.Hashing.RipeMD.Constants;
using static SabreTools.Hashing.MessageDigest.Constants;
namespace SabreTools.Hashing.RipeMD
namespace SabreTools.Hashing.MessageDigest
{
/// <see href="https://cdn.standards.iteh.ai/samples/39876/10f9f9f4bb614eaaaeba7e157e183ca3/ISO-IEC-10118-3-2004.pdf"/>
/// <see href="https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf"/>

View File

@@ -1,8 +1,8 @@
using System;
using static SabreTools.Hashing.HashOperations;
using static SabreTools.Hashing.RipeMD.Constants;
using static SabreTools.Hashing.MessageDigest.Constants;
namespace SabreTools.Hashing.RipeMD
namespace SabreTools.Hashing.MessageDigest
{
/// <see href="https://cdn.standards.iteh.ai/samples/39876/10f9f9f4bb614eaaaeba7e157e183ca3/ISO-IEC-10118-3-2004.pdf"/>
/// <see href="https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf"/>

View File

@@ -1,8 +1,8 @@
using System;
using static SabreTools.Hashing.HashOperations;
using static SabreTools.Hashing.Tiger.Constants;
using static SabreTools.Hashing.MessageDigest.Constants;
namespace SabreTools.Hashing.Tiger
namespace SabreTools.Hashing.MessageDigest
{
/// <see href="https://biham.cs.technion.ac.il/Reports/Tiger//>
public abstract class TigerHash
@@ -43,9 +43,9 @@ namespace SabreTools.Hashing.Tiger
public void Reset()
{
// Reset the seed values
_state[0] = SeedA;
_state[1] = SeedB;
_state[2] = SeedC;
_state[0] = TigerSeedA;
_state[1] = TigerSeedB;
_state[2] = TigerSeedC;
// Reset the byte count
_totalBytes = 0;
@@ -238,14 +238,14 @@ namespace SabreTools.Hashing.Tiger
{
c ^= x;
a -= Table[((c >> (0 * 8)) & 0xFF) + (0 * 256)]
^ Table[((c >> (2 * 8)) & 0xFF) + (1 * 256)]
^ Table[((c >> (4 * 8)) & 0xFF) + (2 * 256)]
^ Table[((c >> (6 * 8)) & 0xFF) + (3 * 256)];
b += Table[((c >> (1 * 8)) & 0xFF) + (3 * 256)]
^ Table[((c >> (3 * 8)) & 0xFF) + (2 * 256)]
^ Table[((c >> (5 * 8)) & 0xFF) + (1 * 256)]
^ Table[((c >> (7 * 8)) & 0xFF) + (0 * 256)];
a -= TigerSBox[((c >> (0 * 8)) & 0xFF) + (0 * 256)]
^ TigerSBox[((c >> (2 * 8)) & 0xFF) + (1 * 256)]
^ TigerSBox[((c >> (4 * 8)) & 0xFF) + (2 * 256)]
^ TigerSBox[((c >> (6 * 8)) & 0xFF) + (3 * 256)];
b += TigerSBox[((c >> (1 * 8)) & 0xFF) + (3 * 256)]
^ TigerSBox[((c >> (3 * 8)) & 0xFF) + (2 * 256)]
^ TigerSBox[((c >> (5 * 8)) & 0xFF) + (1 * 256)]
^ TigerSBox[((c >> (7 * 8)) & 0xFF) + (0 * 256)];
unchecked { b *= (ulong)mul; }
}

View File

@@ -1,124 +0,0 @@
namespace SabreTools.Hashing.RipeMD
{
// <see href="https://cdn.standards.iteh.ai/samples/39876/10f9f9f4bb614eaaaeba7e157e183ca3/ISO-IEC-10118-3-2004.pdf"/>
internal static class Constants
{
#region RIPEMD-128 / RIPEMD-256
public const uint RMD128Round00To15 = 0x00000000;
public const uint RMD128Round16To31 = 0x5A827999;
public const uint RMD128Round32To47 = 0x6ED9EBA1;
public const uint RMD128Round48To63 = 0x8F1BBCDC;
public const uint RMD128RoundPrime00To15 = 0x50A28BE6;
public const uint RMD128RoundPrime16To31 = 0x5C4DD124;
public const uint RMD128RoundPrime32To47 = 0x6D703EF3;
public const uint RMD128RoundPrime48To63 = 0x00000000;
public const uint RMD128Y0 = 0x67452301;
public const uint RMD128Y1 = 0xEFCDAB89;
public const uint RMD128Y2 = 0x98BADCFE;
public const uint RMD128Y3 = 0x10325476;
public const uint RMD256Y4 = 0x76543210;
public const uint RMD256Y5 = 0xFEDCBA98;
public const uint RMD256Y6 = 0x89ABCDEF;
public const uint RMD256Y7 = 0x01234567;
#endregion
#region RIPEMD-160 / RIPEMD-320
public const uint RMD160Round00To15 = 0x00000000;
public const uint RMD160Round16To31 = 0x5A827999;
public const uint RMD160Round32To47 = 0x6ED9EBA1;
public const uint RMD160Round48To63 = 0x8F1BBCDC;
public const uint RMD160Round64To79 = 0xA953FD4E;
public const uint RMD160RoundPrime00To15 = 0x50A28BE6;
public const uint RMD160RoundPrime16To31 = 0x5C4DD124;
public const uint RMD160RoundPrime32To47 = 0x6D703EF3;
public const uint RMD160RoundPrime48To63 = 0x7A6D76E9;
public const uint RMD160RoundPrime64To79 = 0x00000000;
public const uint RMD160Y0 = 0x67452301;
public const uint RMD160Y1 = 0xEFCDAB89;
public const uint RMD160Y2 = 0x98BADCFE;
public const uint RMD160Y3 = 0x10325476;
public const uint RMD160Y4 = 0xC3D2E1F0;
public const uint RMD320Y5 = 0x76543210;
public const uint RMD320Y6 = 0xFEDCBA98;
public const uint RMD320Y7 = 0x89ABCDEF;
public const uint RMD320Y8 = 0x01234567;
public const uint RMD320Y9 = 0x3C2D1E0F;
/// <summary>
/// t_i
/// </summary>
public static readonly byte[] RMD160Ti =
[
11, 14, 15, 12, 5, 8, 7, 9,
11, 13, 14, 15, 6, 7, 9, 8,
7, 6, 8, 13, 11, 9, 7, 15,
7, 12, 15, 9, 11, 7, 13, 12,
11, 13, 6, 7, 14, 9, 13, 15,
14, 8, 13, 6, 5, 12, 7, 5,
11, 12, 14, 15, 14, 15, 9, 8,
9, 14, 5, 6, 8, 6, 5, 12,
9, 15, 5, 11, 6, 8, 13, 12,
5, 12, 13, 14, 11, 8, 5, 6,
];
/// <summary>
/// t'_i
/// </summary>
public static readonly byte[] RMD160Tpi =
[
8, 9, 9, 11, 13, 15, 15, 5,
7, 7, 8, 11, 14, 14, 12, 6,
9, 13, 15, 7, 12, 8, 9, 11,
7, 7, 12, 7, 6, 15, 13, 11,
9, 7, 15, 11, 8, 6, 6, 14,
12, 13, 5, 14, 13, 13, 7, 5,
15, 5, 8, 11, 14, 14, 6, 14,
6, 9, 12, 9, 12, 5, 15, 8,
8, 5, 12, 9, 12, 5, 14, 6,
8, 13, 6, 5, 15, 13, 11, 11,
];
/// <summary>
/// a_i
/// </summary>
public static readonly byte[] RMD160Ai =
[
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
7, 4, 13, 1, 10, 6, 15, 3,
12, 0, 9, 5, 2, 14, 11, 8,
3, 10, 14, 4, 9, 15, 8, 1,
2, 7, 0, 6, 13, 11, 5, 12,
1, 9, 11, 10, 0, 8, 12, 4,
13, 3, 7, 15, 14, 5, 6, 2,
4, 0, 5, 9, 7, 12, 2, 10,
14, 1, 3, 8, 11, 6, 15, 13,
];
/// <summary>
/// a'_i
/// </summary>
public static readonly byte[] RMD160Api =
[
5, 14, 7, 0, 9, 2, 11, 4,
13, 6, 15, 8, 1, 10, 3, 12,
6, 11, 3, 7, 0, 13, 5, 10,
14, 15, 8, 12, 4, 9, 1, 2,
15, 5, 1, 3, 7, 14, 6, 9,
11, 8, 12, 2, 10, 0, 4, 13,
8, 6, 4, 1, 3, 11, 15, 0,
5, 12, 2, 13, 9, 7, 10, 14,
12, 15, 10, 4, 1, 5, 8, 7,
6, 2, 13, 14, 0, 3, 9, 11,
];
#endregion
}
}