K230 SHA256 API reference#
Function introduction#
SHA256 is mainly used to calculate the hash value of data. The SHA256 algorithm is implemented in the large core rt-smart and is used to calculate the hash value of data. The code logic is shown in the figure below:

API Reference#
The SHA256 module mainly provides the following APIs:
kd_mpi_cipher_sha256#
Description
Calculate the hash value of the message based on the incoming message.
Syntax
kd_mpi_cipher_sha256(const void *data, k_u32 len, k_u8 *hash);
Parameters
Parameter Name |
Description |
Input/Output |
|---|---|---|
data |
incoming message |
Input |
len |
The length of the incoming message |
Input |
hash |
The calculated hash value |
Output |
Return Value
Return Value |
Description |
|---|---|
0 |
success. |
Not 0 |
Failure, refer to error code definition |
Chip differences
None
Requirements
Header File: mpi_cipher_api.h
Library File: libcipher.a
Notes
None
Example
None
Related Topics
None
Debugging and printing information#
Write a userland application sample_hash.c to test the SHA256 functionality.
The test code has been written and is located in the src/rtsmart/examples/mpp/sample_cipher/sample_hash directory. The specific debugging method is as follows:
After the big core is started, enter the bin directory;
Run the sample_hash.elf program;
Print information.
The specific printing information is as follows:
msh />cd bin/
msh /bin>./sample_hash.elf
input = ''
digest: e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855
result: PASS
input = 'abc'
digest: ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad
result: PASS
input = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
digest: 248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6ecedd4 19db06c1
result: PASS
input = 'The quick brown fox jumps over the lazy dog'
digest: d7a8fbb3 07d78094 69ca9abc b0082e4f 8d5651e4 6d3cdb76 2d02d0bf 37c9e592
result: PASS
input = 'The quick brown fox jumps over the lazy cog'
digest: e4c4d8f3 bf76b692 de791a17 3e053211 50f7a345 b46484fe 427f6acc 7ecc81be
result: PASS
input = 'bhn5bjmoniertqea40wro2upyflkydsibsk8ylkmgbvwi420t44cq034eou1szc1k0mk46oeb7ktzmlxqkbte2sy'
digest: 9085df2f 02e0cc45 5928d0f5 1b27b4bf 1d9cd260 a66ed1fd a11b0a3f f5756d99
result: PASS
