Background technology
Computer CPU to data store and read there are two types of hold sequence:Big end sequence and small end sequence.Big end sequence is initially in motor sieve
It is used in the chip of drawing, it is widely used in some embedded chips at present.Small end sequence, initially uses in intel chips,
It is widely used at present.
MD5(Message-Digest Algorithm5, Message Digest Algorithm 5)Canonical algorithm assumes that number of files
It is identical with small end sequence platform with the mode of filling data storage according to storage, it is flat to big end sequence when carrying out operation to 64 byte groups
Platform generally first will do syllable sequence reversing processing by 32 bit bytes, then calculate again.
Several pieces to more than ten pieces pluggable veneers are generally included in frame-type switch equipment, every piece of veneer there are independent CPU cores
Piece.In these veneers, software starts and escalation process half is related to verifying the complete of file using MD5 methods of calibration
Property.General checking process is:1)The md5 values of raw data file are first calculated according to the canonical algorithm of MD5 on PC, and and former
Beginning data file synthesizes an APMB package, the specific Format Reference the following table 1 of the APMB package.
Table 1
2)When being handled on veneer, the MD5 values of raw data file in APMB package are also calculated according to the canonical algorithm of MD5;
Then it is compared with the MD5 values in APMB package, unanimously then thinks that file is complete;Otherwise it is assumed that file is imperfect, damage
It is bad.
Due to the cpu chip that the frame-type switch equipment of existing not small number uses, data are stored and are read using big
Sequence is held, thus, it is unified to verified data to carry out syllable sequence reversing processing according to little-endian according to the canonical algorithm of MD5, so
Verification is calculated afterwards and this will cause checking time to increase.
Invention content
The technical issues of present invention need to solve is to provide a kind of calculation process reducing the time-consuming MD5 of verification.
In order to solve the above technical problems, the present invention devises a kind of calculation process of MD5 comprising following steps:
Step 1:First expand raw data file, forms calculation document, the calculation document includes N number of 64Byte original numbers
According to grouping, 1 initial data rest block and 1 expanding data block;
Step 2:Obtain the end sequence type that MD5 is used;
Step 3:Judge whether end sequence type and current computing platform are identical, if identical, directly calculate N number of 64Byte
The MD5 of original data packet is verified and is carried out word by 32 bit bytes if it is not the same, being then first grouped N number of 64Byte original numbers
Save sequence reverse, then calculate MD5 verification and;
Step 4:Judge whether current computing platform is small end sequence computing platform, if so, merging 1 initial data residue
Block and 1 expanding data block, are grouped, and continue to calculate according to 64Byte, obtain final MD5 verification and, if not, merging
1 initial data rest block and 1 expanding data block, and be grouped according to 64Byte, then to each of obtaining grouping by 32
Bit byte carries out syllable sequence reversing, then calculates MD5 verifications and obtains final MD5 values.
Particularly, the end sequence type is big end sequence type or small end sequence type.
Particularly, the current computing platform is big end sequence computing platform or small end sequence computing platform.
The present invention also provides a kind of file verification methods, are the file verification methods of the calculation process based on above-mentioned MD5,
Include the following steps:
Step 1:The calculation process of MD5 according to claim 1 obtains the MD5 values of raw data file on PC;
Step 2:Composite document packet, the file packet include MD5 values, hold sequence type and raw data file;
Step 3:It is handled on veneer, the original in file packet is obtained further according to the calculation process of MD5 described in claim 1
The MD5 values of beginning data file, wherein the end sequence type that acquisition MD5 is used is the end sequence type in file packet;
Step 4:The MD5 values of raw data file obtained above are compared with the MD5 values in the file packet, such as
Fruit is consistent, then it is assumed that raw data file is complete, otherwise, then it is assumed that file is imperfect.
Specific implementation mode
In order to make relevant technical staff in the field more fully understand technical scheme of the present invention, below in conjunction with of the invention real
The technical solution in embodiment of the present invention is clearly and completely described in the attached drawing for applying mode, it is clear that described reality
The mode of applying is only some embodiments of the invention, rather than whole embodiments.
As shown in Figure 1, for the calculation process of MD5 of the present invention, including:
Step 1:First expand raw data file, forms calculation document, the calculation document includes N number of 64Byte original numbers
According to grouping, 1 initial data rest block and 1 expanding data block.
Step 2:The end sequence type that MD5 is used is obtained, end sequence type is big end sequence type or small end sequence type.Work as original number
The format for storing and reading according to file is big end sequence, that is, it is big end sequence type to hold sequence type;When raw data file stores and reads
The format taken is small end sequence, that is, it is small end sequence type to hold sequence type.
Step 3:Judge whether end sequence type and current computing platform are identical, if identical, directly calculate N number of 64Byte
The MD5 of original data packet is verified and is carried out word by 32 bit bytes if it is not the same, being then first grouped N number of 64Byte original numbers
Save sequence reverse, then calculate MD5 verification and.Current computing platform is big end sequence platform or small end sequence platform.It is run in PC machine
When MD5 algorithms, PC machine is generally small end sequence computing platform.When being run on veneer, CPU classes used by veneer are depended on
Type uses big end sequence as CPU stores data and reads, then computing platform is big end sequence computing platform.As CPU stores data
Small end sequence is used with reading, then computing platform is small end sequence computing platform.
Step 4:Judge whether current computing platform is small end sequence computing platform, if so, merging 1 initial data residue
Block and 1 expanding data block, are grouped, and continue to calculate according to 64Byte, obtain final MD5 verification and, if not, merging
1 initial data rest block and 1 expanding data block, and be grouped according to 64Byte, then to each of obtaining grouping by 32
Bit byte carries out syllable sequence reversing, then calculates MD5 verifications and obtains final MD5 values.
Based on the calculation process of MD5 of the present invention, can to avoid without carrying out or carrying out less syllable sequence reversing processing, so as to
It is taken with reducing verification.The calculation process of MD5 is used to verify the file of frame-type switch by the embodiment of the present invention, but is not limited to school
Test the file of frame-type switch.In the present embodiment, the veneer in frame-type switch uses big end sequence CPU.
The present embodiment, the software of veneer starts the verification for being related to file integrality with escalation process, using the verification sides MD5
Method obtains the MD5 values of raw data file according to the calculation process of MD5 of the present invention on PC, specifically implements means first
It is:As shown in Fig. 2, first expanding raw data file, calculation document is formed, the calculation document includes N number of 64Byte original numbers
According to grouping, 1 initial data rest block and 1 expanding data block, as shown in Figure 3.The end sequence type of MD5 uses is obtained again, this
In embodiment, since the veneer in frame-type switch uses big end sequence CPU, therefore it is big end sequence type to hold sequence type, and is currently counted
Calculation platform is PC machine, as small end sequence computing platform.Thus, end sequence type is differed with current computing platform, then to calculating text
N number of 64Byte original data packets in part are first handled, and are carried out syllable sequence reversing by 32 bit bytes, are then calculated the schools MD5
Test and.Certainly, if the CPU that uses of veneer is small end sequence type, that is, hold sequence type identical with current computing platform, it is literary to calculating
N number of 64Byte original data packets in part directly calculate MD5 verifications and need not carry out falling by 32 bit bytes progress syllable sequence
Turn processing." 1 initial data rest block and 1 expanding data block " uncalculated in calculation document is further handled,
Since current computing platform is small end sequence computing platform, " 1 initial data rest block and 1 expansion in joint account file
Data block " is grouped according to 64Byte, and continues to calculate, obtain final MD5 verification and.Final MD5 verifications and as MD5
Value, calculating terminate.
After obtaining MD5 values in PC machine, the MD5 values, raw data file and end sequence type are synthesized into a file packet,
This document, which is wrapped, to be passed on veneer, then carries out verifying its integrality.As shown in figure 4, the file packet includes MD5 values, sequence class is held
Type and raw data file.In the present embodiment, end sequence type is big end sequence type.
It is whether complete to verify it when APMB package, which is transferred on veneer, to be started or upgrade, it needs to handle on veneer, count
The MD5 values of the raw data file in APMB package are calculated, the MD5 values for calculating the raw data file in APMB package are again based on this hair
The calculation process of bright MD5 expands the raw data file in APMB package to obtain calculation document first, and calculation document includes
N number of 64Byte original data packets, 1 initial data rest block and 1 expanding data block.Then the end in APMB package is got
Sequence type, as, the end sequence type that MD5 is used, in the present embodiment, end sequence type are big end sequence type, and calculating at this time
Platform is handled on veneer, as big end sequence computing platform, then it is big end sequence to hold sequence type and current computing platform all, to N
A 64Byte original data packets directly calculate MD5 verification and, need not carry out by 32 bit bytes carry out syllable sequence reversing processing,
It thus avoids and carries out syllable sequence reversing processing, successfully reduce verification and take." 1 original for uncalculated in calculation document
Data redundancy block and 1 expanding data block " is further handled, can not since current computing platform is big end sequence computing platform
Avoid carry out syllable sequence reversing processing, according to canonical algorithm, i.e., in joint account file in " 1 initial data rest block and 1
A expanding data block " merges 1 initial data rest block and 1 expanding data block, and is grouped according to 64Byte, then right
Each of obtain grouping and carry out syllable sequence reversing by 32 bit bytes, then calculate MD5 verifications and, obtain final MD5 values.
After the MD5 values of obtained raw data file, its value is compared with the MD5 values in the file packet, if
Unanimously, then it is assumed that raw data file is complete, otherwise, then it is assumed that file is imperfect.
The calculation process of MD5 of the present invention can avoid not having to carry out on veneer or carry out syllable sequence reversing processing less, from
And verification can be reduced and taken.
Only express one embodiment of the present invention above, the description thereof is more specific and detailed, but can not therefore and
It is interpreted as the limitation to the scope of the claims of the present invention.It should be pointed out that for those of ordinary skill in the art, not taking off
Under the premise of present inventive concept, various modifications and improvements can be made, these are all within the scope of protection of the present invention.Cause
This, the protection domain of patent of the present invention should be determined by the appended claims.