#include "tripe.h"
-/*----- Tunable parameters ------------------------------------------------*/
-
-#define T_EXP MIN(60) /* Expiry time for a key */
-#define T_REGEN MIN(45) /* Regeneration time for a key */
-
/*----- Handy macros ------------------------------------------------------*/
#define KEYOK(ks, now) ((ks)->sz_exp > 0 && (ks)->t_exp > now)
if (psz < ivsz + SEQSZ + tagsz) {
T( trace(T_KEYSET, "keyset: block too small for keyset %u", ks->seq); )
- return (KSERR_DECRYPT);
+ return (KSERR_MALFORMED);
}
sz = psz - ivsz - SEQSZ - tagsz;
pmac = BCUR(b); pseq = pmac + tagsz; piv = pseq + SEQSZ; ppk = piv + ivsz;
return (ks);
}
-/* --- @ks_tregen@ --- *
- *
- * Arguments: @keyset *ks@ = pointer to a keyset
- *
- * Returns: The time at which moves ought to be made to replace this key.
- */
-
-time_t ks_tregen(keyset *ks) { return (ks->t_exp - T_EXP + T_REGEN); }
-
/* --- @ks_activate@ --- *
*
* Arguments: @keyset *ks@ = pointer to a keyset
* @buf *b@ = pointer to an input buffer
* @buf *bb@ = pointer to an output buffer
*
- * Returns: Zero on success; @KSERR_DECRYPT@ on failure. Also returns
+ * Returns: Zero on success; @KSERR_...@ on failure. Also returns
* zero if there was insufficient buffer (but the output buffer
* is broken in this case).
*
{
time_t now = time(0);
uint32 seq;
+ int err;
- if (!KEYOK(ks, now) ||
- buf_ensure(bb, BLEN(b)) ||
- dodecrypt(ks, ty, b, bb, &seq) ||
- seq_check(&ks->iseq, seq, "SYMM"))
- return (KSERR_DECRYPT);
+ if (!KEYOK(ks, now)) return (KSERR_DECRYPT);
+ if (buf_ensure(bb, BLEN(b))) return (0);
+ if ((err = dodecrypt(ks, ty, b, bb, &seq)) != 0) return (err);
+ if (seq_check(&ks->iseq, seq, "SYMM")) return (KSERR_SEQ);
return (0);
}
time_t now = time(0);
keyset *ks;
uint32 seq;
+ int err;
if (buf_ensure(bb, BLEN(b)))
- return (KSERR_DECRYPT);
+ return (0);
for (ks = *ksroot; ks; ks = ks->next) {
if (!KEYOK(ks, now))
continue;
- if (!dodecrypt(ks, ty, b, bb, &seq)) {
+ if ((err = dodecrypt(ks, ty, b, bb, &seq)) == 0) {
if (ks->f & KSF_LISTEN) {
T( trace(T_KEYSET, "keyset: implicitly activating keyset %u",
ks->seq); )
ks->f &= ~KSF_LISTEN;
}
if (seq_check(&ks->iseq, seq, "SYMM"))
- return (KSERR_DECRYPT);
+ return (KSERR_SEQ);
else
return (0);
}
+ if (err != KSERR_DECRYPT) return (err);
}
T( trace(T_KEYSET, "keyset: no matching keys, or incorrect MAC"); )
return (KSERR_DECRYPT);