Commit ac505b1a 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. More fixes.

Rev: src/des.c:1.10
Rev: src/dsa_keygen.c:1.16
Rev: src/rijndael.c:1.5
parent df7d6bf6
......@@ -26,7 +26,7 @@
#include "werror.h"
#include "xalloc.h"
#include "des.h"
#include "nettle/des.h"
#include <assert.h>
......@@ -37,7 +37,7 @@
(name des_instance)
(super crypto_instance)
(vars
(ctx array UINT32 DES_EXPANDED_KEYLEN)))
(ctx . "struct des_ctx")))
*/
static void do_des_encrypt(struct crypto_instance *s,
......@@ -45,8 +45,7 @@ static void do_des_encrypt(struct crypto_instance *s,
{
CAST(des_instance, self, s);
FOR_BLOCKS(length, src, dst, DES_BLOCKSIZE)
DesSmallFipsEncrypt(dst, self->ctx, src);
des_encrypt(&self->ctx, length, dst, src);
}
static void do_des_decrypt(struct crypto_instance *s,
......@@ -54,8 +53,7 @@ static void do_des_decrypt(struct crypto_instance *s,
{
CAST(des_instance, self, s);
FOR_BLOCKS(length, src, dst, DES_BLOCKSIZE)
DesSmallFipsDecrypt(dst, self->ctx, src);
des_decrypt(&self->ctx, length, dst, src);
}
static struct crypto_instance *
......@@ -63,11 +61,11 @@ make_des_instance(struct crypto_algorithm *algorithm UNUSED, int mode,
const UINT8 *key, const UINT8 *iv UNUSED)
{
NEW(des_instance, self);
UINT8 pkey[DES_KEYSIZE];
UINT8 pkey[DES_KEY_SIZE];
unsigned i;
/* Fix odd parity */
for (i=0; i<DES_KEYSIZE; i++)
for (i=0; i<DES_KEY_SIZE; i++)
{
UINT8 p = key[i];
p ^= (p >> 4);
......@@ -82,18 +80,19 @@ make_des_instance(struct crypto_algorithm *algorithm UNUSED, int mode,
#endif
}
self->super.block_size = DES_BLOCKSIZE;
self->super.block_size = DES_BLOCK_SIZE;
self->super.crypt = ( (mode == CRYPTO_ENCRYPT)
? do_des_encrypt
: do_des_decrypt);
switch (DesMethod(self->ctx, pkey))
if (des_set_key(&self->ctx, pkey))
return &self->super;
switch(self->ctx.status)
{
case 0:
return &self->super;
case -1:
case DES_BAD_PARITY:
fatal("Internal error! Bad parity in make_des_instance.\n");
case -2:
case DES_WEAK_KEY:
werror("Detected weak DES key.\n");
KILL(self);
return NULL;
......@@ -104,7 +103,7 @@ make_des_instance(struct crypto_algorithm *algorithm UNUSED, int mode,
struct crypto_algorithm crypto_des_algorithm =
{ STATIC_HEADER,
DES_BLOCKSIZE, DES_KEYSIZE, 0, make_des_instance };
DES_BLOCK_SIZE, DES_KEY_SIZE, 0, make_des_instance };
struct crypto_algorithm *make_des3(void)
{
......
......@@ -60,7 +60,7 @@ hash(mpz_t x, UINT8 *digest)
mpz_clear(t);
sha1_init(&ctx);
sha1_update(&ctx, data, SEED_LENGTH);
sha1_update(&ctx, SEED_LENGTH, data);
sha1_final(&ctx);
sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
}
......@@ -96,12 +96,12 @@ dsa_nist_gen(mpz_t p, mpz_t q, struct randomness *r, unsigned l)
hash(t, h2);
memxor(h1, h2, SHA_DIGESTSIZE);
memxor(h1, h2, SHA1_DIGEST_SIZE);
h1[0] |= 0x80;
h1[SHA_DIGESTSIZE - 1] |= 1;
h1[SHA1_DIGEST_SIZE - 1] |= 1;
bignum_parse_u(q, SHA_DIGESTSIZE, h1);
bignum_parse_u(q, SHA1_DIGEST_SIZE, h1);
if (bignum_small_factor(q, 1000)
|| !mpz_probab_prime_p(q, 18))
......@@ -111,7 +111,7 @@ dsa_nist_gen(mpz_t p, mpz_t q, struct randomness *r, unsigned l)
/* q is a prime, with overwelming probability. */
{
unsigned size = (n+1) * SHA_DIGESTSIZE;
unsigned size = (n+1) * SHA1_DIGEST_SIZE;
UINT8 *buffer = alloca(size);
unsigned i, j;
......@@ -123,7 +123,7 @@ dsa_nist_gen(mpz_t p, mpz_t q, struct randomness *r, unsigned l)
{
mpz_set(t, s);
mpz_add_ui(t, t, j + k);
hash(t, buffer + ( (n-k) * SHA_DIGESTSIZE));
hash(t, buffer + ( (n-k) * SHA1_DIGEST_SIZE));
}
bignum_parse_u(p, size, buffer);
......
......@@ -22,10 +22,11 @@
*/
#include "crypto.h"
#include "rijndael.h"
#include "werror.h"
#include "xalloc.h"
#include "nettle/aes.h"
#include <assert.h>
#include "rijndael.c.x"
......@@ -64,7 +65,7 @@ make_rijndael_instance(struct crypto_algorithm *algorithm, int mode,
{
NEW(rijndael_instance, self);
self->super.block_size = RIJNDAEL_BLOCKSIZE;
self->super.block_size = AES_BLOCK_SIZE;
self->super.crypt = ( (mode == CRYPTO_ENCRYPT)
? do_rijndael_encrypt
: do_rijndael_decrypt);
......@@ -82,7 +83,7 @@ make_rijndael_algorithm(UINT32 key_size)
assert(key_size <= AES_MAX_KEY_SIZE);
assert(key_size >= AES_MIN_KEY_SIZE);
algorithm->block_size = AES_BLOCKSIZE;
algorithm->block_size = AES_BLOCK_SIZE;
algorithm->key_size = key_size;
algorithm->iv_size = 0;
algorithm->make_crypt = make_rijndael_instance;
......@@ -91,10 +92,10 @@ make_rijndael_algorithm(UINT32 key_size)
}
struct crypto_algorithm rijndael128_algorithm =
{ STATIC_HEADER, AES_BLOCKSIZE, 16, 0, make_rijndael_instance};
{ STATIC_HEADER, AES_BLOCK_SIZE, 16, 0, make_rijndael_instance};
struct crypto_algorithm rijndael192_algorithm =
{ STATIC_HEADER, AES_BLOCKSIZE, 24, 0, make_rijndael_instance};
{ STATIC_HEADER, AES_BLOCK_SIZE, 24, 0, make_rijndael_instance};
struct crypto_algorithm rijndael256_algorithm =
{ STATIC_HEADER, AES_BLOCKSIZE, 32, 0, make_rijndael_instance};
{ STATIC_HEADER, AES_BLOCK_SIZE, 32, 0, make_rijndael_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