diff options
author | Angelos D. Keromytis <angelos@cvs.openbsd.org> | 2000-03-25 04:40:45 +0000 |
---|---|---|
committer | Angelos D. Keromytis <angelos@cvs.openbsd.org> | 2000-03-25 04:40:45 +0000 |
commit | 8bef55b0274e7deb6d89e1381f0f1d245816718a (patch) | |
tree | 7526503614232974619aad34594d828ccc8f13d6 /sys/crypto | |
parent | aae9b760243be823f9e5ec3bef0073af24de6feb (diff) |
Add CRD_F_IV_PRESENT, to indicate encryption requests where an
explicit IV preceeds the data to be encrypted.
Nice weather in Australia...
Diffstat (limited to 'sys/crypto')
-rw-r--r-- | sys/crypto/crypto.h | 1 | ||||
-rw-r--r-- | sys/crypto/cryptosoft.c | 28 |
2 files changed, 23 insertions, 6 deletions
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 { |