Main docs: https://pigweed.dev/pw_crypto.
|
constexpr uint32_t | pw::crypto::sha256::kDigestSizeBytes = 32 |
| The size of a SHA256 digest in bytes.
|
|
◆ Sha256State
A state machine of a hashing session.
Enumerator |
---|
kReady | Initialized and accepting input (via Update() ).
|
kFinalized | Finalized by Final() . Any additional requests to Update() or Final() will trigger a transition to kError .
|
kError | In an unrecoverable error state.
|
◆ Final()
Finishes the hashing session and outputs the final digest in the first kDigestSizeBytes
of out_digest
. out_digest
must be at least kDigestSizeBytes
long.
Final()
locks down the Sha256
instance from any additional use.
Any error, including those occurring inside the constructor or Update()
will be reflected in the return value of Final()
.
◆ Hash()
Calculates the SHA256 digest of message
and stores the result in out_digest
. out_digest
must be at least kDigestSizeBytes
long.
One-shot digest example:
#include "pw_crypto/sha256.h"
std::byte digest[32];
}
}
Status Hash(ConstByteSpan message, ByteSpan out_digest)
Definition: sha256.h:167
Long, potentially non-contiguous message example:
#include "pw_crypto/sha256.h"
std::byte digest[32];
.Update(chunk1).Update(chunk2).Update(chunk...)
}
constexpr bool ok() const
Definition: status.h:158
Status Final(ByteSpan out_digest)
Definition: sha256.h:105
◆ Update()
Feeds data
to the running hasher. The feeding can involve zero or more Update()
calls and the order matters.
◆ VerifyP256Signature()
Verifies the signature
of digest
using public_key
.
Example:
#include "pw_crypto/sha256.h"
std::byte digest[32];
}
signature).ok()) {
}
Status VerifyP256Signature(ConstByteSpan public_key, ConstByteSpan digest, ConstByteSpan signature)
- Parameters
-
[in] | public_key | A byte string in SEC 1 uncompressed form (0x04||X||Y) , which is exactly 65 bytes. Compressed forms (02/03||X) may not be supported by some backends, e.g. Mbed TLS. |
[in] | digest | A raw byte string, truncated to 32 bytes. |
[in] | signature | A raw byte string (r||s) of exactly 64 bytes. |
- Returns
embed:rst:inline :c:enumerator:`OK`
for a successful verification, or an error Status
otherwise.