#ifndef SIGSUM_CRYPTO_H_INCLUDED
#define SIGSUM_CRYPTO_H_INCLUDED

#include <stdint.h>
#include <stdlib.h>

typedef uint64_t sigsum_size_t;

/* Sigsum uses SHA256 hashing. */
#define SIGSUM_DIGEST_SIZE 32

struct sigsum_hash
{
  uint8_t h[SIGSUM_DIGEST_SIZE];
};

/* Sigsum uses Ed25519 signatures. */
#define SIGSUM_PUBKEY_SIZE 32
#define SIGSUM_SIGNATURE_SIZE 64

struct sigsum_pubkey
{
  uint8_t k[SIGSUM_PUBKEY_SIZE];
};

struct sigsum_signature
{
  uint8_t s[SIGSUM_SIGNATURE_SIZE];
};

struct sigsum_cosignature
{
  uint64_t timestamp; /* At most 63 bits. */
  struct sigsum_hash key_hash;
  struct sigsum_signature signature;
};

/* A public key and its hash. Intended to aid lookup of keys by hash,
   e.g., to match a cosignature key hash to the corresponding witness
   public key. */
struct sigsum_key_with_hash
{
  struct sigsum_pubkey key;
  struct sigsum_hash hash;
};

/* Looks up a public key by key hash. Returns index, or (size_t) -1 if
   not found. The input list must be sorted by key hash. */
size_t
sigsum_keyhash_lookup (size_t n, const struct sigsum_key_with_hash *keys,
		       const struct sigsum_hash *key_hash);

/* Computes the key hash for a public key. */
void
sigsum_hash_key (struct sigsum_hash *kh, const struct sigsum_pubkey *key);

#endif /* SIGSUM_CRYPTO_H_INCLUDED */
