vlc_md5.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_md5.h: MD5 hash
00003  *****************************************************************************
00004  * Copyright © 2004-2011 VLC authors and VideoLAN
00005  *
00006  * Authors: Rémi Denis-Courmont
00007  *          Rafaël Carré
00008  *
00009  * This program is free software; you can redistribute it and/or modify it
00010  * under the terms of the GNU Lesser General Public License as published by
00011  * the Free Software Foundation; either version 2.1 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017  * GNU Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with this program; if not, write to the Free Software Foundation,
00021  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 #ifndef VLC_MD5_H
00025 # define VLC_MD5_H
00026 
00027 /**
00028  * \file
00029  * This file defines functions and structures to compute MD5 digests
00030  */
00031 
00032 struct md5_s
00033 {
00034     uint32_t A, B, C, D;          /* chaining variables */
00035     uint32_t nblocks;
00036     uint8_t buf[64];
00037     int count;
00038 };
00039 
00040 VLC_API void InitMD5( struct md5_s * );
00041 VLC_API void AddMD5( struct md5_s *, const void *, size_t );
00042 VLC_API void EndMD5( struct md5_s * );
00043 
00044 /**
00045  * Returns a char representation of the md5 hash, as shown by UNIX md5 or
00046  * md5sum tools.
00047  */
00048 static inline char * psz_md5_hash( struct md5_s *md5_s )
00049 {
00050     char *psz = malloc( 33 ); /* md5 string is 32 bytes + NULL character */
00051     if( likely(psz) )
00052     {
00053         for( int i = 0; i < 16; i++ )
00054             sprintf( &psz[2*i], "%02"PRIx8, md5_s->buf[i] );
00055     }
00056     return psz;
00057 }
00058 
00059 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines