==> src/view_pipedemo.c <==1/* @ajax/mesh-abi-view-pipedemo: its tables and functions. */
2#include "mesh/abi/view_pipedemo.h"
3
4void mesh_pipedemo_msg(uint32_t seq, uint64_t stamp, uint32_t origin, uint32_t out[16]) {
5 out[MESH_PIPEDEMO_R_SEQ] = seq;
6 out[MESH_PIPEDEMO_R_STAMP_LO] = (uint32_t)stamp;
7 out[MESH_PIPEDEMO_R_STAMP_HI] = (uint32_t)(stamp >> 32);
8 out[MESH_PIPEDEMO_R_ORIGIN] = origin;
9 for (size_t i = MESH_PIPEDEMO_R_PAYLOAD; i < 16; i++) out[i] = mesh_pipedemo_payload(seq, i);
10}
11
12static uint32_t swap_bytes(uint32_t x) { return x >> 24 | (x >> 8 & 0xff00u) | (x << 8 & 0xff0000u) | x << 24; }
13
14void mesh_pipedemo_sha256d_msg(const uint32_t m[16], uint32_t out[8]) {
15 uint32_t h[8], w[16], pad[16] = {0}, w2[16] = {0};
16 for (int i = 0; i < 8; i++) h[i] = SHA256_H0[i];
17 for (int i = 0; i < 16; i++) w[i] = swap_bytes(m[i]);
18 sha256_compress(h, w);
19 pad[0] = 0x80000000u;
20 pad[15] = 512;
21 sha256_compress(h, pad);
22 for (int j = 0; j < 8; j++) w2[j] = h[j];
23 w2[8] = 0x80000000u;
24 w2[15] = 256;
25 for (int i = 0; i < 8; i++) out[i] = SHA256_H0[i];
26 sha256_compress(out, w2);
27}
28
29void mesh_pipedemo_digest(const uint32_t m[16], uint32_t path, uint32_t out[12]) {
30 uint32_t d[8];
31 mesh_pipedemo_sha256d_msg(m, d);
32 out[MESH_PIPEDEMO_R_SEQ] = m[MESH_PIPEDEMO_R_SEQ];
33 out[MESH_PIPEDEMO_R_STAMP_LO] = m[MESH_PIPEDEMO_R_STAMP_LO];
34 out[MESH_PIPEDEMO_R_STAMP_HI] = m[MESH_PIPEDEMO_R_STAMP_HI];
35 out[MESH_PIPEDEMO_R_ORIGIN] = m[MESH_PIPEDEMO_R_ORIGIN] | path;
36 for (int i = 0; i < 8; i++) out[MESH_PIPEDEMO_R_PAYLOAD + i] = d[i];
37}