Skip to content
Snippets Groups Projects
Commit 94b83a3c authored by Niels Möller's avatar Niels Möller
Browse files

(des_key_sched): Rewrote error checking logic for

the case of non-zero des_check_key.

Rev: nettle/des-compat.c:1.3
parent 05a0279a
Branches
Tags
No related merge requests found
...@@ -202,39 +202,15 @@ int des_check_key = 0; ...@@ -202,39 +202,15 @@ int des_check_key = 0;
int int
des_key_sched(const_des_cblock *key, des_key_schedule ctx) des_key_sched(const_des_cblock *key, des_key_schedule ctx)
{ {
des_cblock nkey; if (des_check_key && !des_check_parity (DES_KEY_SIZE, *key))
const uint8_t *pkey; /* Bad parity */
if (des_check_key)
pkey = *key;
else
{
/* Fix the parity */
nettle_des_fix_parity(DES_KEY_SIZE, nkey, *key);
pkey = nkey;
}
if (nettle_des_set_key(ctx, pkey))
return 0;
else switch(ctx->status)
{
case DES_BAD_PARITY:
if (des_check_key)
return -1; return -1;
else
/* We fixed the parity above */ if (!nettle_des_set_key(ctx, *key) && des_check_key)
abort(); /* Weak key */
case DES_WEAK_KEY:
if (des_check_key)
return -2; return -2;
/* Pretend the key was good */
ctx->status = DES_OK;
return 0; return 0;
default:
abort();
}
} }
int int
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment