1 unit CH_Intf;
2 
3 {Interface unit for CH_DLL}
4 
5 interface
6 
7 (*************************************************************************
8 
9  DESCRIPTION     :  Interface unit for CH_DLL
10 
11  REQUIREMENTS    :  D2-D7/D9/D10/D12/D17-D18, FPC 2+
12 
13  EXTERNAL DATA   :  ---
14 
15  MEMORY USAGE    :  ---
16 
17  DISPLAY MODE    :  ---
18 
19  REFERENCES      :
20 
21 
22  Version  Date      Author      Modification
23  -------  --------  -------     ------------------------------------------
24  0.10     18.03.02  W.Ehrhardt  Initial version
25  2.00     26.07.03  we          common vers., longint for word32
26  2.10     29.08.03  we          XL versions for Win32
27  2.20     29.08.03  we          With Adler32, CRC64
28  2.40     10.10.03  we          common version, english comments
29  2.50     24.11.03  we          with SHA384/512
30  3.00     01.12.03  we          Common version 3.0
31  3.10     02.01.04  we          SHA224
32  3.11     07.07.04  we          New unit name, HMACs, keyderiv
33  3.12     04.01.05  we          HMACSHA256/512, PBKDF2_256/512
34  3.13     11.12.05  we          Whirlpool functions
35  3.14     22.12.05  we          Whirlpool V3.0 only
36  3.15     08.01.06  we          SHA1Compress removed
37  3.16     17.01.06  we          hash, hmac, pb_kdf
38  3.17     18.01.06  we          Descriptor fields HAlgNum, HSig
39  3.18     31.01.06  we          RIPEMD-160
40  3.19     11.02.06  we          Fields: HDSize, HVersion, HPtrOID, HLenOID
41  3.20     02.04.06  we          CRC24
42  3.21     07.08.06  we          $ifdef BIT32: (const fname: shortstring...)
43  3.22     20.02.07  we          MD4, ED2K
44  3.23     22.02.07  we          POID_Vec=^TOID_Vec, typed HPtrOID
45  3.24     30.06.07  we          FCRC32
46  3.25     04.10.07  we          THashContext.Index now longint
47  3.26     07.05.08  we          [Hash]FinalBits/Ex, HashSameDigest
48  3.27     12.07.08  we          crcmodel, removed keyderive routines
49  3.28     12.07.08  we          kdf with kdf1/2/3, mgf1, pbkdf1/2
50  3.29     16.11.08  we          uses BTypes and Str255
51  3.30     05.07.09  we          external 'ch_dll.dll'
52  3.31     06.07.09  we          CH_DLL_Version returns PAnsiChar
53  3.32     06.09.09  we          cm_combine
54  3.32     20.08.10  we          hkdf, hkdfs
55  3.33     17.12.10  we          CRC_Sick
56  3.34     08.03.12  we          SHA512/224 and SHA512/256
57  3.35     15.08.14  we          pbkdf2 functions with longint sLen, dkLen
58 **************************************************************************)
59 
60 (*-------------------------------------------------------------------------
61  (C) Copyright 2002-2014 Wolfgang Ehrhardt
62 
63  This software is provided 'as-is', without any express or implied warranty.
64  In no event will the authors be held liable for any damages arising from
65  the use of this software.
66 
67  Permission is granted to anyone to use this software for any purpose,
68  including commercial applications, and to alter it and redistribute it
69  freely, subject to the following restrictions:
70 
71  1. The origin of this software must not be misrepresented; you must not
72     claim that you wrote the original software. If you use this software in
73     a product, an acknowledgment in the product documentation would be
74     appreciated but is not required.
75 
76  2. Altered source versions must be plainly marked as such, and must not be
77     misrepresented as being the original software.
78 
79  3. This notice may not be removed or altered from any source distribution.
80 ----------------------------------------------------------------------------*)
81 
82 uses
83   BTypes;
84 
85 
CH_DLL_Versionnull86 function CH_DLL_Version: PAnsiChar;
87 stdcall; external 'ch_dll.dll' name 'CH_DLL_Version';
88   {-return DLL version as PAnsiChar}
89 
90 
91 {---------------------------------------------------------------------------}
92 procedure CRC16Init(var CRC: word);
93 stdcall;  external 'ch_dll.dll' name 'CRC16Init';
94   {-initialize context}
95 
96 procedure CRC16Update(var CRC: word; Msg: pointer; Len: word);
97 stdcall;  external 'ch_dll.dll' name 'CRC16Update';
98   {-update CRC16 with Msg data}
99 
100 procedure CRC16Final(var CRC: word);
101 stdcall;  external 'ch_dll.dll' name 'CRC16Final';
102   {-CRC16: finalize calculation (dummy)}
103 
CRC16SelfTestnull104 function  CRC16SelfTest: boolean;
105 stdcall;  external 'ch_dll.dll' name 'CRC16SelfTest';
106   {-Self test for CRC16}
107 
108 procedure CRC16Full(var CRC: word; Msg: pointer; Len: word);
109 stdcall;  external 'ch_dll.dll' name 'CRC16Full';
110   {-CRC16 of Msg with init/update/final}
111 
112 procedure CRC16File(const fname: Str255; var CRC: word; var buf; bsize: word; var Err: word);
113 stdcall;  external 'ch_dll.dll' name 'CRC16File';
114   {-CRC16 of file, buf: buffer with at least bsize bytes}
115 
116 procedure CRC16UpdateXL(var CRC: word; Msg: pointer; Len: longint);
117 stdcall;  external 'ch_dll.dll' name 'CRC16UpdateXL';
118   {-update CRC16 with Msg data}
119 
120 procedure CRC16FullXL(var CRC: word; Msg: pointer; Len: longint);
121 stdcall;  external 'ch_dll.dll' name 'CRC16FullXL';
122   {-CRC16 of Msg with init/update/final}
123 
124 
125 {---------------------------------------------------------------------------}
126 type
127   TPGPDigest = array[0..2] of byte;  {OpenPGP 3 byte MSB first CRC24 digest}
128 
129 procedure Long2PGP(CRC: longint; var PGPCRC: TPGPDigest);
130 stdcall;  external 'ch_dll.dll' name 'Long2PGP';
131   {-convert longint CRC24 to OpenPGP MSB first format}
132 
133 procedure CRC24Init(var CRC: longint);
134 stdcall;  external 'ch_dll.dll' name 'CRC24Init';
135   {-initialize context}
136 
137 procedure CRC24Update(var CRC: longint; Msg: pointer; Len: word);
138 stdcall;  external 'ch_dll.dll' name 'CRC24Update';
139   {-update CRC24 with Msg data}
140 
141 procedure CRC24Final(var CRC: longint);
142 stdcall;  external 'ch_dll.dll' name 'CRC24Final';
143   {-CRC24: finalize calculation}
144 
CRC24SelfTestnull145 function  CRC24SelfTest: boolean;
146 stdcall;  external 'ch_dll.dll' name 'CRC24SelfTest';
147   {-Self test for CRC24}
148 
149 procedure CRC24Full(var CRC: longint; Msg: pointer; Len: word);
150 stdcall;  external 'ch_dll.dll' name 'CRC24Full';
151   {-CRC24 of Msg with init/update/final}
152 
153 procedure CRC24File(const fname: Str255; var CRC: longint; var buf; bsize: word; var Err: word);
154 stdcall;  external 'ch_dll.dll' name 'CRC24File';
155   {-CRC24 of file, buf: buffer with at least bsize bytes}
156 
157 procedure CRC24UpdateXL(var CRC: longint; Msg: pointer; Len: longint);
158 stdcall;  external 'ch_dll.dll' name 'CRC24UpdateXL';
159   {-update CRC24 with Msg data}
160 
161 procedure CRC24FullXL(var CRC: longint; Msg: pointer; Len: longint);
162 stdcall;  external 'ch_dll.dll' name 'CRC24FullXL';
163   {-CRC24 of Msg with init/update/final}
164 
165 
166 {---------------------------------------------------------------------------}
167 procedure CRC32Init(var CRC: longint);
168 stdcall;  external 'ch_dll.dll' name 'CRC32Init';
169   {-initialize context}
170 
171 procedure CRC32Update(var CRC: longint; Msg: pointer; Len: word);
172 stdcall;  external 'ch_dll.dll' name 'CRC32Update';
173   {-update CRC32 with Msg data}
174 
175 procedure CRC32Final(var CRC: longint);
176 stdcall;  external 'ch_dll.dll' name 'CRC32Final';
177   {-CRC32: finalize calculation}
178 
CRC32SelfTestnull179 function  CRC32SelfTest: boolean;
180 stdcall;  external 'ch_dll.dll' name 'CRC32SelfTest';
181   {-Self test for CRC32}
182 
183 procedure CRC32Full(var CRC: longint; Msg: pointer; Len: word);
184 stdcall;  external 'ch_dll.dll' name 'CRC32Full';
185   {-CRC32 of Msg with init/update/final}
186 
187 procedure CRC32File(const fname: Str255; var CRC: longint; var buf; bsize: word; var Err: word);
188 stdcall;  external 'ch_dll.dll' name 'CRC32File';
189   {-CRC32 of file, buf: buffer with at least bsize bytes}
190 
191 procedure CRC32UpdateXL(var CRC: longint; Msg: pointer; Len: longint);
192 stdcall;  external 'ch_dll.dll' name 'CRC32UpdateXL';
193   {-update CRC32 with Msg data}
194 
195 procedure CRC32FullXL(var CRC: longint; Msg: pointer; Len: longint);
196 stdcall;  external 'ch_dll.dll' name 'CRC32FullXL';
197   {-CRC32 of Msg with init/update/final}
198 
199 
200 {---------------------------------------------------------------------------}
201 procedure FCRC32Init(var CRC: longint);
202 stdcall;  external 'ch_dll.dll' name 'FCRC32Init';
203   {-initialize context}
204 
205 procedure FCRC32Update(var CRC: longint; Msg: pointer; Len: word);
206 stdcall;  external 'ch_dll.dll' name 'FCRC32Update';
207   {-update CRC with Msg data}
208 
209 procedure FCRC32Final(var CRC: longint);
210 stdcall;  external 'ch_dll.dll' name 'FCRC32Final';
211   {-FCRC32: finalize calculation}
212 
FCRC32SelfTestnull213 function  FCRC32SelfTest: boolean;
214 stdcall;  external 'ch_dll.dll' name 'FCRC32SelfTest';
215   {-Self test for FCRC32}
216 
217 procedure FCRC32Full(var CRC: longint; Msg: pointer; Len: word);
218 stdcall;  external 'ch_dll.dll' name 'FCRC32Full';
219   {-CRC32 of Msg with init/update/final}
220 
221 procedure FCRC32File(const fname: Str255; var CRC: longint; var buf; bsize: word; var Err: word);
222 stdcall;  external 'ch_dll.dll' name 'FCRC32File';
223   {-CRC32 of file, buf: buffer with at least bsize bytes}
224 
225 procedure FCRC32UpdateXL(var CRC: longint; Msg: pointer; Len: longint);
226 stdcall;  external 'ch_dll.dll' name 'FCRC32UpdateXL';
227   {-update CRC with Msg data}
228 
229 procedure FCRC32FullXL(var CRC: longint; Msg: pointer; Len: longint);
230 stdcall;  external 'ch_dll.dll' name 'FCRC32FullXL';
231   {-CRC32 of Msg with init/update/final}
232 
233 
234 {---------------------------------------------------------------------------}
235 procedure Adler32Init(var CRC: longint);
236 stdcall;  external 'ch_dll.dll' name 'Adler32Init';
237   {-initialize context}
238 
239 procedure Adler32Update(var CRC: longint; Msg: pointer; Len: word);
240 stdcall;  external 'ch_dll.dll' name 'Adler32Update';
241   {-update Adler32 with Msg data}
242 
243 procedure Adler32Final(var CRC: longint);
244 stdcall;  external 'ch_dll.dll' name 'Adler32Final';
245   {-Adler32: finalize calculation}
246 
Adler32SelfTestnull247 function  Adler32SelfTest: boolean;
248 stdcall;  external 'ch_dll.dll' name 'Adler32SelfTest';
249   {-Self test for Adler32}
250 
251 procedure Adler32Full(var CRC: longint; Msg: pointer; Len: word);
252 stdcall;  external 'ch_dll.dll' name 'Adler32Full';
253   {-Adler32 of Msg with init/update/final}
254 
255 procedure Adler32File(const fname: Str255; var CRC: longint; var buf; bsize: word; var Err: word);
256 stdcall;  external 'ch_dll.dll' name 'Adler32File';
257   {-Adler32 of file, buf: buffer with at least bsize bytes}
258 
259 procedure Adler32UpdateXL(var CRC: longint; Msg: pointer; Len: longint);
260 stdcall;  external 'ch_dll.dll' name 'Adler32UpdateXL';
261   {-update Adler32 with Msg data}
262 
263 procedure Adler32FullXL(var CRC: longint; Msg: pointer; Len: longint);
264 stdcall;  external 'ch_dll.dll' name 'Adler32FullXL';
265   {-Adler32 of Msg with init/update/final}
266 
267 
268 {---------------------------------------------------------------------------}
269 type
270   TCRC64 = packed record
271              lo32, hi32: longint;
272            end;
273 
274 procedure CRC64Init(var CRC: TCRC64);
275 stdcall;  external 'ch_dll.dll' name 'CRC64Init';
276   {-CRC64 initialization}
277 
278 procedure CRC64Update(var CRC: TCRC64; Msg: pointer; Len: word);
279 stdcall;  external 'ch_dll.dll' name 'CRC64Update';
280   {-update CRC64 with Msg data}
281 
282 procedure CRC64Final(var CRC: TCRC64);
283 stdcall;  external 'ch_dll.dll' name 'CRC64Final';
284   {-CRC64: finalize calculation, CRC wird geloescht}
285 
CRC64SelfTestnull286 function  CRC64SelfTest: boolean;
287 stdcall;  external 'ch_dll.dll' name 'CRC64SelfTest';
288   {-Self test for CRC64}
289 
290 procedure CRC64Full(var CRC: TCRC64; Msg: pointer; Len: word);
291 stdcall;  external 'ch_dll.dll' name 'CRC64Full';
292   {-CRC64 of Msg with init/update/final}
293 
294 procedure CRC64File(const fname: Str255; var CRC: TCRC64; var buf; bsize: word; var Err: word);
295 stdcall;  external 'ch_dll.dll' name 'CRC64File';
296   {-CRC64 of file, buf: buffer with at least bsize bytes}
297 
298 procedure CRC64UpdateXL(var CRC: TCRC64; Msg: pointer; Len: longint);
299 stdcall;  external 'ch_dll.dll' name 'CRC64UpdateXL';
300   {-update CRC64 with Msg data}
301 
302 procedure CRC64FullXL(var CRC: TCRC64; Msg: pointer; Len: longint);
303 stdcall;  external 'ch_dll.dll' name 'CRC64FullXL';
304   {-CRC64 of Msg with init/update/final}
305 
306 
307 {---------------------------------------------------------------------------}
308 type
309   THashAlgorithm = (_MD4,_MD5,_RIPEMD160,_SHA1,_SHA224,_SHA256,
310                     _SHA384,_SHA512,_Whirlpool,_SHA512_224,_SHA512_256); {Supported hash algorithms}
311 
312 const
313   _RMD160  = _RIPEMD160;     {Alias}
314 
315 const
316   MaxBlockLen  = 128;         {Max. block length (buffer size), multiple of 4}
317   MaxDigestLen = 64;          {Max. length of hash digest}
318   MaxStateLen  = 16;          {Max. size of internal state}
319   MaxOIDLen    = 9;           {Current max. OID length}
320   C_HashSig    = $3D7A;       {Signature for Hash descriptor}
321   C_HashVers   = $00010005;   {Version of Hash definitions}
322   C_MinHash    = _MD4;        {Lowest  hash in THashAlgorithm}
323   C_MaxHash    = _SHA512_256; {Highest hash in THashAlgorithm}
324 
325 type
326   THashState   = packed array[0..MaxStateLen-1] of longint;         {Internal state}
327   THashBuffer  = packed array[0..MaxBlockLen-1] of byte;            {hash buffer block}
328   THashDigest  = packed array[0..MaxDigestLen-1] of byte;           {hash digest}
329   PHashDigest  = ^THashDigest;                                      {pointer to hash digest}
330   THashBuf32   = packed array[0..MaxBlockLen  div 4 -1] of longint; {type cast helper}
331   THashDig32   = packed array[0..MaxDigestLen div 4 -1] of longint; {type cast helper}
332 
333 
334 type
335   THashContext = packed record
336                    Hash  : THashState;             {Working hash}
337                    MLen  : packed array[0..3] of longint; {max 128 bit msg length}
338                    Buffer: THashBuffer;            {Block buffer}
339                    Index : longint;                {Index in buffer}
340                  end;
341 
342 type
343   TMD4Digest       = packed array[0..15] of byte;  {MD4    digest   }
344   TMD5Digest       = packed array[0..15] of byte;  {MD5    digest   }
345   TRMD160Digest    = packed array[0..19] of byte;  {RMD160 digest   }
346   TSHA1Digest      = packed array[0..19] of byte;  {SHA1   digest   }
347   TSHA224Digest    = packed array[0..27] of byte;  {SHA224 digest   }
348   TSHA256Digest    = packed array[0..31] of byte;  {SHA256 digest   }
349   TSHA384Digest    = packed array[0..47] of byte;  {SHA384 digest   }
350   TSHA512Digest    = packed array[0..63] of byte;  {SHA512 digest   }
351   TSHA5_224Digest  = packed array[0..27] of byte;  {SHA512/224 digest}
352   TSHA5_256Digest  = packed array[0..31] of byte;  {SHA512/256 digest}
353   TWhirlDigest     = packed array[0..63] of byte;  {Whirlpool digest}
354 
355 type
356   HashInitProc     = procedure(var Context: THashContext);
357                       {-initialize context}
358                       {$ifdef DLL} stdcall; {$endif}
359 
360   HashUpdateXLProc = procedure(var Context: THashContext; Msg: pointer; Len: longint);
361                       {-update context with Msg data}
362                       {$ifdef DLL} stdcall; {$endif}
363 
364   HashFinalProc    = procedure(var Context: THashContext; var Digest: THashDigest);
365                       {-finalize calculation, clear context}
366                       {$ifdef DLL} stdcall; {$endif}
367 
368   HashFinalBitProc = procedure(var Context: THashContext; var Digest: THashDigest; BData: byte; bitlen: integer);
369                       {-finalize calculation with bitlen bits from BData, clear context}
370                       {$ifdef DLL} stdcall; {$endif}
371 
372 type
373   TOID_Vec  = packed array[1..MaxOIDLen] of longint; {OID vector}
374   POID_Vec  = ^TOID_Vec;                             {ptr to OID vector}
375 
376 type
377   THashName = string[19];                      {Hash algo name type }
378   PHashDesc = ^THashDesc;                      {Ptr to descriptor   }
379   THashDesc = packed record
380                 HSig      : word;              {Signature=C_HashSig }
381                 HDSize    : word;              {sizeof(THashDesc)   }
382                 HDVersion : longint;           {THashDesc Version   }
383                 HBlockLen : word;              {Blocklength of hash }
384                 HDigestlen: word;              {Digestlength of hash}
385                 HInit     : HashInitProc;      {Init  procedure     }
386                 HFinal    : HashFinalProc;     {Final procedure     }
387                 HUpdateXL : HashUpdateXLProc;  {Update procedure    }
388                 HAlgNum   : longint;           {Algo ID, longint avoids problems with enum size/DLL}
389                 HName     : THashName;         {Name of hash algo   }
390                 HPtrOID   : POID_Vec;          {Pointer to OID vec  }
391                 HLenOID   : word;              {Length of OID vec   }
392                 HFill     : word;
393                 HFinalBit : HashFinalBitProc;  {Bit-API Final proc  }
394                 HReserved : packed array[0..19] of byte;
395               end;
396 
397 
398 procedure RegisterHash(AlgId: THashAlgorithm; PHash: PHashDesc);
399 stdcall;  external 'ch_dll.dll' name 'RegisterHash';
400   {-Registers algorithm with AlgID and Hash descriptor PHash^}
401 
FindHash_by_IDnull402 function  FindHash_by_ID(AlgoID: THashAlgorithm): PHashDesc;
403 stdcall;  external 'ch_dll.dll' name 'FindHash_by_ID';
404   {-Return PHashDesc of AlgoID, nil if not found/registered}
405 
FindHash_by_Namenull406 function  FindHash_by_Name(AlgoName: THashName): PHashDesc;
407 stdcall;  external 'ch_dll.dll' name 'FindHash_by_Name';
408   {-Return PHashDesc of Algo with AlgoName, nil if not found/registered}
409 
410 procedure HashFile(const fname: Str255; PHash: PHashDesc; var Digest: THashDigest; var buf; bsize: word; var Err: word);
411 stdcall;  external 'ch_dll.dll' name 'HashFile';
412   {-Calulate hash digest of file, buf: buffer with at least bsize bytes}
413 
414 procedure HashUpdate(PHash: PHashDesc; var Context: THashContext; Msg: pointer; Len: word);
415 stdcall;  external 'ch_dll.dll' name 'HashUpdate';
416   {-update context with Msg data}
417 
418 procedure HashFullXL(PHash: PHashDesc; var Digest: THashDigest; Msg: pointer; Len: longint);
419 stdcall;  external 'ch_dll.dll' name 'HashFullXL';
420   {-Calulate hash digest of Msg with init/update/final}
421 
422 procedure HashFull(PHash: PHashDesc; var Digest: THashDigest; Msg: pointer; Len: word);
423 stdcall;  external 'ch_dll.dll' name 'HashFull';
424   {-Calulate hash digest of Msg with init/update/final}
425 
HashSameDigestnull426 function  HashSameDigest(PHash: PHashDesc; PD1, PD2: PHashDigest): boolean;
427 stdcall;  external 'ch_dll.dll' name 'HashSameDigest';
428   {-Return true if same digests, using HDigestlen of PHash}
429 
430 
431 {---------------------------------------------------------------------------}
432 type
433   THMAC_Context = record
434                     hashctx: THashContext;
435                     hmacbuf: THashBuffer;
436                     phashd : PHashDesc;
437                   end;
438 
439 procedure hmac_init(var ctx: THMAC_Context; phash: PHashDesc; key: pointer; klen: word);
440 stdcall;  external 'ch_dll.dll' name 'hmac_init';
441   {-initialize HMAC context with hash descr phash^ and key}
442 
443 procedure hmac_inits(var ctx: THMAC_Context; phash: PHashDesc; skey: Str255);
444 stdcall;  external 'ch_dll.dll' name 'hmac_inits';
445   {-initialize HMAC context with hash descr phash^ and skey}
446 
447 procedure hmac_update(var ctx: THMAC_Context; data: pointer; dlen: word);
448 stdcall;  external 'ch_dll.dll' name 'hmac_update';
449   {-HMAC data input, may be called more than once}
450 
451 procedure hmac_updateXL(var ctx: THMAC_Context; data: pointer; dlen: longint);
452 stdcall;  external 'ch_dll.dll' name 'hmac_updateXL';
453   {-HMAC data input, may be called more than once}
454 
455 procedure hmac_final(var ctx: THMAC_Context; var mac: THashDigest);
456 stdcall;  external 'ch_dll.dll' name 'hmac_final';
457   {-end data input, calculate HMAC digest}
458 
459 procedure hmac_final_bits(var ctx: THMAC_Context; var mac: THashDigest; BData: byte; bitlen: integer);
460 stdcall;  external 'ch_dll.dll' name 'hmac_final_bits';
461   {-end data input with bitlen bits from BData, calculate HMAC digest}
462 
463 
464 {---------------------------------------------------------------------------}
465 const
466   kdf_err_nil_pointer   = $0001;  {phash descriptor is nil}
467   kdf_err_digestlen     = $0002;  {digest length from descriptor is zero}
468   kdf_err_invalid_dKLen = $0003;  {dKLen greater than hash digest length}
469   kdf_err_nil_input     = $0004;  {input nil pointer and non-zero length}
470 
471 
kdf1null472 function kdf1(phash: PHashDesc; Z: pointer; zLen: word; pOtherInfo: pointer; oiLen: word; var DK; dkLen: word): integer;
473 stdcall;  external 'ch_dll.dll' name 'kdf1';
474   {-Derive key DK from shared secret Z using optional OtherInfo, hash function from phash}
475 
kdf2null476 function kdf2(phash: PHashDesc; Z: pointer; zLen: word; pOtherInfo: pointer; oiLen: word; var DK; dkLen: word): integer;
477 stdcall;  external 'ch_dll.dll' name 'kdf2';
478   {-Derive key DK from shared secret Z using optional OtherInfo, hash function from phash}
479 
kdf3null480 function kdf3(phash: PHashDesc; Z: pointer; zLen: word; pOtherInfo: pointer; oiLen: word; var DK; dkLen: word): integer;
481 stdcall;  external 'ch_dll.dll' name 'kdf3';
482   {-Derive key DK from shared secret Z using optional OtherInfo, hash function from phash}
483 
mgf1null484 function mgf1(phash: PHashDesc; pSeed: pointer; sLen: word; var Mask; mLen: word): integer;
485 stdcall;  external 'ch_dll.dll' name 'mgf1';
486   {-Derive Mask from seed, hash function from phash, Mask Generation Function 1 for PKCS #1}
487 
pbkdf1null488 function pbkdf1(phash: PHashDesc; pPW: pointer; pLen: word; salt: pointer; C: longint; var DK; dkLen: word): integer;
489 stdcall;  external 'ch_dll.dll' name 'pbkdf1';
490   {-Derive key DK from password pPW using 8 byte salt and iteration count C, uses hash function from phash}
491 
pbkdf1snull492 function pbkdf1s(phash: PHashDesc; sPW: Str255; salt: pointer; C: longint; var DK; dkLen: word): integer;
493 stdcall;  external 'ch_dll.dll' name 'pbkdf1s';
494   {-Derive key DK from password string sPW using 8 byte salt and iteration count C, uses hash function from phash}
495 
pbkdf2null496 function pbkdf2(phash: PHashDesc; pPW: pointer; pLen: word; salt: pointer; sLen,C: longint; var DK; dkLen: longint): integer;
497 stdcall;  external 'ch_dll.dll' name 'pbkdf2';
498   {-Derive key DK from password pPW using salt and iteration count C, uses hash function from phash}
499 
pbkdf2snull500 function pbkdf2s(phash: PHashDesc; sPW: Str255; salt: pointer; sLen,C: longint; var DK; dkLen: longint): integer;
501 stdcall;  external 'ch_dll.dll' name 'pbkdf2s';
502   {-Derive key DK from password string sPW using salt and iteration count C, uses hash function from phash}
503 
hkdfnull504 function hkdf(phash: PHashDesc;              {Descriptor of the Hash to use}
505               pIKM: pointer; L_IKM: word;    {input key material: addr/length}
506               salt: pointer; L_salt: word;   {optional salt; can be nil: see below }
507               info: pointer; L_info: word;   {optional context/application specific information}
508               var DK; dkLen: word): integer; {output key material: addr/length}
509 stdcall;  external 'ch_dll.dll' name 'hkdf';
510   {-Derive key DK from input key material and salt/info, uses hash function from phash}
511   { If salt=nil then phash^.HDigestLen binary zeros will be used as salt.}
512 
hkdfsnull513 function hkdfs(phash: PHashDesc; sIKM: Str255; {Hash; input key material as string}
514                salt: pointer; L_salt: word;    {optional salt; can be nil: see below }
515                info: pointer; L_info: word;    {optional context/application specific information}
516                var DK; dkLen: word): integer;  {output key material: addr/length}
517 stdcall;  external 'ch_dll.dll' name 'hkdfs';
518   {-Derive key DK from input key material and salt/info, uses hash function from phash}
519   { If salt=nil then phash^.HDigestLen binary zeros will be used as salt.}
520 
521 
522 {---------------------------------------------------------------------------}
523 type
524   TED2KResult  = packed record
525                    eDonkey: TMD4Digest;  {eDonkey method hash}
526                      eMule: TMD4Digest;  {eMule   method hash}
527                     differ: boolean;     {eDonkey and eMule differ}
528                  end;
529 
530 type
531   TED2KContext = packed record
532                    total_ctx: THashContext;  {outer total context}
533                    chunk_ctx: THashContext;  {inner chunk context}
534                    lastdig  : TMD4Digest;    {hash of completed inner chunk}
535                    cbytecnt : longint;       {byte count within chunk}
536                    chunkcnt : longint;       {chunk count}
537                  end;
538 
539 
540 procedure ED2K_Init(var Context: TED2KContext);
541 stdcall; external 'ch_dll.dll' name 'ED2K_Init';
542   {-initialize context}
543 
544 procedure ED2K_Update(var Context: TED2KContext; Msg: pointer; Len: word);
545 stdcall; external 'ch_dll.dll' name 'ED2K_Update';
546   {-update context with Msg data}
547 
548 procedure ED2K_UpdateXL(var Context: TED2KContext; Msg: pointer; Len: longint);
549 stdcall; external 'ch_dll.dll' name 'ED2K_UpdateXL';
550   {-update context with Msg data}
551 
552 procedure ED2K_Final(var Context: TED2KContext; var ResRec: TED2KResult);
553 stdcall; external 'ch_dll.dll' name 'ED2K_Final';
554   {-finalize eDonkey hash calculation, clear context}
555 
ED2K_SelfTestnull556 function  ED2K_SelfTest: boolean;
557 stdcall; external 'ch_dll.dll' name 'ED2K_SelfTest';
558   {-eDonkey hash self test for two small strings}
559 
560 procedure ED2K_Full(var ResRec: TED2KResult; Msg: pointer; Len: word);
561 stdcall; external 'ch_dll.dll' name 'ED2K_Full';
562   {-eDonkey hash-code of Msg with init/update/final}
563 
564 procedure ED2K_FullXL(var ResRec: TED2KResult; Msg: pointer; Len: longint);
565 stdcall; external 'ch_dll.dll' name 'ED2K_FullXL';
566   {-eDonkey hash-code of Msg with init/update/final}
567 
568 procedure ED2K_File(const fname: Str255; var ResRec: TED2KResult; var buf; bsize: word; var Err: word);
569 stdcall; external 'ch_dll.dll' name 'ED2K_File';
570   {-eDonkey hash-code of file, buf: buffer with at least bsize bytes}
571 
572 
573 {---------------------------------------------------------------------------}
574 procedure MD4Init(var Context: THashContext);
575 stdcall;  external 'ch_dll.dll' name 'MD4Init';
576   {-initialize context}
577 
578 procedure MD4Update(var Context: THashContext; Msg: pointer; Len: word);
579 stdcall;  external 'ch_dll.dll' name 'MD4Update';
580   {-update context with Msg data}
581 
582 procedure MD4Final(var Context: THashContext; var Digest: TMD4Digest);
583 stdcall;  external 'ch_dll.dll' name 'MD4Final';
584   {-finalize MD4 calculation, clear context}
585 
586 procedure MD4FinalBitsEx(var Context: THashContext; var Digest: THashDigest; BData: byte; bitlen: integer);
587 stdcall;  external 'ch_dll.dll' name 'MD4FinalBitsEx';
588   {-finalize MD4 calculation with bitlen bits from BData (big-endian), clear context}
589 
590 procedure MD4FinalBits(var Context: THashContext; var Digest: TMD4Digest; BData: byte; bitlen: integer);
591 stdcall;  external 'ch_dll.dll' name 'MD4FinalBits';
592   {-finalize MD4 calculation with bitlen bits from BData (big-endian), clear context}
593 
MD4SelfTestnull594 function  MD4SelfTest: boolean;
595 stdcall;  external 'ch_dll.dll' name 'MD4SelfTest';
596   {-self test for string from MD4 document}
597 
598 procedure MD4Full(var Digest: TMD4Digest; Msg: pointer; Len: word);
599 stdcall;  external 'ch_dll.dll' name 'MD4Full';
600   {-MD4 of Msg with init/update/final}
601 
602 procedure MD4File(const fname: Str255; var Digest: TMD4Digest; var buf; bsize: word; var Err: word);
603 stdcall;  external 'ch_dll.dll' name 'MD4File';
604   {-MD4 of file, buf: buffer with at least bsize bytes}
605 
606 procedure MD4UpdateXL(var Context: THashContext; Msg: pointer; Len: longint);
607 stdcall;  external 'ch_dll.dll' name 'MD4UpdateXL';
608   {-update context with Msg data}
609 
610 procedure MD4FullXL(var Digest: TMD4Digest; Msg: pointer; Len: longint);
611 stdcall;  external 'ch_dll.dll' name 'MD4FullXL';
612   {-MD4 of Msg with init/update/final}
613 
614 
615 {---------------------------------------------------------------------------}
616 procedure MD5Init(var Context: THashContext);
617 stdcall;  external 'ch_dll.dll' name 'MD5Init';
618   {-initialize context}
619 
620 procedure MD5Update(var Context: THashContext; Msg: pointer; Len: word);
621 stdcall;  external 'ch_dll.dll' name 'MD5Update';
622   {-update context with Msg data}
623 
624 procedure MD5Final(var Context: THashContext; var Digest: TMD5Digest);
625 stdcall;  external 'ch_dll.dll' name 'MD5Final';
626   {-finalize MD5 calculation, clear context}
627 
628 procedure MD5FinalBitsEx(var Context: THashContext; var Digest: THashDigest; BData: byte; bitlen: integer);
629 stdcall;  external 'ch_dll.dll' name 'MD5FinalBitsEx';
630   {-finalize MD5 calculation with bitlen bits from BData (big-endian), clear context}
631 
632 procedure MD5FinalBits(var Context: THashContext; var Digest: TMD5Digest; BData: byte; bitlen: integer);
633 stdcall;  external 'ch_dll.dll' name 'MD5FinalBits';
634   {-finalize MD5 calculation with bitlen bits from BData (big-endian), clear context}
635 
MD5SelfTestnull636 function  MD5SelfTest: boolean;
637 stdcall;  external 'ch_dll.dll' name 'MD5SelfTest';
638   {-self test for string from MD5 document}
639 
640 procedure MD5Full(var Digest: TMD5Digest; Msg: pointer; Len: word);
641 stdcall;  external 'ch_dll.dll' name 'MD5Full';
642   {-MD5 of Msg with init/update/final}
643 
644 procedure MD5File(const fname: Str255; var Digest: TMD5Digest; var buf; bsize: word; var Err: word);
645 stdcall;  external 'ch_dll.dll' name 'MD5File';
646   {-MD5 of file, buf: buffer with at least bsize bytes}
647 
648 procedure MD5UpdateXL(var Context: THashContext; Msg: pointer; Len: longint);
649 stdcall;  external 'ch_dll.dll' name 'MD5UpdateXL';
650   {-update context with Msg data}
651 
652 procedure MD5FullXL(var Digest: TMD5Digest; Msg: pointer; Len: longint);
653 stdcall;  external 'ch_dll.dll' name 'MD5FullXL';
654   {-MD5 of Msg with init/update/final}
655 
656 
657 {---------------------------------------------------------------------------}
658 procedure RMD160Init(var Context: THashContext);
659 stdcall;  external 'ch_dll.dll' name 'RMD160Init';
660   {-initialize context}
661 
662 procedure RMD160Update(var Context: THashContext; Msg: pointer; Len: word);
663 stdcall;  external 'ch_dll.dll' name 'RMD160Update';
664   {-update context with Msg data}
665 
666 procedure RMD160Final(var Context: THashContext; var Digest: TRMD160Digest);
667 stdcall;  external 'ch_dll.dll' name 'RMD160Final';
668   {-finalize RMD160 calculation, clear context}
669 
670 procedure RMD160FinalBitsEx(var Context: THashContext; var Digest: THashDigest; BData: byte; bitlen: integer);
671 stdcall;  external 'ch_dll.dll' name 'RMD160FinalBitsEx';
672   {-finalize RMD160 calculation with bitlen bits from BData (big-endian), clear context}
673 
674 procedure RMD160FinalBits(var Context: THashContext; var Digest: TRMD160Digest; BData: byte; bitlen: integer);
675 stdcall;  external 'ch_dll.dll' name 'RMD160FinalBits';
676   {-finalize RMD160 calculation with bitlen bits from BData (big-endian), clear context}
677 
RMD160SelfTestnull678 function  RMD160SelfTest: boolean;
679 stdcall;  external 'ch_dll.dll' name 'RMD160SelfTest';
680   {-self test for string from RMD160 document}
681 
682 procedure RMD160Full(var Digest: TRMD160Digest; Msg: pointer; Len: word);
683 stdcall;  external 'ch_dll.dll' name 'RMD160Full';
684   {-RMD160 of Msg with init/update/final}
685 
686 procedure RMD160File(const fname: Str255; var Digest: TRMD160Digest; var buf; bsize: word; var Err: word);
687 stdcall;  external 'ch_dll.dll' name 'RMD160File';
688   {-RMD160 of file, buf: buffer with at least bsize bytes}
689 
690 procedure RMD160UpdateXL(var Context: THashContext; Msg: pointer; Len: longint);
691 stdcall;  external 'ch_dll.dll' name 'RMD160UpdateXL';
692   {-update context with Msg data}
693 
694 procedure RMD160FullXL(var Digest: TRMD160Digest; Msg: pointer; Len: longint);
695 stdcall;  external 'ch_dll.dll' name 'RMD160FullXL';
696   {-RMD160 of Msg with init/update/final}
697 
698 
699 {---------------------------------------------------------------------------}
700 procedure SHA1Init(var Context: THashContext);
701 stdcall;  external 'ch_dll.dll' name 'SHA1Init';
702   {-initialize context}
703 
704 procedure SHA1Update(var Context: THashContext; Msg: pointer; Len: word);
705 stdcall;  external 'ch_dll.dll' name 'SHA1Update';
706   {-update context with Msg data}
707 
708 procedure SHA1Final(var Context: THashContext; var Digest: TSHA1Digest);
709 stdcall;  external 'ch_dll.dll' name 'SHA1Final';
710   {-finalize SHA1 calculation, clear context}
711 
712 procedure SHA1FinalBitsEx(var Context: THashContext; var Digest: THashDigest; BData: byte; bitlen: integer);
713 stdcall;  external 'ch_dll.dll' name 'SHA1FinalBitsEx';
714   {-finalize SHA1 calculation with bitlen bits from BData (big-endian), clear context}
715 
716 procedure SHA1FinalBits(var Context: THashContext; var Digest: TSHA1Digest; BData: byte; bitlen: integer);
717 stdcall;  external 'ch_dll.dll' name 'SHA1FinalBits';
718   {-finalize SHA1 calculation with bitlen bits from BData (big-endian), clear context}
719 
SHA1SelfTestnull720 function  SHA1SelfTest: boolean;
721 stdcall;  external 'ch_dll.dll' name 'SHA1SelfTest';
722   {-self test SHA1: compare with known value}
723 
724 procedure SHA1Full(var Digest: TSHA1Digest; Msg: pointer; Len: word);
725 stdcall;  external 'ch_dll.dll' name 'SHA1Full';
726   {-SHA1 of Msg with init/update/final}
727 
728 procedure SHA1File(const fname: Str255; var Digest: TSHA1Digest; var buf; bsize: word; var Err: word);
729 stdcall;  external 'ch_dll.dll' name 'SHA1File';
730   {-SHA1 of file, buf: buffer with at least bsize bytes}
731 
732 procedure SHA1UpdateXL(var Context: THashContext; Msg: pointer; Len: longint);
733 stdcall;  external 'ch_dll.dll' name 'SHA1UpdateXL';
734   {-update context with Msg data}
735 
736 procedure SHA1FullXL(var Digest: TSHA1Digest; Msg: pointer; Len: longint);
737 stdcall;  external 'ch_dll.dll' name 'SHA1FullXL';
738   {-SHA1 of Msg with init/update/final}
739 
740 
741 {---------------------------------------------------------------------------}
742 procedure SHA224Init(var Context: THashContext);
743 stdcall;  external 'ch_dll.dll' name 'SHA224Init';
744   {-initialize context}
745 
746 procedure SHA224Update(var Context: THashContext; Msg: pointer; Len: word);
747 stdcall;  external 'ch_dll.dll' name 'SHA224Update';
748   {-update context with Msg data}
749 
750 procedure SHA224Final(var Context: THashContext; var Digest: TSHA224Digest);
751 stdcall;  external 'ch_dll.dll' name 'SHA224Final';
752   {-finalize SHA224 calculation, clear context}
753 
754 procedure SHA224FinalBitsEx(var Context: THashContext; var Digest: THashDigest; BData: byte; bitlen: integer);
755 stdcall;  external 'ch_dll.dll' name 'SHA224FinalBitsEx';
756   {-finalize SHA224 calculation with bitlen bits from BData (big-endian), clear context}
757 
758 procedure SHA224FinalBits(var Context: THashContext; var Digest: TSHA224Digest; BData: byte; bitlen: integer);
759 stdcall;  external 'ch_dll.dll' name 'SHA224FinalBits';
760   {-finalize SHA224 calculation with bitlen bits from BData (big-endian), clear context}
761 
SHA224SelfTestnull762 function  SHA224SelfTest: boolean;
763 stdcall;  external 'ch_dll.dll' name 'SHA224SelfTest';
764   {-self test for string from SHA224 document}
765 
766 procedure SHA224Full(var Digest: TSHA224Digest; Msg: pointer; Len: word);
767 stdcall;  external 'ch_dll.dll' name 'SHA224Full';
768   {-SHA224 of Msg with init/update/final}
769 
770 procedure SHA224File(const fname: Str255; var Digest: TSHA224Digest; var buf; bsize: word; var Err: word);
771 stdcall;  external 'ch_dll.dll' name 'SHA224File';
772   {-SHA224 of file, buf: buffer with at least bsize bytes}
773 
774 procedure SHA224UpdateXL(var Context: THashContext; Msg: pointer; Len: longint);
775 stdcall;  external 'ch_dll.dll' name 'SHA224UpdateXL';
776   {-update context with Msg data}
777 
778 procedure SHA224FullXL(var Digest: TSHA224Digest; Msg: pointer; Len: longint);
779 stdcall;  external 'ch_dll.dll' name 'SHA224FullXL';
780   {-SHA224 of Msg with init/update/final}
781 
782 
783 {---------------------------------------------------------------------------}
784 procedure SHA256Init(var Context: THashContext);
785 stdcall;  external 'ch_dll.dll' name 'SHA256Init';
786   {-initialize context}
787 
788 procedure SHA256Update(var Context: THashContext; Msg: pointer; Len: word);
789 stdcall;  external 'ch_dll.dll' name 'SHA256Update';
790   {-update context with Msg data}
791 
792 procedure SHA256Final(var Context: THashContext; var Digest: TSHA256Digest);
793 stdcall;  external 'ch_dll.dll' name 'SHA256Final';
794   {-finalize SHA256 calculation, clear context}
795 
796 procedure SHA256FinalBitsEx(var Context: THashContext; var Digest: THashDigest; BData: byte; bitlen: integer);
797 stdcall;  external 'ch_dll.dll' name 'SHA256FinalBitsEx';
798   {-finalize SHA256 calculation with bitlen bits from BData (big-endian), clear context}
799 
800 procedure SHA256FinalBits(var Context: THashContext; var Digest: TSHA256Digest; BData: byte; bitlen: integer);
801 stdcall;  external 'ch_dll.dll' name 'SHA256FinalBits';
802   {-finalize SHA256 calculation with bitlen bits from BData (big-endian), clear context}
803 
SHA256SelfTestnull804 function  SHA256SelfTest: boolean;
805 stdcall;  external 'ch_dll.dll' name 'SHA256SelfTest';
806   {-self test for string from SHA224 document}
807 
808 procedure SHA256Full(var Digest: TSHA256Digest; Msg: pointer; Len: word);
809 stdcall;  external 'ch_dll.dll' name 'SHA256Full';
810   {-SHA256 of Msg with init/update/final}
811 
812 procedure SHA256File(const fname: Str255; var Digest: TSHA256Digest; var buf; bsize: word; var Err: word);
813 stdcall;  external 'ch_dll.dll' name 'SHA256File';
814   {-SHA256 of file, buf: buffer with at least bsize bytes}
815 
816 procedure SHA256UpdateXL(var Context: THashContext; Msg: pointer; Len: longint);
817 stdcall;  external 'ch_dll.dll' name 'SHA256UpdateXL';
818   {-update context with Msg data}
819 
820 procedure SHA256FullXL(var Digest: TSHA256Digest; Msg: pointer; Len: longint);
821 stdcall;  external 'ch_dll.dll' name 'SHA256FullXL';
822   {-SHA256 of Msg with init/update/final}
823 
824 
825 {---------------------------------------------------------------------------}
826 procedure SHA384Init(var Context: THashContext);
827 stdcall;  external 'ch_dll.dll' name 'SHA384Init';
828   {-initialize context}
829 
830 procedure SHA384Update(var Context: THashContext; Msg: pointer; Len: word);
831 stdcall;  external 'ch_dll.dll' name 'SHA384Update';
832   {-update context with Msg data}
833 
834 procedure SHA384Final(var Context: THashContext; var Digest: TSHA384Digest);
835 stdcall;  external 'ch_dll.dll' name 'SHA384Final';
836   {-finalize SHA384 calculation, clear context}
837 
838 procedure SHA384FinalBitsEx(var Context: THashContext; var Digest: THashDigest; BData: byte; bitlen: integer);
839 stdcall;  external 'ch_dll.dll' name 'SHA384FinalBitsEx';
840   {-finalize SHA384 calculation with bitlen bits from BData (big-endian), clear context}
841 
842 procedure SHA384FinalBits(var Context: THashContext; var Digest: TSHA384Digest; BData: byte; bitlen: integer);
843 stdcall;  external 'ch_dll.dll' name 'SHA384FinalBits';
844   {-finalize SHA384 calculation with bitlen bits from BData (big-endian), clear context}
845 
SHA384SelfTestnull846 function  SHA384SelfTest: boolean;
847 stdcall;  external 'ch_dll.dll' name 'SHA384SelfTest';
848   {-self test for string from SHA384 document}
849 
850 procedure SHA384Full(var Digest: TSHA384Digest; Msg: pointer; Len: word);
851 stdcall;  external 'ch_dll.dll' name 'SHA384Full';
852   {-SHA384 of Msg with init/update/final}
853 
854 procedure SHA384File(const fname: Str255; var Digest: TSHA384Digest; var buf; bsize: word; var Err: word);
855 stdcall;  external 'ch_dll.dll' name 'SHA384File';
856   {-SHA384 of file, buf: buffer with at least bsize bytes}
857 
858 procedure SHA384UpdateXL(var Context: THashContext; Msg: pointer; Len: longint);
859 stdcall;  external 'ch_dll.dll' name 'SHA384UpdateXL';
860   {-update context with Msg data}
861 
862 procedure SHA384FullXL(var Digest: TSHA384Digest; Msg: pointer; Len: longint);
863 stdcall;  external 'ch_dll.dll' name 'SHA384FullXL';
864   {-SHA384 of Msg with init/update/final}
865 
866 
867 {---------------------------------------------------------------------------}
868 procedure SHA512Init(var Context: THashContext);
869 stdcall;  external 'ch_dll.dll' name 'SHA512Init';
870   {-initialize context}
871 
872 procedure SHA512Update(var Context: THashContext; Msg: pointer; Len: word);
873 stdcall;  external 'ch_dll.dll' name 'SHA512Update';
874   {-update context with Msg data}
875 
876 procedure SHA512Final(var Context: THashContext; var Digest: TSHA512Digest);
877 stdcall;  external 'ch_dll.dll' name 'SHA512Final';
878   {-finalize SHA512 calculation, clear context}
879 
880 procedure SHA512FinalBitsEx(var Context: THashContext; var Digest: THashDigest; BData: byte; bitlen: integer);
881 stdcall;  external 'ch_dll.dll' name 'SHA512FinalBitsEx';
882   {-finalize SHA512 calculation with bitlen bits from BData (big-endian), clear context}
883 
884 procedure SHA512FinalBits(var Context: THashContext; var Digest: TSHA512Digest; BData: byte; bitlen: integer);
885 stdcall;  external 'ch_dll.dll' name 'SHA512FinalBits';
886   {-finalize SHA512 calculation with bitlen bits from BData (big-endian), clear context}
887 
SHA512SelfTestnull888 function  SHA512SelfTest: boolean;
889 stdcall;  external 'ch_dll.dll' name 'SHA512SelfTest';
890   {-self test for string from SHA512 document}
891 
892 procedure SHA512Full(var Digest: TSHA512Digest; Msg: pointer; Len: word);
893 stdcall;  external 'ch_dll.dll' name 'SHA512Full';
894   {-SHA512 of Msg with init/update/final}
895 
896 procedure SHA512File(const fname: Str255; var Digest: TSHA512Digest; var buf; bsize: word; var Err: word);
897 stdcall;  external 'ch_dll.dll' name 'SHA512File';
898   {-SHA512 of file, buf: buffer with at least bsize bytes}
899 
900 procedure SHA512UpdateXL(var Context: THashContext; Msg: pointer; Len: longint);
901 stdcall;  external 'ch_dll.dll' name 'SHA512UpdateXL';
902   {-update context with Msg data}
903 
904 procedure SHA512FullXL(var Digest: TSHA512Digest; Msg: pointer; Len: longint);
905 stdcall;  external 'ch_dll.dll' name 'SHA512FullXL';
906   {-SHA512 of Msg with init/update/final}
907 
908 {---------------------------------------------------------------------------}
909 procedure SHA5_224Init(var Context: THashContext);
910 stdcall;  external 'ch_dll.dll' name 'SHA5_224Init';
911   {-initialize context}
912 
913 procedure SHA5_224Update(var Context: THashContext; Msg: pointer; Len: word);
914 stdcall;  external 'ch_dll.dll' name 'SHA5_224Update';
915   {-update context with Msg data}
916 
917 procedure SHA5_224UpdateXL(var Context: THashContext; Msg: pointer; Len: longint);
918 stdcall;  external 'ch_dll.dll' name 'SHA5_224UpdateXL';
919   {-update context with Msg data}
920 
921 procedure SHA5_224Final(var Context: THashContext; var Digest: TSHA5_224Digest);
922 stdcall;  external 'ch_dll.dll' name 'SHA5_224Final';
923   {-finalize SHA512/224 calculation, clear context}
924 
925 procedure SHA5_224FinalEx(var Context: THashContext; var Digest: THashDigest);
926 stdcall;  external 'ch_dll.dll' name 'SHA5_224FinalEx';
927   {-finalize SHA512/224 calculation, clear context}
928 
929 procedure SHA5_224FinalBitsEx(var Context: THashContext; var Digest: THashDigest; BData: byte; bitlen: integer);
930 stdcall;  external 'ch_dll.dll' name 'SHA5_224FinalBitsEx';
931   {-finalize SHA512/224 calculation with bitlen bits from BData (big-endian), clear context}
932 
933 procedure SHA5_224FinalBits(var Context: THashContext; var Digest: TSHA5_224Digest; BData: byte; bitlen: integer);
934 stdcall;  external 'ch_dll.dll' name 'SHA5_224FinalBits';
935   {-finalize SHA512/224 calculation with bitlen bits from BData (big-endian), clear context}
936 
SHA5_224SelfTestnull937 function  SHA5_224SelfTest: boolean;
938 stdcall;  external 'ch_dll.dll' name 'SHA5_224SelfTest';
939   {-self test for string from SHA512/224 document}
940 
941 procedure SHA5_224Full(var Digest: TSHA5_224Digest; Msg: pointer; Len: word);
942 stdcall;  external 'ch_dll.dll' name 'SHA5_224Full';
943   {-SHA512/224 of Msg with init/update/final}
944 
945 procedure SHA5_224FullXL(var Digest: TSHA5_224Digest; Msg: pointer; Len: longint);
946 stdcall;  external 'ch_dll.dll' name 'SHA5_224FullXL';
947   {-SHA512/224 of Msg with init/update/final}
948 
949 procedure SHA5_224File(const fname: Str255; var Digest: TSHA5_224Digest; var buf; bsize: word; var Err: word);
950 stdcall;  external 'ch_dll.dll' name 'SHA5_224File';
951   {-SHA512/224 of file, buf: buffer with at least bsize bytes}
952 
953 
954 {---------------------------------------------------------------------------}
955 procedure SHA5_256Init(var Context: THashContext);
956 stdcall;  external 'ch_dll.dll' name 'SHA5_256Init';
957   {-initialize context}
958 
959 procedure SHA5_256Update(var Context: THashContext; Msg: pointer; Len: word);
960 stdcall;  external 'ch_dll.dll' name 'SHA5_256Update';
961   {-update context with Msg data}
962 
963 procedure SHA5_256UpdateXL(var Context: THashContext; Msg: pointer; Len: longint);
964 stdcall;  external 'ch_dll.dll' name 'SHA5_256UpdateXL';
965   {-update context with Msg data}
966 
967 procedure SHA5_256Final(var Context: THashContext; var Digest: TSHA5_256Digest);
968 stdcall;  external 'ch_dll.dll' name 'SHA5_256Final';
969   {-finalize SHA512/256 calculation, clear context}
970 
971 procedure SHA5_256FinalEx(var Context: THashContext; var Digest: THashDigest);
972 stdcall;  external 'ch_dll.dll' name 'SHA5_256FinalEx';
973   {-finalize SHA512/256 calculation, clear context}
974 
975 procedure SHA5_256FinalBitsEx(var Context: THashContext; var Digest: THashDigest; BData: byte; bitlen: integer);
976 stdcall;  external 'ch_dll.dll' name 'SHA5_256FinalBitsEx';
977   {-finalize SHA512/256 calculation with bitlen bits from BData (big-endian), clear context}
978 
979 procedure SHA5_256FinalBits(var Context: THashContext; var Digest: TSHA5_256Digest; BData: byte; bitlen: integer);
980 stdcall;  external 'ch_dll.dll' name 'SHA5_256FinalBits';
981   {-finalize SHA512/256 calculation with bitlen bits from BData (big-endian), clear context}
982 
SHA5_256SelfTestnull983 function  SHA5_256SelfTest: boolean;
984 stdcall;  external 'ch_dll.dll' name 'SHA5_256SelfTest';
985   {-self test for string from SHA512/256 document}
986 
987 procedure SHA5_256Full(var Digest: TSHA5_256Digest; Msg: pointer; Len: word);
988 stdcall;  external 'ch_dll.dll' name 'SHA5_256Full';
989   {-SHA512/256 of Msg with init/update/final}
990 
991 procedure SHA5_256FullXL(var Digest: TSHA5_256Digest; Msg: pointer; Len: longint);
992 stdcall;  external 'ch_dll.dll' name 'SHA5_256FullXL';
993   {-SHA512/256 of Msg with init/update/final}
994 
995 procedure SHA5_256File(const fname: Str255; var Digest: TSHA5_256Digest; var buf; bsize: word; var Err: word);
996 stdcall;  external 'ch_dll.dll' name 'SHA5_256File';
997   {-SHA512/256 of file, buf: buffer with at least bsize bytes}
998 
999 
1000 {---------------------------------------------------------------------------}
1001 procedure Whirl_Init(var Context: THashContext);
1002 stdcall;  external 'ch_dll.dll' name 'Whirl_Init';
1003   {-initialize context}
1004 
1005 procedure Whirl_Update(var Context: THashContext; Msg: pointer; Len: word);
1006 stdcall;  external 'ch_dll.dll' name 'Whirl_Update';
1007   {-update context with Msg data}
1008 
1009 procedure Whirl_Final(var Context: THashContext; var Digest: TWhirlDigest);
1010 stdcall;  external 'ch_dll.dll' name 'Whirl_Final';
1011   {-finalize Whirlpool calculation, clear context}
1012 
1013 procedure Whirl_FinalBitsEx(var Context: THashContext; var Digest: THashDigest; BData: byte; bitlen: integer);
1014 stdcall;  external 'ch_dll.dll' name 'Whirl_FinalBitsEx';
1015   {-finalize Whirlpool calculation with bitlen bits from BData (big-endian), clear context}
1016 
1017 procedure Whirl_FinalBits(var Context: THashContext; var Digest: TWhirlDigest; BData: byte; bitlen: integer);
1018 stdcall;  external 'ch_dll.dll' name 'Whirl_FinalBits';
1019   {-finalize Whirlpool calculation with bitlen bits from BData (big-endian), clear context}
1020 
Whirl_SelfTestnull1021 function  Whirl_SelfTest: boolean;
1022 stdcall;  external 'ch_dll.dll' name 'Whirl_SelfTest';
1023   {-self test for strings from Whirlpool distribution}
1024 
1025 procedure Whirl_Full(var Digest: TWhirlDigest; Msg: pointer; Len: word);
1026 stdcall;  external 'ch_dll.dll' name 'Whirl_Full';
1027   {-Whirlpool hash-code of Msg with init/update/final}
1028 
1029 procedure Whirl_File(const fname: Str255; var Digest: TWhirlDigest; var buf; bsize: word; var Err: word);
1030 stdcall;  external 'ch_dll.dll' name 'Whirl_File';
1031   {-Whirlpool hash-code of file, buf: buffer with at least bsize bytes}
1032 
1033 procedure Whirl_UpdateXL(var Context: THashContext; Msg: pointer; Len: longint);
1034 stdcall;  external 'ch_dll.dll' name 'Whirl_UpdateXL';
1035   {-update context with Msg data}
1036 
1037 procedure Whirl_FullXL(var Digest: TWhirlDigest; Msg: pointer; Len: longint);
1038 stdcall;  external 'ch_dll.dll' name 'Whirl_FullXL';
1039   {-Whirlpool hash-code of Msg with init/update/final}
1040 
1041 
1042 {---------------------------------------------------------------------------}
1043 procedure hmac_MD5_init(var ctx: THMAC_Context; key: pointer; klen: word);
1044 stdcall;  external 'ch_dll.dll' name 'hmac_MD5_init';
1045   {-initialize HMAC context with key}
1046 
1047 procedure hmac_MD5_inits(var ctx: THMAC_Context; skey: Str255);
1048 stdcall;  external 'ch_dll.dll' name 'hmac_MD5_inits';
1049   {-initialize HMAC context with skey}
1050 
1051 procedure hmac_MD5_update(var ctx: THMAC_Context; data: pointer; dlen: word);
1052 stdcall;  external 'ch_dll.dll' name 'hmac_MD5_update';
1053   {-HMAC data input, may be called more than once}
1054 
1055 procedure hmac_MD5_final(var ctx: THMAC_Context; var mac: TMD5Digest);
1056 stdcall;  external 'ch_dll.dll' name 'hmac_MD5_final';
1057   {-end data input, calculate HMAC digest}
1058 
1059 procedure hmac_MD5_updateXL(var ctx: THMAC_Context; data: pointer; dlen: longint);
1060 stdcall;  external 'ch_dll.dll' name 'hmac_MD5_updateXL';
1061   {-HMAC data input, may be called more than once}
1062 
1063 
1064 {---------------------------------------------------------------------------}
1065 procedure hmac_sha1_init(var ctx: THMAC_Context; key: pointer; klen: word);
1066 stdcall;  external 'ch_dll.dll' name 'hmac_sha1_init';
1067   {-initialize HMAC context with key}
1068 
1069 procedure hmac_sha1_inits(var ctx: THMAC_Context; skey: Str255);
1070 stdcall;  external 'ch_dll.dll' name 'hmac_sha1_inits';
1071   {-initialize HMAC context with skey}
1072 
1073 procedure hmac_sha1_update(var ctx: THMAC_Context; data: pointer; dlen: word);
1074 stdcall;  external 'ch_dll.dll' name 'hmac_sha1_update';
1075   {-HMAC data input, may be called more than once}
1076 
1077 procedure hmac_sha1_final(var ctx: THMAC_Context; var mac: TSHA1Digest);
1078 stdcall;  external 'ch_dll.dll' name 'hmac_sha1_final';
1079   {-end data input, calculate HMAC digest}
1080 
1081 procedure hmac_sha1_updateXL(var ctx: THMAC_Context; data: pointer; dlen: longint);
1082 stdcall;  external 'ch_dll.dll' name 'hmac_sha1_updateXL';
1083   {-HMAC data input, may be called more than once}
1084 
1085 
1086 {---------------------------------------------------------------------------}
1087 procedure hmac_SHA256_init(var ctx: THMAC_Context; key: pointer; klen: word);
1088 stdcall;  external 'ch_dll.dll' name 'hmac_SHA256_init';
1089   {-initialize HMAC context with key}
1090 
1091 procedure hmac_SHA256_inits(var ctx: THMAC_Context; skey: Str255);
1092 stdcall;  external 'ch_dll.dll' name 'hmac_SHA256_inits';
1093   {-initialize HMAC context with skey}
1094 
1095 procedure hmac_SHA256_update(var ctx: THMAC_Context; data: pointer; dlen: word);
1096 stdcall;  external 'ch_dll.dll' name 'hmac_SHA256_update';
1097   {-HMAC data input, may be called more than once}
1098 
1099 procedure hmac_SHA256_final(var ctx: THMAC_Context; var mac: TSHA256Digest);
1100 stdcall;  external 'ch_dll.dll' name 'hmac_SHA256_final';
1101   {-end data input, calculate HMAC digest}
1102 
1103 procedure hmac_SHA256_updateXL(var ctx: THMAC_Context; data: pointer; dlen: longint);
1104 stdcall;  external 'ch_dll.dll' name 'hmac_SHA256_updateXL';
1105   {-HMAC data input, may be called more than once}
1106 
1107 
1108 {---------------------------------------------------------------------------}
1109 procedure hmac_SHA512_init(var ctx: THMAC_Context; key: pointer; klen: word);
1110 stdcall;  external 'ch_dll.dll' name 'hmac_SHA512_init';
1111   {-initialize HMAC context with key}
1112 
1113 procedure hmac_SHA512_inits(var ctx: THMAC_Context; skey: Str255);
1114 stdcall;  external 'ch_dll.dll' name 'hmac_SHA512_inits';
1115   {-initialize HMAC context with skey}
1116 
1117 procedure hmac_SHA512_update(var ctx: THMAC_Context; data: pointer; dlen: word);
1118 stdcall;  external 'ch_dll.dll' name 'hmac_SHA512_update';
1119   {-HMAC data input, may be called more than once}
1120 
1121 procedure hmac_SHA512_final(var ctx: THMAC_Context; var mac: TSHA512Digest);
1122 stdcall;  external 'ch_dll.dll' name 'hmac_SHA512_final';
1123   {-end data input, calculate HMAC digest}
1124 
1125 procedure hmac_SHA512_updateXL(var ctx: THMAC_Context; data: pointer; dlen: longint);
1126 stdcall;  external 'ch_dll.dll' name 'hmac_SHA512_updateXL';
1127   {-HMAC data input, may be called more than once}
1128 
1129 
1130 {---------------------------------------------------------------------------}
1131 procedure hmac_Whirl_init(var ctx: THMAC_Context; key: pointer; klen: word);
1132 stdcall;  external 'ch_dll.dll' name 'hmac_Whirl_init';
1133   {-initialize HMAC context with key}
1134 
1135 procedure hmac_Whirl_inits(var ctx: THMAC_Context; skey: Str255);
1136 stdcall;  external 'ch_dll.dll' name 'hmac_Whirl_inits';
1137   {-initialize HMAC context with skey}
1138 
1139 procedure hmac_Whirl_update(var ctx: THMAC_Context; data: pointer; dlen: word);
1140 stdcall;  external 'ch_dll.dll' name 'hmac_Whirl_update';
1141   {-HMAC data input, may be called more than once}
1142 
1143 procedure hmac_Whirl_final(var ctx: THMAC_Context; var mac: TWhirlDigest);
1144 stdcall;  external 'ch_dll.dll' name 'hmac_Whirl_final';
1145   {-end data input, calculate HMAC digest}
1146 
1147 procedure hmac_Whirl_updateXL(var ctx: THMAC_Context; data: pointer; dlen: longint);
1148 stdcall;  external 'ch_dll.dll' name 'hmac_Whirl_updateXL';
1149   {-HMAC data input, may be called more than once}
1150 
1151 
1152 {---------------------------------------------------------------------------}
1153 type
1154   TCRCParam  = packed record
1155                  poly  : longint;    {CRC polynomial, top bit omitted}
1156                  init  : longint;    {Initial value of crc register}
1157                  xorout: longint;    {final xormask for crc register}
1158                  check : longint;    {CRC value for '123456789'}
1159                  width : word;       {width of algorithm, deg(poly)-1}
1160                  refin : boolean;    {reflect input bytes before processing}
1161                  refout: boolean;    {reflect reg before xor with xorout}
1162                  name  : string[19]; {name of the CRC algorithm}
1163                end;
1164 type
1165   PCRC32Tab  = ^TCRC32Tab;             {Pointer to CRC table}
1166   TCRC32Tab  = array[byte] of longint; {CRC table type}
1167 
1168 type
1169   TCRC_ctx   = packed record
1170                  reg   : longint;    {CRC state register}
1171                  poly  : longint;    {CRC polynomial, top bit omitted}
1172                  init  : longint;    {Initial value of crc register}
1173                  xorout: longint;    {final xormask for crc register}
1174                  check : longint;    {CRC value for '123456789'}
1175                  wmask : longint;    {mask with lowest width bits set}
1176                  ptab  : PCRC32Tab;  {pointer to table, may be nil}
1177                  width : word;       {width of algorithm, deg(poly)-1}
1178                  shift : word;       {shift value for table processing}
1179                  refin : boolean;    {reflect input bytes before processing}
1180                  refout: boolean;    {reflect reg before xor with xorout}
1181                  name  : string[19]; {name of the CRC algorithm}
1182                end;
1183 
1184 
1185 procedure cm_CalcTab(const CRCPara: TCRCParam; var Tab: TCRC32Tab);
1186 stdcall;  external 'ch_dll.dll' name 'cm_CalcTab';
1187   {-Calculate CRC table from CRCPara, does nothing if CRCPara.width<8}
1188 
1189 procedure cm_Create(const CRCPara: TCRCParam; ptab: PCRC32Tab; var ctx: TCRC_ctx);
1190 stdcall;  external 'ch_dll.dll' name 'cm_Create';
1191   {-Create crc context from CRCPara, ptab may be nil}
1192 
1193 procedure cm_Init(var ctx: TCRC_ctx);
1194 stdcall;  external 'ch_dll.dll' name 'cm_Init';
1195   {-initialize context}
1196 
1197 procedure cm_Update(var ctx: TCRC_ctx; Msg: pointer; Len: word);
1198 stdcall;  external 'ch_dll.dll' name 'cm_Update';
1199   {-update ctx with Msg data}
1200 
1201 procedure cm_Final(var ctx: TCRC_ctx; var CRC: longint);
1202 stdcall;  external 'ch_dll.dll' name 'cm_Final';
1203   {-finalize calculation and return CRC}
1204 
cm_SelfTestnull1205 function  cm_SelfTest(const CRCPara: TCRCParam) : boolean;
1206 stdcall;  external 'ch_dll.dll' name 'cm_SelfTest';
1207   {-Self test for CRCPara (no table version)}
1208 
1209 procedure cm_Full(var ctx: TCRC_ctx; var CRC: longint; Msg: pointer; Len: word);
1210 stdcall;  external 'ch_dll.dll' name 'cm_Full';
1211   {-process Msg with init/update/final using ctx}
1212 
1213 procedure cm_File(const fname: Str255; var ctx: TCRC_ctx; var CRC: longint; var buf; bsize: word; var Err: word);
1214 stdcall;  external 'ch_dll.dll' name 'cm_File';
1215   {-CRC of file, buf: buffer with at least bsize bytes}
1216 
1217 procedure cm_next(var ctx: TCRC_ctx; b: byte);
1218 stdcall;  external 'ch_dll.dll' name 'cm_next';
1219   {-update ctx with data byte b}
1220 
cm_reflectnull1221 function  cm_reflect(v: longint; b: integer): longint;
1222 stdcall;  external 'ch_dll.dll' name 'cm_reflect';
1223   {-returns the reflected lowest b bits of v}
1224 
cm_combinenull1225 function  cm_combine(const para: TCRCParam; crc1, crc2: longint; len2: longint): longint;
1226 stdcall;  external 'ch_dll.dll' name 'cm_combine';
1227   {-combine two CRCs calculated with para, i.e. if crc1 = CRC(m1) and}
1228   { crc2 = CRC(m2) then cm_combine = CRC(m1||m2); len2 = length(m2).}
1229 
1230 
1231 {---------------------------------------------------------------------------}
1232 type
1233   TSickCTX = packed record
1234                crc: word; {must be swapped for final result}
1235                prv: word; {temporary result for previous byte}
1236              end;
1237 
1238 procedure CRC_Sick_Init(var ctx: TSickCTX);
1239 stdcall;  external 'ch_dll.dll' name 'CRC_Sick_Init';
1240   {-initialize context}
1241 
1242 procedure CRC_Sick_Update(var ctx: TSickCTX; Msg: pointer; Len: word);
1243 stdcall;  external 'ch_dll.dll' name 'CRC_Sick_Update';
1244   {-update CRC_Sick with Msg data}
1245 
CRC_Sick_Finalnull1246 function  CRC_Sick_Final(var ctx: TSickCTX): word;
1247 stdcall;  external 'ch_dll.dll' name 'CRC_Sick_Final';
1248   {-CRC_Sick: finalize calculation (dummy)}
1249 
CRC_Sick_SelfTestnull1250 function  CRC_Sick_SelfTest: boolean;
1251 stdcall;  external 'ch_dll.dll' name 'CRC_Sick_SelfTest';
1252   {-Self test for CRC_Sick with '123456789' and 'abcdefghijklmnopqrstuvwxyz'}
1253 
1254 procedure CRC_Sick_Full(var CRC: word; Msg: pointer; Len: word);
1255 stdcall;  external 'ch_dll.dll' name 'CRC_Sick_Full';
1256   {-CRC_Sick of Msg with init/update/final}
1257 
1258 procedure CRC_Sick_File(const fname: Str255; var CRC: word; var buf; bsize: word; var Err: word);
1259 stdcall;  external 'ch_dll.dll' name 'CRC_Sick_File';
1260   {-CRC_Sick of file, buf: buffer with at least bsize bytes}
1261 
1262 procedure CRC_Sick_UpdateXL(var ctx: TSickCTX; Msg: pointer; Len: longint);
1263 stdcall;  external 'ch_dll.dll' name 'CRC_Sick_UpdateXL';
1264   {-update CRC_Sick with Msg data}
1265 
1266 procedure CRC_Sick_FullXL(var CRC: word; Msg: pointer; Len: longint);
1267 stdcall;  external 'ch_dll.dll' name 'CRC_Sick_FullXL';
1268   {-CRC of Msg with init/update/final}
1269 
1270 
1271 implementation
1272 
1273 end.
1274