Commit caa82fb0 authored by Niels Möller's avatar Niels Möller
Browse files

* src/dsa.c, src/dsa_keygen.c, src/md5.c, src/rijndael.c,

src/sha.c: Adapted to the nettle API.

Rev: src/dsa.c:1.28
Rev: src/dsa_keygen.c:1.15
Rev: src/md5.c:1.6
Rev: src/rijndael.c:1.4
Rev: src/sha.c:1.7
parent a526bc40
......@@ -29,12 +29,13 @@
#include "format.h"
#include "parse.h"
#include "sexp.h"
#include "sha.h"
#include "spki.h"
#include "ssh.h"
#include "werror.h"
#include "xalloc.h"
#include "nettle/sha1.h"
#include <assert.h>
#include "dsa.c.x"
......@@ -45,7 +46,7 @@
#define DSA_MAX_SIZE 300
#define DSA_MAX_QSIZE SHA_DIGESTSIZE
#define DSA_MAX_QSIZE SHA1_DIGEST_SIZE
#define SA(x) sexp_a(ATOM_##x)
......@@ -87,16 +88,16 @@ static void
dsa_hash(mpz_t h, UINT32 length, const UINT8 *msg)
{
/* Compute hash */
struct hash_instance *hash = MAKE_HASH(&sha1_algorithm);
UINT8 *digest = alloca(hash->hash_size);
HASH_UPDATE(hash, length, msg);
HASH_DIGEST(hash, digest);
UINT8 digest[SHA1_DIGEST_SIZE];
struct sha1_ctx ctx;
sha1_init(&ctx);
sha1_update(&ctx, length, msg);
sha1_final(&ctx);
sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
bignum_parse_u(h, hash->hash_size, digest);
bignum_parse_u(h, SHA1_DIGEST_SIZE, digest);
debug("DSA hash: %xn\n", h);
KILL(hash);
}
static struct sexp *
......
......@@ -28,11 +28,12 @@
#include "randomness.h"
#include "sexp.h"
#include "sha.h"
#include "werror.h"
#include "nettle/sha1.h"
#if !HAVE_MEMXOR
#include "memxor.h"
#include "nettle/memxor.h"
#endif
#include <assert.h>
......@@ -42,7 +43,7 @@
/* The (slow) NIST method of generating DSA primes. Algorithm 4.56 of
* Handbook of Applied Cryptography. */
#define SEED_LENGTH SHA_DIGESTSIZE
#define SEED_LENGTH SHA1_DIGEST_SIZE
#define SEED_BITS (SEED_LENGTH * 8)
static void
......@@ -50,7 +51,7 @@ hash(mpz_t x, UINT8 *digest)
{
mpz_t t;
UINT8 data[SEED_LENGTH];
struct sha_ctx ctx;
struct sha1_ctx ctx;
mpz_init_set(t, x);
mpz_fdiv_r_2exp(t, t, SEED_BITS);
......@@ -58,10 +59,10 @@ hash(mpz_t x, UINT8 *digest)
bignum_write(t, SEED_LENGTH, data);
mpz_clear(t);
sha_init(&ctx);
sha_update(&ctx, data, SEED_LENGTH);
sha_final(&ctx);
sha_digest(&ctx, digest);
sha1_init(&ctx);
sha1_update(&ctx, data, SEED_LENGTH);
sha1_final(&ctx);
sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
}
void
......@@ -83,8 +84,8 @@ dsa_nist_gen(mpz_t p, mpz_t q, struct randomness *r, unsigned l)
for (;;)
{
{ /* Generate q */
UINT8 h1[SHA_DIGESTSIZE];
UINT8 h2[SHA_DIGESTSIZE];
UINT8 h1[SHA1_DIGEST_SIZE];
UINT8 h2[SHA1_DIGEST_SIZE];
bignum_random_size(s, r, SEED_BITS);
......
......@@ -25,7 +25,7 @@
#include "xalloc.h"
#include "md5.h"
#include "nettle/md5.h"
#include "md5.c.x"
......@@ -44,7 +44,7 @@ do_md5_update(struct hash_instance *s,
{
CAST(md5_instance, self, s);
md5_update(&self->ctx, data, length);
md5_update(&self->ctx, length, data);
}
static void
......@@ -54,7 +54,7 @@ do_md5_digest(struct hash_instance *s,
CAST(md5_instance, self, s);
md5_final(&self->ctx);
md5_digest(&self->ctx, dst);
md5_digest(&self->ctx, MD5_DIGEST_SIZE, dst);
md5_init(&self->ctx);
}
......@@ -81,5 +81,5 @@ make_md5_instance(struct hash_algorithm *ignored UNUSED)
struct hash_algorithm md5_algorithm =
{ STATIC_HEADER,
MD5_DATASIZE, MD5_DIGESTSIZE, make_md5_instance };
MD5_DATA_SIZE, MD5_DIGEST_SIZE, make_md5_instance };
......@@ -37,7 +37,7 @@
(name rijndael_instance)
(super crypto_instance)
(vars
(ctx . "RIJNDAEL_context")))
(ctx . "struct aes_ctx")))
*/
static void
......@@ -46,8 +46,7 @@ do_rijndael_encrypt(struct crypto_instance *s,
{
CAST(rijndael_instance, self, s);
FOR_BLOCKS(length, src, dst, RIJNDAEL_BLOCKSIZE)
rijndael_encrypt(&self->ctx, src, dst);
aes_encrypt(&self->ctx, length, dst, src);
}
static void
......@@ -56,8 +55,7 @@ do_rijndael_decrypt(struct crypto_instance *s,
{
CAST(rijndael_instance, self, s);
FOR_BLOCKS(length, src, dst, RIJNDAEL_BLOCKSIZE)
rijndael_decrypt(&self->ctx, src, dst);
aes_decrypt(&self->ctx, length, dst, src);
}
static struct crypto_instance *
......@@ -71,7 +69,7 @@ make_rijndael_instance(struct crypto_algorithm *algorithm, int mode,
? do_rijndael_encrypt
: do_rijndael_decrypt);
rijndael_setup(&self->ctx, algorithm->key_size, key);
aes_set_key(&self->ctx, algorithm->key_size, key);
return(&self->super);
}
......@@ -81,10 +79,10 @@ make_rijndael_algorithm(UINT32 key_size)
{
NEW(crypto_algorithm, algorithm);
assert(key_size <= RIJNDAEL_MAX_KEYSIZE);
assert(key_size >= RIJNDAEL_MIN_KEYSIZE);
assert(key_size <= AES_MAX_KEY_SIZE);
assert(key_size >= AES_MIN_KEY_SIZE);
algorithm->block_size = RIJNDAEL_BLOCKSIZE;
algorithm->block_size = AES_BLOCKSIZE;
algorithm->key_size = key_size;
algorithm->iv_size = 0;
algorithm->make_crypt = make_rijndael_instance;
......@@ -93,10 +91,10 @@ make_rijndael_algorithm(UINT32 key_size)
}
struct crypto_algorithm rijndael128_algorithm =
{ STATIC_HEADER, RIJNDAEL_BLOCKSIZE, 16, 0, make_rijndael_instance};
{ STATIC_HEADER, AES_BLOCKSIZE, 16, 0, make_rijndael_instance};
struct crypto_algorithm rijndael192_algorithm =
{ STATIC_HEADER, RIJNDAEL_BLOCKSIZE, 24, 0, make_rijndael_instance};
{ STATIC_HEADER, AES_BLOCKSIZE, 24, 0, make_rijndael_instance};
struct crypto_algorithm rijndael256_algorithm =
{ STATIC_HEADER, RIJNDAEL_BLOCKSIZE, 32, 0, make_rijndael_instance};
{ STATIC_HEADER, AES_BLOCKSIZE, 32, 0, make_rijndael_instance};
......@@ -25,7 +25,7 @@
#include "xalloc.h"
#include "sha.h"
#include "nettle/sha1.h"
#include "sha.c.x"
......@@ -36,7 +36,7 @@
(name sha_instance)
(super hash_instance)
(vars
(ctx . "struct sha_ctx")))
(ctx . "struct sha1_ctx")))
*/
static void
......@@ -45,7 +45,7 @@ do_sha_update(struct hash_instance *s,
{
CAST(sha_instance, self, s);
sha_update(&self->ctx, data, length);
sha1_update(&self->ctx, length, data);
}
static void
......@@ -54,9 +54,9 @@ do_sha_digest(struct hash_instance *s,
{
CAST(sha_instance, self, s);
sha_final(&self->ctx);
sha_digest(&self->ctx, dst);
sha_init(&self->ctx);
sha1_final(&self->ctx);
sha1_digest(&self->ctx, SHA1_DIGEST_SIZE, dst);
sha1_init(&self->ctx);
}
static struct hash_instance *
......@@ -70,17 +70,17 @@ make_sha_instance(struct hash_algorithm *ignored UNUSED)
{
NEW(sha_instance, res);
res->super.hash_size = 20;
res->super.hash_size = SHA1_DIGEST_SIZE;
res->super.update = do_sha_update;
res->super.digest = do_sha_digest;
res->super.copy = do_sha_copy;
sha_init(&res->ctx);
sha1_init(&res->ctx);
return &res->super;
}
struct hash_algorithm sha1_algorithm =
{ STATIC_HEADER,
SHA_DATASIZE, SHA_DIGESTSIZE, make_sha_instance };
SHA1_DATA_SIZE, SHA1_DIGEST_SIZE, make_sha_instance };
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment