| 
41561
 | 
     1  | 
with Wordops;
  | 
| 
 | 
     2  | 
use type Wordops.Word;
  | 
| 
 | 
     3  | 
--# inherit Wordops;
  | 
| 
 | 
     4  | 
  | 
| 
 | 
     5  | 
package RMD
  | 
| 
 | 
     6  | 
is
  | 
| 
 | 
     7  | 
  | 
| 
 | 
     8  | 
   -- Types
  | 
| 
 | 
     9  | 
  | 
| 
 | 
    10  | 
   subtype Word is Wordops.Word;
  | 
| 
 | 
    11  | 
  | 
| 
 | 
    12  | 
   type Chain is
  | 
| 
 | 
    13  | 
     record
  | 
| 
 | 
    14  | 
        H0, H1, H2, H3, H4 : Word;
  | 
| 
 | 
    15  | 
     end record;
  | 
| 
 | 
    16  | 
  | 
| 
 | 
    17  | 
   type Block_Index is range 0..15;
  | 
| 
 | 
    18  | 
   type Block is array(Block_Index) of Word;
  | 
| 
 | 
    19  | 
  | 
| 
 | 
    20  | 
   type Message_Index is range 0..2**32;
  | 
| 
 | 
    21  | 
   type Message is array(Message_Index range <>) of Block;
  | 
| 
 | 
    22  | 
  | 
| 
 | 
    23  | 
   -- Isabelle specification
  | 
| 
 | 
    24  | 
  | 
| 
 | 
    25  | 
   --# function rmd_hash(X : Message; L : Message_Index) return Chain;
  | 
| 
 | 
    26  | 
  | 
| 
 | 
    27  | 
   function Hash(X : Message) return Chain;
  | 
| 
 | 
    28  | 
   --# pre X'First = 0;
  | 
| 
 | 
    29  | 
   --# return rmd_hash(X, X'Last + 1);
  | 
| 
 | 
    30  | 
  | 
| 
 | 
    31  | 
private
  | 
| 
 | 
    32  | 
  | 
| 
 | 
    33  | 
   -- Types
  | 
| 
 | 
    34  | 
  | 
| 
 | 
    35  | 
   type Round_Index is range 0..79;
  | 
| 
 | 
    36  | 
  | 
| 
 | 
    37  | 
   type Chain_Pair is
  | 
| 
 | 
    38  | 
      record
  | 
| 
 | 
    39  | 
         Left, Right : Chain;
  | 
| 
 | 
    40  | 
      end record;
  | 
| 
 | 
    41  | 
  | 
| 
 | 
    42  | 
   type Block_Permutation is array(Round_Index) of Block_Index;
  | 
| 
 | 
    43  | 
  | 
| 
 | 
    44  | 
   subtype Rotate_Amount is Wordops.Rotate_Amount;
  | 
| 
 | 
    45  | 
   type Rotate_Definition is array(Round_Index) of Rotate_Amount;
  | 
| 
 | 
    46  | 
  | 
| 
 | 
    47  | 
  | 
| 
 | 
    48  | 
   -- Isabelle proof functions
  | 
| 
 | 
    49  | 
  | 
| 
 | 
    50  | 
   --# function f_spec(J : Round_Index; X,Y,Z : Word) return Word;
  | 
| 
 | 
    51  | 
   --# function K_l_spec(J : Round_Index) return Word;
  | 
| 
 | 
    52  | 
   --# function K_r_spec(J : Round_Index) return Word;
  | 
| 
 | 
    53  | 
   --# function r_l_spec(J : Round_Index) return Block_Index;
  | 
| 
 | 
    54  | 
   --# function r_r_spec(J : Round_Index) return Block_Index;
  | 
| 
 | 
    55  | 
   --# function s_l_spec(J : Round_Index) return Rotate_Amount;
  | 
| 
 | 
    56  | 
   --# function s_r_spec(J : Round_Index) return Rotate_Amount;
  | 
| 
 | 
    57  | 
   --# function steps(CS : Chain_Pair; I : Round_Index; B : Block)
  | 
| 
 | 
    58  | 
   --#    return Chain_Pair;
  | 
| 
 | 
    59  | 
   --# function round_spec(C : Chain; B : Block) return Chain;
  | 
| 
 | 
    60  | 
   --# function rounds(C : Chain; I : Message_Index; X : Message)
  | 
| 
 | 
    61  | 
   --#    return Chain;
  | 
| 
 | 
    62  | 
  | 
| 
 | 
    63  | 
  | 
| 
 | 
    64  | 
   -- Spark Implementation
  | 
| 
 | 
    65  | 
  | 
| 
 | 
    66  | 
   function F(J : Round_Index; X,Y,Z : Word) return Word;
  | 
| 
 | 
    67  | 
   --# return f_spec(J, X, Y, Z);
  | 
| 
 | 
    68  | 
  | 
| 
 | 
    69  | 
   function K_L(J : Round_Index) return Word;
  | 
| 
 | 
    70  | 
   --# return K_l_spec(J);
  | 
| 
 | 
    71  | 
  | 
| 
 | 
    72  | 
   function K_R(J : Round_Index) return Word;
  | 
| 
 | 
    73  | 
   --# return K_r_spec(J);
  | 
| 
 | 
    74  | 
  | 
| 
 | 
    75  | 
   function R_L(J : Round_Index) return Block_Index;
  | 
| 
 | 
    76  | 
   --# return r_l_spec(J);
  | 
| 
 | 
    77  | 
  | 
| 
 | 
    78  | 
   function R_R(J : Round_Index) return Block_Index;
  | 
| 
 | 
    79  | 
   --# return r_r_spec(J);
  | 
| 
 | 
    80  | 
  | 
| 
 | 
    81  | 
   function S_L(J : Round_Index) return Rotate_Amount;
  | 
| 
 | 
    82  | 
   --# return s_l_spec(J);
  | 
| 
 | 
    83  | 
  | 
| 
 | 
    84  | 
   function S_R(J : Round_Index) return Rotate_Amount;
  | 
| 
 | 
    85  | 
   --# return s_r_spec(J);
  | 
| 
 | 
    86  | 
  | 
| 
 | 
    87  | 
   procedure Round(CA, CB, CC, CD, CE : in out Word; X: in Block);
  | 
| 
 | 
    88  | 
   --# derives CA, CB, CC, CD, CE from X, CA, CB, CC, CD, CE;
  | 
| 
 | 
    89  | 
   --# post Chain'(CA, CB, CC, CD, CE) =
  | 
| 
 | 
    90  | 
   --#        round_spec(Chain'(CA~, CB~, CC~, CD~, CE~), X);
  | 
| 
 | 
    91  | 
  | 
| 
 | 
    92  | 
end RMD;
  |