tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

keccak-tiny.h (1954B)


      1 #ifndef KECCAK_FIPS202_H
      2 #define KECCAK_FIPS202_H
      3 
      4 #include <stddef.h>
      5 #include "lib/cc/torint.h"
      6 
      7 #define KECCAK_MAX_RATE 200
      8 
      9 /* Calculate the rate (block size) from the security target. */
     10 #define KECCAK_RATE(bits) (KECCAK_MAX_RATE - (bits / 4))
     11 
     12 /* The internal structure of a FIPS202 hash/xof instance.  Most callers
     13 * should treat this as an opaque structure.
     14 */
     15 typedef struct keccak_state {
     16  uint8_t a[KECCAK_MAX_RATE];
     17  size_t rate;
     18  uint8_t delim;
     19 
     20  uint8_t block[KECCAK_MAX_RATE];
     21  size_t offset;
     22 
     23  uint8_t finalized : 1;
     24 } __attribute__((aligned(8))) keccak_state;
     25 
     26 /* Initialize a Keccak instance suitable for SHA-3 hash functions. */
     27 int keccak_digest_init(keccak_state *s, size_t bits);
     28 
     29 /* Feed more data into the SHA-3 hash instance. */
     30 int keccak_digest_update(keccak_state *s, const uint8_t *buf, size_t len);
     31 
     32 /* Calculate the SHA-3 hash digest.  The state is unmodified to support
     33 * calculating multiple/rolling digests.
     34 */
     35 int keccak_digest_sum(const keccak_state *s, uint8_t *out, size_t outlen);
     36 
     37 /* Initialize a Keccak instance suitable for XOFs (SHAKE-128/256). */
     38 int keccak_xof_init(keccak_state *s, size_t bits);
     39 
     40 /* Absorb more data into the XOF.  Must not be called after a squeeze call. */
     41 int keccak_xof_absorb(keccak_state *s, const uint8_t *buf, size_t len);
     42 
     43 /* Squeeze data out of the XOF. Must not attempt to absorb additional data,
     44 * after a squeeze has been called.
     45 */
     46 int keccak_xof_squeeze(keccak_state *s, uint8_t *out, size_t outlen);
     47 
     48 /* Clone an existing hash/XOF instance. */
     49 void keccak_clone(keccak_state *out, const keccak_state *in);
     50 
     51 /* Cleanse sensitive data from a given hash instance. */
     52 void keccak_cleanse(keccak_state *s);
     53 
     54 #define decshake(bits) \
     55  int shake##bits(uint8_t*, size_t, const uint8_t*, size_t);
     56 
     57 #define decsha3(bits) \
     58  int sha3_##bits(uint8_t*, size_t, const uint8_t*, size_t);
     59 
     60 decshake(128)
     61 decshake(256)
     62 decsha3(224)
     63 decsha3(256)
     64 decsha3(384)
     65 decsha3(512)
     66 #endif