host/stream_comm.c
/** nanopb field callback which calculates the double SHA-256 of an arbitrary
  * number of bytes. This is useful if we don't care about the contents of a
  * field but want to compress an arbitrarily-sized field into a fixed-length
  * variable.
  * \param stream Input stream to read from.
  * \param field Field which contains an arbitrary number of bytes.
  * \param arg Unused.
  * \return true on success, false on failure (nanopb convention).
  */
nanopb field callback which calculates the double SHA-256 of an arbitrary
number of bytes. This is useful if we don't care about the contents of a
field but want to compress an arbitrarily-sized field into a fixed-length
variable.
\param stream Input stream to read from.
\param field Field which contains an arbitrary number of bytes.
\param arg Unused.
\return true on success, false on failure (nanopb convention).
nanopb field callback which calculates the double SHA - 256 of an arbitrary number of bytes . This is useful if we don ' t care about the contents of a field but want to compress an arbitrarily - sized field into a fixed - length variable . \ param stream Input stream to read from . \ param field Field which contains an arbitrary number of bytes . \ param arg Unused . \ return true on success false on failure ( nanopb convention ) .
bool hashFieldCallback(pb_istream_t *stream, const pb_field_t *field, void **arg)
{
	uint8_t one_byte;
	uint32_t hs[8];
	sha256BeginTZ(1);
	while (stream->bytes_left > 0)
    {
		if (!pb_read(stream, &one_byte, 1))
			return false;
        sha256WriteTZ(&one_byte, (uint32_t)1, 1);
    }
	sha256FinishDoubleTZ(hs, (uint32_t)32, 1);
	writeHashToByteArrayTZ(field_hash, hs, true);
	field_hash_set = true;
    return true;
}
bool hashFieldCallback ( pb_istream_t * stream , const pb_field_t * field , void * * arg ) { uint8_t one_byte ; uint32_t hs [ 8 ] ; sha256BeginTZ ( 1 ) ; while ( stream -> bytes_left > 0 ) { if ( ! pb_read ( stream , & one_byte , 1 ) ) return false ; sha256WriteTZ ( & one_byte , ( uint32_t ) 1 , 1 ) ; } sha256FinishDoubleTZ ( hs , ( uint32_t ) 32 , 1 ) ; writeHashToByteArrayTZ ( field_hash , hs , true ) ; field_hash_set = true ; return true ; }
nanopb field callback which calculates the double SHA-256 of an arbitrary
 number of bytes.
nanopb field callback which calculates the double SHA - 256 of an arbitrary number of bytes .
//HashState hs; //sha256Begin(&hs); //sha256WriteByte(&hs, one_byte); //sha256FinishDouble(&hs); //writeHashToByteArray(field_hash, &hs, true);