Summary of the invention
The technical problem to be solved in the present invention just provides the middle-and-high-ranking encryption standard encryption device of a kind of Gbit passive optical network system and its implementation, overcome and encrypted bandwidth deficiency and the too much shortcoming of logical resource consumption in the prior art, solve the demand of can't adapting to that exists in the prior art, satisfy the requirement of fixed-encryption time delay in the GPON system simultaneously as higher encryption bandwidth and system frequency in the High Speed Systems such as GPON.
In order to solve the problems of the technologies described above, the invention provides the middle-and-high-ranking encryption standard encryption device of a kind of Gbit passive optical network system, comprising:
Write data buffer zone module W-FIFOs is used for the clear data that buffer memory need be encrypted;
The enciphered message cache module is used for the frame length that buffer memory needs each frame of encrypting plaintext, initial counter value and initial key;
Advanced Encryption Standard AES processing module is used to finish data encryption;
Read data buffer module R-FIFOs is used for the encrypt data after encrypting is carried out buffer memory;
Encrypt scheduler module, be used for extracting frame length, initial key, the initial counter value of enciphered message cache module, read clear data from the write data buffer zone module, generate the Counter Value of encrypting needs according to initial counter value, the frame length of the clear data of Jia Miing produces and encrypts enable signal as required, key, Counter Value and clear data are sent into the AES processing module encrypt, and the data encrypted of AES processing module output is sent into the read data buffer module.
Further, the write data buffer zone module comprises:
Write fifo circuit at least two, be used to store the clear data that writes;
The write pointer counter is used for indication in turn and writes fifo circuit;
The shift enable control circuit is used for the value according to the write pointer counter, writes fifo circuit by the displacement turn enable, is enabled state when writing fifo circuit, then clear data can be write this and write in the fifo circuit.
Further, the fifo circuit of writing of write data buffer zone module is 4, and each bit wide is 32.
Further, described enciphered message cache module buffer memory two frame informations use the two-stage d type flip flop to realize that wherein, every frame information comprises the frame length of each frame, initial counter value and initial key.
Further, described encryption scheduler module comprises:
Cipher key frame long letter breath memory module is used to store the frame length that reads out from the enciphered message cache module and the key of current encrypted frame;
Scheduler module is used for receiving, transmitting control signal, and reads the frame length of cipher key frame long letter breath memory module buffer memory and the key of current encrypted frame, send to the AES processing module, and the control counter generation module generates Counter Value;
The counter generation module is used for reading initial counter value from the enciphered message cache module, generates Counter Value, sends to the AES processing module.
Further, at least 2 of described AES processing modules, each AES processing module includes:
The first XOR module is used for the key sum counter value of input is carried out XOR;
First d type flip flop is used to latch the output result of the first XOR module;
First selector, the output that is used for selecting first d type flip flop when the 1st takes turns cryptographic calculation are as input value, and in 9 computings of taking turns, the output of selecting 3d flip-flop is as input value in the back;
Second d type flip flop is used to latch the output result of first selector;
Byte conversion and row shift module are used for the data that receive are carried out byte conversion and row shifting function;
Row hybrid operation module is used for the data that receive are carried out the row hybrid operation;
Second selector is used for taking turns outputs that computing selects row hybrid operation module as input value preceding 9, in the end 1 take turns in the computing, with the output of byte conversion and row shift module as input value;
Cipher key expansion module is used for obtaining current key by getting wheel constant table respective column and last key XOR;
The second XOR module is used for XOR is carried out in the output of second selector and the output of cipher key expansion module;
3d flip-flop is used to latch the output result of the second XOR module;
The 3rd XOR module is used for carrying out XOR to encrypting back Counter Value and clear data;
Four d flip-flop is used to latch the output result of the 3rd XOR module.
Further, getting the wheel constant table in the described cipher key expansion module uses initial value to be respectively two shift registers of hexadecimal number 001 and hexadecimal number 06c, by using these two shift registers of wheel counter gating, ring shift left under the control of wheel counter produces wheel constant table respective column.
Further, described read data buffer module comprises:
Read fifo circuit at least two, be used to store the encrypt data that writes after the encryption;
The read pointer counter is used for indication in turn and reads fifo circuit;
The shift enable control circuit is used for the value according to the read pointer counter, reads fifo circuit by the displacement turn enable, is enabled state when reading fifo circuit, then encrypt data can be read; When data were read sky, the first in first out spacing wave was read in the output of read data buffer module, suspends sense data.
Further, the fifo circuit of reading of described read data buffer module is 4, and each bit wide is 32.
In order to solve the problems of the technologies described above, the present invention also provides the implementation method of the middle-and-high-ranking encryption standard encryption device of a kind of Gbit passive optical network system, comprises the steps:
(1) the write data buffer zone module receives and buffer memory clear data to be encrypted, and enciphered message cache module buffer memory needs the frame length of each frame of encrypting plaintext, initial counter value and initial key;
(2) the encryption scheduler module is extracted frame length, initial key, the initial counter value in the enciphered message cache module, read clear data from the write data buffer zone module, generate the Counter Value of encrypting needs according to initial counter value, according to frame length, key, Counter Value and clear data are sent into the AES processing module encrypt;
(3) ciphertext after the encryption scheduler module will be encrypted is sent into the read data buffer module and is carried out buffer memory.
Further, the write data buffer zone module receives and buffer memory clear data to be encrypted in the described step (1), comprising:
Receive when the write data buffer zone module and to write enable signal, then write fifo circuit in the turn enable write data buffer zone module, in turn clear data to be encrypted is write fifo circuit.
Further, described step (2) comprises the steps:
(a) encrypt scheduler module and extract frame length, initial key, initial counter value from the enciphered message cache module;
(b) encrypt scheduler module and calculate the piece number that needs are encrypted, produce the corresponding enable signal of encrypting according to frame length;
(c) encrypt scheduler module initial key, initial counter value are sent into the AES processing module, the AES processing module is encrypted key sum counter value;
(d) encrypt scheduler module clear data is sent into the AES processing module, carry out XOR, the ciphertext after obtaining encrypting with Counter Value after encrypting.
Further, encrypt scheduler module key, Counter Value are divided into a plurality of 128 pieces, form the key sum counter value of many groups 128 * 2.
Further, described Counter Value comprises frame inside counting device value, interframe Counter Value, encrypt after scheduler module is merged into 46 bit widths with 16 frame inside counting device value and 30 s' interframe Counter Value, again this value of 46 is duplicated 3 times, be spliced into 138 bit wides, remove high 10, remaining 128 as Counter Value.
Further, encrypt scheduler module, use key identical same frame data, 128 of every encryptions, frame inside counting device value adds fixed length 1, does not need carry.
Further, in the described step (c), the AES processing module also generates new key according to initial key: by getting wheel constant table respective column and last key XOR, obtain current key.
Further, after described step (3) is carried out, if receiving, described read data buffer module reads enable signal, then the fifo circuit of reading of read data buffer module is sent data in turn successively, when data are read sky, the first in first out spacing wave is read in the output of read data buffer module, suspends sense data.
Adopt the method for the invention, can guarantee descending encryption bandwidth 2.4Gbits/s, consume 3146 ALUT, only take 2194 registers, compared with prior art, reach the cipher round results of GPON system requirements, obtained higher encryption bandwidth, save logical resource, improved the system works frequency.
Embodiment
The embodiment of the invention combines the application background of GPON system, in ciphering process, introduce two-stage flowing water, once can encrypt two 128 bit data, be complementary with the shortest frame length 32 bytes of GPON system, make full use of streamline length simultaneously, and multiplexing two encrypted circuits, operation simultaneously, improve and encrypt bandwidth, satisfy system requirements, in the cipher key expansion module of AES cryptographic algorithm, realize the function of Rcon (wheel constant table) in addition, saved logical resource by designing two shift registers of 10 ' h001 and 10 ' h06c.Implementation method is as follows:
A) realization of input metadata cache.The write data buffer zone module is used for buffer memory incoming frame data.System descending frame rate peak value is 4Gbits/s, and the maximum processing bandwidth of encrypting scheduler module is that 3.2Gbits/s speed does not each other all match, therefore buffering area need be set carries out smoothly data stream, here adopt the FIFO (fifo circuit) of 4 bit wide 32bits to carry out buffer memory, finish of the splicing of incoming frame data 32bit bit wide simultaneously, improve and encrypt bit wide to encrypting plaintext data 128bits bit wide.
B) realization of enciphered message buffer memory.The enciphered message cache module is the frame length of unit each frame of buffer memory, initial counter value and initial key with the frame.Because only need buffer memory two frame informations, so adopt two-stage d type flip flop buffer memory, realize saving readout time of cache information with d type flip flop, save resource.Also can come buffer memory with RAM, RAM is than the buffer memory that is more suitable for bulk information.
C) encrypt the realization of dispatching.Encrypting scheduler module is design key, it is responsible for reading and buffer memory key and frame length, generation Counter Value stream, finish the scheduling of two AES processing modules and read clear data and send into the AES processing module, and AES processing module encrypted ciphertext is sent into output buffers.When new frame to be encrypted arrives, at first extract the information of frame length, initial key, initial counter value, the frame length of the clear data of encrypting as required produces and encrypts enable signal again, simultaneously key, Counter Value is delivered to the AES processing module together and encrypts.The data of going out from the encryption scheduler module have not just had the notion of frame, but organize 128 * 2 Counter Value more.In order to make full use of flowing water, carry out sending into one group of 256 new bit data when last is taken turns immediately at encrypted circuit, begin next group encryption computing.
D) realization of AES encryption.The AES processing module is introduced two-stage flowing water under the control of encrypting scheduler module, the process that initial counter value that provides according to system and initial key are finished data encryption.Ciphering process need be divided into 10 takes turns circulation and carries out, and whenever takes turns circulation and comprises processes such as byte is replaced, line feed operation, rank transformation, key XOR, and wherein last takes turns the operation that does not have rank transformation.Each key of taking turns is all different, all is to obtain new key as cipher key spreading on the basis of last round of key.The data encrypted that obtains behind Counter Value after the encryption and the clear data XOR.
E) realization of dateout buffer memory.The read data buffer module is carried out buffer memory with data encrypted, and wait is called.Adopt the FIFO of 4 bit wide 32bit to carry out buffer memory, finish simultaneously and encrypt of the conversion of back data 128bit bit wide, return reliable encrypted result to output frame data 32bit bit wide.
The present invention is described in further detail below in conjunction with accompanying drawing:
Aes algorithm has 5 kinds of mode of operations: electronic codebook mode, password packet train, cipher feedback, output feedback and counter mode.What GPON adopted is the counter mode that is fit to express network, can produce random cipher stream in this way easily, is difficult to more be decrypted, and present embodiment adopts following 128 aes algorithms of counter mode to realize.
The principle of aes algorithm counter mode as shown in Figure 1.
K is a key, and ctr0-ctrn is a Counter Value; P0-Pn is the plaintext before encrypting, and each all is 128 expressly, and in this example, n is 128, the value of counter, key, expressly, ciphertext all is 1 of 1 correspondence; C0-Cn is the ciphertext after encrypting.Under counter mode, what carry out the AES encryption is not expressly, but the value of counter.Value after ciphertext is encrypted by counter and plaintext be XOR and producing mutually.
Aes algorithm calculation procedure under the counter mode as shown in Figure 2.
Only carry out key during initialization and add computing, just with Counter Value and key XOR mutually.The 1st takes turns to the 9th takes turns, more than the result that adds of a round key for the basis, carry out byte conversion → row displacement → row hybrid operation → expanded keys add operation.Last is taken turns and takes turns slightly differently with front 9, and row hybrid operation operation has only byte conversion → row displacement → expanded keys add operation.After step was in front finished (also promptly the encryption of Counter Value being finished), Counter Value and corresponding plaintext XOR after will encrypting obtained ciphertext output again.
As shown in Figure 3, the AES encryption device of present embodiment comprises that write data buffer zone module W-FIFOs, enciphered message cache module, read data buffer module R-FIFOs encrypt scheduler module and two AES processing modules are AES processing module a and AES processing module b.Be-encrypted data is buffer memory in the W-FIFOs of encryption device earlier, the frame length of each frame, initial counter value and initial key be buffer memory in the enciphered message cache module, scheduler module is sent be-encrypted data, Counter Value and initial key into AES processing module a or AES processing module b carries out encryption by encrypting then, puts into read data buffer module R-FIFOs again and wait for data after subordinate's module reading encrypted after handling.
As shown in Figure 4, write data buffer zone module W_FIFOs mainly by 4 bit wides be 32, the degree of depth is 16 fifo circuit FIFO (write fifo circuit W_FIFO1~W_FIFO4) and write pointer counter, the shift enable control circuit is formed.Writing end is to cooperate 32 data/address bus to write 32 data at every turn, and four FIFO write in turn; Read end because the encryption bit wide of AES is 128, reading 128 data at every turn simultaneously.
The relevant control that writes end is described below: four FIFO take turns back operations; next frame should begin to write from first FIFO after a frame is handled; and the write signal of higher level's module therefore compose buffer be about to full and suspend and write, need to adopt the write pointer protection this moment but not write pointer resets.In order to address this problem, having adopted the method for displacement control to realize that data select the function that writes: 4 of the shift enable shift_reg sign of the shift register in the shift enable control circuit respectively corresponding four FIFO write enable signal, write in higher level's module and to enable the valid period, realize wheel back operations different FIFO by displacement; Then it goes without doing handles to the data passage, directly is connected to each FIFO and gets final product.When frame data were handled, shift_reg resetted; If in a frame process, interrupt, just suspend displacement, when treating higher level's module recovery write operation, follow original FIFO position again and continue to write new data.
Correlation timing as shown in Figure 5, wherein:
Clk1: expression system clock;
Wren, data_in: writing of expression higher level module enables and write data;
Wfifo_1_wren, wfifo_2_wren, wfifo_3_wren, wfifo_4_wren: writing of 4 FIFO of expression enables;
Shift_reg: the shift enable sign of expression shift register;
Cnt_clr: the reset signal of expression shift register;
Data_cnt: the value of the counter of data fifo is write in expression;
Data_length: the data length that expression higher level module writes.
Concrete operations are as follows: when higher level's module needs write data, send the wren enable signal, and data data_in and the data length data_length that writes provided simultaneously, the write data buffer zone module enables to put 1 with writing of 4 FIFO respectively according to the difference of the value of shift enable sign, after finishing this write operation of taking turns, provide the reset signal cnt_clr of shift register, shift register is clear 0, prepare next data writing operation.
Encrypt that scheduler module is responsible for reading and buffer memory key and frame length, response higher level module, produce Counter Value stream and the scheduling of two AES processing modules.As shown in Figure 6, encrypt scheduler module and comprise cipher key frame long letter breath memory module, scheduler module, counter generation module.Key, frame length information storage module are used for storing the frame length that reads out from the enciphered message cache module and the key of current encrypted frame.The counter generation module is used for reading initial counter value from the enciphered message cache module, generates corresponding Counter Value, sends to the AES processing module.Scheduler module is used for receiving, transmitting control signal, and reads key, the frame length of frame length information storage module buffer memory and the key of current encrypted frame, send to the AES processing module, and the control counter generation module generates Counter Value.
Encrypt scheduler module when new encrypted frame arrives, at first extract Counter Value between frame length, initial key, initial frame inside counting device value, initial frame from the enciphered message cache module, because encrypting, AES carries out according to piece, need calculate how many pieces of needs according to frame length so encrypt scheduler module, produce the corresponding enable signal of encrypting then, simultaneously, key, Counter Value being delivered to the AES processing module together encrypts.From encrypting coded signal that scheduler module goes out and just do not had the notion of frame, but a long frame is cut into the piece of a plurality of 128bits, forms the key sum counter values of many groups 128 * 2.Send into the Counter Value bit wide 128 of counter generation module, be that interframe Counter Value by 16 frame inside counting device value and 30 is merged into after 46 bit widths, again this value of 46 duplicated 3 times, be spliced into 138 bit wides, removing high 10, remaining 128 is exactly Counter Value.What encrypting module was encrypted is the value of counter, because encryption period length is fixed (22 clock cycle), so the Counter Value that can predict after the encryption is effective constantly at what, can in advance the plaintext in the input data cache module be read, with encrypt after the Counter Value XOR after, give the dateout cache module and preserve.
Following method is deferred in scheduling:
A) key of same frame data is identical, 128 of every encryptions, and frame inside counting device value adds fixed length 1;
B) encrypt at least 2 clock cycle of interval that enable encrypt_reqa, encrypt_reqb (encrypt enable signal a, encrypt enable signal b);
C) if AES processing module a and b are idle, preferential calling module a;
When d) adding fixed length 1, do not consider carry for frame inside counting device value.
The key signal sequential of encrypting scheduler module as shown in Figure 7, wherein,
Clk: expression system clock;
Encrypt_req: expression enciphered message request signal;
Encrypt_reqa: the encryption request signal of expression AES processing module a;
Encrypt_reqb: the encryption request signal of expression AES processing module b;
Aes_ready_a: expression AES processing module a idle signal;
Aes_ready_b: expression AES module b idle signal;
Cnt_in_a: the value of the frame inside counting device of AES module a is given in expression;
Cnt_in_b: the value of the frame inside counting device of AES module b is given in expression;
Frame_length: the length of expression scrambled data frame;
Frame_l_cnt: expression enciphered data data counter.
When Frame need be encrypted, send enciphered message request signal encrypt_req, encrypt scheduler module is taken out frame to be encrypted from the enciphered message cache module information such as frame length, initial counter value and initial key.Initial counter value comprises interframe counter and frame inside counting device, and the counter generation module produces the Counter Value that is used for cryptographic algorithm according to the value of these two counters.Scheduler module provides encryption request signal encrypt_reqa or encrypt_reqb according to the idle signal of AES module, provide the value cnt_in_a of frame inside counting device simultaneously, the data frame_l_cnt of a 128bits of every encryption adds 4, the value of the value cnt_in_a of frame inside counting device adds 1, finishes up to enciphered data.
Owing to the encryption bandwidth that an AES circuit provides has only 1.6Gbits/s, so present embodiment has used two identical AES processing modules to handle to reach the processing bandwidth of 3.2Gbits/s.The structure of each AES circuit as shown in Figure 8.
The AES processing module mainly comprises 4 d type flip flops (DFF1~DFF4), 2 selectors, 3 XOR modules, and byte conversion and row shift module, row hybrid operation module, cipher key expansion module.
Wherein,
The first XOR module is used for the key sum counter value of input is carried out XOR;
First d type flip flop is used to latch the output result of the first XOR module;
First selector, the output that is used for selecting first d type flip flop when the 1st takes turns cryptographic calculation are as input value, and in 9 computings of taking turns, the output of selecting 3d flip-flop is as input value in the back;
Second d type flip flop is used to latch the output result of first selector module;
Byte conversion and row shift module are used for the data that receive are carried out byte conversion and row shifting function;
Row hybrid operation module is used for the data that receive are carried out the row hybrid operation;
Second selector is used for taking turns outputs that computing selects row hybrid operation module as input value preceding 9, in the end 1 take turns in the computing, with the output of byte conversion and row shift module as input value;
Cipher key expansion module is used for obtaining current key by getting wheel constant table respective column and last key XOR;
The second XOR module is used for the output of second selector and XOR is carried out in the output of cipher key expansion module;
3d flip-flop is used to latch the output result of the second XOR module;
The 3rd XOR module is used for carrying out XOR to encrypting back Counter Value and clear data;
Four d flip-flop is used to latch the output result of the 3rd XOR module.
The startup of AES processing module is by encryption enable signal encrypt_reqa that encrypts scheduler module output and encrypt_reqb control.After the AES processing module started, two 128 Counter Value entered the AES processing module successively, finished Initial Round (first round) computing with the initial key XOR earlier, carried out 10 interative computations of taking turns afterwards, obtained ciphertext output with the plaintext XOR more at last.Every next AES processing module output ciphertext, this module receives the data of 128bits respectively with regard to continuous two clocks, as can be seen from the figure come, the circulation of 1-9 wheel is in DFF2 (d type flip flop 2) and DFF3 (d type flip flop 3) boundary, and promptly streamline has been located at DFF2 and DFF3.
The key signal sequential of AES processing module as shown in Figure 9.Encrypting after scheduler module will encrypt request encrpty_req signal and put height, the AES processing module is ready to the aes_ready signal with AES and drags down this module of expression and temporarily can not accept new data, and while AES processing module begins enabling counting device aes_cnt.After cryptographic operation was finished, this module was write data and is studied in buffering area, aes_cnt is put 0, drew high aes_ready and represented to handle new data.Since after starting each to handle what data constantly all be known, so available aes_cnt produces relevant control signal: selector mux1 is 1 and selected the input of the output of DFF1 as DFF2 at 2 o'clock at aes_cnt, other the time select the input of the output of DFF3 as DFF2; Selector mux2 is the sub_bytes﹠amp of selection byte conversion in 20 o'clock and row shift module at aes_cnt; The output of shift_rows operation, other the time select the output of the mix_column of row hybrid operation module to participate in XOR; When being 21 and 22, aes_cnt sends out the enable signal of reading of writing buffering; When aes_cnt is 21, the aes_ready signal drawn high and show and to receive new enciphered data.
Cipher key expansion module is responsible for realizing the expansion of key, produces every needed key of interative computation of taking turns.The startup of this module is also by the encrypt_req signal controlling, and when this signal arrived, module started, and reads in initial key, and according to the characteristics of AES processing module two-stage flowing water, per two clock cycle are upgraded a secondary key.The main points of cipher key expansion module design are the realizations of Rcon.Rcon is a table as shown in the table in fact, and (first round is got first row, and second takes turns and get secondary series, participates in by that analogy) XOR (key of catching up with once carries out XOR, produces key next time) to take out respective column during the expansion of each round key.Because the value of Rcon is fixed, so traditional AES realizes it being that it is cured among the ROM.By observing the structure of Rcon, except that first column element, all the other elements all are 0, and first row element is between the first eight and shifted relationship arranged between latter two, therefore can add simple control signal again by shift register realizes: define two shift registers respectively and be used to produce the first eight data and latter two data, their initial value is respectively 10 ' h001 and 10 ' h06c, realizes ring shift left under the control of wheel counter, simultaneously with these two shift registers of wheel counter gating.So just can realize the function of Rcon by less logical resource.
The Rcon structure
01 |
02 |
04 |
08 |
10 |
20 |
40 |
80 |
1b |
36 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
00 |
Similar with the write data buffer zone module, read data buffer module R_FIFOs also mainly by 4 bit wides be 32, the degree of depth is 16 FIFO and read pointer counter, shift enable control circuit are formed.Data concurrent write after having encrypted through the AES circuit is studied in buffering area; After enable signal is read in the downstream module transmission,, make it sequentially data to be read by the generation of read pointer counter controls shift enable signal.Its circuit structure as shown in figure 10.For fear of too high burst read rate, be provided with and read fifo spacing wave r_fifo_aempty signal, when buffering area is read sky soon, tell subordinate's module to suspend read data by this signal.The difficult point of reading the buffering area design is that also its sequential is similar to compose buffer sequential principle to reading the control of end.
The present invention is with the logic scale of some design tactics control circuits, make the encrypted circuit operating frequency up to 125MHz, descending encryption bandwidth 2.4Gbits/s, meet GPON system interface standard fully, overcome in the prior art encrypt the bandwidth deficiency, logical resource consumes shortcomings such as too much, be adapted at using in the High Speed System such as GPON.