mirror of
https://github.com/libretro/beetle-pce-fast-libretro.git
synced 2024-11-23 16:00:08 +00:00
no md5
This commit is contained in:
parent
07a126a8e8
commit
c35d24b1ee
2
Makefile
2
Makefile
@ -227,7 +227,6 @@ CDROM_SOURCES += $(MEDNAFEN_DIR)/cdrom/crc32.cpp
|
||||
CDROM_SOURCES += $(MEDNAFEN_DIR)/cdrom/cdromif.cpp
|
||||
|
||||
|
||||
MEDNAFEN_SOURCES += $(MEDNAFEN_DIR)/math_ops.cpp
|
||||
MEDNAFEN_SOURCES += $(MEDNAFEN_DIR)/settings.cpp
|
||||
MEDNAFEN_SOURCES += $(MEDNAFEN_DIR)/general.cpp
|
||||
MEDNAFEN_SOURCES += $(MEDNAFEN_DIR)/FileWrapper.cpp
|
||||
@ -241,7 +240,6 @@ MEDNAFEN_SOURCES += $(MEDNAFEN_DIR)/video/surface.cpp
|
||||
MEDNAFEN_SOURCES += $(RESAMPLER_SOURCES)
|
||||
MEDNAFEN_SOURCES += $(MEDNAFEN_DIR)/file.cpp
|
||||
MEDNAFEN_SOURCES += $(OKIADPCM_SOURCES)
|
||||
MEDNAFEN_SOURCES += $(MEDNAFEN_DIR)/md5.cpp
|
||||
|
||||
LIBRETRO_SOURCES += libretro.cpp
|
||||
|
||||
|
72
libretro.cpp
72
libretro.cpp
@ -2,7 +2,6 @@
|
||||
#include "mednafen/mednafen.h"
|
||||
#include "mednafen/git.h"
|
||||
#include "mednafen/general.h"
|
||||
#include "mednafen/md5.h"
|
||||
#include "libretro.h"
|
||||
#include "thread.h"
|
||||
|
||||
@ -682,14 +681,8 @@ int HuCLoad(const uint8 *data, uint32 len, uint32 crc32)
|
||||
IsPopulous = 0;
|
||||
PCE_IsCD = 0;
|
||||
|
||||
md5_context md5;
|
||||
md5.starts();
|
||||
md5.update(data, len);
|
||||
md5.finish(MDFNGameInfo->MD5);
|
||||
|
||||
MDFN_printf(("ROM: %dKiB\n"), (len + 1023) / 1024);
|
||||
MDFN_printf(("ROM CRC32: 0x%04x\n"), crc32);
|
||||
MDFN_printf(("ROM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str());
|
||||
|
||||
if(!(HuCROM = (uint8 *)MDFN_malloc(m_len, ("HuCard ROM"))))
|
||||
{
|
||||
@ -810,41 +803,6 @@ int HuCLoadCD(const char *bios_path)
|
||||
PCE_IsCD = 1;
|
||||
PCE_InitCD();
|
||||
|
||||
md5_context md5;
|
||||
md5.starts();
|
||||
// md5_update(&md5, HuCROM, 262144);
|
||||
|
||||
#if 0
|
||||
int32 track = CDIF_GetFirstTrack();
|
||||
int32 last_track = CDIF_GetLastTrack();
|
||||
bool DTFound = 0;
|
||||
for(; track <= last_track; track++)
|
||||
{
|
||||
CDIF_Track_Format format;
|
||||
|
||||
if(CDIF_GetTrackFormat(track, format) && format == CDIF_FORMAT_MODE1)
|
||||
{
|
||||
DTFound = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(DTFound) // Only add the MD5 hash if we were able to find a data track.
|
||||
{
|
||||
uint32 start_sector = CDIF_GetTrackStartPositionLBA(track);
|
||||
uint8 sector_buffer[2048];
|
||||
|
||||
for(int x = 0; x < 128; x++)
|
||||
{
|
||||
memset(sector_buffer, 0, 2048);
|
||||
CDIF_ReadSector(sector_buffer, NULL, start_sector + x, 1);
|
||||
md5.update(sector_buffer, 2048);
|
||||
}
|
||||
}
|
||||
md5.finish(MDFNGameInfo->MD5);
|
||||
MDFN_printf(("CD MD5(first 256KiB): 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str());
|
||||
#endif
|
||||
|
||||
MDFN_printf(("Arcade Card Emulation: %s\n"), PCE_ACEnabled ? ("Enabled") : ("Disabled"));
|
||||
for(int x = 0; x < 0x40; x++)
|
||||
{
|
||||
@ -1065,33 +1023,6 @@ MDFNGI *MDFNI_LoadCD(const char *force_module, const char *devicename)
|
||||
}
|
||||
MDFN_indent(-1);
|
||||
|
||||
// Calculate layout MD5. The system emulation LoadCD() code is free to ignore this value and calculate
|
||||
// its own, or to use it to look up a game in its database.
|
||||
{
|
||||
md5_context layout_md5;
|
||||
|
||||
layout_md5.starts();
|
||||
|
||||
for(unsigned i = 0; i < CDInterfaces.size(); i++)
|
||||
{
|
||||
CD_TOC toc;
|
||||
|
||||
CDInterfaces[i]->ReadTOC(&toc);
|
||||
|
||||
layout_md5.update_u32_as_lsb(toc.first_track);
|
||||
layout_md5.update_u32_as_lsb(toc.last_track);
|
||||
layout_md5.update_u32_as_lsb(toc.tracks[100].lba);
|
||||
|
||||
for(uint32 track = toc.first_track; track <= toc.last_track; track++)
|
||||
{
|
||||
layout_md5.update_u32_as_lsb(toc.tracks[track].lba);
|
||||
layout_md5.update_u32_as_lsb(toc.tracks[track].control & 0x4);
|
||||
}
|
||||
}
|
||||
|
||||
layout_md5.finish(LayoutMD5);
|
||||
}
|
||||
|
||||
// This if statement will be true if force_module references a system without CDROM support.
|
||||
if(!MDFNGameInfo->LoadCD)
|
||||
{
|
||||
@ -1945,9 +1876,6 @@ std::string MDFN_MakeFName(MakeFName_Type type, int id1, const char *cd1)
|
||||
case MDFNMKF_SAV:
|
||||
ret = retro_save_directory +slash + retro_base_name +
|
||||
std::string(".") +
|
||||
#ifndef _XBOX
|
||||
md5_context::asciistr(MDFNGameInfo->MD5, 0) + std::string(".") +
|
||||
#endif
|
||||
std::string(cd1);
|
||||
break;
|
||||
case MDFNMKF_FIRMWARE:
|
||||
|
@ -27,8 +27,6 @@
|
||||
#include "general.h"
|
||||
#include "state.h"
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static bool IsAbsolutePath(const char *path)
|
||||
|
@ -1,103 +0,0 @@
|
||||
#ifndef __MDFN_LEPACKER_H
|
||||
#define __MDFN_LEPACKER_H
|
||||
|
||||
#include "mednafen.h"
|
||||
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Little-endian byte packer(and unpacker). */
|
||||
|
||||
namespace MDFN
|
||||
{
|
||||
|
||||
class LEPacker;
|
||||
class LEPackable
|
||||
{
|
||||
public:
|
||||
virtual void pack(LEPacker &lep) = 0;
|
||||
};
|
||||
|
||||
class LEPacker : public std::vector<uint8>
|
||||
{
|
||||
public:
|
||||
|
||||
LEPacker() : read_mode(0), read_pos(0), randomize_read_mode(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline void set_read_mode(bool new_read_mode, bool new_randomize_read_mode = false)
|
||||
{
|
||||
read_mode = new_read_mode;
|
||||
randomize_read_mode = new_randomize_read_mode;
|
||||
}
|
||||
|
||||
inline void reset_read_pos(void)
|
||||
{
|
||||
read_pos = 0;
|
||||
}
|
||||
|
||||
void operator^(LEPackable &o)
|
||||
{
|
||||
o.pack(*this);
|
||||
}
|
||||
|
||||
template<typename T> INLINE void operator^(T &val)
|
||||
{
|
||||
size_type csize = size();
|
||||
|
||||
if(read_mode)
|
||||
{
|
||||
if((read_pos + sizeof(T)) > csize)
|
||||
throw(std::out_of_range("LEPacker::operator^"));
|
||||
|
||||
uint8 *ptr = &(*this)[read_pos];
|
||||
val = 0;
|
||||
|
||||
if(randomize_read_mode)
|
||||
{
|
||||
for(unsigned int n = 0; n < sizeof(T); n++)
|
||||
val |= ((T)((rand() >> 4) & 0xFF)) << (n << 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(unsigned int n = 0; n < sizeof(T); n++)
|
||||
val |= ((T)ptr[n]) << (n << 3);
|
||||
}
|
||||
|
||||
read_pos += sizeof(T);
|
||||
}
|
||||
else
|
||||
{
|
||||
resize(csize + sizeof(T));
|
||||
|
||||
uint8 *ptr = &(*this)[csize];
|
||||
|
||||
for(unsigned int n = 0; n < sizeof(T); n++)
|
||||
ptr[n] = val >> (n << 3);
|
||||
}
|
||||
}
|
||||
|
||||
INLINE void operator^(bool &val)
|
||||
{
|
||||
uint8 tmp = val;
|
||||
|
||||
(*this) ^ tmp;
|
||||
|
||||
if(read_mode)
|
||||
val = tmp;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
bool read_mode;
|
||||
uint64 read_pos;
|
||||
bool randomize_read_mode;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,209 +0,0 @@
|
||||
#ifndef __MDFN_PSX_MASMEM_H
|
||||
#define __MDFN_PSX_MASMEM_H
|
||||
|
||||
// TODO, WIP (big-endian stores and loads not fully supported yet)
|
||||
|
||||
#ifdef LSB_FIRST
|
||||
#define MAS_NATIVE_IS_BIGENDIAN 0
|
||||
#else
|
||||
#define MAS_NATIVE_IS_BIGENDIAN 1
|
||||
#endif
|
||||
|
||||
static INLINE uint16 LoadU16_RBO(const uint16 *a)
|
||||
{
|
||||
#ifdef ARCH_POWERPC
|
||||
uint16 tmp;
|
||||
|
||||
__asm__ ("lhbrx %0, %y1" : "=r"(tmp) : "Z"(*a));
|
||||
|
||||
return(tmp);
|
||||
|
||||
#else
|
||||
uint16 tmp = *a;
|
||||
return((tmp << 8) | (tmp >> 8));
|
||||
#endif
|
||||
}
|
||||
|
||||
static INLINE uint32 LoadU32_RBO(const uint32 *a)
|
||||
{
|
||||
#ifdef ARCH_POWERPC
|
||||
uint32 tmp;
|
||||
|
||||
__asm__ ("lwbrx %0, %y1" : "=r"(tmp) : "Z"(*a));
|
||||
|
||||
return(tmp);
|
||||
#else
|
||||
uint32 tmp = *a;
|
||||
return((tmp << 24) | ((tmp & 0xFF00) << 8) | ((tmp >> 8) & 0xFF00) | (tmp >> 24));
|
||||
#endif
|
||||
}
|
||||
|
||||
static INLINE void StoreU16_RBO(uint16 *a, const uint16 v)
|
||||
{
|
||||
#ifdef ARCH_POWERPC
|
||||
__asm__ ("sthbrx %0, %y1" : : "r"(v), "Z"(*a));
|
||||
#else
|
||||
uint16 tmp = (v << 8) | (v >> 8);
|
||||
*a = tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
static INLINE void StoreU32_RBO(uint32 *a, const uint32 v)
|
||||
{
|
||||
#ifdef ARCH_POWERPC
|
||||
__asm__ ("stwbrx %0, %y1" : : "r"(v), "Z"(*a));
|
||||
#else
|
||||
uint32 tmp = (v << 24) | ((v & 0xFF00) << 8) | ((v >> 8) & 0xFF00) | (v >> 24);
|
||||
*a = tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
static INLINE uint16 LoadU16_LE(const uint16 *a)
|
||||
{
|
||||
#ifdef MSB_FIRST
|
||||
return LoadU16_RBO(a);
|
||||
#else
|
||||
return *a;
|
||||
#endif
|
||||
}
|
||||
|
||||
static INLINE uint32 LoadU32_LE(const uint32 *a)
|
||||
{
|
||||
#ifdef MSB_FIRST
|
||||
return LoadU32_RBO(a);
|
||||
#else
|
||||
return *a;
|
||||
#endif
|
||||
}
|
||||
|
||||
static INLINE void StoreU16_LE(uint16 *a, const uint16 v)
|
||||
{
|
||||
#ifdef MSB_FIRST
|
||||
StoreU16_RBO(a, v);
|
||||
#else
|
||||
*a = v;
|
||||
#endif
|
||||
}
|
||||
|
||||
static INLINE void StoreU32_LE(uint32 *a, const uint32 v)
|
||||
{
|
||||
#ifdef MSB_FIRST
|
||||
StoreU32_RBO(a, v);
|
||||
#else
|
||||
*a = v;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// address must not be >= size specified by template parameter, and address must be a multiple of the byte-size of the
|
||||
// unit(1,2,4) being read(except for Read/WriteU24, which only needs to be byte-aligned).
|
||||
//
|
||||
// max_unit_type should be uint16 or uint32
|
||||
//
|
||||
// pre_padding and post_padding are specified in units of sizeof(max_unit_type).
|
||||
//
|
||||
template<unsigned size, typename max_unit_type, bool big_endian> //, unsigned pre_padding_count, unsigned post_padding_count>
|
||||
struct MultiAccessSizeMem
|
||||
{
|
||||
//max_unit_type pre_padding[pre_padding_count ? pre_padding_count : 1];
|
||||
|
||||
union
|
||||
{
|
||||
uint8 data8[size];
|
||||
uint16 data16[size / sizeof(uint16)];
|
||||
uint32 data32[size / sizeof(uint32)];
|
||||
};
|
||||
|
||||
//max_unit_type post_padding[post_padding_count ? post_padding_count : 1];
|
||||
|
||||
INLINE uint8 ReadU8(uint32 address)
|
||||
{
|
||||
return data8[address];
|
||||
}
|
||||
|
||||
INLINE uint16 ReadU16(uint32 address)
|
||||
{
|
||||
if(MAS_NATIVE_IS_BIGENDIAN == big_endian)
|
||||
return *(uint16*)(((uint8*)data16) + address);
|
||||
else
|
||||
return LoadU16_RBO((uint16*)(((uint8*)data16) + address));
|
||||
}
|
||||
|
||||
INLINE uint32 ReadU32(uint32 address)
|
||||
{
|
||||
if(MAS_NATIVE_IS_BIGENDIAN == big_endian)
|
||||
return *(uint32*)(((uint8*)data32) + address);
|
||||
else
|
||||
return LoadU32_RBO((uint32*)(((uint8*)data32) + address));
|
||||
}
|
||||
|
||||
INLINE uint32 ReadU24(uint32 address)
|
||||
{
|
||||
uint32 ret;
|
||||
|
||||
if(!big_endian)
|
||||
{
|
||||
ret = ReadU8(address) | (ReadU8(address + 1) << 8) | (ReadU8(address + 2) << 16);
|
||||
}
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
INLINE void WriteU8(uint32 address, uint8 value)
|
||||
{
|
||||
data8[address] = value;
|
||||
}
|
||||
|
||||
INLINE void WriteU16(uint32 address, uint16 value)
|
||||
{
|
||||
if(MAS_NATIVE_IS_BIGENDIAN == big_endian)
|
||||
*(uint16*)(((uint8*)data16) + address) = value;
|
||||
else
|
||||
StoreU16_RBO((uint16*)(((uint8*)data16) + address), value);
|
||||
}
|
||||
|
||||
INLINE void WriteU32(uint32 address, uint32 value)
|
||||
{
|
||||
if(MAS_NATIVE_IS_BIGENDIAN == big_endian)
|
||||
*(uint32*)(((uint8*)data32) + address) = value;
|
||||
else
|
||||
StoreU32_RBO((uint32*)(((uint8*)data32) + address), value);
|
||||
}
|
||||
|
||||
INLINE void WriteU24(uint32 address, uint32 value)
|
||||
{
|
||||
if(!big_endian)
|
||||
{
|
||||
WriteU8(address + 0, value >> 0);
|
||||
WriteU8(address + 1, value >> 8);
|
||||
WriteU8(address + 2, value >> 16);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
INLINE T Read(uint32 address)
|
||||
{
|
||||
if(sizeof(T) == 4)
|
||||
return(ReadU32(address));
|
||||
else if(sizeof(T) == 2)
|
||||
return(ReadU16(address));
|
||||
else
|
||||
return(ReadU8(address));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
INLINE void Write(uint32 address, T value)
|
||||
{
|
||||
if(sizeof(T) == 4)
|
||||
WriteU32(address, value);
|
||||
else if(sizeof(T) == 2)
|
||||
WriteU16(address, value);
|
||||
else
|
||||
WriteU8(address, value);
|
||||
}
|
||||
};
|
||||
|
||||
#undef MAS_NATIVE_IS_BIGENDIAN
|
||||
|
||||
#endif
|
@ -1,36 +0,0 @@
|
||||
/* Mednafen - Multi-system Emulator
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "mednafen.h"
|
||||
#include "math_ops.h"
|
||||
|
||||
// Source: http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
||||
// Rounds up to the nearest power of 2.
|
||||
uint32 round_up_pow2(uint32 v)
|
||||
{
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
|
||||
v += (v == 0);
|
||||
|
||||
return(v);
|
||||
}
|
||||
|
@ -1,8 +1,24 @@
|
||||
#ifndef __MDFN_MATH_OPS_H
|
||||
#define __MDFN_MATH_OPS_H
|
||||
#include "mednafen.h"
|
||||
|
||||
// Source: http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
||||
// Rounds up to the nearest power of 2.
|
||||
static INLINE uint32 round_up_pow2(uint32 v)
|
||||
{
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
|
||||
v += (v == 0);
|
||||
|
||||
return(v);
|
||||
}
|
||||
|
||||
static INLINE uint64 round_up_pow2(uint64 v)
|
||||
{
|
||||
v--;
|
||||
|
260
mednafen/md5.cpp
260
mednafen/md5.cpp
@ -1,260 +0,0 @@
|
||||
/*
|
||||
* RFC 1321 compliant MD5 implementation,
|
||||
* by Christophe Devine <devine@cr0.net>;
|
||||
* this program is licensed under the GPL.
|
||||
*/
|
||||
/* Converted to C++ for use in Mednafen */
|
||||
|
||||
#include "mednafen-types.h"
|
||||
#include <string.h>
|
||||
#include "md5.h"
|
||||
|
||||
#define GET_UINT32(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (uint32) (b)[(i) + 3] << 24 ) \
|
||||
| ( (uint32) (b)[(i) + 2] << 16 ) \
|
||||
| ( (uint32) (b)[(i) + 1] << 8 ) \
|
||||
| ( (uint32) (b)[(i) ] ); \
|
||||
}
|
||||
|
||||
#define PUT_UINT32(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (uint8) ( (n) ); \
|
||||
(b)[(i) + 1] = (uint8) ( (n) >> 8 ); \
|
||||
(b)[(i) + 2] = (uint8) ( (n) >> 16 ); \
|
||||
(b)[(i) + 3] = (uint8) ( (n) >> 24 ); \
|
||||
}
|
||||
|
||||
md5_context::md5_context(void)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
md5_context::~md5_context(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void md5_context::starts(void)
|
||||
{
|
||||
total[0] = 0;
|
||||
total[1] = 0;
|
||||
state[0] = 0x67452301;
|
||||
state[1] = 0xEFCDAB89;
|
||||
state[2] = 0x98BADCFE;
|
||||
state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
void md5_context::process(const uint8 data[64])
|
||||
{
|
||||
uint32 A, B, C, D, X[16];
|
||||
|
||||
GET_UINT32( X[0], data, 0 );
|
||||
GET_UINT32( X[1], data, 4 );
|
||||
GET_UINT32( X[2], data, 8 );
|
||||
GET_UINT32( X[3], data, 12 );
|
||||
GET_UINT32( X[4], data, 16 );
|
||||
GET_UINT32( X[5], data, 20 );
|
||||
GET_UINT32( X[6], data, 24 );
|
||||
GET_UINT32( X[7], data, 28 );
|
||||
GET_UINT32( X[8], data, 32 );
|
||||
GET_UINT32( X[9], data, 36 );
|
||||
GET_UINT32( X[10], data, 40 );
|
||||
GET_UINT32( X[11], data, 44 );
|
||||
GET_UINT32( X[12], data, 48 );
|
||||
GET_UINT32( X[13], data, 52 );
|
||||
GET_UINT32( X[14], data, 56 );
|
||||
GET_UINT32( X[15], data, 60 );
|
||||
|
||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
#define P(a,b,c,d,k,s,t) \
|
||||
{ \
|
||||
a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
|
||||
}
|
||||
|
||||
A = state[0];
|
||||
B = state[1];
|
||||
C = state[2];
|
||||
D = state[3];
|
||||
|
||||
#define F(x,y,z) (z ^ (x & (y ^ z)))
|
||||
|
||||
P( A, B, C, D, 0, 7, 0xD76AA478 );
|
||||
P( D, A, B, C, 1, 12, 0xE8C7B756 );
|
||||
P( C, D, A, B, 2, 17, 0x242070DB );
|
||||
P( B, C, D, A, 3, 22, 0xC1BDCEEE );
|
||||
P( A, B, C, D, 4, 7, 0xF57C0FAF );
|
||||
P( D, A, B, C, 5, 12, 0x4787C62A );
|
||||
P( C, D, A, B, 6, 17, 0xA8304613 );
|
||||
P( B, C, D, A, 7, 22, 0xFD469501 );
|
||||
P( A, B, C, D, 8, 7, 0x698098D8 );
|
||||
P( D, A, B, C, 9, 12, 0x8B44F7AF );
|
||||
P( C, D, A, B, 10, 17, 0xFFFF5BB1 );
|
||||
P( B, C, D, A, 11, 22, 0x895CD7BE );
|
||||
P( A, B, C, D, 12, 7, 0x6B901122 );
|
||||
P( D, A, B, C, 13, 12, 0xFD987193 );
|
||||
P( C, D, A, B, 14, 17, 0xA679438E );
|
||||
P( B, C, D, A, 15, 22, 0x49B40821 );
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (y ^ (z & (x ^ y)))
|
||||
|
||||
P( A, B, C, D, 1, 5, 0xF61E2562 );
|
||||
P( D, A, B, C, 6, 9, 0xC040B340 );
|
||||
P( C, D, A, B, 11, 14, 0x265E5A51 );
|
||||
P( B, C, D, A, 0, 20, 0xE9B6C7AA );
|
||||
P( A, B, C, D, 5, 5, 0xD62F105D );
|
||||
P( D, A, B, C, 10, 9, 0x02441453 );
|
||||
P( C, D, A, B, 15, 14, 0xD8A1E681 );
|
||||
P( B, C, D, A, 4, 20, 0xE7D3FBC8 );
|
||||
P( A, B, C, D, 9, 5, 0x21E1CDE6 );
|
||||
P( D, A, B, C, 14, 9, 0xC33707D6 );
|
||||
P( C, D, A, B, 3, 14, 0xF4D50D87 );
|
||||
P( B, C, D, A, 8, 20, 0x455A14ED );
|
||||
P( A, B, C, D, 13, 5, 0xA9E3E905 );
|
||||
P( D, A, B, C, 2, 9, 0xFCEFA3F8 );
|
||||
P( C, D, A, B, 7, 14, 0x676F02D9 );
|
||||
P( B, C, D, A, 12, 20, 0x8D2A4C8A );
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
|
||||
P( A, B, C, D, 5, 4, 0xFFFA3942 );
|
||||
P( D, A, B, C, 8, 11, 0x8771F681 );
|
||||
P( C, D, A, B, 11, 16, 0x6D9D6122 );
|
||||
P( B, C, D, A, 14, 23, 0xFDE5380C );
|
||||
P( A, B, C, D, 1, 4, 0xA4BEEA44 );
|
||||
P( D, A, B, C, 4, 11, 0x4BDECFA9 );
|
||||
P( C, D, A, B, 7, 16, 0xF6BB4B60 );
|
||||
P( B, C, D, A, 10, 23, 0xBEBFBC70 );
|
||||
P( A, B, C, D, 13, 4, 0x289B7EC6 );
|
||||
P( D, A, B, C, 0, 11, 0xEAA127FA );
|
||||
P( C, D, A, B, 3, 16, 0xD4EF3085 );
|
||||
P( B, C, D, A, 6, 23, 0x04881D05 );
|
||||
P( A, B, C, D, 9, 4, 0xD9D4D039 );
|
||||
P( D, A, B, C, 12, 11, 0xE6DB99E5 );
|
||||
P( C, D, A, B, 15, 16, 0x1FA27CF8 );
|
||||
P( B, C, D, A, 2, 23, 0xC4AC5665 );
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (y ^ (x | ~z))
|
||||
|
||||
P( A, B, C, D, 0, 6, 0xF4292244 );
|
||||
P( D, A, B, C, 7, 10, 0x432AFF97 );
|
||||
P( C, D, A, B, 14, 15, 0xAB9423A7 );
|
||||
P( B, C, D, A, 5, 21, 0xFC93A039 );
|
||||
P( A, B, C, D, 12, 6, 0x655B59C3 );
|
||||
P( D, A, B, C, 3, 10, 0x8F0CCC92 );
|
||||
P( C, D, A, B, 10, 15, 0xFFEFF47D );
|
||||
P( B, C, D, A, 1, 21, 0x85845DD1 );
|
||||
P( A, B, C, D, 8, 6, 0x6FA87E4F );
|
||||
P( D, A, B, C, 15, 10, 0xFE2CE6E0 );
|
||||
P( C, D, A, B, 6, 15, 0xA3014314 );
|
||||
P( B, C, D, A, 13, 21, 0x4E0811A1 );
|
||||
P( A, B, C, D, 4, 6, 0xF7537E82 );
|
||||
P( D, A, B, C, 11, 10, 0xBD3AF235 );
|
||||
P( C, D, A, B, 2, 15, 0x2AD7D2BB );
|
||||
P( B, C, D, A, 9, 21, 0xEB86D391 );
|
||||
|
||||
#undef F
|
||||
|
||||
state[0] += A;
|
||||
state[1] += B;
|
||||
state[2] += C;
|
||||
state[3] += D;
|
||||
}
|
||||
|
||||
void md5_context::update(const uint8 *input, uint32 length )
|
||||
{
|
||||
uint32 left, fill;
|
||||
|
||||
if( ! length ) return;
|
||||
|
||||
left = ( total[0] >> 3 ) & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
total[0] += length << 3;
|
||||
total[1] += length >> 29;
|
||||
|
||||
total[0] &= 0xFFFFFFFF;
|
||||
total[1] += total[0] < ( length << 3 );
|
||||
|
||||
if( left && length >= fill )
|
||||
{
|
||||
memcpy( (void *) (buffer + left), (void *) input, fill );
|
||||
process(buffer );
|
||||
length -= fill;
|
||||
input += fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( length >= 64 )
|
||||
{
|
||||
process(input );
|
||||
length -= 64;
|
||||
input += 64;
|
||||
}
|
||||
|
||||
if( length )
|
||||
{
|
||||
memcpy( (void *) (buffer + left), (void *) input, length );
|
||||
}
|
||||
}
|
||||
|
||||
static const uint8 md5_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
void md5_context::finish(uint8 digest[16] )
|
||||
{
|
||||
uint32 last, padn;
|
||||
uint8 msglen[8];
|
||||
|
||||
PUT_UINT32( total[0], msglen, 0 );
|
||||
PUT_UINT32( total[1], msglen, 4 );
|
||||
|
||||
last = ( total[0] >> 3 ) & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
update( md5_padding, padn );
|
||||
update( msglen, 8 );
|
||||
|
||||
PUT_UINT32( state[0], digest, 0 );
|
||||
PUT_UINT32( state[1], digest, 4 );
|
||||
PUT_UINT32( state[2], digest, 8 );
|
||||
PUT_UINT32( state[3], digest, 12 );
|
||||
}
|
||||
|
||||
|
||||
/* Uses a static buffer, so beware of how it's used. */
|
||||
//static
|
||||
std::string md5_context::asciistr(const uint8 digest[16], bool borked_order)
|
||||
{
|
||||
static char str[33];
|
||||
static char trans[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
|
||||
int x;
|
||||
|
||||
for(x=0;x<16;x++)
|
||||
{
|
||||
if(borked_order)
|
||||
{
|
||||
str[x*2]=trans[digest[x]&0x0F];
|
||||
str[x*2+1]=trans[digest[x]>>4];
|
||||
}
|
||||
else
|
||||
{
|
||||
str[x*2+1]=trans[digest[x]&0x0F];
|
||||
str[x*2]=trans[digest[x]>>4];
|
||||
}
|
||||
}
|
||||
return(std::string(str));
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
#ifndef _MD5_H
|
||||
#define _MD5_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class md5_context
|
||||
{
|
||||
public:
|
||||
md5_context(void);
|
||||
~md5_context(void);
|
||||
|
||||
static std::string asciistr(const uint8 digest[16], bool borked_order);
|
||||
std::string asciistr(void);
|
||||
void starts(void);
|
||||
void update(const uint8 *input, uint32 length);
|
||||
inline void update_u32_as_lsb(const uint32 input)
|
||||
{
|
||||
uint8 buf[4];
|
||||
|
||||
buf[0] = input >> 0;
|
||||
buf[1] = input >> 8;
|
||||
buf[2] = input >> 16;
|
||||
buf[3] = input >> 24;
|
||||
|
||||
update(buf, 4);
|
||||
}
|
||||
|
||||
inline void update_string(const char *string)
|
||||
{
|
||||
update((const uint8 *)string, strlen(string));
|
||||
}
|
||||
void finish(uint8 digest[16]);
|
||||
|
||||
private:
|
||||
void process(const uint8 data[64]);
|
||||
uint32 total[2];
|
||||
uint32 state[4];
|
||||
uint8 buffer[64];
|
||||
};
|
||||
|
||||
#endif /* md5.h */
|
Loading…
Reference in New Issue
Block a user