OpenCores
URL https://opencores.org/ocsvn/pairing/pairing/trunk

Subversion Repositories pairing

[/] [pairing/] [trunk/] [rtl/] [f3m.v] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 homer.xing
`include "inc.v"
2
`define MOST 2*`M+1:2*`M
3
 
4 3 homer.xing
// out = (v1 & l1) | (v2 & l2) | (v3 & l3)
5
module f3m_mux3(v1, l1, v2, l2, v3, l3, out);
6
    input [`WIDTH:0] v1, v2, v3;
7
    input l1, l2, l3;
8
    output [`WIDTH:0] out;
9
    genvar i;
10
    generate
11
        for(i=0;i<=`WIDTH;i=i+1)
12
          begin : label
13
            assign out[i] = (v1[i] & l1) | (v2[i] & l2) | (v3[i] & l3);
14
          end
15
    endgenerate
16
endmodule
17
 
18
// out = (v0 & l0) | (v1 & l1) | (v2 & l2) | ... | (v5 & l5)
19
module f3m_mux6(v0, v1, v2, v3, v4, v5, l0, l1, l2, l3, l4, l5, out);
20
    input l0, l1, l2, l3, l4, l5;
21
    input [`WIDTH:0] v0, v1, v2, v3, v4, v5;
22
    output reg [`WIDTH:0] out;
23
    always @ (l0,l1,l2,l3,l4,l5,v0,v1,v2,v3,v4,v5)
24
      case ({l0,l1,l2,l3,l4,l5})
25
        6'b100000: out = v0;
26
        6'b010000: out = v1;
27
        6'b001000: out = v2;
28
        6'b000100: out = v3;
29
        6'b000010: out = v4;
30
        6'b000001: out = v5;
31
        default: out = 0;
32
      endcase
33
endmodule
34
 
35 2 homer.xing
// f3m_add: C = A + B, in field F_{3^M}
36
module f3m_add(A, B, C);
37
    input [`WIDTH : 0] A, B;
38
    output [`WIDTH : 0] C;
39
    genvar i;
40
    generate
41
        for(i=0; i<`M; i=i+1) begin: aa
42
            f3_add aa(A[(2*i+1) : 2*i], B[(2*i+1) : 2*i], C[(2*i+1) : 2*i]);
43
        end
44
    endgenerate
45
endmodule
46
 
47 3 homer.xing
// f3m_add3: c == a0+a1+a2, in field GF(3^M)
48
module f3m_add3(a0, a1, a2, c);
49
    input [`WIDTH:0] a0,a1,a2;
50
    output [`WIDTH:0] c;
51
    wire [`WIDTH:0] v;
52
    f3m_add
53
        ins1 (a0,a1,v), // v == a0+a1
54
        ins2 (v,a2,c);  // c == v+a2 == a0+a1+a2
55
endmodule
56
 
57
// f3m_add4: c == a0+a1+a2+a3, in field GF(3^M)
58
module f3m_add4(a0, a1, a2, a3, c);
59
    input [`WIDTH:0] a0,a1,a2,a3;
60
    output [`WIDTH:0] c;
61
    wire [`WIDTH:0] v1,v2;
62
    f3m_add
63
        ins1 (a0,a1,v1), // v1 == a0+a1
64
        ins2 (a2,a3,v2), // v2 == a2+a3
65
        ins3 (v1,v2,c);  // c == v1+v2 == a0+a1+a2+a3
66
endmodule
67
 
68 2 homer.xing
// f3m_neg: c == -a in GF(3^M)
69
module f3m_neg(a, c);
70
    input [`WIDTH:0] a;
71
    output [`WIDTH:0] c;
72
    genvar i;
73
    generate
74
        for(i=0;i<=`WIDTH;i=i+2)
75
          begin:label
76
            assign c[i+1:i] = {a[i],a[i+1]};
77
          end
78
    endgenerate
79
endmodule
80
 
81
// f3m_sub: C = A - B, in field F_{3^M}
82
module f3m_sub(A, B, C);
83
    input [`WIDTH : 0] A, B;
84
    output [`WIDTH : 0] C;
85
    genvar i;
86
    generate
87
        for(i=0; i<`M; i=i+1) begin: aa
88
            f3_sub aa(A[(2*i+1) : 2*i], B[(2*i+1) : 2*i], C[(2*i+1) : 2*i]);
89
        end
90
    endgenerate
91
endmodule
92
 
93
// f3m_mult: C = A * B, in field GF(3^M)
94
module f3m_mult(clk, reset, A, B, C, done);
95
    input [`WIDTH : 0] A, B;
96
    input clk;
97
    input reset;
98
    output reg [`WIDTH : 0] C;
99
    output reg done;
100
    reg [`WIDTH : 0] x, y, z;
101
    wire [`WIDTH : 0] z1, z2, z4;
102
    wire [`WIDTH+2 : 0] z3;
103 8 homer.xing
    reg [`M : 0] i;
104 2 homer.xing
    wire done1;
105
    wire [1:0] dummy;
106
 
107
    func4
108
        ins1 ({2'b0,x}, y[1:0], {dummy,z1}); // z1 == A * B[0]
109
    f3m_add
110
        ins2 (z1, z, z2); // z2 == z1 + z == A*B[0] + z
111
    assign z4 = {2'd0, y[`WIDTH:2]}; // z4 == y >> 2
112
    func3
113
        ins3 ({2'd0,x}, z3); // z3 == X*x mod p(x)
114 8 homer.xing
    assign done1 = i[0];
115 2 homer.xing
 
116
    always @ (posedge clk)
117
        if (done1)
118
            C <= z;
119
 
120
    always @ (posedge clk)
121
        if (reset)
122
            done <= 0;
123
        else if (done1)
124
            done <= 1;
125
 
126
    always @ (posedge clk)
127
      begin
128
        if (reset)
129
          begin
130 8 homer.xing
            x <= A; y <= B; z <= 0; i <= {1'b1,{`M{1'b0}}};
131 2 homer.xing
          end
132
        else
133
          begin
134 8 homer.xing
            x <= z3[`WIDTH:0]; y <= z4; z <= z2; i <= i >> 1;
135 2 homer.xing
          end
136
      end
137
endmodule
138
 
139 7 homer.xing
// c0 == a0*b0; c1 == a1*b1; c2 == a2*b2; all in GF(3^M)
140
module f3m_mult3(clk, reset,
141
                 a0, b0, c0,
142
                 a1, b1, c1,
143
                 a2, b2, c2,
144
                 done);
145
    input clk, reset;
146
    input [`WIDTH:0] a0, b0, a1, b1, a2, b2;
147
    output reg [`WIDTH:0] c0, c1, c2;
148
    output reg done;
149
    reg [3:0] K;
150
    reg mult_reset, delay1, delay2;
151
    wire e1, e2, e3, mult_done, delay3, rst;
152
    wire [`WIDTH:0] in1, in2, o;
153
 
154
    assign rst = delay2;
155
    assign {e1,e2,e3} = K[3:1];
156
 
157
    f3m_mux3
158
        ins9 (a0, e1, a1, e2, a2, e3, in1),
159
        ins10 (b0, e1, b1, e2, b2, e3, in2);
160
    f3m_mult
161
        ins11 (clk, mult_reset, in1, in2, o, mult_done); // o == in1 * in2 in GF(3^m)
162
    func6
163 8 homer.xing
        ins12 (clk, reset, mult_done, delay3);
164 7 homer.xing
 
165
    always @ (posedge clk)
166
      begin
167
        if (e1) c0 <= o;
168
        if (e2) c1 <= o;
169
        if (e3) c2 <= o;
170
      end
171
 
172
    always @ (posedge clk)
173
        if (reset) K <= 4'b1000;
174 8 homer.xing
        else if (delay3 | K[0]) K <= {1'b0,K[3:1]};
175 7 homer.xing
 
176
    always @ (posedge clk)
177
      begin
178
        if (rst) mult_reset <= 1;
179
        else if (mult_done) mult_reset <= 1;
180
        else mult_reset <= 0;
181
      end
182
 
183
    always @ (posedge clk)
184
        if (reset)     done <= 0;
185
        else if (K[0]) done <= 1;
186
 
187
    always @ (posedge clk)
188
      begin
189
        delay2 <= delay1; delay1 <= reset;
190
      end
191
endmodule
192
 
193 2 homer.xing
/* out == in^3 mod p(x) */
194
/* p(x) == x^97 + x^12 + 2 */
195
module f3m_cubic(input [193:0] in, output [193:0] out);
196
wire [1:0] w0; f3_add a0(in[131:130], in[139:138], w0);
197
wire [1:0] w1; f3_add a1(in[133:132], in[141:140], w1);
198
wire [1:0] w2; f3_add a2(in[135:134], in[143:142], w2);
199
wire [1:0] w3; f3_add a3(in[137:136], in[145:144], w3);
200
wire [1:0] w4; f3_add a4(in[147:146], in[155:154], w4);
201
wire [1:0] w5; f3_add a5(in[149:148], in[157:156], w5);
202
wire [1:0] w6; f3_add a6(in[151:150], in[159:158], w6);
203
wire [1:0] w7; f3_add a7(in[153:152], in[161:160], w7);
204
wire [1:0] w8; f3_add a8(in[163:162], in[171:170], w8);
205
wire [1:0] w9; f3_add a9(in[165:164], in[173:172], w9);
206
wire [1:0] w10; f3_add a10(in[167:166], in[175:174], w10);
207
wire [1:0] w11; f3_add a11(in[169:168], in[177:176], w11);
208
wire [1:0] w12; f3_add a12(in[179:178], in[187:186], w12);
209
wire [1:0] w13; f3_add a13(in[181:180], in[189:188], w13);
210
wire [1:0] w14; f3_add a14(in[183:182], in[191:190], w14);
211
wire [1:0] w15; f3_add a15(in[185:184], in[193:192], w15);
212
wire [1:0] w16;
213
f3_add a16(in[1:0], w12, w16);
214
assign out[1:0] = w16;
215
wire [1:0] w17;
216
f3_add a17({in[122],in[123]}, in[131:130], w17);
217
assign out[3:2] = w17;
218
assign out[5:4] = in[67:66];
219
wire [1:0] w18;
220
f3_add a18(in[3:2], w13, w18);
221
assign out[7:6] = w18;
222
wire [1:0] w19;
223
f3_add a19({in[124],in[125]}, in[133:132], w19);
224
assign out[9:8] = w19;
225
assign out[11:10] = in[69:68];
226
wire [1:0] w20;
227
f3_add a20(in[5:4], w14, w20);
228
assign out[13:12] = w20;
229
wire [1:0] w21;
230
f3_add a21({in[126],in[127]}, in[135:134], w21);
231
assign out[15:14] = w21;
232
assign out[17:16] = in[71:70];
233
wire [1:0] w22;
234
f3_add a22(in[7:6], w15, w22);
235
assign out[19:18] = w22;
236
wire [1:0] w23;
237
f3_add a23({in[128],in[129]}, in[137:136], w23);
238
assign out[21:20] = w23;
239
assign out[23:22] = in[73:72];
240
wire [1:0] w24;
241
f3_add a24(in[9:8], {in[178],in[179]}, w24);
242
assign out[25:24] = w24;
243
wire [1:0] w25;
244
f3_add a25(in[123:122], w0, w25);
245
assign out[27:26] = w25;
246
wire [1:0] w26;
247
f3_add a26({in[66],in[67]}, in[75:74], w26);
248
assign out[29:28] = w26;
249
wire [1:0] w27;
250
f3_add a27(in[11:10], {in[180],in[181]}, w27);
251
assign out[31:30] = w27;
252
wire [1:0] w28;
253
f3_add a28(in[125:124], w1, w28);
254
assign out[33:32] = w28;
255
wire [1:0] w29;
256
f3_add a29({in[68],in[69]}, in[77:76], w29);
257
assign out[35:34] = w29;
258
wire [1:0] w30;
259
f3_add a30(in[13:12], {in[182],in[183]}, w30);
260
assign out[37:36] = w30;
261
wire [1:0] w31;
262
f3_add a31(in[127:126], w2, w31);
263
assign out[39:38] = w31;
264
wire [1:0] w32;
265
f3_add a32({in[70],in[71]}, in[79:78], w32);
266
assign out[41:40] = w32;
267
wire [1:0] w33;
268
f3_add a33(in[15:14], {in[184],in[185]}, w33);
269
assign out[43:42] = w33;
270
wire [1:0] w34;
271
f3_add a34(in[129:128], w3, w34);
272
assign out[45:44] = w34;
273
wire [1:0] w35;
274
f3_add a35({in[72],in[73]}, in[81:80], w35);
275
assign out[47:46] = w35;
276
wire [1:0] w36;
277
f3_add a36(in[17:16], {in[186],in[187]}, w36);
278
assign out[49:48] = w36;
279
wire [1:0] w37;
280
f3_add a37(in[147:146], w0, w37);
281
assign out[51:50] = w37;
282
wire [1:0] w38;
283
f3_add a38({in[74],in[75]}, in[83:82], w38);
284
assign out[53:52] = w38;
285
wire [1:0] w39;
286
f3_add a39(in[19:18], {in[188],in[189]}, w39);
287
assign out[55:54] = w39;
288
wire [1:0] w40;
289
f3_add a40(in[149:148], w1, w40);
290
assign out[57:56] = w40;
291
wire [1:0] w41;
292
f3_add a41({in[76],in[77]}, in[85:84], w41);
293
assign out[59:58] = w41;
294
wire [1:0] w42;
295
f3_add a42(in[21:20], {in[190],in[191]}, w42);
296
assign out[61:60] = w42;
297
wire [1:0] w43;
298
f3_add a43(in[151:150], w2, w43);
299
assign out[63:62] = w43;
300
wire [1:0] w44;
301
f3_add a44({in[78],in[79]}, in[87:86], w44);
302
assign out[65:64] = w44;
303
wire [1:0] w45;
304
f3_add a45(in[23:22], {in[192],in[193]}, w45);
305
assign out[67:66] = w45;
306
wire [1:0] w46;
307
f3_add a46(in[153:152], w3, w46);
308
assign out[69:68] = w46;
309
wire [1:0] w47;
310
f3_add a47({in[80],in[81]}, in[89:88], w47);
311
assign out[71:70] = w47;
312
assign out[73:72] = in[25:24];
313
wire [1:0] w48;
314
f3_add a48(in[139:138], w4, w48);
315
assign out[75:74] = w48;
316
wire [1:0] w49;
317
f3_add a49({in[82],in[83]}, in[91:90], w49);
318
assign out[77:76] = w49;
319
assign out[79:78] = in[27:26];
320
wire [1:0] w50;
321
f3_add a50(in[141:140], w5, w50);
322
assign out[81:80] = w50;
323
wire [1:0] w51;
324
f3_add a51({in[84],in[85]}, in[93:92], w51);
325
assign out[83:82] = w51;
326
assign out[85:84] = in[29:28];
327
wire [1:0] w52;
328
f3_add a52(in[143:142], w6, w52);
329
assign out[87:86] = w52;
330
wire [1:0] w53;
331
f3_add a53({in[86],in[87]}, in[95:94], w53);
332
assign out[89:88] = w53;
333
assign out[91:90] = in[31:30];
334
wire [1:0] w54;
335
f3_add a54(in[145:144], w7, w54);
336
assign out[93:92] = w54;
337
wire [1:0] w55;
338
f3_add a55({in[88],in[89]}, in[97:96], w55);
339
assign out[95:94] = w55;
340
assign out[97:96] = in[33:32];
341
wire [1:0] w56;
342
f3_add a56(in[163:162], w4, w56);
343
assign out[99:98] = w56;
344
wire [1:0] w57;
345
f3_add a57({in[90],in[91]}, in[99:98], w57);
346
assign out[101:100] = w57;
347
assign out[103:102] = in[35:34];
348
wire [1:0] w58;
349
f3_add a58(in[165:164], w5, w58);
350
assign out[105:104] = w58;
351
wire [1:0] w59;
352
f3_add a59({in[92],in[93]}, in[101:100], w59);
353
assign out[107:106] = w59;
354
assign out[109:108] = in[37:36];
355
wire [1:0] w60;
356
f3_add a60(in[167:166], w6, w60);
357
assign out[111:110] = w60;
358
wire [1:0] w61;
359
f3_add a61({in[94],in[95]}, in[103:102], w61);
360
assign out[113:112] = w61;
361
assign out[115:114] = in[39:38];
362
wire [1:0] w62;
363
f3_add a62(in[169:168], w7, w62);
364
assign out[117:116] = w62;
365
wire [1:0] w63;
366
f3_add a63({in[96],in[97]}, in[105:104], w63);
367
assign out[119:118] = w63;
368
assign out[121:120] = in[41:40];
369
wire [1:0] w64;
370
f3_add a64(in[155:154], w8, w64);
371
assign out[123:122] = w64;
372
wire [1:0] w65;
373
f3_add a65({in[98],in[99]}, in[107:106], w65);
374
assign out[125:124] = w65;
375
assign out[127:126] = in[43:42];
376
wire [1:0] w66;
377
f3_add a66(in[157:156], w9, w66);
378
assign out[129:128] = w66;
379
wire [1:0] w67;
380
f3_add a67({in[100],in[101]}, in[109:108], w67);
381
assign out[131:130] = w67;
382
assign out[133:132] = in[45:44];
383
wire [1:0] w68;
384
f3_add a68(in[159:158], w10, w68);
385
assign out[135:134] = w68;
386
wire [1:0] w69;
387
f3_add a69({in[102],in[103]}, in[111:110], w69);
388
assign out[137:136] = w69;
389
assign out[139:138] = in[47:46];
390
wire [1:0] w70;
391
f3_add a70(in[161:160], w11, w70);
392
assign out[141:140] = w70;
393
wire [1:0] w71;
394
f3_add a71({in[104],in[105]}, in[113:112], w71);
395
assign out[143:142] = w71;
396
assign out[145:144] = in[49:48];
397
wire [1:0] w72;
398
f3_add a72(in[179:178], w8, w72);
399
assign out[147:146] = w72;
400
wire [1:0] w73;
401
f3_add a73({in[106],in[107]}, in[115:114], w73);
402
assign out[149:148] = w73;
403
assign out[151:150] = in[51:50];
404
wire [1:0] w74;
405
f3_add a74(in[181:180], w9, w74);
406
assign out[153:152] = w74;
407
wire [1:0] w75;
408
f3_add a75({in[108],in[109]}, in[117:116], w75);
409
assign out[155:154] = w75;
410
assign out[157:156] = in[53:52];
411
wire [1:0] w76;
412
f3_add a76(in[183:182], w10, w76);
413
assign out[159:158] = w76;
414
wire [1:0] w77;
415
f3_add a77({in[110],in[111]}, in[119:118], w77);
416
assign out[161:160] = w77;
417
assign out[163:162] = in[55:54];
418
wire [1:0] w78;
419
f3_add a78(in[185:184], w11, w78);
420
assign out[165:164] = w78;
421
wire [1:0] w79;
422
f3_add a79({in[112],in[113]}, in[121:120], w79);
423
assign out[167:166] = w79;
424
assign out[169:168] = in[57:56];
425
wire [1:0] w80;
426
f3_add a80(in[171:170], w12, w80);
427
assign out[171:170] = w80;
428
wire [1:0] w81;
429
f3_add a81({in[114],in[115]}, in[123:122], w81);
430
assign out[173:172] = w81;
431
assign out[175:174] = in[59:58];
432
wire [1:0] w82;
433
f3_add a82(in[173:172], w13, w82);
434
assign out[177:176] = w82;
435
wire [1:0] w83;
436
f3_add a83({in[116],in[117]}, in[125:124], w83);
437
assign out[179:178] = w83;
438
assign out[181:180] = in[61:60];
439
wire [1:0] w84;
440
f3_add a84(in[175:174], w14, w84);
441
assign out[183:182] = w84;
442
wire [1:0] w85;
443
f3_add a85({in[118],in[119]}, in[127:126], w85);
444
assign out[185:184] = w85;
445
assign out[187:186] = in[63:62];
446
wire [1:0] w86;
447
f3_add a86(in[177:176], w15, w86);
448
assign out[189:188] = w86;
449
wire [1:0] w87;
450
f3_add a87({in[120],in[121]}, in[129:128], w87);
451
assign out[191:190] = w87;
452
assign out[193:192] = in[65:64];
453
endmodule
454
 
455
/* nine square in GF(3^m), out = in^9 mod p(x) */
456
/* p(x) == x^97 + x^12 + 2 */
457
module f3m_nine(clk, in, out);
458
    input clk;
459
    input [`WIDTH:0] in;
460
    output reg [`WIDTH:0] out;
461
    wire [`WIDTH:0] a,b;
462
    f3m_cubic
463
        ins1 (in, a), // a == in^3
464
        ins2 (a, b);  // b == a^3 == in^9
465
    always @ (posedge clk)
466
        out <= b;
467
endmodule
468
 
469
// inversion in GF(3^m). C = A^(-1)
470 7 homer.xing
module f3m_inv(clk, reset, A, C, done);
471 2 homer.xing
        input [`WIDTH:0] A;
472
        input clk;
473
        input reset;
474
        output reg [`WIDTH:0] C;
475 7 homer.xing
    output reg done;
476 2 homer.xing
 
477 8 homer.xing
        reg [`WIDTH+2:0] S, R, U, V, d;
478
        reg [2*`M:0] i;
479 2 homer.xing
        wire [1:0] q;
480
        wire [`WIDTH+2:0] S1, S2,
481
                          R1,
482
                          U1, U2, U3,
483
                          V1, V2,
484 8 homer.xing
                          d1, d2;
485 7 homer.xing
        wire don;
486 2 homer.xing
 
487
        assign d1 = {d[`WIDTH+1:0], 1'b1}; // d1 == d+1
488
        assign d2 = {1'b0, d[`WIDTH+2:1]}; // d2 == d-1
489 8 homer.xing
        assign don = i[0];
490 2 homer.xing
 
491
        f3_mult
492
            q1(S[`MOST], R[`MOST], q); // q = s_m / r_m
493
        func1
494
            ins1(S, R, q, S1), // S1 = S - q*R
495
            ins2(V, U, q, V1); // V1 = V - q*U
496
        func2
497
            ins3(S1, S2), // S2 = x*S1 = x*(S-q*R)
498
            ins4(R, R1); // R1 = x*R
499
        func3
500
            ins5(U, U1), // U1 = x*U mod p
501
            ins6(V1, V2); // V2 = x*V1 mod p = x*(V-qU) mod p
502
    func4
503
        ins7(U, R[`MOST], U2); // U2 = U/r_m
504
    func5
505
        ins8(U, U3); // U3 = (U/x) mod p
506
 
507 8 homer.xing
        always @ (posedge clk)
508
        if (reset)
509
            done <= 0;
510
            else if (don)
511
          begin
512
                done <= 1; C <= U2[`WIDTH:0];
513
          end
514
 
515 2 homer.xing
    always @ (posedge clk)
516
        if (reset)
517 8 homer.xing
            i <= {1'b1, {(2*`M){1'b0}}};
518 2 homer.xing
        else
519 8 homer.xing
            i <= i >> 1;
520 2 homer.xing
 
521
    always @ (posedge clk)
522
        if (reset)
523
          begin
524
            S<=`PX; R<=A; U<=1; V<=0; d<=0;
525
          end
526
        else if (R[`MOST] == 2'b0)
527
          begin
528
            R<=R1; U<=U1; d<=d1;
529
          end
530
        else if (d[0] == 1'b0) // d == 0
531
          begin
532
            R<=S2; S<=R; U<=V2; V<=U; d<=d1;
533
          end
534
        else // d != 0
535
          begin
536
            S<=S2; V<=V1; U<=U3; d<=d2;
537
          end
538
endmodule
539
 
540 3 homer.xing
// put func1~5 here for breaking circular dependency in "f3m", "fun"
541
 
542
// out = S - q*R
543
module func1(S, R, q, out);
544
    input [`WIDTH+2:0] S, R;
545
    input [1:0] q;
546
    output [`WIDTH+2:0] out;
547
    wire [`WIDTH+2:0] t;
548
    func4 f(R, q, t); // t == q*R
549
    genvar i;
550
    generate for(i=0; i<=`WIDTH+2; i=i+2) begin: label
551
        f3_sub s1(S[i+1:i], t[i+1:i], out[i+1:i]); // out == S - t
552
    end endgenerate
553
endmodule
554
 
555
// out = x*A
556
module func2(A, out);
557
    input [`WIDTH+2:0] A;
558
    output [`WIDTH+2:0] out;
559
    assign out = {A[`WIDTH:0], 2'd0};
560
endmodule
561
 
562
// C = (x*B mod p(x))
563
module func3(B, C);
564
    input [`WIDTH+2:0] B;
565
    output [`WIDTH+2:0] C;
566
    wire [`WIDTH+2:0] A;
567
    assign A = {B[`WIDTH:0], 2'd0}; // A == B*x
568
    wire [1:0] w0;
569
    f3_mult m0 (A[195:194], 2'd2, w0);
570
    f3_sub s0 (A[1:0], w0, C[1:0]);
571
    assign C[23:2] = A[23:2];
572
    wire [1:0] w12;
573
    f3_mult m12 (A[195:194], 2'd1, w12);
574
    f3_sub s12 (A[25:24], w12, C[25:24]);
575
    assign C[193:26] = A[193:26];
576
    assign C[195:194] = 0;
577
endmodule
578
 
579
// C = a * A; A,C \in GF(3^m); a \in GF(3)
580
module func4(A, aa, C);
581
    input [`WIDTH+2:0] A;
582
    input [1:0] aa;
583
    output [`WIDTH+2:0] C;
584
    genvar i;
585
    generate
586
      for(i=0; i<=`WIDTH+2; i=i+2)
587
      begin: label
588
        f3_mult m(A[i+1:i], aa, C[i+1:i]);
589
      end
590
    endgenerate
591
endmodule
592
 
593
// C = (A/x) mod p, \in GF(3^m)
594
module func5(A, C);
595
    input [`WIDTH+2:0] A;
596
    output [`WIDTH+2:0] C;
597
    assign C[195:194] = 0;
598
    assign C[193:192] = A[1:0];
599
    assign C[191:24] = A[193:26];
600
    f3_add a11 (A[25:24], A[1:0], C[23:22]);
601
    assign C[21:0] = A[23:2];
602
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.