예제 #1
0
void
chacha_poly1305_digest (struct chacha_poly1305_ctx *ctx,
			size_t length, uint8_t *digest)
{
  uint8_t buf[8];
  if (!ctx->data_size)
    {
      LE_WRITE_UINT64 (buf, ctx->auth_size);
      poly1305_update (ctx, sizeof(buf), buf);
    }
  LE_WRITE_UINT64 (buf, ctx->data_size);
  poly1305_update (ctx, sizeof(buf), buf);

  /* Final bytes. FIXME: Duplicated in poly1305_aes128.c */
  if (ctx->index > 0)
    {
      assert (ctx->index < POLY1305_BLOCK_SIZE);

      ctx->block[ctx->index] = 1;
      memset (ctx->block + ctx->index + 1,
	      0, POLY1305_BLOCK_SIZE - 1 - ctx->index);

      _poly1305_block (&ctx->poly1305, ctx->block, 0);
    }
  
  poly1305_digest (&ctx->poly1305, &ctx->s);
  memcpy (digest, &ctx->s.b, length);
}
예제 #2
0
void
chacha_poly1305_digest (struct chacha_poly1305_ctx *ctx,
			size_t length, uint8_t *digest)
{
  uint8_t buf[16];

  poly1305_pad (ctx);
  LE_WRITE_UINT64 (buf, ctx->auth_size);
  LE_WRITE_UINT64 (buf + 8, ctx->data_size);

  _poly1305_block (&ctx->poly1305, buf, 1);

  poly1305_digest (&ctx->poly1305, &ctx->s);
  memcpy (digest, &ctx->s.b, length);
}
예제 #3
0
void
_nettle_write_le64(size_t length, uint8_t *dst,
		   uint64_t *src)
{
  size_t i;
  size_t words;
  unsigned leftover;
  
  words = length / 8;
  leftover = length % 8;

  for (i = 0; i < words; i++, dst += 8)
    LE_WRITE_UINT64(dst, src[i]);

  if (leftover)
    {
      uint64_t word;
      
      word = src[i];

      do
	{
	  *dst++ = word & 0xff;
	  word >>= 8;
	}
      while (--leftover);
    }
}
예제 #4
0
void
chacha_poly1305_encrypt (struct chacha_poly1305_ctx *ctx,
			 size_t length, uint8_t *dst, const uint8_t *src)
{
  if (!length)
    return;

  assert (ctx->data_size % CHACHA_POLY1305_BLOCK_SIZE == 0);
  if (!ctx->data_size)
    {
      uint8_t buf[8];
      LE_WRITE_UINT64 (buf, ctx->auth_size);
      poly1305_update (ctx, sizeof(buf), buf);
    }
  chacha_crypt (&ctx->chacha, length, dst, src);
  poly1305_update (ctx, length, dst);
  ctx->data_size += length;
}
예제 #5
0
void
ripemd160_digest(struct ripemd160_ctx *ctx, size_t length, uint8_t *digest)
{
  uint64_t bit_count;

  assert(length <= RIPEMD160_DIGEST_SIZE);

  MD_PAD(ctx, 8, COMPRESS);

  /* There are 2^9 bits in one block */
  bit_count = (ctx->count << 9) | (ctx->index << 3);
									\
  /* append the 64 bit count */
  LE_WRITE_UINT64(ctx->block + 56, bit_count);
  _nettle_ripemd160_compress(ctx->state, ctx->block);

  _nettle_write_le32(length, digest, ctx->state);
  ripemd160_init(ctx);
}
예제 #6
0
파일: md5.c 프로젝트: Distrotech/nettle
void
md5_digest(struct md5_ctx *ctx,
	   size_t length,
	   uint8_t *digest)
{
  uint64_t bit_count;
  
  assert(length <= MD5_DIGEST_SIZE);

  MD_PAD(ctx, 8, COMPRESS);

  /* There are 512 = 2^9 bits in one block */
  bit_count = (ctx->count << 9) | (ctx->index << 3);

  LE_WRITE_UINT64(ctx->block + (MD5_BLOCK_SIZE - 8), bit_count);
  _nettle_md5_compress(ctx->state, ctx->block);

  _nettle_write_le32(length, digest, ctx->state);
  md5_init(ctx);
}