1. 04 3月, 2009 1 次提交
  2. 19 2月, 2009 3 次提交
    • H
      crypto: chainiv - Use kcrypto_wq instead of keventd_wq · 0a2e821d
      Huang Ying 提交于
      keventd_wq has potential starvation problem, so use dedicated
      kcrypto_wq instead.
      Signed-off-by: NHuang Ying <ying.huang@intel.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      0a2e821d
    • H
      crypto: cryptd - Per-CPU thread implementation based on kcrypto_wq · 254eff77
      Huang Ying 提交于
      Original cryptd thread implementation has scalability issue, this
      patch solve the issue with a per-CPU thread implementation.
      
      struct cryptd_queue is defined to be a per-CPU queue, which holds one
      struct cryptd_cpu_queue for each CPU. In struct cryptd_cpu_queue, a
      struct crypto_queue holds all requests for the CPU, a struct
      work_struct is used to run all requests for the CPU.
      
      Testing based on dm-crypt on an Intel Core 2 E6400 (two cores) machine
      shows 19.2% performance gain. The testing script is as follow:
      
      -------------------- script begin ---------------------------
      #!/bin/sh
      
      dmc_create()
      {
              # Create a crypt device using dmsetup
              dmsetup create $2 --table "0 `blockdev --getsize $1` crypt cbc(aes-asm)?cryptd?plain:plain babebabebabebabebabebabebabebabe 0 $1 0"
      }
      
      dmsetup remove crypt0
      dmsetup remove crypt1
      
      dd if=/dev/zero of=/dev/ram0 bs=1M count=4 >& /dev/null
      dd if=/dev/zero of=/dev/ram1 bs=1M count=4 >& /dev/null
      
      dmc_create /dev/ram0 crypt0
      dmc_create /dev/ram1 crypt1
      
      cat >tr.sh <<EOF
      #!/bin/sh
      
      for n in \$(seq 10); do
              dd if=/dev/dm-0 of=/dev/null >& /dev/null &
              dd if=/dev/dm-1 of=/dev/null >& /dev/null &
      done
      wait
      EOF
      
      for n in $(seq 10); do
              /usr/bin/time sh tr.sh
      done
      rm tr.sh
      -------------------- script end   ---------------------------
      
      The separator of dm-crypt parameter is changed from "-" to "?", because
      "-" is used in some cipher driver name too, and cryptds need to specify
      cipher driver name instead of cipher name.
      
      The test result on an Intel Core2 E6400 (two cores) is as follow:
      
      without patch:
      -----------------wo begin --------------------------
      0.04user 0.38system 0:00.39elapsed 107%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6566minor)pagefaults 0swaps
      0.07user 0.35system 0:00.35elapsed 121%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6567minor)pagefaults 0swaps
      0.06user 0.34system 0:00.30elapsed 135%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6562minor)pagefaults 0swaps
      0.05user 0.37system 0:00.36elapsed 119%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6607minor)pagefaults 0swaps
      0.06user 0.36system 0:00.35elapsed 120%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6562minor)pagefaults 0swaps
      0.05user 0.37system 0:00.31elapsed 136%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6594minor)pagefaults 0swaps
      0.04user 0.34system 0:00.30elapsed 126%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6597minor)pagefaults 0swaps
      0.06user 0.32system 0:00.31elapsed 125%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6571minor)pagefaults 0swaps
      0.06user 0.34system 0:00.31elapsed 134%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6581minor)pagefaults 0swaps
      0.05user 0.38system 0:00.31elapsed 138%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6600minor)pagefaults 0swaps
      -----------------wo end   --------------------------
      
      
      with patch:
      ------------------w begin --------------------------
      0.02user 0.31system 0:00.24elapsed 141%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6554minor)pagefaults 0swaps
      0.05user 0.34system 0:00.31elapsed 127%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6606minor)pagefaults 0swaps
      0.07user 0.33system 0:00.26elapsed 155%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6559minor)pagefaults 0swaps
      0.07user 0.32system 0:00.26elapsed 151%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6562minor)pagefaults 0swaps
      0.05user 0.34system 0:00.26elapsed 150%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6603minor)pagefaults 0swaps
      0.03user 0.36system 0:00.31elapsed 124%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6562minor)pagefaults 0swaps
      0.04user 0.35system 0:00.26elapsed 147%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6586minor)pagefaults 0swaps
      0.03user 0.37system 0:00.27elapsed 146%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6562minor)pagefaults 0swaps
      0.04user 0.36system 0:00.26elapsed 154%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6594minor)pagefaults 0swaps
      0.04user 0.35system 0:00.26elapsed 154%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+6557minor)pagefaults 0swaps
      ------------------w end   --------------------------
      
      The middle value of elapsed time is:
      wo cryptwq: 0.31
      w  cryptwq: 0.26
      
      The performance gain is about (0.31-0.26)/0.26 = 0.192.
      Signed-off-by: NHuang Ying <ying.huang@intel.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      254eff77
    • H
      crypto: api - Use dedicated workqueue for crypto subsystem · 25c38d3f
      Huang Ying 提交于
      Use dedicated workqueue for crypto subsystem
      
      A dedicated workqueue named kcrypto_wq is created to be used by crypto
      subsystem. The system shared keventd_wq is not suitable for
      encryption/decryption, because of potential starvation problem.
      Signed-off-by: NHuang Ying <ying.huang@intel.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      25c38d3f
  3. 18 2月, 2009 10 次提交
    • H
      crypto: testmgr - Test skciphers with no IVs · 6fe4a28d
      Herbert Xu 提交于
      As it is an skcipher with no IV escapes testing altogether because
      we only test givcipher objects.  This patch fixes the bypass logic
      to test these algorithms.
      
      Conversely, we're currently testing nivaead algorithms with IVs,
      which would have deadlocked had it not been for the fact that no
      nivaead algorithms have any test vectors.  This patch also fixes
      that case.
      
      Both fixes are ugly as hell, but this ugliness should hopefully
      disappear once we move them into the per-type code (i.e., the
      AEAD test would live in aead.c and the skcipher stuff in ablkcipher.c).
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      6fe4a28d
    • H
      crypto: aead - Avoid infinite loop when nivaead fails selftest · 5852ae42
      Herbert Xu 提交于
      When an aead constructed through crypto_nivaead_default fails
      its selftest, we'll loop forever trying to construct new aead
      objects but failing because it already exists.
      
      The crux of the issue is that once an aead fails the selftest,
      we'll ignore it on the next run through crypto_aead_lookup and
      attempt to construct a new aead.
      
      We should instead return an error to the caller if we find an
      an that has failed the test.
      
      This bug hasn't manifested itself yet because we don't have any
      test vectors for the existing nivaead algorithms.  They're tested
      through the underlying algorithms only.
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      5852ae42
    • H
      crypto: skcipher - Avoid infinite loop when cipher fails selftest · b170a137
      Herbert Xu 提交于
      When an skcipher constructed through crypto_givcipher_default fails
      its selftest, we'll loop forever trying to construct new skcipher
      objects but failing because it already exists.
      
      The crux of the issue is that once a givcipher fails the selftest,
      we'll ignore it on the next run through crypto_skcipher_lookup and
      attempt to construct a new givcipher.
      
      We should instead return an error to the caller if we find a
      givcipher that has failed the test.
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      b170a137
    • H
      crypto: api - Fix crypto_alloc_tfm/create_create_tfm return convention · 3f683d61
      Herbert Xu 提交于
      This is based on a report and patch by Geert Uytterhoeven.
      
      The functions crypto_alloc_tfm and create_create_tfm return a
      pointer that needs to be adjusted by the caller when successful
      and otherwise an error value.  This means that the caller has
      to check for the error and only perform the adjustment if the
      pointer returned is valid.
      
      Since all callers want to make the adjustment and we know how
      to adjust it ourselves, it's much easier to just return adjusted
      pointer directly.
      
      The only caveat is that we have to return a void * instead of
      struct crypto_tfm *.  However, this isn't that bad because both
      of these functions are for internal use only (by types code like
      shash.c, not even algorithms code).
      
      This patch also moves crypto_alloc_tfm into crypto/internal.h
      (crypto_create_tfm is already there) to reflect this.
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      3f683d61
    • H
      crypto: api - crypto_alg_mod_lookup either tested or untested · ff753308
      Herbert Xu 提交于
      As it stands crypto_alg_mod_lookup will search either tested or
      untested algorithms, but never both at the same time.  However,
      we need exactly that when constructing givcipher and aead so
      this patch adds support for that by setting the tested bit in
      type but clearing it in mask.  This combination is currently
      unused.
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      ff753308
    • N
      crypto: ansi_cprng - Panic on CPRNG test failure when in FIPS mode · c5b1e545
      Neil Horman 提交于
      FIPS 140-2 specifies that all access to various cryptographic modules be
      prevented in the event that any of the provided self tests fail on the various
      implemented algorithms.  We already panic when any of the test in testmgr.c
      fail when we are operating in fips mode.  The continuous test in the cprng here
      was missed when that was implmented.  This code simply checks for the
      fips_enabled flag if the test fails, and warns us via syslog or panics the box
      accordingly.
      Signed-off-by: NNeil Horman <nhorman@tuxdriver.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      c5b1e545
    • N
      crypto: ansi_cprng - Force reset on allocation · d7992f42
      Neil Horman 提交于
      Pseudo RNGs provide predictable outputs based on input parateters {key, V, DT},
      the idea behind them is that only the user should know what the inputs are.
      While its nice to have default known values for testing purposes, it seems
      dangerous to allow the use of those default values without some sort of safety
      measure in place, lest an attacker easily guess the output of the cprng.  This
      patch forces the NEED_RESET flag on when allocating a cprng context, so that any
      user is forced to reseed it before use.  The defaults can still be used for
      testing, but this will prevent their inadvertent use, and be more secure.
      Signed-off-by: NNeil Horman <nhorman@redhat.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      d7992f42
    • H
      crypto: aes-ni - Add support to Intel AES-NI instructions for x86_64 platform · 54b6a1bd
      Huang Ying 提交于
      Intel AES-NI is a new set of Single Instruction Multiple Data (SIMD)
      instructions that are going to be introduced in the next generation of
      Intel processor, as of 2009. These instructions enable fast and secure
      data encryption and decryption, using the Advanced Encryption Standard
      (AES), defined by FIPS Publication number 197.  The architecture
      introduces six instructions that offer full hardware support for
      AES. Four of them support high performance data encryption and
      decryption, and the other two instructions support the AES key
      expansion procedure.
      
      The white paper can be downloaded from:
      
      http://softwarecommunity.intel.com/isn/downloads/intelavx/AES-Instructions-Set_WP.pdf
      
      AES may be used in soft_irq context, but MMX/SSE context can not be
      touched safely in soft_irq context. So in_interrupt() is checked, if
      in IRQ or soft_irq context, the general x86_64 implementation are used
      instead.
      Signed-off-by: NHuang Ying <ying.huang@intel.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      54b6a1bd
    • H
      crypto: cryptd - Add support to access underlying blkcipher · 1cac2cbc
      Huang Ying 提交于
      cryptd_alloc_ablkcipher() will allocate a cryptd-ed ablkcipher for
      specified algorithm name. The new allocated one is guaranteed to be
      cryptd-ed ablkcipher, so the blkcipher underlying can be gotten via
      cryptd_ablkcipher_child().
      Signed-off-by: NHuang Ying <ying.huang@intel.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      1cac2cbc
    • H
      crypto: shash - Remove superfluous check in init_tfm · 1693531e
      Herbert Xu 提交于
      We're currently checking the frontend type in init_tfm.  This is
      completely pointless because the fact that we're called at all
      means that the frontend is ours so the type must match as well.
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      1693531e
  4. 17 2月, 2009 1 次提交
    • H
      crypto: lrw - Fix big endian support · 8eb2dfac
      Herbert Xu 提交于
      It turns out that LRW has never worked properly on big endian.
      This was never discussed because nobody actually used it that
      way.  In fact, it was only discovered when Geert Uytterhoeven
      loaded it through tcrypt which failed the test on it.
      
      The fix is straightforward, on big endian the to find the nth
      bit we should be grouping them by words instead of bytes.  So
      setbit128_bbe should xor with 128 - BITS_PER_LONG instead of
      128 - BITS_PER_BYTE == 0x78.
      Tested-by: NGeert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      8eb2dfac
  5. 09 2月, 2009 1 次提交
  6. 05 2月, 2009 2 次提交
  7. 28 1月, 2009 1 次提交
    • H
      crypto: api - Fix algorithm test race that broke aead initialisation · b8e15992
      Herbert Xu 提交于
      When we complete a test we'll notify everyone waiting on it, drop
      the mutex, and then remove the test larval (after reacquiring the
      mutex).  If one of the notified parties tries to register another
      algorithm with the same driver name prior to the removal of the
      test larval, they will fail with EEXIST as only one algorithm of
      a given name can be tested at any time.
      
      This broke the initialisation of aead and givcipher algorithms as
      they will register two algorithms with the same driver name, in
      sequence.
      
      This patch fixes the problem by marking the larval as dead before
      we drop the mutex, and also ignoring all dead or dying algorithms
      on the registration path.
      Tested-by: NAndreas Steffen <andreas.steffen@strongswan.org>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      b8e15992
  8. 27 1月, 2009 2 次提交
    • J
      crypto: ccm - Fix handling of null assoc data · 516280e7
      Jarod Wilson 提交于
      Its a valid use case to have null associated data in a ccm vector, but
      this case isn't being handled properly right now.
      
      The following ccm decryption/verification test vector, using the
      rfc4309 implementation regularly triggers a panic, as will any
      other vector with null assoc data:
      
      * key: ab2f8a74b71cd2b1ff802e487d82f8b9
      * iv: c6fb7d800d13abd8a6b2d8
      * Associated Data: [NULL]
      * Tag Length: 8
      * input: d5e8939fc7892e2b
      
      The resulting panic looks like so:
      
      Unable to handle kernel paging request at ffff810064ddaec0 RIP: 
       [<ffffffff8864c4d7>] :ccm:get_data_to_compute+0x1a6/0x1d6
      PGD 8063 PUD 0 
      Oops: 0002 [1] SMP 
      last sysfs file: /module/libata/version
      CPU 0
      Modules linked in: crypto_tester_kmod(U) seqiv krng ansi_cprng chainiv rng ctr aes_generic aes_x86_64 ccm cryptomgr testmgr_cipher testmgr aead crypto_blkcipher crypto_a
      lgapi des ipv6 xfrm_nalgo crypto_api autofs4 hidp l2cap bluetooth nfs lockd fscache nfs_acl sunrpc ip_conntrack_netbios_ns ipt_REJECT xt_state ip_conntrack nfnetlink xt_
      tcpudp iptable_filter ip_tables x_tables dm_mirror dm_log dm_multipath scsi_dh dm_mod video hwmon backlight sbs i2c_ec button battery asus_acpi acpi_memhotplug ac lp sg 
      snd_intel8x0 snd_ac97_codec ac97_bus snd_seq_dummy snd_seq_oss joydev snd_seq_midi_event snd_seq snd_seq_device snd_pcm_oss snd_mixer_oss ide_cd snd_pcm floppy parport_p
      c shpchp e752x_edac snd_timer e1000 i2c_i801 edac_mc snd soundcore snd_page_alloc i2c_core cdrom parport serio_raw pcspkr ata_piix libata sd_mod scsi_mod ext3 jbd uhci_h
      cd ohci_hcd ehci_hcd
      Pid: 12844, comm: crypto-tester Tainted: G      2.6.18-128.el5.fips1 #1
      RIP: 0010:[<ffffffff8864c4d7>]  [<ffffffff8864c4d7>] :ccm:get_data_to_compute+0x1a6/0x1d6
      RSP: 0018:ffff8100134434e8  EFLAGS: 00010246
      RAX: 0000000000000000 RBX: ffff8100104898b0 RCX: ffffffffab6aea10
      RDX: 0000000000000010 RSI: ffff8100104898c0 RDI: ffff810064ddaec0
      RBP: 0000000000000000 R08: ffff8100104898b0 R09: 0000000000000000
      R10: ffff8100103bac84 R11: ffff8100104898b0 R12: ffff810010489858
      R13: ffff8100104898b0 R14: ffff8100103bac00 R15: 0000000000000000
      FS:  00002ab881adfd30(0000) GS:ffffffff803ac000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
      CR2: ffff810064ddaec0 CR3: 0000000012a88000 CR4: 00000000000006e0
      Process crypto-tester (pid: 12844, threadinfo ffff810013442000, task ffff81003d165860)
      Stack:  ffff8100103bac00 ffff8100104898e8 ffff8100134436f8 ffffffff00000000
       0000000000000000 ffff8100104898b0 0000000000000000 ffff810010489858
       0000000000000000 ffff8100103bac00 ffff8100134436f8 ffffffff8864c634
      Call Trace:
       [<ffffffff8864c634>] :ccm:crypto_ccm_auth+0x12d/0x140
       [<ffffffff8864cf73>] :ccm:crypto_ccm_decrypt+0x161/0x23a
       [<ffffffff88633643>] :crypto_tester_kmod:cavs_test_rfc4309_ccm+0x4a5/0x559
      [...]
      
      The above is from a RHEL5-based kernel, but upstream is susceptible too.
      
      The fix is trivial: in crypto/ccm.c:crypto_ccm_auth(), pctx->ilen contains
      whatever was in memory when pctx was allocated if assoclen is 0. The tested
      fix is to simply add an else clause setting pctx->ilen to 0 for the
      assoclen == 0 case, so that get_data_to_compute() doesn't try doing
      things its not supposed to.
      Signed-off-by: NJarod Wilson <jarod@redhat.com>
      Acked-by: NNeil Horman <nhorman@tuxdriver.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      516280e7
    • H
      crypto: blkcipher - Fix WARN_ON handling in walk_done · bac1b5c4
      Herbert Xu 提交于
      When we get left-over bits from a slow walk, it means that the
      underlying cipher has gone troppo.  However, as we're handling
      that case we should ensure that the caller terminates the walk.
      
      This patch does this by setting walk->nbytes to zero.
      Reported-by: NRoel Kluin <roel.kluin@gmail.com>
      Reported-by: NHuang Ying <ying.huang@intel.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      bac1b5c4
  9. 15 1月, 2009 1 次提交
  10. 07 1月, 2009 4 次提交
  11. 06 1月, 2009 1 次提交
  12. 25 12月, 2008 13 次提交