1 |
6 |
kfleming |
//----------------------------------------------------------------------//
|
2 |
|
|
// The MIT License
|
3 |
|
|
//
|
4 |
|
|
// Copyright (c) 2008 Kermin Fleming, kfleming@mit.edu
|
5 |
|
|
//
|
6 |
|
|
// Permission is hereby granted, free of charge, to any person
|
7 |
|
|
// obtaining a copy of this software and associated documentation
|
8 |
|
|
// files (the "Software"), to deal in the Software without
|
9 |
|
|
// restriction, including without limitation the rights to use,
|
10 |
|
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
|
|
// copies of the Software, and to permit persons to whom the
|
12 |
|
|
// Software is furnished to do so, subject to the following conditions:
|
13 |
|
|
//
|
14 |
|
|
// The above copyright notice and this permission notice shall be
|
15 |
|
|
// included in all copies or substantial portions of the Software.
|
16 |
|
|
//
|
17 |
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18 |
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
19 |
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20 |
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
21 |
|
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
22 |
|
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23 |
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
24 |
|
|
// OTHER DEALINGS IN THE SOFTWARE.
|
25 |
|
|
//----------------------------------------------------------------------//
|
26 |
2 |
kfleming |
import MD6Parameters::*;
|
27 |
|
|
import MD6Types::*;
|
28 |
|
|
import CompressionFunctionTypes::*;
|
29 |
|
|
|
30 |
|
|
// The following are magic, externally defined parameters in MD6
|
31 |
|
|
// Other important parameters are derived from them.
|
32 |
|
|
// These parameters are used solely within the compression
|
33 |
|
|
// function.
|
34 |
|
|
|
35 |
|
|
function MD6Word s0();
|
36 |
|
|
return truncateLSB(64'h0123456789abcdef);
|
37 |
|
|
endfunction
|
38 |
|
|
|
39 |
|
|
function MD6Word sStar();
|
40 |
|
|
return truncateLSB(64'h7311c2812425cfa0);
|
41 |
|
|
endfunction
|
42 |
|
|
|
43 |
|
|
// These tables are all of size 16. MD6 does not have a definition for
|
44 |
|
|
// Non-size 16 value of MD6_c
|
45 |
|
|
ShiftFactor c64ShiftR[16] = {4,11,10,32,13,3,10,23,22,6,5,12,15,1,18,28};
|
46 |
|
|
|
47 |
|
|
ShiftFactor c64ShiftL[16] = {5,6,19,4,8,9,24,15,7,3,20,29,13,3,15,14};
|
48 |
|
|
|
49 |
|
|
ShiftFactor c32ShiftR[16] = {7,13,1,8,15,3,16,13,2,3,13,9,7,10,2,4};
|
50 |
|
|
|
51 |
|
|
ShiftFactor c32ShiftL[16] = {15,12,3,16,10,7,5,9,4,9,16,12,11,5,1,13};
|
52 |
|
|
|
53 |
|
|
ShiftFactor c16ShiftR[16] = {7,4,1,7,2,1,5,7,2,1,7,1,2,7,7,8};
|
54 |
|
|
|
55 |
|
|
ShiftFactor c16ShiftL[16] = {3,5,2,2,4,5,3,4,6,5,4,2,3,2,6,5};
|
56 |
|
|
|
57 |
|
|
ShiftFactor c8ShiftR[16] = {1,1,2,1,2,3,2,3,1,3,2,2,1,1,4,2};
|
58 |
|
|
|
59 |
|
|
ShiftFactor c8ShiftL[16] = {3,2,4,3,3,4,1,1,2,4,4,3,4,2,3,3};
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
// This is the sqrt(6) vector value. It should probably be longer than this
|
66 |
|
|
Bit#(TMul#(16,64)) vectorQ = {
|
67 |
|
|
64'h8b30ed2e9956c6a0,
|
68 |
|
|
64'h0d6f3522631effcb,
|
69 |
|
|
64'h3b72066c7a1552ac,
|
70 |
|
|
64'hc878c1dd04c4b633,
|
71 |
|
|
64'h995ad1178bd25c31,
|
72 |
|
|
64'h8af8671d3fb50c2c,
|
73 |
|
|
64'h3e7f16bb88222e0d,
|
74 |
|
|
64'h4ad12aae0a6d6031,
|
75 |
|
|
64'h54e5ed5b88e3775d,
|
76 |
|
|
64'h1f8ccf6823058f8a,
|
77 |
|
|
64'h0cd0d63b2c30bc41,
|
78 |
|
|
64'hdd2e76cba691e5bf,
|
79 |
|
|
64'he8fb23908d9f06f1,
|
80 |
|
|
64'hb60450e9ef68b7c1,
|
81 |
|
|
64'h6432286434aac8e7,
|
82 |
|
|
64'h7311c2812425cfa0};
|
83 |
|
|
|
84 |
|
|
//This might well be enormous.
|
85 |
|
|
function MD6Word getQWord(Bit#(TLog#(MD6_q)) index);
|
86 |
|
|
Bit#(TLog#(TMul#(MD6_q,MD6_WordWidth))) baseIndex = fromInteger(valueof(MD6_WordWidth))*zeroExtend(index);
|
87 |
|
|
return vectorQ[(baseIndex+fromInteger(valueof(MD6_WordWidth)-1)):baseIndex];
|
88 |
|
|
endfunction
|
89 |
|
|
|
90 |
|
|
function MD6Word extractWord(Bit#(n) bitVector, Bit#(m) index)
|
91 |
|
|
provisos(
|
92 |
|
|
Add#(a,m,TAdd#(m,TLog#(MD6_WordWidth))));
|
93 |
|
|
Bit#(TAdd#(m,TLog#(MD6_WordWidth))) baseIndex = fromInteger(valueof(MD6_WordWidth))*zeroExtend(index);
|
94 |
|
|
return bitVector[(baseIndex+fromInteger(valueof(MD6_WordWidth)-1)):baseIndex];
|
95 |
|
|
endfunction
|
96 |
|
|
|