0
\$\begingroup\$

I am trying to code the RC6 (Rivest cipher 6) algorithm using Verilog. The algorithm requires addition, subtraction and multiplication in modulo 232. I've been told that I can use conventional +, -, * and / operators in Verilog if I define <stdint.h> in the header and use variables of type uint32_t.

I've pasted my attempt below in defining the header and the variable types, but I keep getting syntax errors. Could someone help me understand if this is the correct way to do modulo 232 arithmetic in Verilog and what is the required syntax?

#include <stdint.h>;
module RC6_encryption( in, clk, out );
input [0:127] in ;
input clk;
output reg [0:127] out;
uint32_t wire [0:31] A;
uint32_t wire [0:31] B;
uint32_t wire [0:31] C;
uint32_t wire [0:31] D;
//<statements>
assign A = in[0:31] ;
assign B = in[32:63] ;
assign C = in[64:95] ;
assign D = in[96:127] ;
endmodule
asked Sep 20, 2021 at 23:47
\$\endgroup\$
3
  • 1
    \$\begingroup\$ #include is illegal syntax for Verilog. If stdint.h is C code, that will also be illegal syntax. \$\endgroup\$ Commented Sep 20, 2021 at 23:49
  • \$\begingroup\$ @toolic Yes you're right, this is C code but I'm not sure what the Verilog equivalent is \$\endgroup\$ Commented Sep 20, 2021 at 23:57
  • 1
    \$\begingroup\$ You can do some experiments yourself, but I'm pretty sure that given 32-bit variables Verilog will do mod-2^32 arithmetic by default. \$\endgroup\$ Commented Sep 21, 2021 at 0:50

1 Answer 1

0
\$\begingroup\$

Your assign A = in[0:31]; works in fact as a modulo function.

Since the higher bits ( in[32:127] ) are truncated all you get is a reminder of the operation

in / 2^32

as you wanted.

answered Sep 21, 2021 at 1:48
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.