2002-04-02 David S. Miller <davem@redhat.com>
[official-gcc.git] / gcc / ada / g-md5.ads
blob2e0f27cb9c3b2be4bf27263b356aec18079f31fb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- G N A T . M D 5 --
6 -- --
7 -- S p e c --
8 -- --
9 -- --
10 -- Copyright (C) 2002 Ada Core Technologies, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
29 -- --
30 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
31 -- --
32 ------------------------------------------------------------------------------
34 -- This package implements the MD5 Message-Digest Algorithm as described in
35 -- RFC 1321. The complete text of RFC 1321 can be found at:
37 -- http://www.ietf.org/rfc/rfc1321.txt
39 -- The implementation is derived from the RSA Data Secutity, Inc. MD5
40 -- Message-Digest Algorithm, as described in RFC 1321.
42 with Ada.Streams;
43 with Interfaces;
45 package GNAT.MD5 is
47 type Context is private;
48 -- This type is the four-word (16 byte) MD buffer, as described in
49 -- RFC 1321 (3.3). It initial value is Initial_Context below.
51 Initial_Context : constant Context;
52 -- Initial value of a Context object. May be used to reinitialize
53 -- a Context value by simple assignment of this value to the object.
55 procedure Update
56 (C : in out Context;
57 Input : String);
58 procedure Wide_Update
59 (C : in out Context;
60 Input : Wide_String);
61 procedure Update
62 (C : in out Context;
63 Input : Ada.Streams.Stream_Element_Array);
64 -- Modify the Context C. If C has the initial value Initial_Context,
65 -- then, after a call to one of these procedures, Digest (C) will return
66 -- the Message-Digest of Input.
68 -- These procedures may be called successively with the same context and
69 -- different inputs. However, several successive calls will not produce
70 -- the same final context as a call with the concatenation of the inputs.
72 subtype Message_Digest is String (1 .. 32);
73 -- The string type returned by function Digest.
75 function Digest (C : Context) return Message_Digest;
76 -- Extracts the Message-Digest from a context. This function should be
77 -- used after one or several calls to Update.
79 function Digest (S : String) return Message_Digest;
80 function Wide_Digest (W : Wide_String) return Message_Digest;
81 function Digest
82 (A : Ada.Streams.Stream_Element_Array)
83 return Message_Digest;
84 -- These functions are equivalent to the corresponding Update (or
85 -- Wide_Update) on a default initialized Context, followed by Digest
86 -- on the resulting Context.
88 private
90 -- Magic numbers
91 Initial_A : constant := 16#67452301#;
92 Initial_B : constant := 16#EFCDAB89#;
93 Initial_C : constant := 16#98BADCFE#;
94 Initial_D : constant := 16#10325476#;
96 type Context is record
97 A : Interfaces.Unsigned_32 := Initial_A;
98 B : Interfaces.Unsigned_32 := Initial_B;
99 C : Interfaces.Unsigned_32 := Initial_C;
100 D : Interfaces.Unsigned_32 := Initial_D;
101 end record;
103 Initial_Context : constant Context :=
104 (A => Initial_A, B => Initial_B, C => Initial_C, D => Initial_D);
106 end GNAT.MD5;