diff --git a/.gitattributes b/.gitattributes index 21a665060d..5023afb68f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2591,6 +2591,7 @@ packages/hash/examples/Makefile.fpc svneol=native#text/plain packages/hash/examples/crctest.pas svneol=native#text/plain packages/hash/examples/md5.ref svneol=native#text/plain packages/hash/examples/mdtest.pas svneol=native#text/plain +packages/hash/examples/sha1test.pp svneol=native#text/plain packages/hash/fpmake.pp svneol=native#text/plain packages/hash/src/crc.pas svneol=native#text/plain packages/hash/src/md5.pp svneol=native#text/plain diff --git a/packages/hash/examples/Makefile b/packages/hash/examples/Makefile index aa4fd34b9d..3a9071cb5a 100644 --- a/packages/hash/examples/Makefile +++ b/packages/hash/examples/Makefile @@ -1,5 +1,5 @@ # -# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/08/02] +# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/08/28] # default: all MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded @@ -265,178 +265,178 @@ UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET)) endif PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages $(FPCDIR)/packages/base $(FPCDIR)/packages/extra) ifeq ($(FULL_TARGET),i386-linux) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-go32v2) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-win32) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-os2) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-freebsd) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-beos) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-haiku) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-netbsd) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-solaris) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-qnx) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-netware) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-openbsd) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-wdosx) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-darwin) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-emx) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-watcom) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-netwlibc) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-wince) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-embedded) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),i386-symbian) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),m68k-linux) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),m68k-freebsd) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),m68k-netbsd) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),m68k-amiga) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),m68k-atari) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),m68k-openbsd) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),m68k-palmos) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),m68k-embedded) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),powerpc-linux) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),powerpc-netbsd) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),powerpc-amiga) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),powerpc-macos) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),powerpc-darwin) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),powerpc-morphos) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),powerpc-embedded) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),sparc-linux) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),sparc-netbsd) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),sparc-solaris) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),sparc-embedded) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),x86_64-linux) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),x86_64-freebsd) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),x86_64-darwin) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),x86_64-win64) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),x86_64-embedded) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),arm-linux) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),arm-palmos) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),arm-darwin) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),arm-wince) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),arm-gba) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),arm-nds) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),arm-embedded) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),arm-symbian) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),powerpc64-linux) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),powerpc64-darwin) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),powerpc64-embedded) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),avr-embedded) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),armeb-linux) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif ifeq ($(FULL_TARGET),armeb-embedded) -override TARGET_PROGRAMS+=mdtest crctest +override TARGET_PROGRAMS+=mdtest crctest sha1test endif override INSTALL_FPCPACKAGE=y ifdef REQUIRE_UNITSDIR diff --git a/packages/hash/examples/Makefile.fpc b/packages/hash/examples/Makefile.fpc index ea30058cd7..285ac70250 100644 --- a/packages/hash/examples/Makefile.fpc +++ b/packages/hash/examples/Makefile.fpc @@ -3,7 +3,7 @@ # [target] -programs=mdtest crctest +programs=mdtest crctest sha1test [require] packages=hash diff --git a/packages/hash/examples/sha1test.pp b/packages/hash/examples/sha1test.pp new file mode 100644 index 0000000000..c3340d66ef --- /dev/null +++ b/packages/hash/examples/sha1test.pp @@ -0,0 +1,38 @@ +program sha1test; +{$mode objfpc}{$h+} + +uses sha1; + +var + code: cardinal; + s, sdig: string; + i: integer; + ctx: TSHA1Context; + d: TSHA1Digest; +begin + code := 0; + sdig := SHA1Print(SHA1String('abc')); + if sdig <> 'a9993e364706816aba3e25717850c26c9cd0d89d' then + code := code or 1; + + sdig := SHA1Print(SHA1String('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')); + if sdig <> '84983e441c3bd26ebaae4aa1f95129e5e54670f1' then + code := code or 2; + + // SHA-1 of a million 'a' symbols + SetLength(s, 1000); + for i := 1 to 1000 do s[i] := 'a'; + SHA1Init(ctx); + for i := 0 to 999 do + SHA1Update(ctx, PChar(s)^, 1000); + SHA1Final(ctx, d); + sdig := SHA1Print(d); + if sdig <> '34aa973cd4c4daa4f61eeb2bdbad27316534016f' then + code := code or 4; + + if code = 0 then + writeln('Basic SHA-1 tests passed') + else + writeln('SHA-1 tests failed: ', code); + Halt(code); +end. \ No newline at end of file diff --git a/packages/hash/fpmake.pp b/packages/hash/fpmake.pp index f281d1f0fe..68283b9954 100644 --- a/packages/hash/fpmake.pp +++ b/packages/hash/fpmake.pp @@ -29,10 +29,13 @@ begin T:=P.Targets.AddUnit('src/sha1.pp'); T:=P.Targets.AddUnit('src/crc.pas'); T:=P.Targets.AddUnit('src/ntlm.pas'); + T:=P.Targets.AddUnit('src/sha1.pas'); T:=P.Targets.AddUnit('src/uuid.pas'); T:=P.Targets.AddUnit('src/unixcrypt.pas'); T.OSes:=[Linux]; T:=P.Targets.AddExampleunit('examples/mdtest.pas'); + T:=P.Targets.AddExampleunit('examples/crctest.pas'); + T:=P.Targets.AddExampleunit('examples/sha1test.pas'); // md5.ref {$ifndef ALLPACKAGES} Run;