1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
9 -- Copyright (C) 2002 Ada Core Technologies, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
31 ------------------------------------------------------------------------------
33 -- This package implements the MD5 Message-Digest Algorithm as described in
34 -- RFC 1321. The complete text of RFC 1321 can be found at:
36 -- http://www.ietf.org/rfc/rfc1321.txt
38 -- The implementation is derived from the RSA Data Secutity, Inc. MD5
39 -- Message-Digest Algorithm, as described in RFC 1321.
46 type Context
is private;
47 -- This type is the four-word (16 byte) MD buffer, as described in
48 -- RFC 1321 (3.3). It initial value is Initial_Context below.
50 Initial_Context
: constant Context
;
51 -- Initial value of a Context object. May be used to reinitialize
52 -- a Context value by simple assignment of this value to the object.
62 Input
: Ada
.Streams
.Stream_Element_Array
);
63 -- Modify the Context C. If C has the initial value Initial_Context,
64 -- then, after a call to one of these procedures, Digest (C) will return
65 -- the Message-Digest of Input.
67 -- These procedures may be called successively with the same context and
68 -- different inputs. However, several successive calls will not produce
69 -- the same final context as a call with the concatenation of the inputs.
71 subtype Message_Digest
is String (1 .. 32);
72 -- The string type returned by function Digest.
74 function Digest
(C
: Context
) return Message_Digest
;
75 -- Extracts the Message-Digest from a context. This function should be
76 -- used after one or several calls to Update.
78 function Digest
(S
: String) return Message_Digest
;
79 function Wide_Digest
(W
: Wide_String) return Message_Digest
;
81 (A
: Ada
.Streams
.Stream_Element_Array
)
82 return Message_Digest
;
83 -- These functions are equivalent to the corresponding Update (or
84 -- Wide_Update) on a default initialized Context, followed by Digest
85 -- on the resulting Context.
90 Initial_A
: constant := 16#
67452301#
;
91 Initial_B
: constant := 16#EFCDAB89#
;
92 Initial_C
: constant := 16#
98BADCFE#
;
93 Initial_D
: constant := 16#
10325476#
;
95 type Context
is record
96 A
: Interfaces
.Unsigned_32
:= Initial_A
;
97 B
: Interfaces
.Unsigned_32
:= Initial_B
;
98 C
: Interfaces
.Unsigned_32
:= Initial_C
;
99 D
: Interfaces
.Unsigned_32
:= Initial_D
;
102 Initial_Context
: constant Context
:=
103 (A
=> Initial_A
, B
=> Initial_B
, C
=> Initial_C
, D
=> Initial_D
);