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

(des_set_key): New iteration logic, to keep key pointer unchanged.

Moved weak key check to the end, and don't set the status
attribute.
(des_encrypt): Ignore status attribute.
(des_decrypt): Likewise.

Rev: nettle/des.c:1.3
parent 053bf073
...@@ -198,15 +198,13 @@ des_set_key(struct des_ctx *ctx, const uint8_t *key) ...@@ -198,15 +198,13 @@ des_set_key(struct des_ctx *ctx, const uint8_t *key)
uint32_t *method; uint32_t *method;
const uint8_t *k; const uint8_t *k;
ctx->status = des_weak_p(key) ? DES_WEAK_KEY : DES_OK;
/* NOTE: We go on and expand the key, even if it was weak */
/* explode the bits */ /* explode the bits */
n = 56; n = 56;
b0 = bits0; b0 = bits0;
b1 = bits1; b1 = bits1;
k = key;
do { do {
w = (256 | *key++) << 2; w = (256 | *k++) << 2;
do { do {
--n; --n;
b1[n] = 8 & w; b1[n] = 8 & w;
...@@ -262,7 +260,7 @@ des_set_key(struct des_ctx *ctx, const uint8_t *key) ...@@ -262,7 +260,7 @@ des_set_key(struct des_ctx *ctx, const uint8_t *key)
method += 2; method += 2;
} while ( --n ); } while ( --n );
return (ctx->status == DES_OK); return !des_weak_p (key);
} }
void void
...@@ -271,7 +269,6 @@ des_encrypt(const struct des_ctx *ctx, ...@@ -271,7 +269,6 @@ des_encrypt(const struct des_ctx *ctx,
const uint8_t *src) const uint8_t *src)
{ {
assert(!(length % DES_BLOCK_SIZE)); assert(!(length % DES_BLOCK_SIZE));
assert(ctx->status == DES_OK);
while (length) while (length)
{ {
...@@ -288,7 +285,6 @@ des_decrypt(const struct des_ctx *ctx, ...@@ -288,7 +285,6 @@ des_decrypt(const struct des_ctx *ctx,
const uint8_t *src) const uint8_t *src)
{ {
assert(!(length % DES_BLOCK_SIZE)); assert(!(length % DES_BLOCK_SIZE));
assert(ctx->status == DES_OK);
while (length) while (length)
{ {
......
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