This article is shared from Huawei cloud community< A taste of LiteOS components - play RHas >, by Lionlace.
RHash is a hash function library written in C language, which is a console utility for calculating and verifying magnetic links and various message summaries.
Program features:
- The ability to recursively process directories;
- Output in predefined (SFV, BSD like) or user-defined format;
- Calculate flux linkage;
- Update the hash file (add the message summary of the missing file in the hash file);
- Calculate multiple message summaries at one time;
- Portability: the program works the same way on Linux, Unix, macOS, or Windows.
List of hash functions supported by Rhash:
Enable RHash Demo
In the root directory of the LiteOS source code, copy the default configuration file ${platform} in the tools/build/config / directory according to the actual development board Config to the root directory and rename to config.
Continue to execute the make menuconfig command in the root directory of the LiteOS source code, and enable RHash Demo according to the following menu path.
Demos ---> Security Demo ---> [*] Enable RHash Demo
RHash components are automatically enabled after enabling RHash Demo.
After saving and exiting, the RHash source code will be automatically downloaded from github, and the patch package suitable for LiteOS system will be downloaded from gitee and entered into patch. For the detailed process of Component download, please refer to: https://gitee.com/LiteOS/LiteOS_Components#%E5%9C%A8%E7%BA%BF%E7%BB%84%E4%BB%B6%E4%B8%8B%E8%BD%BD%E6%B5%81%E7%A8%8B
Note: the download requires that the Linux host can access the Internet and install git.
Compile and run RHash Demo
After enabling RHash Demo, execute make clean under the root directory of liteos source code; The make - J command compiles the liteos project. After successful compilation, librhash will be generated in the out/{platform}/lib path A and librhash_demo.a file, and the system image file is Huawei_LiteOS.bin.
Cloud_ STM32F429IGTx_ Take fire development board as an example to run RHash Demo. Please refer to other development board operations Quick start.
After LiteOS is started, RHash Demo will be run. This demo demonstrates the use of MD5 and sha256 hash functions. By calculating the MD5 and sha256 hash values of the given data, the hash values of the original data are compared. The given data is:
#define DEMO_STR "This is Huawei LiteOS RHash Demo.\n"
Create a new file test under linux Txt, copy the contents of demoStr to test Txt and execute the following command to generate the values of md5 and sha256:
$ md5sum test.txt $ sha256sum test.txt
The obtained md5 and sha256 values are:
#define MD5_SUM "7990beea258031735be06254cea58a89" #define SHA256_SUM "d56910304664d3d3a439968b020bb465d5de33715cfb109d71704b91f85db30c"
In LiteOS environment, RHash Demo runs as follows:
********Hello Huawei LiteOS******** LiteOS Kernel Version : 5.1.0 build data : Aug 12 2021 10:32:28 ********************************** OsAppInit cpu 0 entering scheduler app init! Hello, welcome to liteos demo! RHash demo start to run. Original md5: 7990beea258031735be06254cea58a89 RHash calculate md5: 7990beea258031735be06254cea58a89 Original sha256: d56910304664d3d3a439968b020bb465d5de33715cfb109d71704b91f85db30c RHash calculate sha256: d56910304664d3d3a439968b020bb465d5de33715cfb109d71704b91f85db30c RHash demo finished. Huawei LiteOS #
It can be seen from the above routine that the hash value calculated by RHash is completely consistent with the calculation results of similar tools on linux platform.
Click focus to learn about Huawei cloud's new technologies for the first time~