update core

This commit is contained in:
Logan McNaughton
2024-05-21 07:10:07 -06:00
parent 0321396ca4
commit cec77f8842
12 changed files with 195 additions and 167 deletions
+12 -14
View File
@@ -32,26 +32,26 @@ jobs:
- uses: actions/checkout@v4
- name: Get build dependencies and arrange the environment
run: |
export C_CLANG_SUFFIX="-15" C_GCC_SUFFIX="-12"
export BUILD_DEPS="libfreetype6-dev libgl1-mesa-dev libglu1-mesa-dev libpng-dev libsdl1.2-dev libsdl2-dev libvulkan-dev zlib1g-dev"
./.github/workflows/scripts/ci_install_ubuntu_deps.sh ${{ matrix.arch }} ${{ matrix.cc }}
- name: Build and related stuff, backup binaries
run: |
export C_CLANG_SUFFIX="-15" C_GCC_SUFFIX="-12"
export PATH="$(pwd)/.github/workflows/scripts:${PATH}"
export BUILD_CONFIG="ACCURATE_FPU=0 NEW_DYNAREC=0 SDL_CONFIG=\"sdl-config\"" POSTFIX="-old"
export CONFIG_OVERRIDE="ACCURATE_FPU=1 NEW_DYNAREC=1 SDL_CONFIG="sdl-config""
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }}
export BUILD_CONFIG="ACCURATE_FPU=1 NEW_DYNAREC=1 SDL_CONFIG=\"sdl-config\""
unset POSTFIX
export CONFIG_OVERRIDE="ACCURATE_FPU=1 NEW_DYNAREC=1 SDL_CONFIG="sdl2-config""
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }}
export BUILD_CONFIG="ACCURATE_FPU=0 NEW_DYNAREC=0 SDL_CONFIG=\"sdl2-config\"" POSTFIX="-old"
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }}
export BUILD_CONFIG="ACCURATE_FPU=1 NEW_DYNAREC=1 SDL_CONFIG=\"sdl2-config\"" MAKE_PKG=1
unset POSTFIX
export CONFIG_OVERRIDE="ACCURATE_FPU=0 NEW_DYNAREC=0 SDL_CONFIG="sdl-config" POSTFIX="-old""
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }}
export CONFIG_OVERRIDE="ACCURATE_FPU=0 NEW_DYNAREC=0 SDL_CONFIG="sdl2-config" POSTFIX="-old""
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }} makepkg
- name: Upload artifact
if: matrix.cc == 'GCC'
uses: actions/upload-artifact@v4
with:
name: mupen64plus-core-linux-${{ matrix.arch }}-g${{ env.G_REV }}
name: ${{ env.PKG_NAME }}
path: pkg/*.tar.gz
MSYS2:
@@ -91,14 +91,12 @@ jobs:
mingw-w64-${{ matrix.cross }}-SDL2
mingw-w64-${{ matrix.cross }}-vulkan-headers
mingw-w64-${{ matrix.cross }}-zlib
mingw-w64-${{ matrix.cross }}-vulkan-headers
- name: Build and related stuff, backup binaries
run: |
export PATH="$(pwd)/.github/workflows/scripts:${PATH}"
export BUILD_CONFIG="ACCURATE_FPU=0 NEW_DYNAREC=0" POSTFIX="-old"
export CONFIG_OVERRIDE="ACCURATE_FPU=1 NEW_DYNAREC=1"
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }}
export BUILD_CONFIG="ACCURATE_FPU=1 NEW_DYNAREC=1"
unset POSTFIX
export CONFIG_OVERRIDE="ACCURATE_FPU=0 NEW_DYNAREC=0 POSTFIX="-old""
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }}
- name: Backup dependencies, etc...
run: |
@@ -106,7 +104,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: mupen64plus-core-msys2-${{ matrix.arch }}-g${{ env.G_REV }}
name: ${{ env.PKG_NAME }}
path: pkg/*
MSVC:
@@ -140,7 +138,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: mupen64plus-core-msvc-${{ matrix.arch }}-g${{ env.G_REV }}
name: ${{ env.PKG_NAME }}
path: pkg/*
Nightly-build:
+13 -14
View File
@@ -1,4 +1,4 @@
name: Core
name: Core - Scheduled
on:
schedule:
@@ -26,26 +26,26 @@ jobs:
- uses: actions/checkout@v4
- name: Get build dependencies and arrange the environment
run: |
export C_CLANG_SUFFIX="-15" C_GCC_SUFFIX="-12"
export BUILD_DEPS="libfreetype6-dev libgl1-mesa-dev libglu1-mesa-dev libpng-dev libsdl1.2-dev libsdl2-dev libvulkan-dev zlib1g-dev"
./.github/workflows/scripts/ci_install_ubuntu_deps.sh ${{ matrix.arch }} ${{ matrix.cc }}
- name: Build and related stuff, backup binaries
run: |
export C_CLANG_SUFFIX="-15" C_GCC_SUFFIX="-12"
export PATH="$(pwd)/.github/workflows/scripts:${PATH}"
export BUILD_CONFIG="ACCURATE_FPU=0 NEW_DYNAREC=0 SDL_CONFIG=\"sdl-config\"" POSTFIX="-old"
export CONFIG_OVERRIDE="ACCURATE_FPU=1 NEW_DYNAREC=1 SDL_CONFIG="sdl-config""
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }}
export BUILD_CONFIG="ACCURATE_FPU=1 NEW_DYNAREC=1 SDL_CONFIG=\"sdl-config\""
unset POSTFIX
export CONFIG_OVERRIDE="ACCURATE_FPU=1 NEW_DYNAREC=1 SDL_CONFIG="sdl2-config""
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }}
export BUILD_CONFIG="ACCURATE_FPU=0 NEW_DYNAREC=0 SDL_CONFIG=\"sdl2-config\"" POSTFIX="-old"
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }}
export BUILD_CONFIG="ACCURATE_FPU=1 NEW_DYNAREC=1 SDL_CONFIG=\"sdl2-config\"" MAKE_PKG=1
unset POSTFIX
export CONFIG_OVERRIDE="ACCURATE_FPU=0 NEW_DYNAREC=0 SDL_CONFIG="sdl-config" POSTFIX="-old""
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }}
export CONFIG_OVERRIDE="ACCURATE_FPU=0 NEW_DYNAREC=0 SDL_CONFIG="sdl2-config" POSTFIX="-old""
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }} makepkg
- name: Upload artifact
if: matrix.cc == 'GCC'
uses: actions/upload-artifact@v4
with:
name: mupen64plus-core-linux-${{ matrix.arch }}-g${{ env.G_REV }}
name: ${{ env.PKG_NAME }}
path: pkg/*.tar.gz
MSYS2:
@@ -89,10 +89,9 @@ jobs:
- name: Build and related stuff, backup binaries
run: |
export PATH="$(pwd)/.github/workflows/scripts:${PATH}"
export BUILD_CONFIG="ACCURATE_FPU=0 NEW_DYNAREC=0" POSTFIX="-old"
export CONFIG_OVERRIDE="ACCURATE_FPU=1 NEW_DYNAREC=1"
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }}
export BUILD_CONFIG="ACCURATE_FPU=1 NEW_DYNAREC=1"
unset POSTFIX
export CONFIG_OVERRIDE="ACCURATE_FPU=0 NEW_DYNAREC=0 POSTFIX="-old""
ci_build.sh ${{ matrix.arch }} ${{ matrix.cc }}
- name: Backup dependencies, etc...
run: |
@@ -100,7 +99,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: mupen64plus-core-msys2-${{ matrix.arch }}-g${{ env.G_REV }}
name: ${{ env.PKG_NAME }}
path: pkg/*
MSVC:
@@ -135,7 +134,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: mupen64plus-core-msvc-${{ matrix.arch }}-g${{ env.G_REV }}
name: ${{ env.PKG_NAME }}
path: pkg/*
Nightly-build:
@@ -3,16 +3,19 @@ set -e +u
if [[ ${#} -ne 1 ]]; then exit 9; fi
export ENV_MSYS="$(echo "${1}" | sed y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/)"
export DEPS="$(LC_ALL=C grep "${ENV_MSYS}" "pkg/ldd.log" | sort | cut -d ' ' -f1)"
if [[ "${DEPS}" == "" ]]; then exit 0; fi
for LIB in ${DEPS}; do
echo ":: Copying ${LIB}"
cp "/${ENV_MSYS}/bin/${LIB}" pkg/
done
export ENV_MSYS="$(echo "${1}" | tr [A-Z] [a-z])"
export DEPS="$(LC_ALL=C grep "${ENV_MSYS}" pkg/ldd.log | tr -s '\t' ' ' | sort | cut -d ' ' -f4 | tr '\\' '/' | tr -d ':')"
rm -f pkg/ldd.log
if [[ "${DEPS}" == "" ]]; then
echo ":: None..."
exit 0
fi
for LIB in ${DEPS}; do
echo ":: Copying ${LIB##*/}"
cp "/${LIB}" pkg/
done
exit 0
@@ -13,19 +13,23 @@ for %%P in (%*) do (
)
if not defined ARCH exit /b 7
if not defined DEPS exit /b 6
if exist "data\" xcopy /e data pkg
if errorlevel 1 exit /b 5
if errorlevel 1 exit /b 6
if exist "pkg\mupen64plus.desktop" del /f /q pkg\mupen64plus.desktop
if not defined DEPS (
echo :: None...
exit /b 0
)
set PKG=%CD%\pkg
cd ..\mupen64plus-win32-deps
if errorlevel 1 exit /b 4
if errorlevel 1 exit /b 5
for %%D in (%DEPS%) do (
for /f "tokens=*" %%T in ('dir /b /s %%D ^| findstr "%ARCH%"') do (
if exist "%%T" copy "%%T" "%PKG%\"
if errorlevel 1 exit /b 3
if exist "%%T" xcopy "%%T" "%PKG%\"
if errorlevel 1 exit /b 4
)
)
+27 -16
View File
@@ -4,16 +4,19 @@ set -e +u
if [[ ${#} -lt 2 ]]; then exit 9; fi
unset ARCH_ARG CC_ARG
export MULTILIB=0
export ENV_ARGS="$(echo "${*}" | sed y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/)"
export MAKE_PKG=0 MULTILIB=0
export ENV_ARGS="$(echo "${*}" | tr [A-Z] [a-z])"
for ARG in ${ENV_ARGS}; do
case "${ARG}" in
clang )
export CC_ARG="Clang" CC="clang" CXX="clang++"
export CC_ARG="Clang" CC="clang${C_CLANG_SUFFIX}" CXX="clang++${C_CLANG_SUFFIX}"
;;
gcc )
export CC_ARG="GCC" CC="gcc" CXX="g++"
export CC_ARG="GCC" CC="gcc${C_GCC_SUFFIX}" CXX="g++${C_GCC_SUFFIX}"
;;
makepkg )
export MAKE_PKG=1
;;
multilib )
export MULTILIB=1
@@ -33,7 +36,7 @@ if [[ -z ${CC_ARG} ]]; then exit 7; fi
export REPO="${PWD##*/}"
if [[ "${REPO}" == "" ]]; then exit 6; fi
export BIN_OS="$(uname -s | sed y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/)"
export BIN_OS="$(uname -s | tr [A-Z] [a-z])"
if [[ ! -z ${MSYSTEM} ]]; then export BIN_OS="msys2"; fi
export ENV_NAME="$(uname -s)"
export LDD="ldd"
@@ -48,47 +51,55 @@ if [[ "${ENV_NAME}" == *"Linux"* ]]; then
if [[ "${ARCH_ARG}" == "x86" ]]; then export PIC=1 PIE=1; fi
if [[ ${MULTILIB} -eq 0 ]]; then
if [[ "${CC_ARG}" == "GCC" ]]; then
if [[ "${ARCH_ARG}" == "x86" ]]; then export CC="i686-linux-gnu-gcc" CXX="i686-linux-gnu-g++"; fi
if [[ "${ARCH_ARG}" == "x86" ]]; then export CC="i686-linux-gnu-${CC}" CXX="i686-linux-gnu-${CXX}"; fi
fi
fi
fi
if [[ "${ENV_NAME}" == *"MINGW"* ]]; then
export INSTALL_OVERRIDE="PLUGINDIR=\"\" SHAREDIR=\"\" BINDIR=\"\" MANDIR=\"\" LIBDIR=\"\" APPSDIR=\"\" ICONSDIR=\"icons\" INCDIR=\"api\""
export LDD="ntldd"
export INSTALL_OVERRIDE="PLUGINDIR="" SHAREDIR="" BINDIR="" MANDIR="" LIBDIR="" APPSDIR="" ICONSDIR="icons" INCDIR="api""
export LDD="ntldd -R"
unset PKG_PATH
fi
export G_REV="$(git rev-parse --short HEAD)"
export PKG_NAME="${REPO}-${BIN_OS}-${ARCH_ARG}-g${G_REV}"
if [[ -f "${GITHUB_ENV}" ]]; then
set +e
grep "G_REV=${G_REV}" "${GITHUB_ENV}" > /dev/null
if [[ ${?} -ne 0 ]]; then echo "G_REV=${G_REV}" >> "${GITHUB_ENV}"; fi
grep "PKG_NAME=${PKG_NAME}" "${GITHUB_ENV}" > /dev/null
if [[ ${?} -ne 0 ]]; then echo "PKG_NAME=${PKG_NAME}" >> "${GITHUB_ENV}"; fi
set -e
fi
if [[ -z ${OPTFLAGS} ]]; then export OPTFLAGS="-O3 -flto ${CPU_TUNE}"; fi
echo ""
echo ":: CC=${CC} CXX=${CXX} BITS=${BITS} ${CONFIG_OVERRIDE} ::"
echo ""
${CC} --version
echo ""
make CC="${CC}" CXX="${CXX}" BITS="${BITS}" ${BUILD_CONFIG} -C projects/unix clean
echo ""
make CC="${CC}" CXX="${CXX}" BITS="${BITS}" ${BUILD_CONFIG} -C projects/unix all -j4
make_clean () {
make CC="${CC}" CXX="${CXX}" BITS=${BITS} ${CONFIG_OVERRIDE} -C projects/unix clean
echo ""
}
make_clean
make CC="${CC}" CXX="${CXX}" BITS=${BITS} ${CONFIG_OVERRIDE} -C projects/unix all -j4
echo ""
if [[ ! -d pkg ]]; then
mkdir pkg
chmod -R 755 pkg
fi
pushd projects/unix > /dev/null
export ARTIFACT="$(find *mupen64plus* -type f 2> /dev/null | head -n 1)"
popd > /dev/null
make CC="${CC}" CXX="${CXX}" BITS=${BITS} ${CONFIG_OVERRIDE} -C projects/unix install ${INSTALL_OVERRIDE} DESTDIR="$(pwd)/pkg/"
echo ""
make CC="${CC}" CXX="${CXX}" BITS="${BITS}" ${BUILD_CONFIG} -C projects/unix install ${INSTALL_OVERRIDE} DESTDIR="$(pwd)/pkg/"
echo ""
make_clean
if [[ -z ${ARTIFACT} ]]; then
exit 5
@@ -99,7 +110,7 @@ else
${LDD} "${PKG_PATH}${ARTIFACT}" > ldd.log
cat ldd.log
echo ""
if [[ "${MAKE_PKG}" == "1" ]]; then tar --owner=0 --group=0 --mode='og-w' -czf "${REPO}-${BIN_OS}-${ARCH_ARG}-g${G_REV}.tar.gz" usr; fi
if [[ ${MAKE_PKG} -eq 1 ]]; then tar --owner=0 --group=0 --mode='og-w' -czf "${PKG_NAME}.tar.gz" usr; fi
fi
exit 0
@@ -4,20 +4,20 @@ set -e +u
if [[ ${#} -lt 2 ]]; then exit 9; fi
unset ARCH_DEP CC_DEP
export BUILD_DEPS_I386="crossbuild-essential-i386 libc6-i386"
export BUILD_DEPS_I386="crossbuild-essential-i386 g++${C_GCC_SUFFIX}-i686-linux-gnu gcc${C_GCC_SUFFIX}-i686-linux-gnu libc6-i386"
export HOTFIX_I386="libatomic1:i386 libgcc-s1:i386 libstdc++6:i386 ${HOTFIX_I386}"
export ENV_ARGS="$(echo "${*}" | sed y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/)"
export ENV_ARGS="$(echo "${*}" | tr [A-Z] [a-z])"
for ARG in ${ENV_ARGS}; do
case "${ARG}" in
clang )
export CC_DEP="clang"
export CC_DEP="clang${C_CLANG_SUFFIX}"
;;
gcc )
export CC_DEP="g++ gcc"
export CC_DEP="g++${C_GCC_SUFFIX} gcc${C_GCC_SUFFIX}"
;;
multilib )
export BUILD_DEPS_I386="g++-multilib gcc-multilib libc6-dev-i386"
export BUILD_DEPS_I386="g++${C_GCC_SUFFIX}-multilib gcc${C_GCC_SUFFIX}-multilib libc6-dev-i386"
;;
x64 )
export ARCH_DEP="x64"
@@ -31,6 +31,7 @@ done
if [[ -z ${ARCH_DEP} ]]; then exit 8; fi
if [[ -z ${CC_DEP} ]]; then exit 7; fi
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
if [[ "${ARCH_DEP}" == "x86" ]]; then sudo dpkg --add-architecture i386; fi
sudo apt-get update
sudo apt-get -y install build-essential git nasm pkg-config ${CC_DEP} ${BUILD_DEPS}
+17 -10
View File
@@ -7,21 +7,28 @@ set ARCH=
set CONF=Release
if "%*" == "" exit /b 8
for %%P in (%*) do (
if /i "%%P" == "x86" set ARCH=Win32
if /i "%%P" == "x64" set ARCH=x64
if /i "%%P" == "x86" set ARCH_ARG=x86& set ARCH=Win32
if /i "%%P" == "x64" set ARCH_ARG=x64& set ARCH=x64
if /i "%%P" == "newdyn" set CONF=New_Dynarec_Release
)
if not defined ARCH exit /b 7
for %%T in (.) do set REPO=%%~nxT
if not defined REPO exit /b 6
set ARTIFACT=
set FPROJ=
if not defined EXT set EXT=dll
set EXT=dll
echo %REPO% | findstr "ui-console" >nul 2>&1
if not errorlevel 1 set EXT=exe
if not defined TOOLSET set TOOLSET=v143
for /f "tokens=1" %%R in ('git rev-parse --short HEAD') do set G_REV=%%R
set PKG_NAME=%REPO%-msvc-%ARCH_ARG%-g%G_REV%
if exist "%GITHUB_ENV%" (
type "%GITHUB_ENV%" | findstr "G_REV=%G_REV%" >nul 2>&1
if errorlevel 1 echo G_REV=%G_REV%>> "%GITHUB_ENV%"
type "%GITHUB_ENV%" | findstr "PKG_NAME=%PKG_NAME%" >nul 2>&1
if errorlevel 1 echo PKG_NAME=%PKG_NAME%>> "%GITHUB_ENV%"
)
echo.
@@ -33,11 +40,11 @@ if not exist "..\mupen64plus-win32-deps\" git clone --depth 1 https://github.com
pushd projects\msvc\
for /f "tokens=*" %%F in ('dir /b *.vcxproj') do set FPROJ=%%F
popd
if not defined FPROJ exit /b 6
if not defined FPROJ exit /b 5
echo.
msbuild "projects\msvc\%FPROJ%" /p:Configuration=%CONF%;Platform=%ARCH%;PlatformToolset=%TOOLSET% /t:Rebuild
if errorlevel 1 exit /b 5
if errorlevel 1 exit /b 4
echo.
if exist "projects\msvc\%ARCH%\Release\mupen64plus.dll" ren "projects\msvc\%ARCH%\Release\mupen64plus.dll" mupen64plus-old.dll
@@ -45,11 +52,11 @@ if exist "projects\msvc\%ARCH%\Release\mupen64plus.dll" ren "projects\msvc\%ARCH
pushd projects\msvc\%ARCH%\%CONF%\
for /f "tokens=*" %%S in ('dir /b mupen64plus*%EXT%') do set ARTIFACT=%%S
popd
if not defined ARTIFACT exit /b 4
if not defined ARTIFACT exit /b 3
md pkg 2>nul
copy "projects\msvc\%ARCH%\%CONF%\%ARTIFACT%" pkg\
if errorlevel 1 exit /b 3
xcopy "projects\msvc\%ARCH%\%CONF%\%ARTIFACT%" pkg\
if errorlevel 1 exit /b 2
dir "pkg\%ARTIFACT%"
exit /b 0
@@ -23,6 +23,7 @@ for BIN in *; do
done
cd ../pkg
echo ""
for ZIP in *; do
ls -gG ${ZIP}
tigerdeep -lz ${ZIP} >> ../${REPO}.tiger.txt
@@ -31,20 +32,13 @@ for ZIP in *; do
b2sum ${ZIP} >> ../${REPO}.blake2.txt
done
mv ../${REPO}.*.txt .
echo ""
echo ""
echo "TIGER:"
cat *.tiger.txt
echo ""
echo "SHA256:"
cat *.sha256.txt
echo ""
echo "SHA512:"
cat *.sha512.txt
echo ""
echo "BLAKE2:"
cat *.blake2.txt
echo ""
for HASH in tiger sha256 sha512 blake2; do
echo "${HASH}:" | tr [a-z] [A-Z]
cat *.${HASH}.txt
echo ""
done
if [[ -f "${GITHUB_ENV}" ]]; then
git tag -f nightly-build
+1 -1
View File
@@ -833,7 +833,7 @@ uninstall:
$(RM) "$(DESTDIR)$(SHAREDIR)/mupencheat.txt"
clean:
$(RM) -r *mupen64plus*.* $(TARGET) $(SONAME) _obj $(OBJDIR) $(SRCDIR)/asm_defines/asm_defines_*.h
$(RM) -r _obj $(OBJDIR) $(TARGET) $(SONAME) $(SRCDIR)/asm_defines/asm_defines_*.h
# build dependency files
CFLAGS += -MD -MP
@@ -61,8 +61,8 @@ static void do_sp_dma(struct rsp_core* sp, const struct sp_dma* dma)
memaddr++;
dramaddr++;
}
post_framebuffer_write(&sp->dp->fb, dramaddr - length, length);
if (dramaddr <= 0x800000)
post_framebuffer_write(&sp->dp->fb, dramaddr - length, length);
dramaddr+=skip;
}
@@ -73,7 +73,8 @@ static void do_sp_dma(struct rsp_core* sp, const struct sp_dma* dma)
else
{
for(j=0; j<count; j++) {
pre_framebuffer_read(&sp->dp->fb, dramaddr);
if (dramaddr < 0x800000)
pre_framebuffer_read(&sp->dp->fb, dramaddr);
for(i=0; i<length; i++) {
spmem[(memaddr & 0xfff)^S8] = dram[dramaddr^S8];
+77 -66
View File
@@ -27,7 +27,7 @@
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
@@ -38,24 +38,24 @@
that follows (in reverse chronological order):
2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
either statically or dynamically; added missing #include <string.h>
in library.
either statically or dynamically; added missing #include <string.h>
in library.
2002-03-11 lpd Corrected argument list for main(), and added int return
type, in test program and T value program.
type, in test program and T value program.
2002-02-21 lpd Added missing #include <stdio.h> in test program.
2000-07-03 lpd Patched to eliminate warnings about "constant is
unsigned in ANSI C, signed in traditional"; made test program
self-checking.
unsigned in ANSI C, signed in traditional"; made test program
self-checking.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
1999-05-03 lpd Original version.
*/
#include "md5.h"
#include <string.h>
#include <limits.h>
#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
#ifdef ARCH_IS_BIG_ENDIAN
# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
#else
@@ -133,8 +133,8 @@ static void
md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
{
md5_word_t
a = pms->abcd[0], b = pms->abcd[1],
c = pms->abcd[2], d = pms->abcd[3];
a = pms->abcd[0], b = pms->abcd[1],
c = pms->abcd[2], d = pms->abcd[3];
md5_word_t t;
#if BYTE_ORDER > 0
/* Define storage only for big-endian CPUs. */
@@ -147,51 +147,51 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
{
#if BYTE_ORDER == 0
/*
* Determine dynamically whether this is a big-endian or
* little-endian machine, since we can use a more efficient
* algorithm on the latter.
*/
static const int w = 1;
if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
#endif
#if BYTE_ORDER <= 0 /* little-endian */
{
/*
* On little-endian machines, we can process properly aligned
* data without copying it.
* Determine dynamically whether this is a big-endian or
* little-endian machine, since we can use a more efficient
* algorithm on the latter.
*/
if (!((data - (const md5_byte_t *)0) & 3)) {
/* data are properly aligned */
X = (const md5_word_t *)data;
} else {
/* not aligned */
memcpy(xbuf, data, 64);
X = xbuf;
static const int w = 1;
if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
#endif
#if BYTE_ORDER <= 0 /* little-endian */
{
/*
* On little-endian machines, we can process properly aligned
* data without copying it.
*/
if (!((data - (const md5_byte_t *)0) & 3)) {
/* data are properly aligned */
X = (const md5_word_t *)data;
} else {
/* not aligned */
memcpy(xbuf, data, 64);
X = xbuf;
}
}
}
#endif
#if BYTE_ORDER == 0
else /* dynamic big-endian */
else /* dynamic big-endian */
#endif
#if BYTE_ORDER >= 0 /* big-endian */
{
/*
* On big-endian machines, we must arrange the bytes in the
* right order.
*/
const md5_byte_t *xp = data;
int i;
#if BYTE_ORDER >= 0 /* big-endian */
{
/*
* On big-endian machines, we must arrange the bytes in the
* right order.
*/
const md5_byte_t *xp = data;
int i;
# if BYTE_ORDER == 0
X = xbuf; /* (dynamic only) */
X = xbuf; /* (dynamic only) */
# else
# define xbuf X /* (static only) */
# define xbuf X /* (static only) */
# endif
for (i = 0; i < 16; ++i, xp += 4)
xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
}
for (i = 0; i < 16; ++i, xp += 4)
xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
}
#endif
}
@@ -321,63 +321,74 @@ md5_init(md5_state_t *pms)
}
void
md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
md5_append(md5_state_t *pms, const md5_byte_t *data, unsigned int nbytes)
{
const md5_byte_t *p = data;
int left = nbytes;
int offset = (pms->count[0] >> 3) & 63;
unsigned int left = nbytes;
unsigned int offset = (pms->count[0] >> 3) & 63;
md5_word_t nbits = (md5_word_t)(nbytes << 3);
if (nbytes <= 0)
return;
return;
/* this special case is handled recursively */
if (nbytes > INT_MAX - offset) {
unsigned int overlap;
/* handle the append in two steps to prevent overflow */
overlap = 64 - offset;
md5_append(pms, data, overlap);
md5_append(pms, data + overlap, nbytes - overlap);
return;
}
/* Update the message length. */
pms->count[1] += nbytes >> 29;
pms->count[0] += nbits;
if (pms->count[0] < nbits)
pms->count[1]++;
pms->count[1]++;
/* Process an initial partial block. */
if (offset) {
int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
unsigned int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
memcpy(pms->buf + offset, p, copy);
if (offset + copy < 64)
return;
p += copy;
left -= copy;
md5_process(pms, pms->buf);
memcpy(pms->buf + offset, p, copy);
if (offset + copy < 64)
return;
p += copy;
left -= copy;
md5_process(pms, pms->buf);
}
/* Process full blocks. */
for (; left >= 64; p += 64, left -= 64)
md5_process(pms, p);
md5_process(pms, p);
/* Process a final partial block. */
if (left)
memcpy(pms->buf, p, left);
memcpy(pms->buf, p, left);
}
void
md5_finish(md5_state_t *pms, md5_byte_t digest[16])
{
static const md5_byte_t pad[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
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
};
md5_byte_t data[8];
int i;
/* Save the length before padding. */
for (i = 0; i < 8; ++i)
data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
/* Pad to 56 bytes mod 64. */
md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
/* Append the length. */
md5_append(pms, data, 8);
for (i = 0; i < 16; ++i)
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
}
+10 -11
View File
@@ -21,13 +21,13 @@
ghost@aladdin.com
*/
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
/* $Id$ */
/*
Independent implementation of MD5 (RFC 1321).
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
@@ -38,12 +38,12 @@
that follows (in reverse chronological order):
2002-04-13 lpd Removed support for non-ANSI compilers; removed
references to Ghostscript; clarified derivation from RFC 1321;
now handles byte order either statically or dynamically.
references to Ghostscript; clarified derivation from RFC 1321;
now handles byte order either statically or dynamically.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
added conditionalization for C++ compilation from Martin
Purschke <purschke@bnl.gov>.
added conditionalization for C++ compilation from Martin
Purschke <purschke@bnl.gov>.
1999-05-03 lpd Original version.
*/
@@ -65,9 +65,9 @@ typedef unsigned int md5_word_t; /* 32-bit word */
/* Define the state of the MD5 Algorithm. */
typedef struct md5_state_s {
md5_word_t count[2]; /* message length in bits, lsw first */
md5_word_t abcd[4]; /* digest buffer */
md5_byte_t buf[64]; /* accumulate block */
md5_word_t count[2]; /* message length in bits, lsw first */
md5_word_t abcd[4]; /* digest buffer */
md5_byte_t buf[64]; /* accumulate block */
} md5_state_t;
#ifdef __cplusplus
@@ -79,7 +79,7 @@ extern "C"
void md5_init(md5_state_t *pms);
/* Append a string to the message. */
void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
void md5_append(md5_state_t *pms, const md5_byte_t *data, unsigned int nbytes);
/* Finish the message and return the digest. */
void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
@@ -89,4 +89,3 @@ void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
#endif
#endif /* md5_INCLUDED */