vlc_md5.h 1.88 KB
Newer Older
1 2 3
/*****************************************************************************
 * vlc_md5.h: MD5 hash
 *****************************************************************************
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
4
 * Copyright © 2004-2011 VLC authors and VideoLAN
5
 *
6 7
 * Authors: Rémi Denis-Courmont
 *          Rafaël Carré
8
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
9 10
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
11
 * the Free Software Foundation; either version 2.1 of the License, or
12 13 14 15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Lesser General Public License for more details.
18
 *
19 20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23
 *****************************************************************************/

24 25
#ifndef VLC_MD5_H
# define VLC_MD5_H
26

27 28
/**
 * \file
29
 * This file defines functions and structures to compute MD5 digests
30 31
 */

32 33
struct md5_s
{
34 35 36 37
    uint32_t A, B, C, D;          /* chaining variables */
    uint32_t nblocks;
    uint8_t buf[64];
    int count;
38 39
};

40 41 42
VLC_API void InitMD5( struct md5_s * );
VLC_API void AddMD5( struct md5_s *, const void *, size_t );
VLC_API void EndMD5( struct md5_s * );
43

44
/**
45 46 47 48 49
 * Returns a char representation of the md5 hash, as shown by UNIX md5 or
 * md5sum tools.
 */
static inline char * psz_md5_hash( struct md5_s *md5_s )
{
50
    char *psz = (char*)malloc( 33 ); /* md5 string is 32 bytes + NULL character */
51
    if( likely(psz) )
52
    {
53
        for( int i = 0; i < 16; i++ )
54
            sprintf( &psz[2*i], "%02" PRIx8, md5_s->buf[i] );
55 56 57 58
    }
    return psz;
}

59
#endif