Image encrypting and decrypting system and method thereof based on FPGA platform and evolution hardware
Technical field
The present invention relates to information encryption, decryption technology field, particularly a kind of image encrypting and decrypting and method thereof based on FPGA platform and evolution hardware.
Background technology
Evolution hardware (Evolvable Hardware, EHW) be a kind of by with the hardware circuit that can change himself structure and behavior alternately dynamically of environment.It has the ability of self-organizing, self adaptation, selfreparing, can adapt to the varying environment requirement and improve self performance.The general solution procedure of evolution hardware is: adopt earlier the evolution of evolution algorithmic to hardware circuit configuration string, find out satisfactory configuration string then and then go here and there configuring hardware circuit with this configuration.The main application fields of evolution hardware has: the automatic design of ball bearing made using, solve the problem of difficult definition, and create Adaptable System, create the design innovation of tolerant system and indigestibility design field.Aspect image processing, the main application has application such as Design of Digital Filter and Image Edge-Detection, Kyrre Glette uses FPGA that the evolution hardware adaptations has also been obtained good effect (Glette in image recognition, K., Torresen, J., Yasunaga, M., Yamaguchi, Y.:On-chip evolution using a soft processor core applied to image recognition.In:Proc.of the First NASA/ESA Conference on Adaptive Hardware and Systems (AHS 2006), LosAlamitos, CA, USA, IEEE Computer Society (2006)).
Cellular automaton (Cellular Automata, CA) be the dynamical system that a kind of time, space and state all disperse, because it has regular, modularization and inherent concurrency, is convenient to characteristics such as software and hardware realization, makes cellular automaton especially be fit to be applied to cryptography.1985, Wolfram utilized cellular automaton to generate key stream first, but this method has two weakness: at first be that the key stream that generates does not have long period; Next is that fail safe is not high enough.After this much studies show that, can be by improving the complexity of cellular automaton structure, as improve the dimension of CA or adopt method such as dynamic programming to improve the cycle and fail safe (being the randomness) (Xia Xuewen of key stream, Li Yuanxiang, once brightness. trigger the image encryption algorithm [J] of cellular automaton based on coupling. computer science, 2009).2004, Zhang Chuanwu proposed a kind of cryptographic algorithm based on the triggering cellular automaton, and this algorithm has bigger key space and better simply hardware configuration, was well suited for FPGA and realized.But not all rule can both be as key, and traditional method for designing is separated with encryption the design of key, and must design a set of group keys, very flexible in advance.
Summary of the invention
For solving cellular automaton image encryption safety issue and efficiency, the invention provides based on the image encrypting and decrypting method of FPGA platform and evolution hardware and the system that gives and realize.
A kind of image encrypting and decrypting system provided by the invention based on FPGA platform and evolution hardware, described FPGA platform comprises PLB bus, OPB bus and as the PowerPC of processor, PowerPC is connected to the PLB bus, and the PLB bus is connected by bus bridge with the OPB bus; Following each several part is set in the FPGA platform:
The Hardware I P nuclear that is connected with the OPB bus comprises configurable embryonic circuit IP kernel, is used to produce encryption rule and deciphering rule; Cellular automaton image encryption IP kernel is used for according to configurable embryonic circuit encryption rule that IP kernel provides view data being encrypted; Cellular automaton image deciphering IP kernel is used for providing the deciphering rule that view data is deciphered according to configurable embryonic circuit IP kernel; The function selecting IP kernel is used for decision and uses cellular automaton image encryption IP kernel or cellular automaton image deciphering IP kernel image data processing;
The configuration string that genetic algorithm module that realizes on PowerPC and central control module, genetic algorithm module are used to develop and find the solution configurable embryonic circuit IP kernel, central control module are used for collaborative Hardware I P and examine existing to view data encryption or deciphering;
Nonvolatile memory with the OPB bus is connected is used for storing image data.
And, configurable embryonic circuit in the described configurable embryonic circuit IP kernel is made of 8 row, 8 row basic logic units, each basic logic unit has three inputs, one output, and each input is selected one from the output of the basic logic unit of previous column, the concrete selection by the decision of configuration string; The function of each basic logic unit is by the function decision of basic logic unit, and type function is by the decision of configuration string;
The input of configurable embryonic circuit IP kernel comprises that original text data item and genetic algorithm module provide the configuration string, are output as the encrypt data item;
The encryption rule of same configuration string correspondence is identical with the deciphering rule, is concatenated into encryption rule or deciphered regular mode by configuration to be, the radius of establishing encryption or deciphering is r, and then the original text data item is the 2r+1 position, and the encrypt data item is 1, and generative process may further comprise the steps,
Step 2.1 is with the configurable embryonic circuit in the configurable embryonic circuit IP kernel of configuration string configuration;
Step 2.2 is successively with 0 to 2
2r+1Number between-1 calculates the encrypt data item as the original text data item;
Step 2.3, whole 2
2r+1After the encrypt data item of individual original text data item calculates and finishes, with 2
2r+1Individual encrypt data item is arranged in order from high to low, and the binary string of being formed has just constituted corresponding encryption rule or the deciphering rule of this configuration string.
And 8 row, the 8 row basic logic units that described configurable embryonic circuit IP kernel is comprised are executed in parallel in row, are that serial is carried out between row.
And, described cellular automaton image encryption IP kernel adopts the forward circulation displacement cipher mode in the cellular automaton inverse iteration encryption technology to realize encrypting, and comprises original text register, commencing signal register, regular register, result register and finishes sign register; Cellular automaton image encryption IP kernel be input as view data to be encrypted and encryption rule, be output as encrypted result to view data.
And, described cellular automaton image deciphering IP kernel adopts the reverse circulation displacement manner of decryption in the cellular automaton inverse iteration encryption technology to realize deciphering, comprises original text register, commencing signal register, regular register, result register and finishes sign register; Being input as view data to be deciphered and deciphering rule of cellular automaton image deciphering IP kernel is output as the decrypted result to view data.
And described function selecting IP kernel comprises a register that the function selecting position is arranged at least, if the function selecting position requires system to encrypt for " very " expression, if for " vacation " then require system carry out to decipher.
The present invention also provides corresponding image encrypting and decrypting method.
Wherein, encryption method comprises following steps:
Step 7.1, the genetic algorithm module of calling central control module develops and finds the solution the configuration string of configurable embryonic circuit IP kernel, after evolution obtains the proper configuration string, use the configurable embryonic circuit IP kernel of this configuration string configuration, obtain encryption rule by configurable embryonic circuit IP kernel, and export this encryption rule in the regular register of cellular automaton image encryption IP kernel;
Step 7.2, central control module read image file to be encrypted, then view data to be encrypted in the image file are carried out segmentation and obtain the plurality of data section;
Step 7.3, central control module writes the original text register of cellular automaton image encryption IP kernel with current data segment to be encrypted, and the commencing signal register at cellular automaton image encryption IP kernel writes ' 1 ' then;
Step 7.4, central control module cycle detection cellular automaton image encryption IP kernel finish the signal of finishing that sign register provides, be ' 1 ' if finish signal, read the data in the result register of cellular automaton image encryption IP kernel;
Then create cryptograph files if current data segment to be encrypted is first section of view data to be encrypted, cellular automaton encrypted data write this cryptograph files in the result register of IP kernel,
Otherwise data write the end-of-file that this cryptograph files is appended to existing cryptograph files in the result register of direct just cellular automaton encryption IP kernel;
Step 7.5 is taken off a data segment and is returned step 7.3 as current data segment to be encrypted and proceed to encrypt, and after to the last a data segment is encrypted, closes cryptograph files, preserves the configuration string.
Wherein, decryption method comprises following steps:
Step 8.1, used configuration string during the central control module reading encrypted, use the configurable embryonic circuit IP kernel of this configuration string configuration, obtain the deciphering rule of its correspondence, and export this deciphering rule in the regular register of cellular automaton image deciphering IP kernel by configurable embryonic circuit IP kernel;
Step 8.2, central control module reads cryptograph files, and the view data for the treatment of deciphering is carried out segmentation and is obtained the plurality of data section;
Step 8.3, central control module writes the original text register of cellular automaton image deciphering IP kernel with the current decrypted data section for the treatment of, and the commencing signal register at cellular automaton image deciphering IP kernel writes ' 1 ' then;
Step 8.4, the sign register of finishing of central control module cycle detection cellular automaton image deciphering IP kernel provides and finishes signal, is ' 1 ' if finish signal, and read the cellular automaton image and decipher data in the result register of IP kernel,
If the current decrypted data section for the treatment of is to treat that first section of decrypted image data then create text file, and the data in the result register of cellular automaton image deciphering IP kernel are write text file,
Otherwise with the end-of-file of the data supplementing in the result register of cellular automaton image deciphering IP kernel to existing text file;
Step 8.5 is got and is carried out next data segment and return step 8.3 and proceed deciphering as the current decrypted data section for the treatment of, after data segment deciphering to the last, closes text file.
The present invention combines evolution hardware and cellular automaton encryption technology, realize image is encrypted with the FPGA platform, because evolution hardware is configurable, so it both can search for the instrument of key, also can be used as the logical circuit of rule list, key does not need to change hardware when changing, and has increased the reusability of hardware.Image encrypting and decrypting system provided by the present invention carries out encrypting and decrypting with the inverse iteration technology, and not only enciphering rate is fast, and has realized the key dispersion, can produce key at random, has enlarged key space, makes the fail safe of encrypting obtain enhancing.
Description of drawings
Fig. 1 is the system global structure figure of embodiment;
Fig. 2 is the embryonic circuit structure chart of embodiment;
Fig. 3 is the structure chart of the cellular automaton image encryption IP kernel of embodiment;
Fig. 4 is the primary control program control flow chart of embodiment;
Fig. 5 is the encryption flow figure of embodiment;
Fig. 6 is the use cellular automaton image encryption IP kernel procedure chart of embodiment;
Fig. 7 is the deciphering flow chart of embodiment.
Embodiment
Describe the present invention below in conjunction with accompanying drawing and embodiment:
This example is to realize on XC2VP30 FPGA development board, use PowerPC as processor, the outer internal memory DDR SDRAM (embodiment adopts the 512MB capacity) of internal memory BRAM (embodiment adopts the 128KB capacity) and sheet adopts the CF card as the nonvolatile memory stores view data as memory on the use sheet.The view data that is the encryption and decryption front and back all leaves in the CF card.Because internal memory BRAM is limited on the sheet of FPGA platform, increase the memory bar DDRSDRAM of a 512MB, can be used for depositing the storehouse of software project.
Shown in Fig. 1 is the overall construction drawing of system, owing to adopted PowerPC as processor, there are two buses in system, PLB (Processor Local Bus, processor local bus) and OPB (On-Chip Peripheral Bus, peripheral bus on the sheet).The OPB bus connects some low speed and low-performance equipment, as configurable embryonic circuit IP kernel (MMA), cellular automaton image encryption IP kernel (Encryption), cellular automaton image deciphering IP kernel (Decryption) and function selecting IP kernel.The OPB bus is not directly connected to processor cores, gets in touch by the equipment on bus bridge (plb2opb_bridge) and the PLB bus such as kernel and memory.And the PLB bus is used for connecting some equipment at a high speed, as BRAM and DDR SDRAM.During concrete enforcement, for the ease of reading CF card content, the IP kernel SysACE that is used to read CF Cavan part (System Advanced Configuration Environment) that has used this FPGA development board to provide.In fact genetic algorithm module that realizes on PowerPC and central control module, these modules can adopt the software modularity designing technique to realize.
For the ease of implementing reference, provide the each several part specific design of embodiment as follows:
Fig. 2 shows the structure of the possible embryonic circuit that a kind of configurable embryonic circuit IP kernel provided.This circuit is made of 8 row, 8 row basic logic units, and basic logic unit is labeled as among the figure
Basic logic unit has three inputs, one output, and each imports in the output (totally 8) of optional previous column basic logic unit one, the concrete selection by configuration string (Configuration) decision.If the input selective value is n in the configuration string of the some inputs of basic logic unit, the value of just representing this input of basic logic unit is the output of the capable basic logic unit of previous column n.The function of basic logic unit is by the function decision of basic logic unit, and type function is by the decision of configuration string.Every input is no more than three, output equal one type function all can, but in order to simplify calculating, increase the speed of service, can select some better simply type function.The corresponding relation (A, B, C are respectively three inputs) as shown in the table of function numerical value and function type in the configuration string in the present embodiment:
Central control module is communicated by letter with configurable embryonic circuit IP kernel by read-write register.The input register of configurable embryonic circuit IP kernel comprises reset signal position, start bit, original text data item position and configuration displacement; Output register comprises encrypt data item position and finishes signal bits.
Suppose that the radius of encrypting is r, the original text data item of the input register of then configurable embryonic circuit IP kernel is the 2r+1 position, and the encrypt data item of output register is 1.
The encryption rule of same configuration string correspondence is identical with the deciphering rule, and the method for being concatenated into encryption rule or deciphering rule by configuration is:
1. with the configurable embryonic circuit in the configurable embryonic circuit IP kernel of this configuration string configuration.In the specific embodiment: central control module at first writes ' 1 ' in the reset signal position of the input register of configurable embryonic circuit IP kernel, writes ' 0 ' then, finishes the reset operation of this IP kernel.Configuration displacement at the input register of this IP kernel writes the configuration string that genetic algorithm provides then.
2. successively with 0 to 2
2r+1Number between-1 calculates the encrypt data item as the original text data item of configurable embryonic circuit IP kernel input register.In the specific embodiment: central control module at first writes ' 1 ' in the start bit of the input register of configurable embryonic circuit IP kernel, finish signal bits in this IP kernel output register of cycle detection then, in case detecting and finishing signal bits is ' 1 ', expression is calculated and is finished, and central control module reads the data of encrypt data item in the output register.
3. whole 2
2r+1After the encrypt data item of individual original text data item calculated and finishes, central control module was with 2
2r+1Individual encrypt data item is arranged in order from high to low, and the binary string of being formed has just constituted corresponding encryption rule or the deciphering rule of this configuration string.
The 1st row are calculated successively for after ' 1 ' in the start bit that configurable embryonic circuit IP kernel detects its input register under the control of this IP kernel internal clock signal (being the system clock of FPGA), the 2nd row are to the output of each basic logic unit of the 8th row.When calculating a certain row, 8 elementary cells of these row are to carry out computing simultaneously.Can set the computing time of every row in concrete the enforcement according to the time delay situation of FPGA, be set at 1 clock cycle in the present embodiment, calculate the value of next column after a column count is finished.After last column count finishes, the output valve of the basic logic unit of first row the 8th row is written to the encrypt data item position of the output register of configurable embryonic circuit IP kernel, and the signal bits of finishing of putting output register is ' 1 ';
Described cellular automaton image encryption IP kernel adopts the forward circulation displacement cipher mode in the cellular automaton inverse iteration encryption technology of the prior art to realize data encryption, the realization program is not introduced in detail, specifically implement to see reference document: Zhang Chuanwu, Shen Yeqiao, Peng Qizong, cellular automaton inverse iteration Encryption Technology Research [J], Chinese journal of computers, 2004.Among the embodiment, adopt hardware evolution mode to realize cellular automaton image encryption IP kernel, original text register, commencing signal register, regular register, result register can be set and finish sign register; Cellular automaton image encryption IP kernel be input as view data to be encrypted and encryption rule, be output as encrypted result to view data.Fig. 3 shows the structure chart of cellular automaton image encryption IP kernel.This IP kernel be input as encryption rule rule, original text indata and commencing signal start; Be output as output ciphertext outdata and finish signal finish, the regular register in the corresponding respectively program, original text register, commencing signal register, result register and finish sign register; The function of finishing is to the data encryption in the original text register, and encrypted result is placed in the result register.When generating this IP kernel, FPGA platform meeting clock signal clk and reset signal reset are so that provide work clock and support reset operation.
Cellular automaton image deciphering IP kernel adopts the reverse circulation displacement manner of decryption in the cellular automaton inverse iteration encryption technology to realize data decryption, the realization program is not introduced in detail, specifically implement to see reference document: Zhang Chuanwu, Shen Yeqiao, Peng Qizong, cellular automaton inverse iteration Encryption Technology Research [J], Chinese journal of computers, 2004.The structure of cellular automaton image deciphering IP kernel and the structure of cellular automaton image encryption IP kernel can be identical, and cellular automaton image deciphering IP kernel comprises original text register, reset signal register, commencing signal register, regular register, result register and finishes sign register among the embodiment; Being input as view data to be deciphered and deciphering rule of cellular automaton image deciphering IP kernel is output as the decrypted result to view data.Its function of finishing is to data decryption in the original text register, and the result that will decipher is placed in the result register.
Described function selecting IP kernel comprises a register that the function selecting position is arranged at least, if the function selecting position requires system to encrypt for " very " expression, if for " vacation " then require system carry out to decipher.During concrete enforcement, the function selecting IP kernel can be tied to the function selecting position by pin with the switch on the FPGA platform, with " very " of switch, " vacation ", " very " that presentation function is selected, " vacation ".
Fig. 4 illustrates the control flow chart of the central control module of embodiment.Central control module at first measuring ability is selected function selecting position in the IP kernel register, if be " very ", and the execution ciphering process; For " vacation " then carries out decrypting process.
Fig. 5 illustrates ciphering process.The embodiment of configurable embryonic circuit of developing is: with the configuration string of the configurable embryonic circuit individuality as genetic algorithm, genetic algorithm module is by the genetic algorithm configurable embryonic circuit that develops.Genetic algorithm is a kind of intelligent algorithm that is in daily use, and the present invention will not give unnecessary details.Individuality in the genetic algorithm is sent to central control module and is estimated its adaptive value.Central control module is concatenated into encryption rule according to the configuration that genetic algorithm module provides, and analyzes encryption rule and returns this individual adaptive value and give genetic algorithm module (in the present embodiment with the absolute value of the difference of 0 and 1 number in the encryption rule binary representation adaptive value as the genetic algorithm individuality).After certain individual adaptive value reaches the target adaptive value, should individuality as optimum individual, the genetic algorithm module configurable embryonic circuit that stops to develop.Central control module as the embryonic circuit in the configurable embryonic circuit IP kernel of configuration string configuration, calculates the encryption rule of optimum individual correspondence with optimum individual.
Central control module is written to the resulting encrypted rule in the regular register of cellular automaton image encryption IP kernel, central control module reads image file to be encrypted and with wherein view data segmentation, uses cellular automaton image encryption IP kernel to encrypt to each section successively then.After cellular automaton image encryption IP kernel is finished encryption, if first data segment of image, then central control module will be created cryptograph files on nonvolatile memory, and the data in the result register of cellular automaton image encryption IP kernel are written in this cryptograph files, if last data segment of image, then central control module is closed this cryptograph files after writing data in the result register, if neither first segmentation neither end section, then with the data supplementing in the result register of cellular automaton image encryption IP kernel to the cryptograph files tail.The present invention advises adopting the circular treatment mode, after each current data segment to be encrypted encryption is finished, take off a data segment and repeat same ciphering process, close current cryptograph files after to the last a data segment is encrypted as current data segment to be encrypted.Can also preserve configuration at last and go here and there nonvolatile memory, so that use when being decrypted.
Fig. 6 shows and uses the course of work of cellular automaton image encryption IP kernel to be: at first write encryption rule in the regular register of cellular automaton encryption IP kernel before to whole file encryption; In the original text register, write current data segment to be encrypted then; Putting the start bit at the beginning register again is ' 1 ', i.e. commencing signal start=1; Central control module constantly detects finishing of cellular automaton image encryption IP kernel and finishes signal finish in the sign register afterwards, in case detect to finish and finish signal finish=1 in the sign register, show then to encrypt and finish that the data in the cellular automaton image encryption IP kernel result register are the result that data are encrypted by encryption rule in the original text register.
Fig. 7 shows the image decrypting process: decrypting process is: central control module reads the key of deciphering, and promptly the configuration string of configurable embryonic circuit with the configurable embryonic circuit of this configuration string configuration, calculates the deciphering rule.Central control module is written to resulting deciphering rule in the regular register of cellular automaton image deciphering IP kernel, central control module reads image file to be deciphered and with wherein view data segmentation, successively each section is used the deciphering of cellular automaton image deciphering IP kernel then.After cellular automaton image deciphering IP kernel is finished deciphering, if the decrypted data section is first data sementation of image, then central control module will be created text file on nonvolatile memory, and the data in the result register of cellular automaton image deciphering IP kernel are written in this text file, if last data segment of image file, then central control module is closed this text file after writing data in the result register, if neither first segmentation neither end section, then with the data supplementing in the result register of cellular automaton image deciphering IP kernel to the text file tail.The present invention advises adopting the circular treatment mode, each current treat that decrypted data section deciphering is finished after, take off a data segment and repeat same decrypting process, to the last close current text file after a data segment deciphering as the current decrypted data section for the treatment of.Decrypting process does not need to develop, and configuration is gone here and there and preservation configuration string.
Use the course of work of cellular automaton image deciphering IP kernel similar: before to whole file decryption, at first in the regular register of cellular automaton deciphering IP kernel, to write the deciphering rule with use cellular automaton image encryption IP kernel; During to certain segment data deciphering, at first in the original text register, write and treat the decrypted data section; Putting the start bit at the beginning register again is ' 1 ', i.e. commencing signal start=1; Central control module constantly detects the sign register of finishing of cellular automaton image deciphering IP kernel afterwards, in case detect to finish and finish signal finish=1 in the sign register, show then to decipher and finish that the data in the cellular automaton image deciphering IP kernel result register are the result that data are deciphered by the deciphering rule in the original text register.