Skip to content
Snippets Groups Projects
  1. Nov 10, 2024
    •  's avatar
      crypto: rsassa-pkcs1 - Reinstate support for legacy protocols · a03a728e
        authored
      Commit 1e562dea ("crypto: rsassa-pkcs1 - Migrate to sig_alg backend")
      enforced that rsassa-pkcs1 sign/verify operations specify a hash
      algorithm.  That is necessary because per RFC 8017 sec 8.2, a hash
      algorithm identifier must be prepended to the hash before generating or
      verifying the signature ("Full Hash Prefix").
      
      However the commit went too far in that it changed user space behavior:
      KEYCTL_PKEY_QUERY system calls now return -EINVAL unless they specify a
      hash algorithm.  Intel Wireless Daemon (iwd) is one application issuing
      such system calls (for EAP-TLS).
      
      Closer analysis of the Embedded Linux Library (ell) used by iwd reveals
      that the problem runs even deeper:  When iwd uses TLS 1.1 or earlier, it
      not only queries for keys, but performs sign/verify operations without
      specifying a hash algorithm.  These legacy TLS versions concatenate an
      MD5 to a SHA-1 hash and omit the Full Hash Prefix:
      
      https://git.kernel.org/pub/scm/libs/ell/ell.git/tree/ell/tls-suites.c#n97
      
      TLS 1.1 was deprecated in 2021 by RFC 8996, but removal of support was
      inadvertent in this case.  It probably should be coordinated with iwd
      maintainers first.
      
      So reinstate support for such legacy protocols by defaulting to hash
      algorithm "none" which uses an empty Full Hash Prefix.
      
      If it is later on decided to remove TLS 1.1 support but still allow
      KEYCTL_PKEY_QUERY without a hash algorithm, that can be achieved by
      reverting the present commit and replacing it with the following patch:
      
      https://lore.kernel.org/r/ZxalYZwH5UiGX5uj@wunner.de/
      
      It's worth noting that Python's cryptography library gained support for
      such legacy use cases very recently, so they do seem to still be a thing.
      The Python developers identified IKE version 1 as another protocol
      omitting the Full Hash Prefix:
      
      https://github.com/pyca/cryptography/issues/10226
      https://github.com/pyca/cryptography/issues/5495
      
      
      
      The author of those issues, Zoltan Kelemen, spent considerable effort
      searching for test vectors but only found one in a 2019 blog post by
      Kevin Jones.  Add it to testmgr.h to verify correctness of this feature.
      
      Examination of wpa_supplicant as well as various IKE daemons (libreswan,
      strongswan, isakmpd, raccoon) has determined that none of them seems to
      use the kernel's Key Retention Service, so iwd is the only affected user
      space application known so far.
      
      Fixes: 1e562dea ("crypto: rsassa-pkcs1 - Migrate to sig_alg backend")
      Reported-by: default avatarKlara Modin <klarasmodin@gmail.com>
      Tested-by: default avatarKlara Modin <klarasmodin@gmail.com>
      Closes: https://lore.kernel.org/r/2ed09a22-86c0-4cf0-8bda-ef804ccb3413@gmail.com/
      
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      a03a728e
  2. Nov 02, 2024
  3. Oct 28, 2024
  4. Oct 26, 2024
    •  's avatar
      crypto: sig - Fix oops on KEYCTL_PKEY_QUERY for RSA keys · b358f23a
        authored
      
      Commit a2471684 ("crypto: ecdsa - Move X9.62 signature size
      calculation into template") introduced ->max_size() and ->digest_size()
      callbacks to struct sig_alg.  They return an algorithm's maximum
      signature size and digest size, respectively.
      
      For algorithms which lack these callbacks, crypto_register_sig() was
      amended to use the ->key_size() callback instead.
      
      However the commit neglected to also amend sig_register_instance().
      As a result, the ->max_size() and ->digest_size() callbacks remain NULL
      pointers if instances do not define them.  A KEYCTL_PKEY_QUERY system
      call results in an oops for such instances:
      
        BUG: kernel NULL pointer dereference, address: 0000000000000000
        Call Trace:
        software_key_query+0x169/0x370
        query_asymmetric_key+0x67/0x90
        keyctl_pkey_query+0x86/0x120
        __do_sys_keyctl+0x428/0x480
        do_syscall_64+0x4b/0x110
      
      The only instances affected by this are "pkcs1(rsa, ...)".
      
      Fix by moving the callback checks from crypto_register_sig() to
      sig_prepare_alg(), which is also invoked by sig_register_instance().
      Change the return type of sig_prepare_alg() from void to int to be able
      to return errors.  This matches other algorithm types, see e.g.
      aead_prepare_alg() or ahash_prepare_alg().
      
      Fixes: a2471684 ("crypto: ecdsa - Move X9.62 signature size calculation into template")
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      b358f23a
  5. Oct 19, 2024
    • Joachim Vandersmissen's avatar
      crypto: jitter - output full sample from test interface · 04305f83
      Joachim Vandersmissen authored
      
      The Jitter RNG time delta is computed based on the difference of two
      high-resolution, 64-bit time stamps. However, the test interface added
      in 69f1c387 only outputs the lower 32 bits of those time stamps. To
      ensure all information is available during the evaluation process of
      the Jitter RNG, output the full 64-bit time stamps.
      
      Any clients collecting data from the test interface will need to be
      updated to take this change into account.
      
      Additionally, the size of the temporary buffer that holds the data for
      user space has been clarified. Previously, this buffer was
      JENT_TEST_RINGBUFFER_SIZE (= 1000) bytes in size, however that value
      represents the number of samples held in the kernel space ring buffer,
      with each sample taking 8 (previously 4) bytes.
      
      Rather than increasing the size to allow for all 1000 samples to be
      output, we keep it at 1000 bytes, but clarify that this means at most
      125 64-bit samples will be output every time this interface is called.
      
      Reviewed-by: default avatarStephan Mueller <smueller@chronox.de>
      Signed-off-by: default avatarJoachim Vandersmissen <git@jvdsn.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      04305f83
  6. Oct 10, 2024
    • Herbert Xu's avatar
      crypto: testmgr - Hide ENOENT errors better · 6318fbe2
      Herbert Xu authored
      
      The previous patch removed the ENOENT warning at the point of
      allocation, but the overall self-test warning is still there.
      
      Fix all of them by returning zero as the test result.  This is
      safe because if the algorithm has gone away, then it cannot be
      marked as tested.
      
      Fixes: 4eded6d1 ("crypto: testmgr - Hide ENOENT errors")
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      6318fbe2
    • Herbert Xu's avatar
      crypto: api - Fix liveliness check in crypto_alg_tested · b81e286b
      Herbert Xu authored
      
      As algorithm testing is carried out without holding the main crypto
      lock, it is always possible for the algorithm to go away during the
      test.
      
      So before crypto_alg_tested updates the status of the tested alg,
      it checks whether it's still on the list of all algorithms.  This
      is inaccurate because it may be off the main list but still on the
      list of algorithms to be removed.
      
      Updating the algorithm status is safe per se as the larval still
      holds a reference to it.  However, killing spawns of other algorithms
      that are of lower priority is clearly a deficiency as it adds
      unnecessary churn.
      
      Fix the test by checking whether the algorithm is dead.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      b81e286b
  7. Oct 05, 2024
    •  's avatar
      crypto: ecrdsa - Fix signature size calculation · b9cbf691
        authored
      
      software_key_query() returns the curve size as maximum signature size
      for ecrdsa.  However it should return twice as much.
      
      It's only the maximum signature size that seems to be off.  The maximum
      digest size is likewise set to the curve size, but that's correct as it
      matches the checks in ecrdsa_set_pub_key() and ecrdsa_verify().
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      b9cbf691
    •  's avatar
      crypto: ecdsa - Support P1363 signature decoding · b0416386
        authored
      Alternatively to the X9.62 encoding of ecdsa signatures, which uses
      ASN.1 and is already supported by the kernel, there's another common
      encoding called P1363.  It stores r and s as the concatenation of two
      big endian, unsigned integers.  The name originates from IEEE P1363.
      
      Add a P1363 template in support of the forthcoming SPDM library
      (Security Protocol and Data Model) for PCI device authentication.
      
      P1363 is prescribed by SPDM 1.2.1 margin no 44:
      
         "For ECDSA signatures, excluding SM2, in SPDM, the signature shall be
          the concatenation of r and s.  The size of r shall be the size of
          the selected curve.  Likewise, the size of s shall be the size of
          the selected curve.  See BaseAsymAlgo in NEGOTIATE_ALGORITHMS for
          the size of r and s.  The byte order for r and s shall be in big
          endian order.  When placing ECDSA signatures into an SPDM signature
          field, r shall come first followed by s."
      
      Link: https://www.dmtf.org/sites/default/files/standards/documents/DSP0274_1.2.1.pdf
      
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      b0416386
    •  's avatar
      crypto: ecdsa - Move X9.62 signature size calculation into template · a2471684
        authored
      software_key_query() returns the maximum signature and digest size for a
      given key to user space.  When it only supported RSA keys, calculating
      those sizes was trivial as they were always equivalent to the key size.
      
      However when ECDSA was added, the function grew somewhat complicated
      calculations which take the ASN.1 encoding and curve into account.
      This doesn't scale well and adjusting the calculations is easily
      forgotten when adding support for new encodings or curves.  In fact,
      when NIST P521 support was recently added, the function was initially
      not amended:
      
      https://lore.kernel.org/all/b749d5ee-c3b8-4cbd-b252-7773e4536e07@linux.ibm.com/
      
      
      
      Introduce a ->max_size() callback to struct sig_alg and take advantage
      of it to move the signature size calculations to ecdsa-x962.c.
      
      Introduce a ->digest_size() callback to struct sig_alg and move the
      maximum ECDSA digest size to ecdsa.c.  It is common across ecdsa-x962.c
      and the upcoming ecdsa-p1363.c and thus inherited by both of them.
      
      For all other algorithms, continue using the key size as maximum
      signature and digest size.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      a2471684
    •  's avatar
      crypto: sig - Rename crypto_sig_maxsize() to crypto_sig_keysize() · 221f0041
        authored
      
      crypto_sig_maxsize() is a bit of a misnomer as it doesn't return the
      maximum signature size, but rather the key size.
      
      Rename it as well as all implementations of the ->max_size callback.
      A subsequent commit introduces a crypto_sig_maxsize() function which
      returns the actual maximum signature size.
      
      While at it, change the return type of crypto_sig_keysize() from int to
      unsigned int for consistency with crypto_akcipher_maxsize().  None of
      the callers checks for a negative return value and an error condition
      can always be indicated by returning zero.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      221f0041
    •  's avatar
      crypto: ecdsa - Move X9.62 signature decoding into template · d6793ff9
        authored
      Unlike the rsa driver, which separates signature decoding and
      signature verification into two steps, the ecdsa driver does both in one.
      
      This restricts users to the one signature format currently supported
      (X9.62) and prevents addition of others such as P1363, which is needed
      by the forthcoming SPDM library (Security Protocol and Data Model) for
      PCI device authentication.
      
      Per Herbert's suggestion, change ecdsa to use a "raw" signature encoding
      and then implement X9.62 and P1363 as templates which convert their
      respective encodings to the raw one.  One may then specify
      "x962(ecdsa-nist-XXX)" or "p1363(ecdsa-nist-XXX)" to pick the encoding.
      
      The present commit moves X9.62 decoding to a template.  A separate
      commit is going to introduce another template for P1363 decoding.
      
      The ecdsa driver internally represents a signature as two u64 arrays of
      size ECC_MAX_BYTES.  This appears to be the most natural choice for the
      raw format as it can directly be used for verification without having to
      further decode signature data or copy it around.
      
      Repurpose all the existing test vectors for "x962(ecdsa-nist-XXX)" and
      create a duplicate of them to test the raw encoding.
      
      Link: https://lore.kernel.org/all/ZoHXyGwRzVvYkcTP@gondor.apana.org.au/
      
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Tested-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      d6793ff9
    •  's avatar
      crypto: ecdsa - Avoid signed integer overflow on signature decoding · 3b0565c7
        authored
      
      When extracting a signature component r or s from an ASN.1-encoded
      integer, ecdsa_get_signature_rs() subtracts the expected length
      "bufsize" from the ASN.1 length "vlen" (both of unsigned type size_t)
      and stores the result in "diff" (of signed type ssize_t).
      
      This results in a signed integer overflow if vlen > SSIZE_MAX + bufsize.
      
      The kernel is compiled with -fno-strict-overflow, which implies -fwrapv,
      meaning signed integer overflow is not undefined behavior.  And the
      function does check for overflow:
      
             if (-diff >= bufsize)
                     return -EINVAL;
      
      So the code is fine in principle but not very obvious.  In the future it
      might trigger a false-positive with CONFIG_UBSAN_SIGNED_WRAP=y.
      
      Avoid by comparing the two unsigned variables directly and erroring out
      if "vlen" is too large.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      3b0565c7
    •  's avatar
      crypto: sig - Move crypto_sig_*() API calls to include file · 5ba29667
        authored
      
      The crypto_sig_*() API calls lived in sig.c so far because they needed
      access to struct crypto_sig_type:  This was necessary to differentiate
      between signature algorithms that had already been migrated from
      crypto_akcipher to crypto_sig and those that hadn't yet.
      
      Now that all algorithms have been migrated, the API calls can become
      static inlines in <crypto/sig.h> to mimic what <crypto/akcipher.h> is
      doing.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      5ba29667
    •  's avatar
      crypto: akcipher - Drop sign/verify operations · 6b34562f
        authored
      
      A sig_alg backend has just been introduced and all asymmetric
      sign/verify algorithms have been migrated to it.
      
      The sign/verify operations can thus be dropped from akcipher_alg.
      It is now purely for asymmetric encrypt/decrypt.
      
      Move struct crypto_akcipher_sync_data from internal.h to akcipher.c and
      unexport crypto_akcipher_sync_{prep,post}():  They're no longer used by
      sig.c but only locally in akcipher.c.
      
      In crypto_akcipher_sync_{prep,post}(), drop various NULL pointer checks
      for data->dst as they were only necessary for the verify operation.
      
      In the crypto_sig_*() API calls, remove the forks that were necessary
      while algorithms were converted from crypto_akcipher to crypto_sig
      one by one.
      
      In struct akcipher_testvec, remove the "params", "param_len" and "algo"
      elements as they were only needed for the ecrdsa verify operation.
      Remove corresponding dead code from test_akcipher_one() as well.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      6b34562f
    •  's avatar
      crypto: rsassa-pkcs1 - Avoid copying hash prefix · 778206d8
        authored
      
      When constructing the EMSA-PKCS1-v1_5 padding for the sign operation,
      a buffer for the padding is allocated and the Full Hash Prefix is copied
      into it.  The padding is then passed to the RSA decrypt operation as an
      sglist entry which is succeeded by a second sglist entry for the hash.
      
      Actually copying the hash prefix around is completely unnecessary.
      It can simply be referenced from a third sglist entry which sits
      in-between the padding and the digest.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      778206d8
    •  's avatar
      crypto: rsassa-pkcs1 - Harden digest length verification · 5e00481b
        authored
      
      The RSASSA-PKCS1-v1_5 sign operation currently only checks that the
      digest length is less than "key_size - hash_prefix->size - 11".
      The verify operation merely checks that it's more than zero.
      
      Actually the precise digest length is known because the hash algorithm
      is specified upon instance creation and the digest length is encoded
      into the final byte of the hash algorithm's Full Hash Prefix.
      
      So check for the exact digest length rather than solely relying on
      imprecise maximum/minimum checks.
      
      Keep the maximum length check for the sign operation as a safety net,
      but drop the now unnecessary minimum check for the verify operation.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      5e00481b
    •  's avatar
      crypto: rsassa-pkcs1 - Migrate to sig_alg backend · 1e562dea
        authored
      
      A sig_alg backend has just been introduced with the intent of moving all
      asymmetric sign/verify algorithms to it one by one.
      
      Migrate the sign/verify operations from rsa-pkcs1pad.c to a separate
      rsassa-pkcs1.c which uses the new backend.
      
      Consequently there are now two templates which build on the "rsa"
      akcipher_alg:
      
      * The existing "pkcs1pad" template, which is instantiated as an
        akcipher_instance and retains the encrypt/decrypt operations of
        RSAES-PKCS1-v1_5 (RFC 8017 sec 7.2).
      
      * The new "pkcs1" template, which is instantiated as a sig_instance
        and contains the sign/verify operations of RSASSA-PKCS1-v1_5
        (RFC 8017 sec 8.2).
      
      In a separate step, rsa-pkcs1pad.c could optionally be renamed to
      rsaes-pkcs1.c for clarity.  Additional "oaep" and "pss" templates
      could be added for RSAES-OAEP and RSASSA-PSS.
      
      Note that it's currently allowed to allocate a "pkcs1pad(rsa)" transform
      without specifying a hash algorithm.  That makes sense if the transform
      is only used for encrypt/decrypt and continues to be supported.  But for
      sign/verify, such transforms previously did not insert the Full Hash
      Prefix into the padding.  The resulting message encoding was incompliant
      with EMSA-PKCS1-v1_5 (RFC 8017 sec 9.2) and therefore nonsensical.
      
      From here on in, it is no longer allowed to allocate a transform without
      specifying a hash algorithm if the transform is used for sign/verify
      operations.  This simplifies the code because the insertion of the Full
      Hash Prefix is no longer optional, so various "if (digest_info)" clauses
      can be removed.
      
      There has been a previous attempt to forbid transform allocation without
      specifying a hash algorithm, namely by commit c0d20d22 ("crypto:
      rsa-pkcs1pad - Require hash to be present").  It had to be rolled back
      with commit b3a8c8a5 ("crypto: rsa-pkcs1pad: Allow hash to be
      optional [ver #2]"), presumably because it broke allocation of a
      transform which was solely used for encrypt/decrypt, not sign/verify.
      Avoid such breakage by allowing transform allocation for encrypt/decrypt
      with and without specifying a hash algorithm (and simply ignoring the
      hash algorithm in the former case).
      
      So again, specifying a hash algorithm is now mandatory for sign/verify,
      but optional and ignored for encrypt/decrypt.
      
      The new sig_alg API uses kernel buffers instead of sglists, which
      avoids the overhead of copying signature and digest from sglists back
      into kernel buffers.  rsassa-pkcs1.c is thus simplified quite a bit.
      
      sig_alg is always synchronous, whereas the underlying "rsa" akcipher_alg
      may be asynchronous.  So await the result of the akcipher_alg, similar
      to crypto_akcipher_sync_{en,de}crypt().
      
      As part of the migration, rename "rsa_digest_info" to "hash_prefix" to
      adhere to the spec language in RFC 9580.  Otherwise keep the code
      unmodified wherever possible to ease reviewing and bisecting.  Leave
      several simplification and hardening opportunities to separate commits.
      
      rsassa-pkcs1.c uses modern __free() syntax for allocation of buffers
      which need to be freed by kfree_sensitive(), hence a DEFINE_FREE()
      clause for kfree_sensitive() is introduced herein as a byproduct.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      1e562dea
    •  's avatar
      crypto: rsa-pkcs1pad - Deduplicate set_{pub,priv}_key callbacks · 7964b0d4
        authored
      
      pkcs1pad_set_pub_key() and pkcs1pad_set_priv_key() are almost identical.
      
      The upcoming migration of sign/verify operations from rsa-pkcs1pad.c
      into a separate crypto_template will require another copy of the exact
      same functions.  When RSASSA-PSS and RSAES-OAEP are introduced, each
      will need yet another copy.
      
      Deduplicate the functions into a single one which lives in a common
      header file for reuse by RSASSA-PKCS1-v1_5, RSASSA-PSS and RSAES-OAEP.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      7964b0d4
    •  's avatar
      crypto: ecrdsa - Migrate to sig_alg backend · ae117924
        authored
      
      A sig_alg backend has just been introduced with the intent of moving all
      asymmetric sign/verify algorithms to it one by one.
      
      Migrate ecrdsa.c to the new backend.
      
      One benefit of the new API is the use of kernel buffers instead of
      sglists, which avoids the overhead of copying signature and digest
      sglists back into kernel buffers.  ecrdsa.c is thus simplified quite
      a bit.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      ae117924
    •  's avatar
      crypto: ecdsa - Migrate to sig_alg backend · ef132350
        authored
      
      A sig_alg backend has just been introduced with the intent of moving all
      asymmetric sign/verify algorithms to it one by one.
      
      Migrate ecdsa.c to the new backend.
      
      One benefit of the new API is the use of kernel buffers instead of
      sglists, which avoids the overhead of copying signature and digest
      sglists back into kernel buffers.  ecdsa.c is thus simplified quite
      a bit.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      ef132350
    •  's avatar
      crypto: sig - Introduce sig_alg backend · 65c4c93c
        authored
      Commit 6cb8815f ("crypto: sig - Add interface for sign/verify")
      began a transition of asymmetric sign/verify operations from
      crypto_akcipher to a new crypto_sig frontend.
      
      Internally, the crypto_sig frontend still uses akcipher_alg as backend,
      however:
      
         "The link between sig and akcipher is meant to be temporary.  The
          plan is to create a new low-level API for sig and then migrate
          the signature code over to that from akcipher."
          https://lore.kernel.org/r/ZrG6w9wsb-iiLZIF@gondor.apana.org.au/
      
         "having a separate alg for sig is definitely where we want to
          be since there is very little that the two types actually share."
          https://lore.kernel.org/r/ZrHlpz4qnre0zWJO@gondor.apana.org.au/
      
      
      
      Take the next step of that migration and augment the crypto_sig frontend
      with a sig_alg backend to which all algorithms can be moved.
      
      During the migration, there will briefly be signature algorithms that
      are still based on crypto_akcipher, whilst others are already based on
      crypto_sig.  Allow for that by building a fork into crypto_sig_*() API
      calls (i.e. crypto_sig_maxsize() and friends) such that one of the two
      backends is selected based on the transform's cra_type.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      65c4c93c
    •  's avatar
      crypto: ecdsa - Drop unused test vector elements · beea3201
        authored
      The ECDSA test vectors contain "params", "param_len" and "algo" elements
      even though ecdsa.c doesn't make any use of them.  The only algorithm
      implementation using those elements is ecrdsa.c.
      
      Drop the unused test vector elements.
      
      For the curious, "params" is an ASN.1 SEQUENCE of OID_id_ecPublicKey
      and a second OID identifying the curve.  For example:
      
          "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48"
          "\xce\x3d\x03\x01\x01"
      
      ... decodes to:
      
          SEQUENCE (OID_id_ecPublicKey, OID_id_prime192v1)
      
      The curve OIDs used in those "params" elements are unsurprisingly:
      
          OID_id_prime192v1 (2a8648ce3d030101)
          OID_id_prime256v1 (2a8648ce3d030107)
          OID_id_ansip384r1 (2b81040022)
          OID_id_ansip521r1 (2b81040023)
      
      Those are just different names for secp192r1, secp256r1, secp384r1 and
      secp521r1, respectively, per RFC 8422 appendix A:
      https://www.rfc-editor.org/rfc/rfc8422#appendix-A
      
      
      
      The entries for secp384r1 and secp521r1 curves contain a useful code
      comment calling out the curve and hash.  Add analogous code comments
      to secp192r1 and secp256r1 curve entries.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      beea3201
  8. Oct 03, 2024
  9. Oct 02, 2024
    • Al Viro's avatar
      move asm/unaligned.h to linux/unaligned.h · 5f60d5f6
      Al Viro authored
      asm/unaligned.h is always an include of asm-generic/unaligned.h;
      might as well move that thing to linux/unaligned.h and include
      that - there's nothing arch-specific in that header.
      
      auto-generated by the following:
      
      for i in `git grep -l -w asm/unaligned.h`; do
      	sed -i -e "s/asm\/unaligned.h/linux\/unaligned.h/" $i
      done
      for i in `git grep -l -w asm-generic/unaligned.h`; do
      	sed -i -e "s/asm-generic\/unaligned.h/linux\/unaligned.h/" $i
      done
      git mv include/asm-generic/unaligned.h include/linux/unaligned.h
      git mv tools/include/asm-generic/unaligned.h tools/include/linux/unaligned.h
      sed -i -e "/unaligned.h/d" include/asm-generic/Kbuild
      sed -i -e "s/__ASM_GENERIC/__LINUX/" include/linux/unaligned.h tools/include/linux/unaligned.h
      5f60d5f6
  10. Sep 20, 2024
  11. Sep 13, 2024
  12. Sep 06, 2024
    • Herbert Xu's avatar
      crypto: testmgr - Hide ENOENT errors · 4eded6d1
      Herbert Xu authored
      
      When a crypto algorithm with a higher priority is registered, it
      kills the spawns of all lower-priority algorithms.  Thus it is to
      be expected for an algorithm to go away at any time, even during
      a self-test.  This is now much more common with asynchronous testing.
      
      Remove the printk when an ENOENT is encountered during a self-test.
      This is not really an error since the algorithm being tested is no
      longer there (i.e., it didn't fail the test which is what we care
      about).
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      4eded6d1
    • Herbert Xu's avatar
      crypto: algboss - Pass instance creation error up · 795f85fc
      Herbert Xu authored
      
      Pass any errors we get during instance creation up through the
      larval.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      795f85fc
    • Herbert Xu's avatar
      crypto: api - Fix generic algorithm self-test races · e7a4142b
      Herbert Xu authored
      
      On Fri, Aug 30, 2024 at 10:51:54AM -0700, Eric Biggers wrote:
      >
      > Given below in defconfig form, use 'make olddefconfig' to apply.  The failures
      > are nondeterministic and sometimes there are different ones, for example:
      >
      > [    0.358017] alg: skcipher: failed to allocate transform for cbc(twofish-generic): -2
      > [    0.358365] alg: self-tests for cbc(twofish) using cbc(twofish-generic) failed (rc=-2)
      > [    0.358535] alg: skcipher: failed to allocate transform for cbc(camellia-generic): -2
      > [    0.358918] alg: self-tests for cbc(camellia) using cbc(camellia-generic) failed (rc=-2)
      > [    0.371533] alg: skcipher: failed to allocate transform for xts(ecb(aes-generic)): -2
      > [    0.371922] alg: self-tests for xts(aes) using xts(ecb(aes-generic)) failed (rc=-2)
      >
      > Modules are not enabled, maybe that matters (I haven't checked yet).
      
      Yes I think that was the key.  This triggers a massive self-test
      run which executes in parallel and reveals a few race conditions
      in the system.  I think it boils down to the following scenario:
      
      Base algorithm X-generic, X-optimised
      Template Y
      Optimised algorithm Y-X-optimised
      
      Everything gets registered, and then the self-tests are started.
      When Y-X-optimised gets tested, it requests the creation of the
      generic Y(X-generic).  Which then itself undergoes testing.
      
      The race is that after Y(X-generic) gets registered, but just
      before it gets tested, X-optimised finally finishes self-testing
      which then causes all spawns of X-generic to be destroyed.  So
      by the time the self-test for Y(X-generic) comes along, it can
      no longer find the algorithm.  This error then bubbles up all
      the way up to the self-test of Y-X-optimised which then fails.
      
      Note that there is some complexity that I've omitted here because
      when the generic self-test fails to find Y(X-generic) it actually
      triggers the construction of it again which then fails for various
      other reasons (these are not important because the construction
      should *not* be triggered at this point).
      
      So in a way the error is expected, and we should probably remove
      the pr_err for the case where ENOENT is returned for the algorithm
      that we're currently testing.
      
      The solution is two-fold.  First when an algorithm undergoes
      self-testing it should not trigger its construction.  Secondly
      if an instance larval fails to materialise due to it being destroyed
      by a more optimised algorithm coming along, it should obviously
      retry the construction.
      
      Remove the check in __crypto_alg_lookup that stops a larval from
      matching new requests based on differences in the mask.  It is better
      to block new requests even if it is wrong and then simply retry the
      lookup.  If this ends up being the wrong larval it will sort iself
      out during the retry.
      
      Reduce the CRYPTO_ALG_TYPE_MASK bits in type during larval creation
      as otherwise LSKCIPHER algorithms may not match SKCIPHER larvals.
      
      Also block the instance creation during self-testing in the function
      crypto_larval_lookup by checking for CRYPTO_ALG_TESTED in the mask
      field.
      
      Finally change the return value when crypto_alg_lookup fails in
      crypto_larval_wait to EAGAIN to redo the lookup.
      
      Fixes: 37da5d0f ("crypto: api - Do not wait for tests during registration")
      Reported-by: default avatarEric Biggers <ebiggers@kernel.org>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      e7a4142b
  13. Aug 30, 2024
  14. Aug 24, 2024
    • Herbert Xu's avatar
      crypto: simd - Do not call crypto_alloc_tfm during registration · 3c44d31c
      Herbert Xu authored
      
      Algorithm registration is usually carried out during module init,
      where as little work as possible should be carried out.  The SIMD
      code violated this rule by allocating a tfm, this then triggers a
      full test of the algorithm which may dead-lock in certain cases.
      
      SIMD is only allocating the tfm to get at the alg object, which is
      in fact already available as it is what we are registering.  Use
      that directly and remove the crypto_alloc_tfm call.
      
      Also remove some obsolete and unused SIMD API.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      3c44d31c
    • Herbert Xu's avatar
      crypto: api - Do not wait for tests during registration · 37da5d0f
      Herbert Xu authored
      
      As registration is usually carried out during module init, this
      is a context where as little work as possible should be carried
      out.  Testing may trigger module loads of underlying components,
      which could even lead back to the module that is registering at
      the moment.  This may lead to dead-locks outside of the Crypto API.
      
      Avoid this by not waiting for the tests to complete.  They will
      be scheduled but completion will be asynchronous.  Any users will
      still wait for completion.
      
      Reported-by: default avatarRussell King <linux@armlinux.org.uk>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      37da5d0f
    • Herbert Xu's avatar
      crypto: api - Remove instance larval fulfilment · 96ad5955
      Herbert Xu authored
      
      In order to allow testing to complete asynchronously after the
      registration process, instance larvals need to complete prior
      to having a test result.  Support this by redoing the lookup for
      instance larvals after completion.   This should locate the pending
      test larval and then repeat the wait on that (if it is still pending).
      
      As the lookup is now repeated there is no longer any need to compute
      the fulfilment status and all that code can be removed.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      96ad5955
    • Stephan Mueller's avatar
      crypto: jitter - set default OSR to 3 · 95a798d2
      Stephan Mueller authored
      
      The user space Jitter RNG library uses the oversampling rate of 3 which
      implies that each time stamp is credited with 1/3 bit of entropy. To
      obtain 256 bits of entropy, 768 time stamps need to be sampled. The
      increase in OSR is applied based on a report where the Jitter RNG is
      used on a system exhibiting a challenging environment to collect
      entropy.
      
      This OSR default value is now applied to the Linux kernel version of
      the Jitter RNG as well.
      
      The increase in the OSR from 1 to 3 also implies that the Jitter RNG is
      now slower by default.
      
      Reported-by: default avatarJeff Barnes <jeffbarnes@microsoft.com>
      Signed-off-by: default avatarStephan Mueller <smueller@chronox.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      95a798d2
Loading