1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- G N A T . S H A 1 --
9 -- Copyright (C) 2002-2006, AdaCore --
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. --
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 was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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
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.
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
;
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.
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
:=
105 type Context
is record
106 H
: H_Type
:= Initial_H
;
107 Buffer
: String (1 .. 64) := (others => ASCII
.NUL
);
109 Length
: Natural := 0;
112 Initial_Context
: constant Context
:=
114 Buffer
=> (others => ASCII
.NUL
), Last
=> 0, Length
=> 0);