43 #ifndef HAVE_MAVLINK_SHA256 45 #ifdef MAVLINK_USE_CXX_NAMESPACE 49 #ifndef MAVLINK_HELPER 50 #define MAVLINK_HELPER 57 unsigned char save_bytes[64];
58 uint32_t save_u32[16];
62 #define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) 63 #define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) 65 #define ROTR(x,n) (((x)>>(n)) | ((x) << (32 - (n)))) 67 #define Sigma0(x) (ROTR(x,2) ^ ROTR(x,13) ^ ROTR(x,22)) 68 #define Sigma1(x) (ROTR(x,6) ^ ROTR(x,11) ^ ROTR(x,25)) 69 #define sigma0(x) (ROTR(x,7) ^ ROTR(x,18) ^ ((x)>>3)) 70 #define sigma1(x) (ROTR(x,17) ^ ROTR(x,19) ^ ((x)>>10)) 72 #define A m->counter[0] 73 #define B m->counter[1] 74 #define C m->counter[2] 75 #define D m->counter[3] 76 #define E m->counter[4] 77 #define F m->counter[5] 78 #define G m->counter[6] 79 #define H m->counter[7] 82 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
83 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
84 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
85 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
86 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
87 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
88 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
89 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
90 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
91 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
92 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
93 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
94 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
95 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
96 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
97 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
116 uint32_t AA, BB, CC, DD, EE, FF, GG, HH;
129 for (i = 0; i < 16; ++i)
131 for (i = 16; i < 64; ++i)
132 data[i] =
sigma1(data[i-2]) + data[i-7] +
133 sigma0(data[i-15]) + data[i - 16];
135 for (i = 0; i < 64; i++) {
138 T1 = HH +
Sigma1(EE) +
Ch(EE, FF, GG) + mavlink_sha256_constant_256[i] + data[i];
163 const unsigned char *p = (
const unsigned char *)v;
164 uint32_t old_sz = m->
sz[0];
168 if (m->
sz[0] < old_sz)
170 offset = (old_sz / 8) % 64;
172 uint32_t
l = 64 - offset;
182 uint32_t current[16];
184 for (i = 0; i < 16; i++){
185 const uint8_t *
p1 = (
const uint8_t *)&u[i];
186 uint8_t *
p2 = (uint8_t *)¤t[i];
203 unsigned char zeros[72];
204 unsigned offset = (m->
sz[0] / 8) % 64;
205 unsigned int dstart = (120 - offset - 1) % 64 + 1;
206 uint8_t *p = (uint8_t *)&m->
counter[0];
209 memset (zeros + 1, 0,
sizeof(zeros) - 1);
210 zeros[dstart+7] = (m->
sz[0] >> 0) & 0xff;
211 zeros[dstart+6] = (m->
sz[0] >> 8) & 0xff;
212 zeros[dstart+5] = (m->
sz[0] >> 16) & 0xff;
213 zeros[dstart+4] = (m->
sz[0] >> 24) & 0xff;
214 zeros[dstart+3] = (m->
sz[1] >> 0) & 0xff;
215 zeros[dstart+2] = (m->
sz[1] >> 8) & 0xff;
216 zeros[dstart+1] = (m->
sz[1] >> 16) & 0xff;
217 zeros[dstart+0] = (m->
sz[1] >> 24) & 0xff;
248 #ifdef MAVLINK_USE_CXX_NAMESPACE 252 #endif // HAVE_MAVLINK_SHA256
MAVLINK_HELPER void mavlink_sha256_init(mavlink_sha256_ctx *m)
unsigned char save_bytes[64]
union mavlink_sha256_ctx::@2 u
static void mavlink_sha256_calc(mavlink_sha256_ctx *m, uint32_t *in)
MAVLINK_HELPER void mavlink_sha256_update(mavlink_sha256_ctx *m, const void *v, uint32_t len)
MAVLINK_HELPER void mavlink_sha256_final_48(mavlink_sha256_ctx *m, uint8_t result[6])
static const uint32_t mavlink_sha256_constant_256[64]