AllenNeuralDynamics / AllenNeuralDynamics/harp.device.quac

Compute SHA256 for Files written to the SD Card

Aperta
#27 0 commenti 0 reazioni 1 assegnatario Rivendicata da @anjaldoshi Vedi su GitHub
firmware
Lingua principale
C#
Stelle
0
Fork
0
Merge medio
2g 14h
PR unite (30g)
8

Descrizione

Because writing files to the SD card over Full Speed USB is slow (70-seconds for 4 waveforms!), it would be useful to store a small signature (a hash) instead. Then previously-uploaded files that persist across experiments need only be loaded once where we compare the hash of existing files first only upload if the hash is different.

Thankfully, the RP2350 has a built-in SHA256 calculator that can take an arbitrary stream of bytes and compute a SHA256 hash from it. (See [datasheet](https://pip-assets.raspberrypi.com/categories/1214-rp2350/documents/RP-008373-DS-2-rp2350-datasheet.pdf?disposition=inline) section 12.13: SHA-256 accelerator.) It's also fast, being able to compute hashes at 79.3 MB/s from a 150MHz system clock.

Let's figure out how to use this hashing peripheral to produce a SHA256 hash of an uploaded waveform upon write. Ideally, we write bytes both to the SD card and to the SHA256-calculator concurrently using DMA, so that we can produce the hash on-the-fly without needing to re-read the file. Hashes should persist as long as the files persist, so we should change them when we write new channel data. We can store these hashes as separate files, maybe `channel_x_sha256.bin`, on the SD card along with the data.

## Proposed Pipeline

Image

## Pico Implementation
It looks like the Pico SDK takes care of most of the complexity for you. Here's
* an [example](https://github.com/raspberrypi/pico-examples/blob/master/sha/sha256/hello_sha256.c)
* the pico sdk [documentation](https://www.raspberrypi.com/documentation/pico-sdk/high_level.html#functions-14)

## Message Padding Details
While the input to the hash calculator can be an arbitrary length of bytes, the hash algorithm works on multiples of 64 bytes (512 bits). To pad out a message to the correct multiple, terminate the message with a single 1 bit and 7 or more zeros to pad out the result to 56 bytes. Then attach the length of the message as a 64-bit number at the end. (Note that we are working in bytes, but the algorithm described in the spec is written with the flexibility to enable you work with bits).

More deets in the [spec](https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.180-4.pdf) here:

Image

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.