|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2011-2012 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
* Portions Copyright (C) 2001 Niels Moeller
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Nikos Mavrogiannopoulos
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GNUTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The GNUTLS library is free software; you can redistribute it and/or
|
|
Packit Service |
4684c1 |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
4684c1 |
* the License, or (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This library is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* Lesser General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "gnutls_int.h"
|
|
Packit Service |
4684c1 |
#include <hash_int.h>
|
|
Packit Service |
4684c1 |
#include "errors.h"
|
|
Packit Service |
4684c1 |
#include <nettle/sha.h>
|
|
Packit Service |
4684c1 |
#include <nettle/hmac.h>
|
|
Packit Service |
4684c1 |
#include <nettle/macros.h>
|
|
Packit Service |
4684c1 |
#include <aes-padlock.h>
|
|
Packit Service |
4684c1 |
#include <assert.h>
|
|
Packit Service |
4684c1 |
#include <sha-padlock.h>
|
|
Packit Service |
4684c1 |
#include <x86-common.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef HAVE_LIBNETTLE
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
typedef void (*update_func) (void *, size_t, const uint8_t *);
|
|
Packit Service |
4684c1 |
typedef void (*digest_func) (void *, size_t, uint8_t *);
|
|
Packit Service |
4684c1 |
typedef void (*set_key_func) (void *, size_t, const uint8_t *);
|
|
Packit Service |
4684c1 |
typedef void (*init_func) (void *);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
struct padlock_hash_ctx {
|
|
Packit Service |
4684c1 |
union {
|
|
Packit Service |
4684c1 |
struct sha1_ctx sha1;
|
|
Packit Service |
4684c1 |
struct sha224_ctx sha224;
|
|
Packit Service |
4684c1 |
struct sha256_ctx sha256;
|
|
Packit Service |
4684c1 |
struct sha384_ctx sha384;
|
|
Packit Service |
4684c1 |
struct sha512_ctx sha512;
|
|
Packit Service |
4684c1 |
} ctx;
|
|
Packit Service |
4684c1 |
void *ctx_ptr;
|
|
Packit Service |
4684c1 |
gnutls_digest_algorithm_t algo;
|
|
Packit Service |
4684c1 |
size_t length;
|
|
Packit Service |
4684c1 |
update_func update;
|
|
Packit Service |
4684c1 |
digest_func digest;
|
|
Packit Service |
4684c1 |
init_func init;
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int
|
|
Packit Service |
4684c1 |
wrap_padlock_hash_update(void *_ctx, const void *text, size_t textsize)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
struct padlock_hash_ctx *ctx = _ctx;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ctx->update(ctx->ctx_ptr, textsize, text);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return GNUTLS_E_SUCCESS;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void wrap_padlock_hash_deinit(void *hd)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
gnutls_free(hd);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define MD1_INCR(c) (c->count++)
|
|
Packit Service |
4684c1 |
#define SHA1_COMPRESS(ctx, data) (padlock_sha1_blocks((void*)(ctx)->state, data, 1))
|
|
Packit Service |
4684c1 |
#define SHA256_COMPRESS(ctx, data) (padlock_sha256_blocks((void*)(ctx)->state, data, 1))
|
|
Packit Service |
4684c1 |
#define SHA512_COMPRESS(ctx, data) (padlock_sha512_blocks((void*)(ctx)->state, data, 1))
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void
|
|
Packit Service |
4684c1 |
padlock_sha1_update(struct sha1_ctx *ctx,
|
|
Packit Service |
4684c1 |
size_t length, const uint8_t * data)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
MD_UPDATE(ctx, length, data, SHA1_COMPRESS, MD1_INCR(ctx));
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void
|
|
Packit Service |
4684c1 |
padlock_sha256_update(struct sha256_ctx *ctx,
|
|
Packit Service |
4684c1 |
size_t length, const uint8_t * data)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
MD_UPDATE(ctx, length, data, SHA256_COMPRESS, MD1_INCR(ctx));
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void
|
|
Packit Service |
4684c1 |
padlock_sha512_update(struct sha512_ctx *ctx,
|
|
Packit Service |
4684c1 |
size_t length, const uint8_t * data)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
MD_UPDATE(ctx, length, data, SHA512_COMPRESS, MD_INCR(ctx));
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void
|
|
Packit Service |
4684c1 |
_nettle_write_be32(unsigned length, uint8_t * dst, uint32_t * src)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
unsigned i;
|
|
Packit Service |
4684c1 |
unsigned words;
|
|
Packit Service |
4684c1 |
unsigned leftover;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
words = length / 4;
|
|
Packit Service |
4684c1 |
leftover = length % 4;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
for (i = 0; i < words; i++, dst += 4)
|
|
Packit Service |
4684c1 |
WRITE_UINT32(dst, src[i]);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (leftover) {
|
|
Packit Service |
4684c1 |
uint32_t word;
|
|
Packit Service |
4684c1 |
unsigned j = leftover;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
word = src[i];
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
switch (leftover) {
|
|
Packit Service |
4684c1 |
default:
|
|
Packit Service |
4684c1 |
abort();
|
|
Packit Service |
4684c1 |
case 3:
|
|
Packit Service |
4684c1 |
dst[--j] = (word >> 8) & 0xff;
|
|
Packit Service |
4684c1 |
FALLTHROUGH;
|
|
Packit Service |
4684c1 |
case 2:
|
|
Packit Service |
4684c1 |
dst[--j] = (word >> 16) & 0xff;
|
|
Packit Service |
4684c1 |
FALLTHROUGH;
|
|
Packit Service |
4684c1 |
case 1:
|
|
Packit Service |
4684c1 |
dst[--j] = (word >> 24) & 0xff;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void
|
|
Packit Service |
4684c1 |
padlock_sha1_digest(struct sha1_ctx *ctx,
|
|
Packit Service |
4684c1 |
size_t length, uint8_t * digest)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
uint64_t bit_count;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
assert(length <= SHA1_DIGEST_SIZE);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
MD_PAD(ctx, 8, SHA1_COMPRESS);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* There are 512 = 2^9 bits in one block */
|
|
Packit Service |
4684c1 |
bit_count = (ctx->count << 9) | (ctx->index << 3);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* append the 64 bit count */
|
|
Packit Service |
4684c1 |
WRITE_UINT64(ctx->block + (SHA1_BLOCK_SIZE - 8), bit_count);
|
|
Packit Service |
4684c1 |
SHA1_COMPRESS(ctx, ctx->block);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
_nettle_write_be32(length, digest, ctx->state);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void
|
|
Packit Service |
4684c1 |
padlock_sha256_digest(struct sha256_ctx *ctx,
|
|
Packit Service |
4684c1 |
size_t length, uint8_t * digest)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
uint64_t bit_count;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
assert(length <= SHA256_DIGEST_SIZE);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
MD_PAD(ctx, 8, SHA256_COMPRESS);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* There are 512 = 2^9 bits in one block */
|
|
Packit Service |
4684c1 |
bit_count = (ctx->count << 9) | (ctx->index << 3);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* This is slightly inefficient, as the numbers are converted to
|
|
Packit Service |
4684c1 |
big-endian format, and will be converted back by the compression
|
|
Packit Service |
4684c1 |
function. It's probably not worth the effort to fix this. */
|
|
Packit Service |
4684c1 |
WRITE_UINT64(ctx->block + (SHA256_BLOCK_SIZE - 8), bit_count);
|
|
Packit Service |
4684c1 |
SHA256_COMPRESS(ctx, ctx->block);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
_nettle_write_be32(length, digest, ctx->state);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void
|
|
Packit Service |
4684c1 |
padlock_sha512_digest(struct sha512_ctx *ctx,
|
|
Packit Service |
4684c1 |
size_t length, uint8_t * digest)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
uint64_t high, low;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
unsigned i;
|
|
Packit Service |
4684c1 |
unsigned words;
|
|
Packit Service |
4684c1 |
unsigned leftover;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
assert(length <= SHA512_DIGEST_SIZE);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
MD_PAD(ctx, 16, SHA512_COMPRESS);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* There are 1024 = 2^10 bits in one block */
|
|
Packit Service |
4684c1 |
high = (ctx->count_high << 10) | (ctx->count_low >> 54);
|
|
Packit Service |
4684c1 |
low = (ctx->count_low << 10) | (ctx->index << 3);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* This is slightly inefficient, as the numbers are converted to
|
|
Packit Service |
4684c1 |
big-endian format, and will be converted back by the compression
|
|
Packit Service |
4684c1 |
function. It's probably not worth the effort to fix this. */
|
|
Packit Service |
4684c1 |
WRITE_UINT64(ctx->block + (SHA512_DATA_SIZE - 16), high);
|
|
Packit Service |
4684c1 |
WRITE_UINT64(ctx->block + (SHA512_DATA_SIZE - 8), low);
|
|
Packit Service |
4684c1 |
SHA512_COMPRESS(ctx, ctx->block);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
words = length / 8;
|
|
Packit Service |
4684c1 |
leftover = length % 8;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
for (i = 0; i < words; i++, digest += 8)
|
|
Packit Service |
4684c1 |
WRITE_UINT64(digest, ctx->state[i]);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (leftover) {
|
|
Packit Service |
4684c1 |
/* Truncate to the right size */
|
|
Packit Service |
4684c1 |
uint64_t word = ctx->state[i] >> (8 * (8 - leftover));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
do {
|
|
Packit Service |
4684c1 |
digest[--leftover] = word & 0xff;
|
|
Packit Service |
4684c1 |
word >>= 8;
|
|
Packit Service |
4684c1 |
} while (leftover);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int _ctx_init(gnutls_digest_algorithm_t algo,
|
|
Packit Service |
4684c1 |
struct padlock_hash_ctx *ctx)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
switch (algo) {
|
|
Packit Service |
4684c1 |
case GNUTLS_DIG_SHA1:
|
|
Packit Service |
4684c1 |
sha1_init(&ctx->ctx.sha1);
|
|
Packit Service |
4684c1 |
ctx->update = (update_func) padlock_sha1_update;
|
|
Packit Service |
4684c1 |
ctx->digest = (digest_func) padlock_sha1_digest;
|
|
Packit Service |
4684c1 |
ctx->init = (init_func) sha1_init;
|
|
Packit Service |
4684c1 |
ctx->ctx_ptr = &ctx->ctx.sha1;
|
|
Packit Service |
4684c1 |
ctx->length = SHA1_DIGEST_SIZE;
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
case GNUTLS_DIG_SHA224:
|
|
Packit Service |
4684c1 |
sha224_init(&ctx->ctx.sha224);
|
|
Packit Service |
4684c1 |
ctx->update = (update_func) padlock_sha256_update;
|
|
Packit Service |
4684c1 |
ctx->digest = (digest_func) padlock_sha256_digest;
|
|
Packit Service |
4684c1 |
ctx->init = (init_func) sha224_init;
|
|
Packit Service |
4684c1 |
ctx->ctx_ptr = &ctx->ctx.sha224;
|
|
Packit Service |
4684c1 |
ctx->length = SHA224_DIGEST_SIZE;
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
case GNUTLS_DIG_SHA256:
|
|
Packit Service |
4684c1 |
sha256_init(&ctx->ctx.sha256);
|
|
Packit Service |
4684c1 |
ctx->update = (update_func) padlock_sha256_update;
|
|
Packit Service |
4684c1 |
ctx->digest = (digest_func) padlock_sha256_digest;
|
|
Packit Service |
4684c1 |
ctx->init = (init_func) sha256_init;
|
|
Packit Service |
4684c1 |
ctx->ctx_ptr = &ctx->ctx.sha256;
|
|
Packit Service |
4684c1 |
ctx->length = SHA256_DIGEST_SIZE;
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
case GNUTLS_DIG_SHA384:
|
|
Packit Service |
4684c1 |
sha384_init(&ctx->ctx.sha384);
|
|
Packit Service |
4684c1 |
ctx->update = (update_func) padlock_sha512_update;
|
|
Packit Service |
4684c1 |
ctx->digest = (digest_func) padlock_sha512_digest;
|
|
Packit Service |
4684c1 |
ctx->init = (init_func) sha384_init;
|
|
Packit Service |
4684c1 |
ctx->ctx_ptr = &ctx->ctx.sha384;
|
|
Packit Service |
4684c1 |
ctx->length = SHA384_DIGEST_SIZE;
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
case GNUTLS_DIG_SHA512:
|
|
Packit Service |
4684c1 |
sha512_init(&ctx->ctx.sha512);
|
|
Packit Service |
4684c1 |
ctx->update = (update_func) padlock_sha512_update;
|
|
Packit Service |
4684c1 |
ctx->digest = (digest_func) padlock_sha512_digest;
|
|
Packit Service |
4684c1 |
ctx->init = (init_func) sha512_init;
|
|
Packit Service |
4684c1 |
ctx->ctx_ptr = &ctx->ctx.sha512;
|
|
Packit Service |
4684c1 |
ctx->length = SHA512_DIGEST_SIZE;
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
default:
|
|
Packit Service |
4684c1 |
gnutls_assert();
|
|
Packit Service |
4684c1 |
return GNUTLS_E_INVALID_REQUEST;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int
|
|
Packit Service |
4684c1 |
wrap_padlock_hash_init(gnutls_digest_algorithm_t algo, void **_ctx)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
struct padlock_hash_ctx *ctx;
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ctx = gnutls_malloc(sizeof(struct padlock_hash_ctx));
|
|
Packit Service |
4684c1 |
if (ctx == NULL) {
|
|
Packit Service |
4684c1 |
gnutls_assert();
|
|
Packit Service |
4684c1 |
return GNUTLS_E_MEMORY_ERROR;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ctx->algo = algo;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if ((ret = _ctx_init(algo, ctx)) < 0) {
|
|
Packit Service |
4684c1 |
gnutls_assert();
|
|
Packit Service |
4684c1 |
return ret;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
*_ctx = ctx;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void *
|
|
Packit Service |
4684c1 |
wrap_padlock_hash_copy(const void *_ctx)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
struct padlock_hash_ctx *new_ctx;
|
|
Packit Service |
4684c1 |
const struct padlock_hash_ctx *ctx=_ctx;
|
|
Packit Service |
4684c1 |
ptrdiff_t off = (uint8_t *)ctx->ctx_ptr - (uint8_t *)(&ctx->ctx);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
new_ctx = gnutls_malloc(sizeof(struct padlock_hash_ctx));
|
|
Packit Service |
4684c1 |
if (new_ctx == NULL) {
|
|
Packit Service |
4684c1 |
gnutls_assert();
|
|
Packit Service |
4684c1 |
return NULL;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
memcpy(new_ctx, ctx, sizeof(*new_ctx));
|
|
Packit Service |
4684c1 |
new_ctx->ctx_ptr = (uint8_t *)&new_ctx->ctx + off;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return new_ctx;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int
|
|
Packit Service |
4684c1 |
wrap_padlock_hash_output(void *src_ctx, void *digest, size_t digestsize)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
struct padlock_hash_ctx *ctx;
|
|
Packit Service |
4684c1 |
ctx = src_ctx;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (digestsize < ctx->length)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_SHORT_MEMORY_BUFFER);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ctx->digest(ctx->ctx_ptr, digestsize, digest);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ctx->init(ctx->ctx_ptr);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int wrap_padlock_hash_fast(gnutls_digest_algorithm_t algo,
|
|
Packit Service |
4684c1 |
const void *text, size_t text_size,
|
|
Packit Service |
4684c1 |
void *digest)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
if (text_size == 0 && text == NULL)
|
|
Packit Service |
4684c1 |
text = digest;
|
|
Packit Service |
4684c1 |
if (algo == GNUTLS_DIG_SHA1) {
|
|
Packit Service |
4684c1 |
uint32_t iv[5] = {
|
|
Packit Service |
4684c1 |
0x67452301UL,
|
|
Packit Service |
4684c1 |
0xEFCDAB89UL,
|
|
Packit Service |
4684c1 |
0x98BADCFEUL,
|
|
Packit Service |
4684c1 |
0x10325476UL,
|
|
Packit Service |
4684c1 |
0xC3D2E1F0UL,
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
padlock_sha1_oneshot(iv, text, text_size);
|
|
Packit Service |
4684c1 |
_nettle_write_be32(20, digest, iv);
|
|
Packit Service |
4684c1 |
} else if (algo == GNUTLS_DIG_SHA256) {
|
|
Packit Service |
4684c1 |
uint32_t iv[8] = {
|
|
Packit Service |
4684c1 |
0x6a09e667UL, 0xbb67ae85UL, 0x3c6ef372UL,
|
|
Packit Service |
4684c1 |
0xa54ff53aUL,
|
|
Packit Service |
4684c1 |
0x510e527fUL, 0x9b05688cUL, 0x1f83d9abUL,
|
|
Packit Service |
4684c1 |
0x5be0cd19UL,
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
padlock_sha256_oneshot(iv, text, text_size);
|
|
Packit Service |
4684c1 |
_nettle_write_be32(32, digest, iv);
|
|
Packit Service |
4684c1 |
} else {
|
|
Packit Service |
4684c1 |
struct padlock_hash_ctx ctx;
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = _ctx_init(algo, &ctx;;
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
ctx.algo = algo;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
wrap_padlock_hash_update(&ctx, text, text_size);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
wrap_padlock_hash_output(&ctx, digest, ctx.length);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
const struct nettle_hash padlock_sha1 = NN_HASH(sha1, padlock_sha1_update, padlock_sha1_digest, SHA1);
|
|
Packit Service |
4684c1 |
const struct nettle_hash padlock_sha224 = NN_HASH(sha224, padlock_sha256_update, padlock_sha256_digest, SHA224);
|
|
Packit Service |
4684c1 |
const struct nettle_hash padlock_sha256 = NN_HASH(sha256, padlock_sha256_update, padlock_sha256_digest, SHA256);
|
|
Packit Service |
4684c1 |
const struct nettle_hash padlock_sha384 = NN_HASH(sha384, padlock_sha512_update, padlock_sha512_digest, SHA384);
|
|
Packit Service |
4684c1 |
const struct nettle_hash padlock_sha512 = NN_HASH(sha512, padlock_sha512_update, padlock_sha512_digest, SHA512);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
const gnutls_crypto_digest_st _gnutls_sha_padlock = {
|
|
Packit Service |
4684c1 |
.init = NULL,
|
|
Packit Service |
4684c1 |
.hash = NULL,
|
|
Packit Service |
4684c1 |
.output = NULL,
|
|
Packit Service |
4684c1 |
.deinit = NULL,
|
|
Packit Service |
4684c1 |
.fast = wrap_padlock_hash_fast
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
const gnutls_crypto_digest_st _gnutls_sha_padlock_nano = {
|
|
Packit Service |
4684c1 |
.init = wrap_padlock_hash_init,
|
|
Packit Service |
4684c1 |
.hash = wrap_padlock_hash_update,
|
|
Packit Service |
4684c1 |
.output = wrap_padlock_hash_output,
|
|
Packit Service |
4684c1 |
.copy = wrap_padlock_hash_copy,
|
|
Packit Service |
4684c1 |
.deinit = wrap_padlock_hash_deinit,
|
|
Packit Service |
4684c1 |
.fast = wrap_padlock_hash_fast,
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#endif /* HAVE_LIBNETTLE */
|