opencrypto - (minor) sync with OpenBSD
authorAlex Hornung <ahornung@gmail.com>
Mon, 27 Jun 2011 18:07:03 +0000 (19:07 +0100)
committerAlex Hornung <ahornung@gmail.com>
Fri, 1 Jul 2011 20:57:00 +0000 (21:57 +0100)
sys/opencrypto/cryptodev.c
sys/opencrypto/cryptosoft.c
sys/opencrypto/xform.c

index 33d2c3e..91d3a5b 100644 (file)
@@ -309,10 +309,14 @@ cryptof_ioctl(struct file *fp, u_long cmd, caddr_t data,
                }
 bail:
                if (error) {
-                       if (crie.cri_key)
+                       if (crie.cri_key) {
+                               bzero(crie.cri_key, crie.cri_klen / 8);
                                kfree(crie.cri_key, M_XDATA);
-                       if (cria.cri_key)
+                       }
+                       if (cria.cri_key) {
+                               bzero(crie.cri_key, crie.cri_klen / 8);
                                kfree(cria.cri_key, M_XDATA);
+                       }
                }
                break;
        case CIOCFSESSION:
@@ -649,8 +653,11 @@ fail:
        if (krp) {
                kop->crk_status = krp->krp_status;
                for (i = 0; i < CRK_MAXPARAM; i++) {
-                       if (krp->krp_param[i].crp_p)
+                       if (krp->krp_param[i].crp_p) {
+                               bzero(krp->krp_param[i].crp_p,
+                                   (krp->krp_param[i].crp_nbits + 7) / 8);
                                kfree(krp->krp_param[i].crp_p, M_XDATA);
+                       }
                }
                kfree(krp, M_XDATA);
        }
index 7f18f7a..15e3ba1 100644 (file)
@@ -76,7 +76,7 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
     int flags)
 {
        unsigned char iv[EALG_MAX_BLOCK_LEN], blk[EALG_MAX_BLOCK_LEN], *idat;
-       unsigned char *ivp, piv[EALG_MAX_BLOCK_LEN];
+       unsigned char *ivp, *nivp, iv2[EALG_MAX_BLOCK_LEN];
        u_int8_t *kschedule;
        u_int8_t *okschedule;
        struct enc_xform *exf;
@@ -189,10 +189,8 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
                                         * Keep encrypted block for XOR'ing
                                         * with next block
                                         */
-                                       if (ivp == iv)
-                                               bcopy(blk, piv, blks);
-                                       else
-                                               bcopy(blk, iv, blks);
+                                       nivp = (ivp == iv) ? iv2 : iv;
+                                       bcopy(blk, nivp, blks);
 
                                        exf->decrypt(kschedule, blk, iv);
 
@@ -200,10 +198,7 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
                                        for (j = 0; j < blks; j++)
                                                blk[j] ^= ivp[j];
 
-                                       if (ivp == iv)
-                                               bcopy(piv, iv, blks);
-                                       else
-                                               ivp = iv;
+                                       ivp = nivp;
                                }
 
                                /* Copy back decrypted block */
@@ -265,10 +260,8 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
                                         * Keep encrypted block to be used
                                         * in next block's processing.
                                         */
-                                       if (ivp == iv)
-                                               bcopy(idat, piv, blks);
-                                       else
-                                               bcopy(idat, iv, blks);
+                                       nivp = (ivp == iv) ? iv2 : iv;
+                                       bcopy(idat, nivp, blks);
 
                                        exf->decrypt(kschedule, idat, iv);
 
@@ -276,10 +269,7 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
                                        for (j = 0; j < blks; j++)
                                                idat[j] ^= ivp[j];
 
-                                       if (ivp == iv)
-                                               bcopy(piv, iv, blks);
-                                       else
-                                               ivp = iv;
+                                       ivp = nivp;
                                }
 
                                idat += blks;
@@ -336,10 +326,8 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
                                         * Keep encrypted block for XOR'ing
                                         * with next block
                                         */
-                                       if (ivp == iv)
-                                               bcopy(blk, piv, blks);
-                                       else
-                                               bcopy(blk, iv, blks);
+                                       nivp = (ivp == iv) ? iv2 : iv;
+                                       bcopy(blk, nivp, blks);
 
                                        exf->decrypt(kschedule, blk, iv);
 
@@ -347,10 +335,7 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
                                        for (j = 0; j < blks; j++)
                                                blk[j] ^= ivp[j];
 
-                                       if (ivp == iv)
-                                               bcopy(piv, iv, blks);
-                                       else
-                                               ivp = iv;
+                                       ivp = nivp;
                                }
 
                                /* Copy back decrypted block */
@@ -398,10 +383,8 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
                                         * Keep encrypted block to be used
                                         * in next block's processing.
                                         */
-                                       if (ivp == iv)
-                                               bcopy(idat, piv, blks);
-                                       else
-                                               bcopy(idat, iv, blks);
+                                       nivp = (ivp == iv) ? iv2 : iv;
+                                       bcopy(idat, nivp, blks);
 
                                        exf->decrypt(kschedule, idat, iv);
 
@@ -409,10 +392,7 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
                                        for (j = 0; j < blks; j++)
                                                idat[j] ^= ivp[j];
 
-                                       if (ivp == iv)
-                                               bcopy(piv, iv, blks);
-                                       else
-                                               ivp = iv;
+                                       ivp = nivp;
                                }
 
                                idat += blks;
index 85885e4..2560785 100644 (file)
@@ -729,6 +729,7 @@ aes_ctr_crypt(caddr_t key, u_int8_t *data, u_int8_t *iv)
        rijndaelEncrypt(ctx->ac_ek, ctx->ac_nr, iv, keystream);
        for (i = 0; i < AESCTR_BLOCK_LEN; i++)
                data[i] ^= keystream[i];
+       bzero(keystream, sizeof(keystream));
 }
 
 int