#include <nettle/eddsa.h>
#include <nettle/version.h>

#include "crypto-internal.h"

void
_sigsum_hash_init (struct sigsum_hash_ctx *ctx)
{
  sha256_init (&ctx->sha256);
}

void
_sigsum_hash_update (struct sigsum_hash_ctx *ctx, size_t size, const uint8_t *data)
{
  sha256_update (&ctx->sha256, size, data);
}

void
_sigsum_hash_digest (struct sigsum_hash_ctx *ctx, struct sigsum_hash *digest)
{
#if NETTLE_VERSION_MAJOR < 4
  sha256_digest (&ctx->sha256, SHA256_DIGEST_SIZE, digest->h);
#else
  sha256_digest (&ctx->sha256, digest->h);
#endif
}

bool
_sigsum_signature_verify (const struct sigsum_pubkey *pub,
			  size_t msg_size, const uint8_t *msg,
			  const struct sigsum_signature *signature)
{
  return ed25519_sha512_verify (pub->k, msg_size, msg, signature->s);
}
