Skip to content

Commit f896250

Browse files
committed
sample: Add HMAC
Add a HMAC sample code. Signed-off-by: Yasushi SHOJI <[email protected]>
1 parent ce47437 commit f896250

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

samples/posix/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
add_subdirectory(simple-send-canbus)
22
add_subdirectory(simple-send-usart)
3+
add_subdirectory(hmac)

samples/posix/hmac/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_executable(sample-hmac EXCLUDE_FROM_ALL src/main.c)
2+
target_include_directories(sample-hmac PRIVATE ${csp_inc})
3+
target_link_libraries(sample-hmac PRIVATE csp)

samples/posix/hmac/src/main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <csp/csp.h>
2+
#include <csp/csp_debug.h>
3+
#include <csp/csp_id.h>
4+
#include <csp/crypto/csp_hmac.h>
5+
6+
int main(int argc, char * argv[])
7+
{
8+
csp_packet_t * packet;
9+
10+
csp_init();
11+
12+
packet = csp_buffer_get_always();
13+
14+
csp_id_prepend(packet);
15+
16+
memcpy(packet->data, "abc", 3);
17+
packet->length += 3;
18+
packet->frame_length += 3;
19+
20+
csp_hmac_append(packet, true);
21+
csp_hmac_verify(packet, true);
22+
23+
return 0;
24+
}

0 commit comments

Comments
 (0)