Sha1¶
| Spice | |
|---|---|
Sha1 struct¶
SHA-1 message digest, as specified in RFC 3174.
SHA-1 is considered cryptographically broken: chosen-prefix collisions are computationally feasible. It is provided for interoperability with existing formats and protocols (git object ids, legacy certificates, older signature schemes) only. Never use it for new security-relevant work - reach for std/crypto/sha256 instead.
The digest is computed incrementally, so arbitrarily large messages can be fed in chunk by chunk:
spice Sha1 hasher; hasher.update("Hello, "); hasher.update("World!"); printf("%s\n", hasher.finalize().getRaw()); // 0a0a9f2a6772942557ab5355d76af442f8f65e01
For one-shot use, the free sha1 functions wrap the same steps in a single call.
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct a hasher that is ready to consume the first message byte
Methods¶
reset¶
| Spice | |
|---|---|
Discard any consumed input and return to the initial state, ready for a new message
update¶
| Spice | |
|---|---|
Feed the given raw bytes into the digest
Parameters
| Name | Type | Description |
|---|---|---|
data |
const byte[] |
Bytes to consume |
length |
unsigned long |
Number of bytes to consume |
update¶
| Spice | |
|---|---|
Feed the chars of the given raw string into the digest, excluding the null terminator
Parameters
| Name | Type | Description |
|---|---|---|
data |
string |
String to consume |
update¶
| Spice | |
|---|---|
Feed the chars of the given string into the digest
Parameters
| Name | Type | Description |
|---|---|---|
data |
const String& |
String to consume |
finalizeInto¶
| Spice | |
|---|---|
Complete the digest and write its 20 raw bytes to the given output array. The hasher is reset afterwards, so it can be reused for the next message.
Parameters
| Name | Type | Description |
|---|---|---|
digest |
byte[] |
Output array, that has to offer room for at least 20 bytes |
finalize¶
| Spice | |
|---|---|
Complete the digest and return it as a lowercase hex string. The hasher is reset afterwards, so it can be reused for the next message.
Returns: String — Digest as 40 lowercase hex chars
getDigestSize¶
| Spice | |
|---|---|
Retrieve the number of bytes a SHA-1 digest occupies
Returns: unsigned long — Digest size in bytes
getBlockSize¶
| Spice | |
|---|---|
Retrieve the number of bytes SHA-1 consumes per compression step
Returns: unsigned long — Block size in bytes
Functions¶
sha1¶
| Spice | |
|---|---|
Compute the SHA-1 digest of the given raw string
Parameters
| Name | Type | Description |
|---|---|---|
input |
string |
String to hash |
Returns: String — Digest as 40 lowercase hex chars
sha1¶
| Spice | |
|---|---|
Compute the SHA-1 digest of the given string
Parameters
| Name | Type | Description |
|---|---|---|
input |
const String& |
String to hash |
Returns: String — Digest as 40 lowercase hex chars
sha1¶
| Spice | |
|---|---|
Compute the SHA-1 digest of the given raw bytes
Parameters
| Name | Type | Description |
|---|---|---|
input |
const byte[] |
Bytes to hash |
length |
unsigned long |
Number of bytes to hash |
Returns: String — Digest as 40 lowercase hex chars