Near Final PEP 247 - API for Cryptographic Hash Functions

Boyd Roberts boyd at insultant.net
Sat Sep 29 01:20:27 CEST 2001


"Andrew Kuchling" <akuchlin at mems-exchange.org> a écrit dans le message news: mailman.1001707952.19388.python-list at python.org...
> We program in a byte-oriented world. :)

MD5 is _bit_ orientated.

> >What exactly does update() do?  Does it replace or append?
>
> "Append", meaning that the string is hashed into the current state of
> the object.

it has to appended to the current MD5 block.  when you have
a whole block you can process the block.  could you clarify
what you just said?

the digest is computed on the padded block and it's length:

    /* pad message */
    *me++ = 0x80;

    if ((me - mb) > MSG_LEN0_BYTE)
    {
        /* digest this block and substitute a padded block */
        bzero(me, MSG_BYTES - (me - mb));
        md5block(mb, digest);
        bzero(mb, MSG_LEN0_BYTE);
    }
    else
        bzero(me, MSG_LEN0_BYTE - (me - mb));

    /* append size in bits */
    unpack(bits[0], &mb[MSG_LEN0_BYTE]);
    unpack(bits[1], &mb[MSG_LEN1_BYTE]);
    md5block(mb, digest);

if you want all the code:

    http://home.fr.inter.net/boyd/code/md5.bundle






More information about the Python-list mailing list