Daily bump.
[official-gcc.git] / gcc / ada / g-sha1.ads
blob36e2e25d853683b2002ac6c37bcd30aca3584684
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- G N A T . S H A 1 --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2002-2006, AdaCore --
10 -- --
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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
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. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 -- This package implements the US Secure Hash Algorithm 1 (SHA1) as described
35 -- in RFC 3174. The complete text of RFC 3174 can be found at:
37 -- http://www.ietf.org/rfc/rfc3174.txt
39 -- Note: the code for this unit is derived from GNAT.MD5
41 with Ada.Streams;
42 with Interfaces;
44 package GNAT.SHA1 is
46 type Context is private;
47 -- This type holds the five-word (20 byte) buffer H, as described in
48 -- RFC 3174 (6.1). Its 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.
54 procedure Update
55 (C : in out Context;
56 Input : String);
57 procedure Wide_Update
58 (C : in out Context;
59 Input : Wide_String);
60 procedure Update
61 (C : in out Context;
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, and these several successive calls will produce
69 -- the same final context as a call with the concatenation of the inputs.
71 subtype Message_Digest is String (1 .. 40);
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;
80 function Digest
81 (A : Ada.Streams.Stream_Element_Array) return Message_Digest;
82 -- These functions are equivalent to the corresponding Update (or
83 -- Wide_Update) on a default initialized Context, followed by Digest
84 -- on the resulting Context.
86 private
88 -- Magic numbers
90 Initial_H0 : constant := 16#67452301#;
91 Initial_H1 : constant := 16#EFCDAB89#;
92 Initial_H2 : constant := 16#98BADCFE#;
93 Initial_H3 : constant := 16#10325476#;
94 Initial_H4 : constant := 16#C3D2E1F0#;
96 type H_Type is array (0 .. 4) of Interfaces.Unsigned_32;
98 Initial_H : constant H_Type :=
99 (0 => Initial_H0,
100 1 => Initial_H1,
101 2 => Initial_H2,
102 3 => Initial_H3,
103 4 => Initial_H4);
105 type Context is record
106 H : H_Type := Initial_H;
107 Buffer : String (1 .. 64) := (others => ASCII.NUL);
108 Last : Natural := 0;
109 Length : Natural := 0;
110 end record;
112 Initial_Context : constant Context :=
113 (H => Initial_H,
114 Buffer => (others => ASCII.NUL), Last => 0, Length => 0);
116 end GNAT.SHA1;