Calculating Checksum in Eiffel

3 Messages Forum Options Options
Permalink
Andreas Leitner
Calculating Checksum in Eiffel
Reply Threaded More
Print post
Permalink
Hi all,

we need to calculate the checksum of a stream of characters. Basically
we would like to a quick way to check if two streams of characters are
he same. False positives are not a big deal, since we can always fall
back and compare the streams character for character (as long as it does
not happen too often).

Does anybody know if such an algorithm is already implemented somewhere
in Eiffel that we could use?

I only found Franck's library
(http://eiffelzone.com/esd/crc/index.html), but it is written against
TowerEiffel using BIT, both of which are no longer supported.

many thanks in advance,
Andreas


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
gobo-eiffel-develop mailing list
gobo-eiffel-develop@...
https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop
Howard Thomson
Re: Calculating Checksum in Eiffel
Reply Threaded More
Print post
Permalink
Hi Andreas,

Well I would wrap C routines for either MD5 or SHA1, which I have been
intending to complete Real-Soon-Now for sometime.

Only four C calls are needed:

        sha1.initialize
        sha1.process (address: POINTER; count: INTEGER)
        sha1.finalize
        signature := sha1.result_as_string

or something like that ...

I will send you a couple of Eiffel files that will need adapting; they were
last used with SmartEiffel and the result_as_string routine will need to be
adapted to Gobo's string and character routines.

See md5deep.sourceforge.net

If you get it working, I would be obliged if you would return the working
classes ...

Howard


#############################################################
indexing

        description: "Hashing Algorithms"

deferred class FILE_HASH

feature

        init is
                        -- Initialise prior to processing a byte sequence
                deferred
                end

        process(area: POINTER; count: INTEGER) is
                        -- Process a contiguous sequence of bytes
                deferred
                end

        finalise is
                        -- Post processing of remaining steps
                deferred
                end

end
#############################################################
indexing

        description: "SHA1 Secure Hash Algorithm"

class HASH_STREAM_SHA1

inherit

        FILE_HASH -- Note name to be changed

create

        make

feature -- Attributes

        sha1_context: POINTER

        result_buffer: ARRAY [ INTEGER_8 ]

feature -- Routines

        make is
                local
                        b: ARRAY [ INTEGER_8 ]
                do
                        create b.make (1, sha1_context_size_temp)
                        sha1_context := b.to_external
                        create result_buffer.make(1, 20)
                end

        init is
                do
                        sha1_init (sha1_context)
                end

        process (data: POINTER; count: INTEGER) is
                do
                        sha1_process (sha1_context, data, count)
                end

        finalise is
                do
                        sha1_finalise (result_buffer.to_external, sha1_context)
                end

        result_as_string: STRING is
                local
                        i: INTEGER
                do
                        create Result.make (40)
                        from
                                i := 1
                        until
                                i > 20
                        loop
                        -- Result.append ((result_buffer @ i).to_hex_string)
                                (result_buffer @ i).to_hexadecimal_in(Result)
                                i := i + 1
                        end
                end

feature {NONE} -- TEMP

        sha1_context_size_temp: INTEGER is
                do
                        Result := (5 + 2) * 8
                        Result := Result + 64
                end

feature {NONE} -- External routines, SHA1 implementation

        sha1_context_size: INTEGER is
                        -- Size of the C struct containing the SHA1 Context
                external "C use %"md5deep.h%""
                alias "sizeof(SHA1_CTX)"
                end

        sha1_init (p: POINTER) is
                        -- Call initialisation routine for the Context
                external "C"
                alias "SHA1Init"
                end

        sha1_process (p_ctx: POINTER; p_data: POINTER; n: INTEGER) is
                external "C"
                alias "SHA1Update"
                end

        sha1_finalise (p_result: POINTER; p_ctx: POINTER) is
                external "C"
                alias "SHA1Final"
                end

invariant

        sha1_context /= default_pointer

end
################################################################

On Friday 14 Mar 2008, Andreas Leitner wrote:

> Hi all,
>
> we need to calculate the checksum of a stream of characters. Basically
> we would like to a quick way to check if two streams of characters are
> he same. False positives are not a big deal, since we can always fall
> back and compare the streams character for character (as long as it does
> not happen too often).
>
> Does anybody know if such an algorithm is already implemented somewhere
> in Eiffel that we could use?
>
> I only found Franck's library
> (http://eiffelzone.com/esd/crc/index.html), but it is written against
> TowerEiffel using BIT, both of which are no longer supported.
>
> many thanks in advance,
> Andreas
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> gobo-eiffel-develop mailing list
> gobo-eiffel-develop@...
> https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop



--
Howard Thomson

--
"Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former." -- Albert Einstein


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
gobo-eiffel-develop mailing list
gobo-eiffel-develop@...
https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop
Andreas Leitner
Re: Calculating Checksum in Eiffel
Reply Threaded More
Print post
Permalink

On Wed, 2008-03-26 at 18:22 +0000, Howard Thomson wrote:

> Hi Andreas,
>
> Well I would wrap C routines for either MD5 or SHA1, which I have been
> intending to complete Real-Soon-Now for sometime.
>
> Only four C calls are needed:
>
> sha1.initialize
> sha1.process (address: POINTER; count: INTEGER)
> sha1.finalize
> signature := sha1.result_as_string
>
> or something like that ...
>
> I will send you a couple of Eiffel files that will need adapting; they were
> last used with SmartEiffel and the result_as_string routine will need to be
> adapted to Gobo's string and character routines.
>
> See md5deep.sourceforge.net
>
> If you get it working, I would be obliged if you would return the working
> classes ...

Hi Howard,

many thanks for your code. Sorry for not getting back earlier. Stefan
Mori was really excited by the idea of implementing the Whirlpool
algorithm and has already finished it by now. If you are interested you
can grab it from
http://svn.origo.ethz.ch/wsvn/eiffelstudio/branches/eth/cdd/Eiffel_61/Src/Eiffel/cdd/support/#_branches_eth_cdd_Eiffel_61_Src_Eiffel_cdd_support_

Andreas


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
gobo-eiffel-develop mailing list
gobo-eiffel-develop@...
https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop