Files
roro9stack/lib/ota/src/sha256.h
T
twislaandClaude Opus 5.5 326e864264 OTA step 1: Update File format and streaming parser (host-tested)
lib/ota: a 160-byte header (magic, format, image size and SHA-256,
version, ECDSA signature over the first 80 bytes) then the image.
UpdateParser checks the header and signature before writing anything,
hashes the image as it streams into an UpdateSink, and only finishes
the sink when the hash matches. Downgrades are flagged, not refused.
Includes a dependency-free SHA-256 and semver comparison.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-03 21:30:13 +02:00

31 lines
634 B
C++

#pragma once
#include <cstddef>
#include <cstdint>
namespace roro {
// Plain SHA-256 (FIPS 180-4), streaming. Small and dependency-free, so the same code runs in the
// PC tests and on the device.
class Sha256 {
public:
Sha256();
void update(const uint8_t* data, size_t len);
void finish(uint8_t out[32]);
static void hash(const uint8_t* data, size_t len, uint8_t out[32]) {
Sha256 s;
s.update(data, len);
s.finish(out);
}
private:
void block(const uint8_t* p);
uint32_t h_[8];
uint8_t buf_[64];
size_t used_ = 0;
uint64_t bits_ = 0;
};
} // namespace roro