Оглавление Free Pascal: CRC, хеширование, шифрование

Интерфейсы модулей, полезных для вычисления CRC, хеширования, шифрования. (не включены модули: uuid, unixcrypt)

{**************** UNIT CRC Начало  **************************}
unit crc;

  crc32.c -- compute the CRC-32 of a data stream
  Copyright (C) 1995-1998 Mark Adler

  Pascal tranlastion
  Copyright (C) 1998 by Jacques Nomssi Nzali
  For conditions of distribution and use, see copyright notice in readme.txt


function crc32(crc : cardinal; buf : Pbyte; len : cardinal) : cardinal;

{  Update a running crc with the bytes buf[0..len-1] and return the updated
   crc. If buf is NULL, this function returns the required initial value
   for the crc. Pre- and post-conditioning (one's complement) is performed
   within this function so it shouldn't be done by the application.
   Пример использования: --- Usage example:

      crc : cardinal;
      crc := crc32(0, nil, 0);

      while (read_buffer(buffer, length) <> EOF) do
        crc := crc32(crc, buffer, length);

      if (crc <> original_crc) then error();

function get_crc_table : Pcardinal;  { can be used by asm versions of crc32() }
{**************** UNIT CRC Конец  **************************}

{**************** UNIT MD5 Начало  **************************
    This file is part of the Free Pascal packages.
    Copyright (c) 1999-2006 by the Free Pascal development team

    Implements a MD2 digest algorithm (RFC 1319)
    Implements a MD4 digest algorithm (RFC 1320)
    Implements a MD5 digest algorithm (RFC 1321)

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of


unit md5;

{$mode objfpc}
{$inline on}


 * types and constants

  MDDefBufSize = 1024;

  TMDVersion = (

  PMDDigest = ^TMDDigest;
  TMDDigest = array[0..15] of Byte;

  PMD2Digset = PMDDigest;
  TMD2Digest = TMDDigest;

  PMD4Digset = PMDDigest;
  TMD4Digest = TMDDigest;

  PMD5Digset = PMDDigest;
  TMD5Digest = TMDDigest;

  PMDContext = ^TMDContext;
  TMDContext = record
    Version : TMDVersion;
    Align   : PtrUInt;
    State   : array[0..3] of Cardinal;
    BufCnt  : QWord;
    Buffer  : array[0..63] of Byte;
    case Integer of
      0: (Length   : PtrUInt);
      1: (Checksum : array[0..15] of Byte);

  PMD2Context = PMDContext;
  TMD2Context = TMDContext;

  PMD4Context = PMDContext;
  TMD4Context = TMDContext;

  PMD5Context = PMDContext;
  TMD5Context = TMDContext;

 * Core raw functions

procedure MDInit(var Context: TMDContext; const Version: TMDVersion);
procedure MDUpdate(var Context: TMDContext; var Buf; const BufLen: PtrUInt);
procedure MDFinal(var Context: TMDContext; var Digest: TMDDigest);

 * Auxilary functions

function MDString(const S: String; const Version: TMDVersion): TMDDigest;
function MDBuffer(var Buf; const BufLen: PtrUInt; const Version: TMDVersion): TMDDigest;
function MDFile(const Filename: String; const Version: TMDVersion; 
const Bufsize: PtrUInt = MDDefBufSize): TMDDigest;

 * Helper functions

function MDPrint(const Digest: TMDDigest): String;
function MDMatch(const Digest1, Digest2: TMDDigest): Boolean;

 * Dedicated raw functions

procedure MD2Init(var Context: TMD2Context); inline;
procedure MD2Update(var Context: TMD2Context; var Buf; const BufLen: PtrUInt); inline;
procedure MD2Final(var Context: TMD2Context; var Digest: TMD2Digest); inline;

procedure MD4Init(var Context: TMD4Context); inline;
procedure MD4Update(var Context: TMD4Context; var Buf; const BufLen: PtrUInt); inline;
procedure MD4Final(var Context: TMD4Context; var Digest: TMD4Digest); inline;

procedure MD5Init(var Context: TMD5Context); inline;
procedure MD5Update(var Context: TMD5Context; var Buf; const BufLen: PtrUInt); inline;
procedure MD5Final(var Context: TMD5Context; var Digest: TMD5Digest); inline;

 * Dedicated auxilary functions

function MD2String(const S: String): TMD2Digest; inline;
function MD2Buffer(var Buf; const BufLen: PtrUInt): TMD2Digest; inline;
function MD2File(const Filename: String; const Bufsize: PtrUInt = MDDefBufSize): TMD2Digest; inline;

function MD4String(const S: String): TMD4Digest; inline;
function MD4Buffer(var Buf; const BufLen: PtrUInt): TMD4Digest; inline;
function MD4File(const Filename: String; const Bufsize: PtrUInt = MDDefBufSize): TMD4Digest; inline;

function MD5String(const S: String): TMD5Digest; inline;
function MD5Buffer(var Buf; const BufLen: PtrUInt): TMD5Digest; inline;
function MD5File(const Filename: String; const Bufsize: PtrUInt = MDDefBufSize): TMD5Digest; inline;

 * Dedicated helper functions

function MD2Print(const Digest: TMD2Digest): String; inline;
function MD2Match(const Digest1, Digest2: TMD2Digest): Boolean; inline;

function MD4Print(const Digest: TMD4Digest): String; inline;
function MD4Match(const Digest1, Digest2: TMD4Digest): Boolean; inline;

function MD5Print(const Digest: TMD5Digest): String; inline;
function MD5Match(const Digest1, Digest2: TMD5Digest): Boolean; inline;
{**************** UNIT MD5 Конец  **************************}

{**************** UNIT NTLM Начало  **************************}
unit ntlm;

{$mode objfpc}

  Math, Strings, md5;

function LMGenerate(const Password: PChar): TMDDigest;
function NTGenerate(const Password: PChar): TMDDigest;
{**************** UNIT NTLM Конец  **************************}
Rambler's Top100
Hosted by uCoz