• Welcome to Valhalla Legends Archive.
 

MBNCSUtil 1.0.4.1 (Managed BNCSUtil) released.

Started by MyndFyre, July 26, 2005, 07:20 PM

Previous topic - Next topic

MyndFyre

No, no, I'm not just doing this to promote my stuff.

MBNCSUtil, a managed (.NET) implementation of BNCSUtil, is being released.

Shadypalm was talking to me about making a wrapper DLL for the original BNCSUtil, and having problems, when I asked (more or less) "Why don't you just make a clean implementation of it in .NET?"  We talked it over and decided I would do it.

The versioning works in such a way that the major, minor, and build numbers correspond to the version of BNCSUtil code it's based on.  Documentation at that link has more information on versioning.

[Looking back]
I had several problems with the X-SHA-1 implementation.  In an attempt to just get things done, I more or less ported (with pointers) the C version of calcHashBuf from BNCSUtil (assuming the macro USE_NEW_BSHA1 was defined 0).  I regret doing so but am confident it will work out until a better solution can be worked out.

[Planned changes]
The ROL function used in BNCSUtil, implemented in the Microsoft Visual C Runtime libraries as _lrotl, I did not implement but chose to simply import to use through P/Invoke.  This will most likely be changed in 1.0.4.2.  The other planned change is to include localization and COM support.  This will be done very soon.  Version 1.0.4.1 is therefore limited to Windows-only use (or Linux use with WINE), but version 1.0.4.2 should run on any x86-based system with the Shared Source CLI.

[On the horizon]
I may depart from implementing strictly the functionality from BNCSUtil.  One change I am considering is that of a server function -- caching the results of CheckRevision in something of a server-friendly class.  While this can already be done with the functionality provided with an external class, it might be useful to someone down the road.  I'm also considering implementing the server portions of NLS.

This code was tested with one each of Starcraft, Diablo II Retail, and Warcraft III Retail CD keys.  NLS is untested in its current implementation; however, it is based on code I previously wrote and tested previously, so it should work correctly.  However, if you choose to use it and encounter bugs, please let me know.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Kp

Quote from: MyndFyre on July 26, 2005, 07:20 PMThe ROL function used in BNCSUtil, implemented in the Microsoft Visual C Runtime libraries as _lrotl, I did not implement but chose to simply import to use through P/Invoke.  This will most likely be changed in 1.0.4.2.

Why not just keep ROL as a macro?  Under gcc, ROL gets optimized into a roll instructon.  I've never checked, but VC probably does the same.  A reasonably decent parser/JITer should do the same, whereas an explicit invocation of the function likely will not be inlined.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

MyndFyre

#2
Quote from: Kp on July 26, 2005, 08:48 PM
Quote from: MyndFyre on July 26, 2005, 07:20 PMThe ROL function used in BNCSUtil, implemented in the Microsoft Visual C Runtime libraries as _lrotl, I did not implement but chose to simply import to use through P/Invoke.  This will most likely be changed in 1.0.4.2.

Why not just keep ROL as a macro?  Under gcc, ROL gets optimized into a roll instructon.  I've never checked, but VC probably does the same.  A reasonably decent parser/JITer should do the same, whereas an explicit invocation of the function likely will not be inlined.

Because the C# preprocessor doesn't support macros.

[edit]I'm fairly certain you know this and are attempting to use it to point out a lack of language feature....

[edit 2]I've updated to 1.0.4.2.  This changes the ROL function to be a short function call rather than a platform-invoke.  This enables Linux users with the SSCLI to use the related function.  I've also removed out the English strings and localized the assembly.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

dxoigmn

#3
Here is my implementation in VB.NET of Blizzard's SHA1 ported from iago's JavaOp:


Imports System.Security.Cryptography

Namespace Bncs.Util
    Public Class BlizzardSHA
        Inherits SHA1

        Private _Buffer(1024) As Byte
        Private _Length As Integer

        Public Overrides Sub Initialize()
            _Length = 0
        End Sub

        Protected Overrides Sub HashCore(ByVal array() As Byte, ByVal ibStart As Integer, ByVal cbSize As Integer)
            If _Length + cbSize > _Buffer.Length Then
                ReDim Preserve _Buffer(2 * (_Length + cbSize))
            End If

            System.Buffer.BlockCopy(array, ibStart, _Buffer, _Length, cbSize)
            _Length += cbSize
        End Sub

        Protected Overrides Function HashFinal() As Byte()
            Dim hashBuffer(&H10 + 5 - 1) As UInteger
            ReDim Preserve _Buffer(_Length)

            hashBuffer(0) = &H67452301UI
            hashBuffer(1) = &HEFCDAB89UI
            hashBuffer(2) = &H98BADCFEUI
            hashBuffer(3) = &H10325476UI
            hashBuffer(4) = &HC3D2E1F0UI

            If _Buffer.Length Mod 4 <> 0 Then
                ReDim Preserve _Buffer(_Buffer.Length + (4 - _Buffer.Length Mod 4))
            End If

            For i As Integer = 0 To _Buffer.Length - 1 Step &H40
                Dim length As Integer = _Buffer.Length - i

                If length > &H40 Then
                    length = &H40
                End If

                System.Buffer.BlockCopy(_Buffer, i, hashBuffer, 20, length)

                If length < &H40 Then
                    Dim zeroBuffer(&H40 - length) As Byte

                    System.Buffer.BlockCopy(zeroBuffer, 0, hashBuffer, 20 + length, zeroBuffer.Length - 1)
                End If

                DataHash(hashBuffer)
            Next

            Dim hashBytes(19) As Byte

            System.Buffer.BlockCopy(hashBuffer, 0, hashBytes, 0, 20)

            Return hashBytes
        End Function

        Private Shared Sub DataHash(ByVal param() As UInteger)
            Dim buf(&H50) As UInteger
            Dim dw As UInteger
            Dim a As UInteger = param(0)
            Dim b As UInteger = param(1)
            Dim c As UInteger = param(2)
            Dim d As UInteger = param(3)
            Dim e As UInteger = param(4)
            Dim p As Integer = 0

            Array.Copy(param, 5, buf, 0, param.Length - 5)

            For i As Integer = &H10 To &H4F
                dw = CByte((buf(i - &H10) Xor buf(i - &H8) Xor buf(i - &HE) Xor buf(i - &H3)) And &HFF)

                buf(i) = (1 >> (&H20 - dw)) Or (1 << dw)
            Next

            For i As Integer = 0 To &H13
                dw = ((a << 5) Or (a >> &H1B)) + (((Not b) And d) Or (c And b)) + e + buf(p) + &H5A827999UI
                e = d
                d = c
                c = (b >> 2) Or (b << &H1E)
                b = a
                a = dw

                p += 1
            Next

            For i As Integer = 0 To &H13
                dw = (d Xor c Xor b) + e + ((a << 5) Or (a >> &H1B)) + buf(p) + &H6ED9EBA1UI
                e = d
                d = c
                c = (b >> 2) Or (b << &H1E)
                b = a
                a = dw

                p += 1
            Next

            For i As Integer = 0 To &H13
                dw = ((c And b) Or (d And c) Or (d And b)) + e + ((a << 5) Or (a >> &H1B)) + buf(p) - &H70E44324
                e = d
                d = c
                c = (b >> 2) Or (b << &H1E)
                b = a
                a = dw

                p += 1
            Next

            For i As Integer = 0 To &H13
                dw = ((a << 5) Or (a >> &H1B)) + e + (d Xor c Xor b) + buf(p) - &H359D3E2AUI
                e = d
                d = c
                c = (b >> 2) Or (b << &H1E)
                b = a
                a = dw

                p += 1
            Next

            param(0) += a
            param(1) += b
            param(2) += c
            param(3) += d
            param(4) += e
        End Sub
    End Class
End Namespace


I don't know if that helps but a nice thing to do would to inherit from SHA1 just because it's nice to be able to change the SHA implementation dynamically depending on the product.

Edit: Removed HashPassword function.

shout

#4
Omg ripoff of my bnethashing.dll... j/k.

*cry* Why does no one want my stuff? *cry*

Lenny

#5
QuoteI don't know if that helps but a nice thing to do would to inherit from SHA1 just because it's nice to be able to change the SHA implementation dynamically depending on the product.
Done...

(worked from BNCSUtil source)
The Bovine Revolution
Something unimportant

Live Battle.net:

WARNING: The preceding message may have contained content unsuitable for young children.

MyndFyre

Quote from: dxoigmn on July 26, 2005, 10:43 PM
I don't know if that helps but a nice thing to do would to inherit from SHA1 just because it's nice to be able to change the SHA implementation dynamically depending on the product.

Thanks for the input.  :)  I'll look into using it down the road.

As far as inheriting from SHA1, the most local variables you should ever have to have is 2 (if you have a local SHA1 instance and a local XSha1 instance -- but even so, XSha1 isn't implemented as an instance object), so I don't think it'll be that big of a deal.  My original XSha1 implementation was based on iago's JavaOp code -- I worked for three days to try to work out what was wrong with it and never managed to.  There were things that I didn't see I needed, like TransformBlock and such.  *shrug*
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

dxoigmn

Quote from: Lenny on July 27, 2005, 12:37 AM
Done...

(worked from BNCSUtil source)

You're not inheriting from SHA1...

Quote from: MyndFyre on July 27, 2005, 01:06 AM
Thanks for the input.  :)  I'll look into using it down the road.

As far as inheriting from SHA1, the most local variables you should ever have to have is 2 (if you have a local SHA1 instance and a local XSha1 instance -- but even so, XSha1 isn't implemented as an instance object), so I don't think it'll be that big of a deal.  My original XSha1 implementation was based on iago's JavaOp code -- I worked for three days to try to work out what was wrong with it and never managed to.  There were things that I didn't see I needed, like TransformBlock and such.  *shrug*

It's true you only 2 variables but I like elegance ;). As far as extending SHA1, you only need to implement HashCore(), HashFinal(), and Initialize(). I probably should have used the protected variables HashValue and HashSizeValue instead of creating my own, but that eluded me when I first wrote that.

Lenny

As far as inheritance in java goes, there's no public SHA1 class.  So I took your comment as asking for a more direct implementation of the actual SHA1 algorithm.  As far as I have seen, all implementations of XSHA1 have been radically different from standard SHA1 (but each sharing the same differences  ;)).

My XSHA1 is implemented directly from http://www.itl.nist.gov/fipspubs/fip180-1.htm.  The only difference is the incorrect shift (hence, XSHA1) and the formalities standard SHA-1 takes in preparing the message for digest.  I wrote the class for the sake of correctness as well as ease of reading for someone familar with standard SHA1.
The Bovine Revolution
Something unimportant

Live Battle.net:

WARNING: The preceding message may have contained content unsuitable for young children.

dxoigmn

Quote from: Lenny on July 27, 2005, 02:34 AM
As far as inheritance in java goes, there's no public SHA1 class.  So I took your comment as asking for a more direct implementation of the actual SHA1 algorithm.  As far as I have seen, all implementations of XSHA1 have been radically different from standard SHA1 (but each sharing the same differences  ;)).

There may not be a SHA1 class, but there is a MessageDigest class which happens to be abstract and allows you to use the SHA1 algorithm via getInstance("SHA"). So, you could inherit from that.

Kp

Quote from: MyndFyre on July 26, 2005, 09:26 PMBecause the C# preprocessor doesn't support macros.

[edit]I'm fairly certain you know this and are attempting to use it to point out a lack of language feature....

[edit 2]I've updated to 1.0.4.2.  This changes the ROL function to be a short function call rather than a platform-invoke.  This enables Linux users with the SSCLI to use the related function.  I've also removed out the English strings and localized the assembly.

I knew Java had this terrible deficiency, but I thought Microsoft might've had the sense not to replicate that mistake.  I suppose they were forced to keep it if they wanted a Java rip-off, though. :)  Making ROL an inline function will actually get you the best of both worlds.  You get the type checking of a compiler-supported feature and the performance/space gain of not using a function call.  I suppose next you're going to tell me that C# also copied Java's braindamage about lack of implicit comparison to null when you write "if (ptr)"?
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

shadypalm88

Quote from: Kp on July 27, 2005, 09:28 PMI suppose next you're going to tell me that C# also copied Java's braindamage about lack of implicit comparison to null when you write "if (ptr)"?
Like you said, they wanted a Java rip-off... It triggers a compiler error: "Cannot implicitly convert type (object) to 'bool'".

MyndFyre

Quote from: Kp on July 27, 2005, 09:28 PM
I suppose next you're going to tell me that C# also copied Java's braindamage about lack of implicit comparison to null when you write "if (ptr)"?

I know that you and Zorm share this opinion (the positive one) of implicit null comparison, but I stand by my belief that it's bad practice.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Lenny

Quote from: dxoigmn on July 27, 2005, 05:22 AM
Quote from: Lenny on July 27, 2005, 02:34 AM
As far as inheritance in java goes, there's no public SHA1 class.  So I took your comment as asking for a more direct implementation of the actual SHA1 algorithm.  As far as I have seen, all implementations of XSHA1 have been radically different from standard SHA1 (but each sharing the same differences  ;)).

There may not be a SHA1 class, but there is a MessageDigest class which happens to be abstract and allows you to use the SHA1 algorithm via getInstance("SHA"). So, you could inherit from that.

True, but that wouldn't be inheriting from SHA1.  That would simply be inheriting from a class which SHA1 also inherits.
The Bovine Revolution
Something unimportant

Live Battle.net:

WARNING: The preceding message may have contained content unsuitable for young children.

MyndFyre

Quote from: Lenny on July 27, 2005, 10:11 PM
Quote from: dxoigmn on July 27, 2005, 05:22 AM
Quote from: Lenny on July 27, 2005, 02:34 AM
As far as inheritance in java goes, there's no public SHA1 class.  So I took your comment as asking for a more direct implementation of the actual SHA1 algorithm.  As far as I have seen, all implementations of XSHA1 have been radically different from standard SHA1 (but each sharing the same differences  ;)).

There may not be a SHA1 class, but there is a MessageDigest class which happens to be abstract and allows you to use the SHA1 algorithm via getInstance("SHA"). So, you could inherit from that.

True, but that wouldn't be inheriting from SHA1.  That would simply be inheriting from a class which SHA1 also inherits.

You're missing the point.  In the .NET Framework, SHA1 is a class descendent from HashAlgorithm.  Deriving XSha1 from either HashAlgorithm or SHA1 would be equally valid, although it's probably more worthwhile to derive from SHA1 because it's more specific.

It appears that you can register a Provider object to act as an interface to using XSha1.  You implemented XSha1 as a descendent of MessageDigest, and then call getInstance("XSHA1") to access it.  It provides a transparent way of using XSha1 just like any other cryptographic service provider.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.