Add CRD_F_IV_PRESENT, to indicate encryption requests where an
authorangelos <angelos@openbsd.org>
Sat, 25 Mar 2000 04:40:44 +0000 (04:40 +0000)
committerangelos <angelos@openbsd.org>
Sat, 25 Mar 2000 04:40:44 +0000 (04:40 +0000)
explicit IV preceeds the data to be encrypted.

Nice weather in Australia...

sys/crypto/crypto.h
sys/crypto/cryptosoft.c

index 7bbd45c..ef11a18 100644 (file)
@@ -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
index 2a8aaa1..ec29117 100644 (file)
@@ -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
        {