OSDN Git Service

293d06f71c437438578b906dc70aad0899690512
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-shsh32.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --         S Y S T E M . S E C U R E _ H A S H E S . S H A 2 _ 3 2          --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --           Copyright (C) 2009, Free Software Foundation, Inc.             --
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 3,  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.                                     --
17 --                                                                          --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception,   --
20 -- version 3.1, as published by the Free Software Foundation.               --
21 --                                                                          --
22 -- You should have received a copy of the GNU General Public License and    --
23 -- a copy of the GCC Runtime Library Exception along with this program;     --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25 -- <http://www.gnu.org/licenses/>.                                          --
26 --                                                                          --
27 -- GNAT was originally developed  by the GNAT team at  New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
29 --                                                                          --
30 ------------------------------------------------------------------------------
31
32 --  This pacakge provides support for the 32-bit FIPS PUB 180-3 functions
33 --  SHA-256 and SHA-224.
34
35 with Interfaces;
36 with GNAT.Byte_Swapping;
37 with System.Secure_Hashes.SHA2_Common;
38
39 package System.Secure_Hashes.SHA2_32 is
40
41    subtype Word is Interfaces.Unsigned_32;
42
43    package Hash_State is new Hash_Function_State
44      (Word           => Word,
45       Swap           => GNAT.Byte_Swapping.Swap4,
46       Hash_Bit_Order => System.High_Order_First);
47    --  SHA-224 and SHA-256 operate on 32-bit big endian words
48
49    K : constant Hash_State.State (0 .. 63) :=
50          (16#428a2f98#, 16#71374491#, 16#b5c0fbcf#, 16#e9b5dba5#,
51           16#3956c25b#, 16#59f111f1#, 16#923f82a4#, 16#ab1c5ed5#,
52           16#d807aa98#, 16#12835b01#, 16#243185be#, 16#550c7dc3#,
53           16#72be5d74#, 16#80deb1fe#, 16#9bdc06a7#, 16#c19bf174#,
54           16#e49b69c1#, 16#efbe4786#, 16#0fc19dc6#, 16#240ca1cc#,
55           16#2de92c6f#, 16#4a7484aa#, 16#5cb0a9dc#, 16#76f988da#,
56           16#983e5152#, 16#a831c66d#, 16#b00327c8#, 16#bf597fc7#,
57           16#c6e00bf3#, 16#d5a79147#, 16#06ca6351#, 16#14292967#,
58           16#27b70a85#, 16#2e1b2138#, 16#4d2c6dfc#, 16#53380d13#,
59           16#650a7354#, 16#766a0abb#, 16#81c2c92e#, 16#92722c85#,
60           16#a2bfe8a1#, 16#a81a664b#, 16#c24b8b70#, 16#c76c51a3#,
61           16#d192e819#, 16#d6990624#, 16#f40e3585#, 16#106aa070#,
62           16#19a4c116#, 16#1e376c08#, 16#2748774c#, 16#34b0bcb5#,
63           16#391c0cb3#, 16#4ed8aa4a#, 16#5b9cca4f#, 16#682e6ff3#,
64           16#748f82ee#, 16#78a5636f#, 16#84c87814#, 16#8cc70208#,
65           16#90befffa#, 16#a4506ceb#, 16#bef9a3f7#, 16#c67178f2#);
66    --  Constants from FIPS PUB 180-3
67
68    function Sigma0 (X : Word) return Word;
69    function Sigma1 (X : Word) return Word;
70    function S0 (X : Word) return Word;
71    function S1 (X : Word) return Word;
72    pragma Inline (Sigma0, Sigma1, S0, S1);
73    --  Elementary functions Sigma^256_0, Sigma^256_1, sigma^256_0, sigma^256_1
74    --  from FIPS PUB 180-3.
75
76    procedure Transform is new SHA2_Common.Transform
77      (Hash_State => Hash_State,
78       K          => K,
79       Rounds     => 64,
80       Sigma0     => Sigma0,
81       Sigma1     => Sigma1,
82       S0         => S0,
83       S1         => S1);
84
85    SHA224_Init_State : constant Hash_State.State (0 .. 7) :=
86                          (0 => 16#c1059ed8#,
87                           1 => 16#367cd507#,
88                           2 => 16#3070dd17#,
89                           3 => 16#f70e5939#,
90                           4 => 16#ffc00b31#,
91                           5 => 16#68581511#,
92                           6 => 16#64f98fa7#,
93                           7 => 16#befa4fa4#);
94    SHA256_Init_State : constant Hash_State.State (0 .. 7) :=
95                          (0 => 16#6a09e667#,
96                           1 => 16#bb67ae85#,
97                           2 => 16#3c6ef372#,
98                           3 => 16#a54ff53a#,
99                           4 => 16#510e527f#,
100                           5 => 16#9b05688c#,
101                           6 => 16#1f83d9ab#,
102                           7 => 16#5be0cd19#);
103    --  Initialization vectors from FIPS PUB 180-3
104
105 end System.Secure_Hashes.SHA2_32;