User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
resources:rc4 [2019/07/11 22:04]
jgoeders
resources:rc4 [2019/11/01 16:39] (current)
jgoeders
Line 6: Line 6:
 As you may be aware, if we XOR a value with another value twice, we get back the original value (''​A ^ B ^ B == A''​). ​ Thus, if we use the same key to generate the same pseudo-random stream of bytes, and XOR'd them with the cyphertext, we will get back the original plaintext. ​ Using the same key and algorithm for encryption and decryption makes RC4 a **symmetric** encryption algorithm. ​ This means that the provided module can be used to perform either encryption or decryption.  ​ As you may be aware, if we XOR a value with another value twice, we get back the original value (''​A ^ B ^ B == A''​). ​ Thus, if we use the same key to generate the same pseudo-random stream of bytes, and XOR'd them with the cyphertext, we will get back the original plaintext. ​ Using the same key and algorithm for encryption and decryption makes RC4 a **symmetric** encryption algorithm. ​ This means that the provided module can be used to perform either encryption or decryption.  ​
  
-Assuming one is using the provided module to perform RC4 decryption, the cyphertext is provided to the ''​bytes_in''​ input, and the key to the ''​key''​ input. ​ The decryption process begins when the ''​start''​ signal is raised, and when completed, the output ​''​done'' ​signals ​will be high for a single cycle. The resulting plaintext is available from the ''​bytes_out''​ output.+Assuming one is using the provided module to perform RC4 decryption, the cyphertext is provided to the ''​bytes_in''​ input, and the key to the ''​key''​ input. ​ The decryption process begins when the ''​enable''​ signal is raised, and when completed, the ''​done'' ​output ​will be high for a single cycle. The resulting plaintext is available from the ''​bytes_out''​ output, which won't change until you start a new encryption/​decryption process (by lower and raising the enable signal).
  
 ^ Module Name = decrypt_rc4 ^^^^ ^ Module Name = decrypt_rc4 ^^^^
Line 14: Line 14:
 | clk | Input | 1 | 100 MHz Clock | | clk | Input | 1 | 100 MHz Clock |
 | reset | Input | 1 | Active-high reset | | reset | Input | 1 | Active-high reset |
-start | Input | 1 | Active-highstart encryption/decryption |+enable| Input | 1 | Set high to start running the decryption. ​ Once started the decryption will continue until finished. ​ You need to lower this signal and then raise it again to start a new decryption ​process. ​|
 | key | Input | 24 | Encryption key | | key | Input | 24 | Encryption key |
 | done | Output | 1 | Active-high for one cycle when the encryption/​decryption completes| | done | Output | 1 | Active-high for one cycle when the encryption/​decryption completes|
Line 21: Line 21:
  
 Click the link below to download the file. Click the link below to download the file.
-<​file ​SystemVerilog ​decrypt_rc4.sv>​+<​file ​Verilog ​decrypt_rc4.sv>​
 module decrypt_rc4 #( module decrypt_rc4 #(
     parameter BYTES_LEN = 16     parameter BYTES_LEN = 16
Line 27: Line 27:
     input wire logic                                        clk,        // Clock     input wire logic                                        clk,        // Clock
     input wire logic                                        reset, ​     // Active-high reset     input wire logic                                        reset, ​     // Active-high reset
-    input wire logic                                        ​start     // Start encryption/​decryption+    input wire logic                                        ​enable    ​// Start encryption/​decryption
     input wire logic    [23:​0] ​                             key,        // 3 byte key     input wire logic    [23:​0] ​                             key,        // 3 byte key
     input wire logic    [(BYTES_LEN * 8) - 1:0]             ​bytes_in, ​  // byte stream in     input wire logic    [(BYTES_LEN * 8) - 1:0]             ​bytes_in, ​  // byte stream in
Line 101: Line 101:
             case(cs) ​             case(cs) ​
                 S_INIT:                 S_INIT:
-                    if (start)+                    if (enable)
                         cs <= S_LOOP1;                         cs <= S_LOOP1;
                 S_LOOP1:                 S_LOOP1:
Line 129: Line 129:
                 S_update_text_out:​ begin                 S_update_text_out:​ begin
                     if (msg_byte_idx == 0) begin                     if (msg_byte_idx == 0) begin
-                        cs <= S_INIT;+                        cs <= S_DONE;
                         done <= 1'b1;                         done <= 1'b1;
                     end else begin                     end else begin
Line 135: Line 135:
                     end                     end
                 end                 end
 +                S_DONE:
 +                    if (!enable)
 +                        cs <= S_INIT;
             endcase             endcase
         end         end