From: angelos Date: Sat, 25 Mar 2000 04:40:44 +0000 (+0000) Subject: Add CRD_F_IV_PRESENT, to indicate encryption requests where an X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4b44d36fff749a5624d632506d9ab7c41d317393;p=openbsd Add CRD_F_IV_PRESENT, to indicate encryption requests where an explicit IV preceeds the data to be encrypted. Nice weather in Australia... --- diff --git a/sys/crypto/crypto.h b/sys/crypto/crypto.h index 7bbd45c1f0f..ef11a18ec3e 100644 --- a/sys/crypto/crypto.h +++ b/sys/crypto/crypto.h @@ -79,6 +79,7 @@ struct cryptodesc #define CRD_F_ENCRYPT 0x1 /* Set when doing encryption */ #define CRD_F_HALFIV 0x2 +#define CRD_F_IV_PRESENT 0x4 /* Used/sensible only when encrypting */ struct cryptoini CRD_INI; /* Initialization/context data */ #define crd_key CRD_INI.cri_key diff --git a/sys/crypto/cryptosoft.c b/sys/crypto/cryptosoft.c index 2a8aaa11332..ec291177422 100644 --- a/sys/crypto/cryptosoft.c +++ b/sys/crypto/cryptosoft.c @@ -88,6 +88,9 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf, /* Inject IV */ if (crd->crd_flags & CRD_F_HALFIV) { + if (crd->crd_flags & CRD_F_IV_PRESENT) + bcopy(buf + crd->crd_inject, sw->sw_iv, blks / 2); + /* "Cook" half-IV */ for (k = 0; k < blks / 2; k++) sw->sw_iv[(blks / 2) + k] = ~sw->sw_iv[k]; @@ -95,7 +98,12 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf, bcopy(sw->sw_iv, buf + crd->crd_inject, blks / 2); } else - bcopy(sw->sw_iv, buf + crd->crd_inject, blks); + { + if (crd->crd_flags & CRD_F_IV_PRESENT) + bcopy(buf + crd->crd_inject, sw->sw_iv, blks); + else + bcopy(sw->sw_iv, buf + crd->crd_inject, blks); + } for (i = crd->crd_skip; i < crd->crd_skip + crd->crd_len; @@ -154,15 +162,23 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf, /* Initialize the IV */ if (crd->crd_flags & CRD_F_ENCRYPT) { - bcopy(sw->sw_iv, iv, blks); + if (crd->crd_flags & CRD_F_IV_PRESENT) + m_copydata(m, crd->crd_inject, blks, iv); + else + bcopy(sw->sw_iv, iv, blks); /* "Cook" half-IV */ if (crd->crd_flags & CRD_F_HALFIV) - for (k = 0; k < blks / 2; k++) - iv[(blks / 2) + k] = ~iv[k]; + { + for (k = 0; k < blks / 2; k++) + iv[(blks / 2) + k] = ~iv[k]; - /* Inject IV */ - m_copyback(m, crd->crd_inject, blks, iv); + if (!(crd->crd_flags & CRD_F_IV_PRESENT)) + m_copyback(m, crd->crd_inject, blks / 2, iv); + } + else + if (!(crd->crd_flags & CRD_F_IV_PRESENT)) + m_copyback(m, crd->crd_inject, blks, iv); } else {