[libdvdnav-devel] src/md5: Replace the MD5 implementation with the FSF LGPL one

Andrew Clayton git at videolan.org
Thu Nov 6 19:32:20 CET 2014


libdvdread | branch: master | Andrew Clayton <andrew at digital-domain.net> | Wed Nov  5 21:36:37 2014 +0000| [3dbbdfb548135eb73a06cf01ac0a0b3fde48b5ab] | committer: Jean-Baptiste Kempf

src/md5: Replace the MD5 implementation with the FSF LGPL one

With GCC 4.8.3 on x86_64 Fedora 20 we get the following warnings from
src/md5.c

    src/md5.c: In function 'md5_finish_ctx':
    src/md5.c:102:3: warning: dereferencing type-punned pointer will
     break strict-aliasing rules [-Wstrict-aliasing]
    *(md5_uint32 *) &ctx->buffer[bytes + pad] = SWAP (ctx->total[0] <<
     3);
    ^
    src/md5.c:103:3: warning: dereferencing type-punned pointer will
     break strict-aliasing rules [-Wstrict-aliasing]
    *(md5_uint32 *) &ctx->buffer[bytes + pad + 4] = SWAP
     ((ctx->total[1] << 3) |
    ^

Rather than trying to fix this, Jean-Baptiste Kempf suggested it would
be better to replace this old implementation with something newer such
as the one used in VLC. So, this is what this does.

We take src/misc/md5.c as src/md5.c and include/vlc_md5.h as src/md5.h

md5.c had little changed in it, just some #include changes, I also had
to remove the restrict keyword from the AddMD5() function definition as
this is a C99 thing. This shouldn't really make much difference in this
usage.

md5.h had the VLC_API macro usage removed and I removed the psz_md5_hash
function as it's not used.

Finally DVDDiscID() in src/dvd_reader.c was changed to make use of this
new implementation. I tested this with the following program

    /*
     * gcc -O2 -Wall -o dvddiscid dvddiscid.c -ldvdread
     */

    #include <stdio.h>

    #include <dvdread/dvd_reader.h>

    int main(void)
    {
        int i;
        dvd_reader_t *dvd;
        unsigned char id[16];

        dvd = DVDOpen("/dev/sr0");
        DVDDiscID(dvd, id);
        DVDClose(dvd);

        for (i = 0; i < 16; i++)
             printf("%.2x", id[i]);
        printf("\n");

        return 0;
    }

and get the same MD5 before and after this change.

    $ ./dvddiscid
    a02f30eb3e76e624b766ec0248757901

    $ LD_LIBRARY_PATH=/opt/libdvdread/lib ./dvddiscid
    a02f30eb3e76e624b766ec0248757901

Signed-off-by: Andrew Clayton <andrew at digital-domain.net>
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
Tested-by: Steve Dibb <beandog at gentoo.org>

> http://git.videolan.org/gitweb.cgi/libdvdread.git/?a=commit;h=3dbbdfb548135eb73a06cf01ac0a0b3fde48b5ab
---

 src/dvd_reader.c |    9 +-
 src/md5.c        |  640 +++++++++++++++++++++++++-----------------------------
 src/md5.h        |  185 +++-------------
 3 files changed, 332 insertions(+), 502 deletions(-)

Diff:   http://git.videolan.org/gitweb.cgi/libdvdread.git/?a=commitdiff;h=3dbbdfb548135eb73a06cf01ac0a0b3fde48b5ab


More information about the libdvdnav-devel mailing list