Commit 8f327be7 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Replace MD5 implementation with FSF LGPL'd one

This was originally written by Ulrich Drepper for glibc. However, this
particular version is copied from libgcrypt (simpler to adapt).
parent 2f873669
/***************************************************************************** /*****************************************************************************
* vlc_md5.h: MD5 hash * vlc_md5.h: MD5 hash
***************************************************************************** *****************************************************************************
* Copyright (C) 2004-2005 the VideoLAN team * Copyright (C) 2004-2011 the VideoLAN team
* $Id$
* *
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net> * Authors: Rémi Denis-Courmont
* Sam Hocevar <sam@zoy.org> * Rafaël Carré
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software Foundation,
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef VLC_MD5_H #ifndef VLC_MD5_H
...@@ -27,20 +26,15 @@ ...@@ -27,20 +26,15 @@
/** /**
* \file * \file
* This file defines functions and structures for handling md5 checksums * This file defines functions and structures to compute MD5 digests
*/ */
/*****************************************************************************
* md5_s: MD5 message structure
*****************************************************************************
* This structure stores the static information needed to compute an MD5
* hash. It has an extra data buffer to allow non-aligned writes.
*****************************************************************************/
struct md5_s struct md5_s
{ {
uint64_t i_bits; /* Total written bits */ uint32_t A, B, C, D; /* chaining variables */
uint32_t p_digest[4]; /* The MD5 digest */ uint32_t nblocks;
uint32_t p_data[16]; /* Buffer to cache non-aligned writes */ uint8_t buf[64];
int count;
}; };
VLC_API void InitMD5( struct md5_s * ); VLC_API void InitMD5( struct md5_s * );
...@@ -54,20 +48,11 @@ VLC_API void EndMD5( struct md5_s * ); ...@@ -54,20 +48,11 @@ VLC_API void EndMD5( struct md5_s * );
static inline char * psz_md5_hash( struct md5_s *md5_s ) static inline char * psz_md5_hash( struct md5_s *md5_s )
{ {
char *psz = malloc( 33 ); /* md5 string is 32 bytes + NULL character */ char *psz = malloc( 33 ); /* md5 string is 32 bytes + NULL character */
if( !psz ) return NULL; if( likely(psz) )
int i;
for ( i = 0; i < 4; i++ )
{ {
sprintf( &psz[8*i], "%02x%02x%02x%02x", for( int i = 0; i < 16; i++ )
md5_s->p_digest[i] & 0xff, sprintf( &psz[2*i], "%02"PRIx8, md5_s->buf[i] );
( md5_s->p_digest[i] >> 8 ) & 0xff,
( md5_s->p_digest[i] >> 16 ) & 0xff,
md5_s->p_digest[i] >> 24
);
} }
psz[32] = '\0';
return psz; return psz;
} }
......
...@@ -354,7 +354,7 @@ int drms_init( void *_p_drms, uint32_t i_type, ...@@ -354,7 +354,7 @@ int drms_init( void *_p_drms, uint32_t i_type,
InitAES( &p_drms->aes, p_drms->p_key ); InitAES( &p_drms->aes, p_drms->p_key );
memcpy( p_priv, p_info, 64 ); memcpy( p_priv, p_info, 64 );
memcpy( p_drms->p_key, md5.p_digest, 16 ); memcpy( p_drms->p_key, md5.buf, 16 );
drms_decrypt( p_drms, p_priv, 64, NULL ); drms_decrypt( p_drms, p_priv, 64, NULL );
REVERSE( p_priv, 64 ); REVERSE( p_priv, 64 );
...@@ -511,8 +511,8 @@ static void InitShuffle( struct shuffle_s *p_shuffle, uint32_t *p_sys_key, ...@@ -511,8 +511,8 @@ static void InitShuffle( struct shuffle_s *p_shuffle, uint32_t *p_sys_key,
p_secret1[ 3 ]++; p_secret1[ 3 ]++;
REVERSE( md5.p_digest, 1 ); REVERSE( (void *)md5.buf, 1 ); /* FIXME */
i_hash = ((int32_t)U32_AT(md5.p_digest)) % 1024; i_hash = ((int32_t)U32_AT(md5.buf)) % 1024;
p_shuffle->p_commands[ i ] = i_hash < 0 ? i_hash * -1 : i_hash; p_shuffle->p_commands[ i ] = i_hash < 0 ? i_hash * -1 : i_hash;
} }
...@@ -624,7 +624,7 @@ static void DoShuffle( struct shuffle_s *p_shuffle, ...@@ -624,7 +624,7 @@ static void DoShuffle( struct shuffle_s *p_shuffle,
/* XOR our buffer with the computed checksum */ /* XOR our buffer with the computed checksum */
for( i = 0; i < i_size; i++ ) for( i = 0; i < i_size; i++ )
{ {
p_buffer[ i ] ^= md5.p_digest[ i ]; p_buffer[ i ] ^= U32_AT(md5.buf + (4 * i));
} }
} }
...@@ -1330,7 +1330,7 @@ static int GetSystemKey( uint32_t *p_sys_key, bool b_ipod ) ...@@ -1330,7 +1330,7 @@ static int GetSystemKey( uint32_t *p_sys_key, bool b_ipod )
EndMD5( &md5 ); EndMD5( &md5 );
memcpy( p_sys_key, md5.p_digest, 16 ); memcpy( p_sys_key, md5.buf, 16 );
return 0; return 0;
} }
...@@ -1707,7 +1707,7 @@ static int HashSystemInfo( uint32_t *p_system_hash ) ...@@ -1707,7 +1707,7 @@ static int HashSystemInfo( uint32_t *p_system_hash )
#endif #endif
EndMD5( &md5 ); EndMD5( &md5 );
memcpy( p_system_hash, md5.p_digest, 16 ); memcpy( p_system_hash, md5.buf, 16 );
return i_ret; return i_ret;
} }
......
This diff is collapsed.
...@@ -107,18 +107,18 @@ void vlc_rand_bytes (void *buf, size_t len) ...@@ -107,18 +107,18 @@ void vlc_rand_bytes (void *buf, size_t len)
AddMD5 (&mdi, &stamp, sizeof (stamp)); AddMD5 (&mdi, &stamp, sizeof (stamp));
AddMD5 (&mdi, &val, sizeof (val)); AddMD5 (&mdi, &val, sizeof (val));
EndMD5 (&mdi); EndMD5 (&mdi);
AddMD5 (&mdo, mdi.p_digest, sizeof (mdi.p_digest)); AddMD5 (&mdo, mdi.buf, 16);
EndMD5 (&mdo); EndMD5 (&mdo);
if (len < sizeof (mdo.p_digest)) if (len < 16)
{ {
memcpy (buf, mdo.p_digest, len); memcpy (buf, mdo.buf, len);
break; break;
} }
memcpy (buf, mdo.p_digest, sizeof (mdo.p_digest)); memcpy (buf, mdo.buf, 16);
len -= sizeof (mdo.p_digest); len -= 16;
buf = ((uint8_t *)buf) + sizeof (mdo.p_digest); buf = ((uint8_t *)buf) + 16;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment