helper/command: simplify exec_command()
[openocd.git] / src / helper / crc32.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 /***************************************************************************
4 * Copyright (C) 2013-2014 by Franck Jullien *
5 * elec4fun@gmail.com *
6 * *
7 * Copyright (C) 2022 Otto-von-Guericke-Universität Magdeburg *
8 * marian.buschsieweke@ovgu.de *
9 ***************************************************************************/
10
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14
15 #include "crc32.h"
16 #include <stdint.h>
17 #include <stddef.h>
18
19 static uint32_t crc_le_step(uint32_t poly, uint32_t crc, uint32_t data_in,
20 unsigned int data_bits)
21 {
22 for (unsigned int i = 0; i < data_bits; i++) {
23 uint32_t d, c;
24 d = ((data_in >> i) & 0x1) ? 0xffffffff : 0;
25 c = (crc & 0x1) ? 0xffffffff : 0;
26 crc = crc >> 1;
27 crc = crc ^ ((d ^ c) & poly);
28 }
29
30 return crc;
31 }
32
33 uint32_t crc32_le(uint32_t poly, uint32_t seed, const void *_data,
34 size_t data_len)
35 {
36 if (((uintptr_t)_data & 0x3) || (data_len & 0x3)) {
37 /* data is unaligned, processing data one byte at a time */
38 const uint8_t *data = _data;
39 for (size_t i = 0; i < data_len; i++)
40 seed = crc_le_step(poly, seed, data[i], 8);
41 } else {
42 /* data is aligned, processing 32 bit at a time */
43 data_len >>= 2;
44 const uint32_t *data = _data;
45 for (size_t i = 0; i < data_len; i++)
46 seed = crc_le_step(poly, seed, data[i], 32);
47 }
48
49 return seed;
50 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)