-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector_mult.vhd
107 lines (89 loc) · 2.64 KB
/
vector_mult.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
-- entity name: vector_mult
-- Stephen Carter - 260500858
-- Copyright (C) 2016 Stephen Carter
-- Version 1.0
-- Author: Stephen Carter; [email protected]
-- Date: Jan. 10, 2016
-- This circuit performs vector multiplication of a 1x3 vector and a 3x1 vector(key_loader column)
-- This circuit is a structural submodule for the matrix_mult_struct entity
library lpm;
use lpm.lpm_components.all; -- used to preform calculations
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all; -- Treat vectors as unsigned
entity vector_mult is
port( p1 : in std_logic_vector(3 downto 0); -- inputs of 1x3 vector (plaintext)
p2 : in std_logic_vector(3 downto 0);
p3 : in std_logic_vector(3 downto 0);
k1x : in std_logic_vector(3 downto 0); -- inputs of keyloader column (encryption key)
k2x : in std_logic_vector(3 downto 0);
k3x : in std_logic_vector(3 downto 0);
clk : in std_logic; -- clock for synch
cx : out std_logic_vector(3 downto 0) -- output (ciphertext)
);
end vector_mult;
architecture structural of vector_mult is
Signal add_temp : std_logic_vector(3 downto 0); -- temporary add signal used for intermediate add
Signal mult1,mult2,mult3 : std_logic_vector(7 downto 0); -- temporary mult signals used for intermediate mults
begin
lpm_mult_component1 : lpm_mult -- peforms the first mult (p1*k1x) stored in mult1
GENERIC MAP (
lpm_widtha => 4,
lpm_widthb => 4,
lpm_type => "LPM_MULT",
lpm_widthp => 8
)
PORT MAP (
dataa => p1,
datab => k1x,
result => mult1
);
lpm_mult_component2 : lpm_mult -- peforms the mult (p2*k2x) stored in mult2
GENERIC MAP (
lpm_widtha => 4,
lpm_widthb => 4,
lpm_type => "LPM_MULT",
lpm_widthp => 8
)
PORT MAP (
dataa => p2,
datab => k2x,
result => mult2
);
lpm_mult_component3 : lpm_mult -- peforms the mult (p3*k3x) stored in mult3
GENERIC MAP (
lpm_widtha => 4,
lpm_widthb => 4,
lpm_type => "LPM_MULT",
lpm_widthp => 8
)
PORT MAP (
dataa => p3,
datab => k3x,
result => mult3
);
lpm_add_compontent1 : lpm_add_sub -- peforms the add (p1*k1x + p2*k2x) stored in add_temp
GENERIC MAP (
lpm_width => 4,
lpm_direction => "ADD",
lpm_representation => "UNSIGNED",
lpm_type => "LPM_ADD_SUB"
)
PORT MAP (
dataa => mult1(3 downto 0),
datab => mult2(3 downto 0),
result => add_temp
);
lpm_add_compontent2 : lpm_add_sub -- performs the add ((p1*k1x + p2*k2x) + p3*k3x) stored in output
GENERIC MAP (
lpm_width => 4,
lpm_direction => "ADD",
lpm_representation => "UNSIGNED",
lpm_type => "LPM_ADD_SUB"
)
PORT MAP (
dataa => add_temp,
datab => mult3(3 downto 0),
result => cx
);
end structural;