You are looking at historical revision 15594 of this page. It may differ significantly from its current revision.

message-digest

Documentation

Message Digest provides support for message digest primitives. A message-digest is a function taking an arbitrary input and returning a fixed-length hash. For best results the input should be something easily treated as a byte-block.

make-binary-message-digest

[procedure] (make-binary-message-digest SOURCE CONTEXT-INFO DIGEST-LENGTH INIT UPDATE FINAL [CALLER]) => STRING

Returns the message-digest for SOURCE as a string of bytes.

SOURCE is any Scheme-object. See the UPDATE entry below for interpretation of the SOURCE.

CONTEXT-INFO is either a procedure that returns an object CONTEXT, or a positive fixnum. When a fixnum a memory-block of length CONTEXT-INFO is allocated (and automatically free'ed). The CONTEXT is often a pointer but maybe any Scheme-object.

DIGEST-LENGTH is the fixnum count of bytes in the result string.

The phase procedures:

[procedure] ({{INIT}} CONTEXT)

Initialization phase procedure. Sets up the CONTEXT, if necessary. The result is ignored.

[procedure] ({{UPDATE}} CONTEXT BUFFER COUNT)

Accumulation phase procedure. Must accumulate the BUFFER, where BUFFER is a Scheme-object. Will be called one or more times. The result is ignored.

Where SOURCE is-a:

string
BUFFER = SOURCE.
blob
BUFFER = SOURCE.
procedure
updates with BUFFER = (procedure) until #f = (procedure).
input-port
like procedure above but from message-digest-chunk-reader.
object
BUFFER = (message-digest-chunk-converter SOURCE).

Where the actual number of bytes in the BUFFER can be determined COUNT will be a positive-integer. Otherwise COUNT is -1.

See message-digest-chunk-size to set the number of bytes read per update invocation.

See message-digest-chunk-reader to set the chunk reader procedure creator.

See message-digest-chunk-converter to set the chunk representation translation procedure.

[procedure] ({{FINAL}} CONTEXT RESULT)

Finalization phase procedure. Must build the resulting message-digest in the supplied RESULT string of length DIGEST-LENGTH. The result is ignored.

The optional CALLER is for identification.

make-message-digest

[procedure] (make-message-digest SOURCE CONTEXT-INFO DIGEST-LENGTH INIT UPDATE FINAL [CALLER]) => STRING

Exactly as above but returns the message-digest for SOURCE using byte-string->hexadecimal.

message-digest-primitive

 [record] (message-digest-primitive CONTEXT-INFO DIGEST-LENGTH INIT UPDATE FINAL ID)

The meaning of the fields are exactly as above.

[procedure] message-digest?
[procedure] message-digest-context-info
[procedure] message-digest-digest-length
[procedure] message-digest-init
[procedure] message-digest-update
[procedure] message-digest-final
[procedure] message-digest-name

message-digest-primitive-apply

[procedure] (message-digest-primitive-apply MESSAGE-DIGEST-PRIMITIVE SOURCE [CALLER])

Returns a binary-message-digest of SOURCE using MESSAGE-DIGEST-PRIMITIVE.

Parameters

message-digest-chunk-size

[parameter] (message-digest-chunk-size [SIZE])

The number of bytes to read during the message-digest update phase. SIZE is a positive fixnum, default 1024.

message-digest-chunk-reader

[parameter] (message-digest-chunk-reader [READER-CREATOR])

The procedure used to create an input procedure.

 [procedure] ({{READER-CREATOR}} INPUT-PORT) => PROCEDURE/0

The default READER-CREATOR will return a reader that takes from INPUT-PORT in (message-digest-chunk-size) bytes. The INPUT-PORT is treated as a binary-stream no matter how it is defined.

message-digest-chunk-converter

[parameter] (message-digest-chunk-converter [CONVERTER])

The procedure used to translate an arbitrary Scheme-object into something suitable for an UPDATE procedure. Should the CONVERTER be #f then no translation is attempted.

 [procedure] ({{CONVERTER}} OBJECT) => OBJECT

The default CONVERTER will convert a heterogeneous-vector to a blob with shared-storage. No translation otherwise.

Auxillary Procedures

byte-string->substring-list

[procedure] (byte-string->substring-list STRING CHUNK-SIZE [START [END]]) => LIST

Returns a list of CHUNK-SIZE substrings of STRING, on the interval [START END). Defaults are [0 string-length).

Any remaining substring less than CHUNK-SIZE is appended to the list.

byte-string->substring-list/shared

[procedure] (byte-string->substring-list/shared STRING CHUNK-SIZE [START [END]]) => LIST

Returns a list of CHUNK-SIZE substrings of STRING, on the interval [START END). Defaults are [0 byte-string-length).

Any remaining substring less than CHUNK-SIZE is appended to the list.

The substrings can share storage with the STRING!

byte-string->hexadecimal

[procedure] (byte-string->hexadecimal STRING [START [END]]) => STRING

Returns a hex-encoded representation of STRING, on the interval [START END). Defaults are [0 byte-string-length).

Usage

(require-library message-digest)
(import message-digest)

Examples

Notes

Requirements

[miscmacros] [check-errors]

Bugs and Limitations

Author

kon lovett

Version history

2.0.0
Release for Chicken 4 [From a diff provided by Christian Kellermann]

License

Copyright (C) 2009 Kon Lovett. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.