diff options
author | Yawning Angel <yawning@schwanenlied.me> | 2015-12-18 21:15:52 +0000 |
---|---|---|
committer | Yawning Angel <yawning@schwanenlied.me> | 2015-12-19 22:34:39 +0000 |
commit | 18685df031b4d5c0f1f0b20394d3d7f64d155cb4 (patch) | |
tree | 474c232e8642e0e482dc33ad087294f2ce64e6e0 /src/ext/keccak-tiny/keccak-tiny.h | |
parent | e993003792f4905db9d6271c809c708b2e9f8cf4 (diff) | |
download | tor-18685df031b4d5c0f1f0b20394d3d7f64d155cb4.tar.gz tor-18685df031b4d5c0f1f0b20394d3d7f64d155cb4.zip |
Expose an incremental API in addition to the one-shot routines.
The digest routines use init/update/sum, where sum will automatically
copy the internal state to support calculating running digests.
The XOF routines use init/absorb/squeeze, which behave exactly as stated
on the tin.
Diffstat (limited to 'src/ext/keccak-tiny/keccak-tiny.h')
-rw-r--r-- | src/ext/keccak-tiny/keccak-tiny.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/ext/keccak-tiny/keccak-tiny.h b/src/ext/keccak-tiny/keccak-tiny.h index c4c678e874..04044cdc64 100644 --- a/src/ext/keccak-tiny/keccak-tiny.h +++ b/src/ext/keccak-tiny/keccak-tiny.h @@ -4,6 +4,53 @@ #include <stdint.h> #include <stdlib.h> +#define KECCAK_MAX_RATE 200 + +/* Calculate the rate (block size) from the security target. */ +#define KECCAK_RATE(bits) (KECCAK_MAX_RATE - (bits / 4)) + +/* The internal structure of a FIPS202 hash/xof instance. Most callers + * should treat this as an opaque structure. + */ +typedef struct keccak_state { + uint8_t a[KECCAK_MAX_RATE]; + size_t rate; + uint8_t delim; + + uint8_t block[KECCAK_MAX_RATE]; + size_t offset; + + uint8_t finalized : 1; +} keccak_state; + +/* Initialize a Keccak instance suitable for SHA-3 hash functions. */ +int keccak_digest_init(keccak_state *s, size_t bits); + +/* Feed more data into the SHA-3 hash instance. */ +int keccak_digest_update(keccak_state *s, const uint8_t *buf, size_t len); + +/* Calculate the SHA-3 hash digest. The state is unmodified to support + * calculating multiple/rolling digests. + */ +int keccak_digest_sum(const keccak_state *s, uint8_t *out, size_t outlen); + +/* Initialize a Keccak instance suitable for XOFs (SHAKE-128/256). */ +int keccak_xof_init(keccak_state *s, size_t bits); + +/* Absorb more data into the XOF. Must not be called after a squeeze call. */ +int keccak_xof_absorb(keccak_state *s, const uint8_t *buf, size_t len); + +/* Squeeze data out of the XOF. Must not attempt to absorb additional data, + * after a squeeze has been called. + */ +int keccak_xof_squeeze(keccak_state *s, uint8_t *out, size_t outlen); + +/* Clone an existing hash/XOF instance. */ +void keccak_clone(keccak_state *out, const keccak_state *in); + +/* Cleanse sensitive data from a given hash instance. */ +void keccak_cleanse(keccak_state *s); + #define decshake(bits) \ int shake##bits(uint8_t*, size_t, const uint8_t*, size_t); |