SyoSil ApS UVM Scoreboard  1.0.3.0
cl_syoscb_md5_packer.svh
1 /// An implementation of a uvm_packer which returns bitstreams that are ready for md5 packing.
2 /// Generates bitstreams which follow the format below, as specified in RFC 1321
3 /// <table>
4 /// <tr>
5 /// <th>Bits</th>
6 /// <th>Information</th>
7 /// </tr>
8 /// <tr>
9 /// <td> 0 - length of the serialized item-1</td>
10 /// <td> Serialized item</td>
11 /// </tr>
12 /// <tr>
13 /// <td> length of the serialized item - lentgh of the serialized item+6</td>
14 /// <td> Zeros</td>
15 /// </tr>
16 /// <tr>
17 /// <td>length of the serialized item+7</td>
18 /// <td> One </td>
19 /// </tr>
20 /// <tr>
21 /// <td>length of the serialized item+8 - (512*x-64)</td>
22 /// <td> Zeros</td>
23 /// </tr>
24 /// <tr>
25 /// <td> last 64 bits</td>
26 /// <td> length of the item modulo 2^64</td>
27 /// </tr>
28 /// </table>
29 ///
30 /// <b>NOTICE</b>: The current implementation of the md5_packer only manipulates the
31 /// bitstream returned when #get_bits or #get_packed_bits is called, and does not modify
32 /// the underlying bitstream.
33 /// After calling \c get_packed_bits or \c get_bits, call #clean to clean
34 /// the underlying bitstream, allowing the packer to be reused
36  //-------------------------------------
37  // Non randomizable variables
38  //-------------------------------------
39 
40 
41  //-------------------------------------
42  // UVM Macros
43  //-------------------------------------
44 
45  //-------------------------------------
46  // Constructor
47  //-------------------------------------
48  function new();
49  super.new();
50  `ifndef UVM_VERSION
51  this.big_endian = 0; //Must use this value to correctly pack strings
52  `endif
53  endfunction: new
54 
55  //-------------------------------------
56  // Functions
57  //-------------------------------------
58  `ifdef UVM_VERSION //UVM-IEEE implementation
59  extern virtual function void get_packed_bits(ref bit unsigned stream[]);
60  `else
61  extern virtual function void get_bits(ref bit unsigned bits[]);
62  `endif
63 
64 endclass: cl_syoscb_md5_packer
65 
66 `ifdef UVM_VERSION //UVM-IEEE implementation
67 /// Gets the packer's bitstream, modifying the contents such that it conforms to RFC 1321
68 function void cl_syoscb_md5_packer::get_packed_bits(ref bit unsigned stream[]);
69  //See implementation of get_bits of non-IEEE implementations for a more thoroughly commented implementation
70 
71  //uvm-IEEE packers use the first 64 bits to store metadata - we don't want to include that
72  //Also point to first available character, meaning that we have another 8 bits of junk to discard
73  //m_pack_iter points to
74  int data_size = m_pack_iter - 64 - 8;
75  int stream_size = data_size + 512 - (data_size % 512);
76  bit [63:0] length = data_size;
77 
78  if(512 - (data_size % 512) < 72) begin
79  stream_size += 512;
80  end
81 
82  //get_packed_bits also copies the iterator values
83  //instead, we just copy the bits 64 and upward
84  stream = new[stream_size];
85  for(int i=0; i<data_size; i++) begin
86  stream[i] = m_bits[i+64];
87  end
88 
89  stream[data_size+7] = 1'b1;
90 
91  for(int i=0; i<64; i++) begin
92  stream[stream_size-64+i] = length[i];
93  end
94 endfunction: get_packed_bits
95 
96 `else
97 
98 /// Gets the packer's bitstream, modifying the contents such that it conforms to RFC 1321
99 function void cl_syoscb_md5_packer::get_bits(ref bit unsigned bits[]);
100  int size, m_packed_size_old;
101  bit [63:0] length;
102  this.set_packed_size(); //Must call before manipulating bitstream
103 
104  //Size of bits-array should be next multiple of 512 which is larger than m_packed_size
105  size = m_packed_size + 512 - (m_packed_size % 512);
106  m_packed_size_old = m_packed_size;
107  length = m_packed_size_old;
108 
109  //If difference between new size and m_packed_size is less than 72, we require another 512 bits due to MD5 spec
110  if(512 - (m_packed_size % 512) < 72) begin //Less than 72, so we need the next multiple of 512
111  size += 512;
112  end
113 
114  this.m_packed_size = size;
115 
116  super.get_bits(bits); //Get bits from super implementation, uses new value of m_packed_size to allocate bits-array
117 
118  //Bits 0:6 after item should be 0's, but that is default behaviour
119  //Bits 7 after item should be 1
120  bits[m_packed_size_old+7] = 1'b1;
121 
122  //All bits between that 1'b1 and m_packed_size-64 need to be 0's
123  //Bits default to zero, so nothing is set
124 
125  //Final length of item: The UVM implementation of get_bits uses an int
126  //to traverse the bits-array. Therefore, size of bits-array is expressed with at most
127  //32 bits => we can simply set the size of item without taking the modulo with 2^64
128  for(int i=0; i<64; i++) begin
129  bits[size-64+i] = length[i];
130  end
131 
132  this.m_packed_size = m_packed_size_old;
133 endfunction: get_bits
134 
135 `endif
A base class for packers which should be used with hash algorithms in the scoreboard.
An implementation of a uvm_packer which returns bitstreams that are ready for md5 packing...
virtual void get_bits(ref bit unsigned bits[])
Gets the packer&#39;s bitstream, modifying the contents such that it conforms to RFC 1321.

Project: SyoSil ApS UVM Scoreboard, Revision: 1.0.3.0

Copyright 2014-2022 SyoSil ApS
All Rights Reserved Worldwide

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
doxygen
Doxygen Version: 1.8.14
Generated with IDV SV Filter Version: 2.6.3
Fri Sep 2 2022 14:39:25
Find a documentation bug? Report bugs to: scoreboard@syosil.com