1md5(n)                   MD5 Message-Digest Algorithm                   md5(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       md5 - MD5 Message-Digest Algorithm
9

SYNOPSIS

11       package require Tcl  8.2
12
13       package require md5  ?2.0.7?
14
15       ::md5::md5 ?-hex? [ -channel channel | -file filename | string ]
16
17       ::md5::hmac  ?-hex?  -key  key  [  -channel  channel | -file filename |
18       string ]
19
20       ::md5::MD5Init
21
22       ::md5::MD5Update token data
23
24       ::md5::MD5Final token
25
26       ::md5::HMACInit key
27
28       ::md5::HMACUpdate token data
29
30       ::md5::HMACFinal token
31
32______________________________________________________________________________
33

DESCRIPTION

35       This package is an implementation in  Tcl  of  the  MD5  message-digest
36       algorithm  as  described in RFC 1321 (1). This algorithm takes an arbi‐
37       trary quantity of data and generates a 128-bit message digest from  the
38       input.  The  MD5  algorithm is related to the MD4 algorithm (2) but has
39       been strengthened against certain types of potential attack. MD5 should
40       be used in preference to MD4 for new applications.
41
42       If  you  have critcl and have built the tcllibc package then the imple‐
43       mentation of the hashing function will be performed by  compiled  code.
44       Alternatively  if  you have either cryptkit or Trf then either of these
45       can be used to accelerate the digest computation. If no  suitable  com‐
46       piled  package  is  available  then  the pure-Tcl implementation wil be
47       used. The programming interface remains the same in all cases.
48
49       Note the previous version of this package always returned a hex encoded
50       string. This has been changed to simplify the programming interface and
51       to make this version more compatible  with  other  implementations.  To
52       obtain  the previous usage, either explicitly specify package version 1
53       or use the -hex option to the md5 command.
54

COMMANDS

56       ::md5::md5 ?-hex? [ -channel channel | -file filename | string ]
57              Calculate the MD5 digest of the data given in  string.  This  is
58              returned  as  a binary string by default. Giving the -hex option
59              will return a hexadecimal encoded version of the digest.
60
61              The data to be hashed can be specified either as a string  argu‐
62              ment  to the md5 command, or as a filename or a pre-opened chan‐
63              nel. If the -filename argument is given then the file is opened,
64              the data read and hashed and the file is closed. If the -channel
65              argument is given then data is read from the channel  until  the
66              end of file. The channel is not closed.
67
68              Only one of -file, -channel or string should be given.
69
70       ::md5::hmac  ?-hex?  -key  key  [  -channel  channel | -file filename |
71       string ]
72              Calculate an Hashed Message Authentication digest  (HMAC)  using
73              the  MD5  digest  algorithm. HMACs are described in RFC 2104 (3)
74              and provide an MD5 digest that includes a key. All options other
75              than -key are as for the ::md5::md5 command.
76

PROGRAMMING INTERFACE

78       For  the  programmer, the MD5 hash can be viewed as a bucket into which
79       one pours data. When you have finished, you extract  a  value  that  is
80       derived  from the data that was poured into the bucket. The programming
81       interface to the MD5 hash  operates  on  a  token  (equivalent  to  the
82       bucket).  You call MD5Init to obtain a token and then call MD5Update as
83       many times as required  to  add  data  to  the  hash.  To  release  any
84       resources and obtain the hash value, you then call MD5Final. An equiva‐
85       lent set of functions gives you a keyed digest (HMAC).
86
87       ::md5::MD5Init
88              Begins a new MD5 hash. Returns a token ID that must be used  for
89              the remaining functions.
90
91       ::md5::MD5Update token data
92              Add  data  to  the  hash  identified by token. Calling MD5Update
93              $token "abcd" is equivalent to  calling  MD5Update  $token  "ab"
94              followed by MD5Update $token "cb". See EXAMPLES.
95
96       ::md5::MD5Final token
97              Returns  the  hash value and releases any resources held by this
98              token. Once this command completes the token  will  be  invalid.
99              The  result  is a binary string of 16 bytes representing the 128
100              bit MD5 digest value.
101
102       ::md5::HMACInit key
103              This is equivalent to the ::md5::MD5Init command except that  it
104              requires the key that will be included in the HMAC.
105
106       ::md5::HMACUpdate token data
107
108       ::md5::HMACFinal token
109              These commands are identical to the MD5 equivalent commands.
110

EXAMPLES

112              % md5::md5 -hex "Tcl does MD5"
113              8AAC1EE01E20BB347104FABB90310433
114
115
116
117              % md5::hmac -hex -key Sekret "Tcl does MD5"
118              35BBA244FD56D3EDF5F3C47474DACB5D
119
120
121
122              % set tok [md5::MD5Init]
123              ::md5::1
124              % md5::MD5Update $tok "Tcl "
125              % md5::MD5Update $tok "does "
126              % md5::MD5Update $tok "MD5"
127              % md5::Hex [md5::MD5Final $tok]
128              8AAC1EE01E20BB347104FABB90310433
129
130

REFERENCES

132       [1]    Rivest,  R.,  "The  MD5 Message-Digest Algorithm", RFC 1321, MIT
133              and RSA Data Security, Inc,  April  1992.   (http://www.rfc-edi
134              tor.org/rfc/rfc1321.txt)
135
136       [2]    Rivest,  R.,  "The MD4 Message Digest Algorithm", RFC 1320, MIT,
137              April 1992. (http://www.rfc-editor.org/rfc/rfc1320.txt)
138
139       [3]    Krawczyk, H., Bellare, M. and Canetti, R.  "HMAC:  Keyed-Hashing
140              for   Message   Authentication",   RFC   2104,   February  1997.
141              (http://www.rfc-editor.org/rfc/rfc2104.txt)
142

BUGS, IDEAS, FEEDBACK

144       This document, and the package it describes, will  undoubtedly  contain
145       bugs and other problems.  Please report such in the category md5 of the
146       Tcllib Trackers  [http://core.tcl.tk/tcllib/reportlist].   Please  also
147       report  any  ideas  for  enhancements  you  may have for either package
148       and/or documentation.
149
150       When proposing code changes, please provide unified diffs, i.e the out‐
151       put of diff -u.
152
153       Note  further  that  attachments  are  strongly  preferred over inlined
154       patches. Attachments can be made by going  to  the  Edit  form  of  the
155       ticket  immediately  after  its  creation, and then using the left-most
156       button in the secondary navigation bar.
157

SEE ALSO

159       md4, sha1
160

KEYWORDS

162       hashing, md5, message-digest, rfc 1320, rfc 1321, rfc 2104, security
163

CATEGORY

165       Hashes, checksums, and encryption
166
168       Copyright (c) 2003, Pat Thoyts <patthoyts@users.sourceforge.net>
169
170
171
172
173tcllib                               2.0.7                              md5(n)
Impressum