05 Dec, 2014

1 commit

  • AEAD requires the caller to specify the following information separate
    from the data stream. This information allows the AEAD interface handler
    to identify the AAD, ciphertext/plaintext and the authentication tag:

    * Associated authentication data of arbitrary length and
    length

    * Length of authentication tag for encryption

    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    Stephan Mueller
     

17 Nov, 2014

1 commit


13 Nov, 2014

4 commits


14 Oct, 2014

1 commit

  • Add a macro which replaces the use of a Variable Length Array In Struct (VLAIS)
    with a C99 compliant equivalent. This macro instead allocates the appropriate
    amount of memory using an char array.

    The new code can be compiled with both gcc and clang.

    struct shash_desc contains a flexible array member member ctx declared with
    CRYPTO_MINALIGN_ATTR, so sizeof(struct shash_desc) aligns the beginning
    of the array declared after struct shash_desc with long long.

    No trailing padding is required because it is not a struct type that can
    be used in an array.

    The CRYPTO_MINALIGN_ATTR is required so that desc is aligned with long long
    as would be the case for a struct containing a member with
    CRYPTO_MINALIGN_ATTR.

    If you want to get to the ctx at the end of the shash_desc as before you can do
    so using shash_desc_ctx(shash)

    Signed-off-by: Behan Webster
    Reviewed-by: Mark Charlebois
    Acked-by: Herbert Xu
    Cc: Michał Mirosław

    Behan Webster
     

12 Oct, 2014

1 commit

  • Pull security subsystem updates from James Morris.

    Mostly ima, selinux, smack and key handling updates.

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (65 commits)
    integrity: do zero padding of the key id
    KEYS: output last portion of fingerprint in /proc/keys
    KEYS: strip 'id:' from ca_keyid
    KEYS: use swapped SKID for performing partial matching
    KEYS: Restore partial ID matching functionality for asymmetric keys
    X.509: If available, use the raw subjKeyId to form the key description
    KEYS: handle error code encoded in pointer
    selinux: normalize audit log formatting
    selinux: cleanup error reporting in selinux_nlmsg_perm()
    KEYS: Check hex2bin()'s return when generating an asymmetric key ID
    ima: detect violations for mmaped files
    ima: fix race condition on ima_rdwr_violation_check and process_measurement
    ima: added ima_policy_flag variable
    ima: return an error code from ima_add_boot_aggregate()
    ima: provide 'ima_appraise=log' kernel option
    ima: move keyring initialization to ima_init()
    PKCS#7: Handle PKCS#7 messages that contain no X.509 certs
    PKCS#7: Better handling of unsupported crypto
    KEYS: Overhaul key identification when searching for asymmetric keys
    KEYS: Implement binary asymmetric key ID handling
    ...

    Linus Torvalds
     

06 Oct, 2014

1 commit


17 Sep, 2014

1 commit

  • Make use of the new match string preparsing to overhaul key identification
    when searching for asymmetric keys. The following changes are made:

    (1) Use the previously created asymmetric_key_id struct to hold the following
    key IDs derived from the X.509 certificate or PKCS#7 message:

    id: serial number + issuer
    skid: subjKeyId + subject
    authority: authKeyId + issuer

    (2) Replace the hex fingerprint attached to key->type_data[1] with an
    asymmetric_key_ids struct containing the id and the skid (if present).

    (3) Make the asymmetric_type match data preparse select one of two searches:

    (a) An iterative search for the key ID given if prefixed with "id:". The
    prefix is expected to be followed by a hex string giving the ID to
    search for. The criterion key ID is checked against all key IDs
    recorded on the key.

    (b) A direct search if the key ID is not prefixed with "id:". This will
    look for an exact match on the key description.

    (4) Make x509_request_asymmetric_key() take a key ID. This is then converted
    into "id:" and passed into keyring_search() where match preparsing
    will turn it back into a binary ID.

    (5) X.509 certificate verification then takes the authority key ID and looks
    up a key that matches it to find the public key for the certificate
    signature.

    (6) PKCS#7 certificate verification then takes the id key ID and looks up a
    key that matches it to find the public key for the signed information
    block signature.

    Additional changes:

    (1) Multiple subjKeyId and authKeyId values on an X.509 certificate cause the
    cert to be rejected with -EBADMSG.

    (2) The 'fingerprint' ID is gone. This was primarily intended to convey PGP
    public key fingerprints. If PGP is supported in future, this should
    generate a key ID that carries the fingerprint.

    (3) Th ca_keyid= kernel command line option is now converted to a key ID and
    used to match the authority key ID. Possibly this should only match the
    actual authKeyId part and not the issuer as well.

    Signed-off-by: David Howells
    Acked-by: Vivek Goyal

    David Howells
     

26 Aug, 2014

1 commit


25 Aug, 2014

2 commits

  • SP800-90A mandates several hard-coded values. The old drbg_cores allows
    the setting of these values per DRBG implementation. However, due to the
    hard requirement of SP800-90A, these values are now returned globally
    for each DRBG.

    The ability to set such values per DRBG is therefore removed.

    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    Stephan Mueller
     
  • This patch introduces the multi-buffer crypto daemon which is responsible
    for submitting crypto jobs in a work queue to the responsible multi-buffer
    crypto algorithm. The idea of the multi-buffer algorihtm is to put
    data streams from multiple jobs in a wide (AVX2) register and then
    take advantage of SIMD instructions to do crypto computation on several
    buffers simultaneously.

    The multi-buffer crypto daemon is also responsbile for flushing the
    remaining buffers to complete the computation if no new buffers arrive
    for a while.

    Signed-off-by: Tim Chen
    Signed-off-by: Herbert Xu

    Tim Chen
     

06 Aug, 2014

1 commit

  • Pull security subsystem updates from James Morris:
    "In this release:

    - PKCS#7 parser for the key management subsystem from David Howells
    - appoint Kees Cook as seccomp maintainer
    - bugfixes and general maintenance across the subsystem"

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (94 commits)
    X.509: Need to export x509_request_asymmetric_key()
    netlabel: shorter names for the NetLabel catmap funcs/structs
    netlabel: fix the catmap walking functions
    netlabel: fix the horribly broken catmap functions
    netlabel: fix a problem when setting bits below the previously lowest bit
    PKCS#7: X.509 certificate issuer and subject are mandatory fields in the ASN.1
    tpm: simplify code by using %*phN specifier
    tpm: Provide a generic means to override the chip returned timeouts
    tpm: missing tpm_chip_put in tpm_get_random()
    tpm: Properly clean sysfs entries in error path
    tpm: Add missing tpm_do_selftest to ST33 I2C driver
    PKCS#7: Use x509_request_asymmetric_key()
    Revert "selinux: fix the default socket labeling in sock_graft()"
    X.509: x509_request_asymmetric_keys() doesn't need string length arguments
    PKCS#7: fix sparse non static symbol warning
    KEYS: revert encrypted key change
    ima: add support for measuring and appraising firmware
    firmware_class: perform new LSM checks
    security: introduce kernel_fw_from_file hook
    PKCS#7: Missing inclusion of linux/err.h
    ...

    Linus Torvalds
     

01 Aug, 2014

1 commit


29 Jul, 2014

1 commit

  • pkcs7_request_asymmetric_key() and x509_request_asymmetric_key() do the same
    thing, the latter being a copy of the former created by the IMA folks, so drop
    the PKCS#7 version as the X.509 location is more general.

    Whilst we're at it, rename the arguments of x509_request_asymmetric_key() to
    better reflect what the values being passed in are intended to match on an
    X.509 cert.

    Signed-off-by: David Howells
    Acked-by: Mimi Zohar

    David Howells
     

08 Jul, 2014

4 commits

  • The current locking approach of the DRBG tries to keep the protected
    code paths very minimal. It is therefore possible that two threads query
    one DRBG instance at the same time. When thread A requests random
    numbers, a shadow copy of the DRBG state is created upon which the
    request for A is processed. After finishing the state for A's request is
    merged back into the DRBG state. If now thread B requests random numbers
    from the same DRBG after the request for thread A is received, but
    before A's shadow state is merged back, the random numbers for B will be
    identical to the ones for A. Please note that the time window is very
    small for this scenario.

    To prevent that there is even a theoretical chance for thread A and B
    having the same DRBG state, the current time stamp is provided as
    additional information string for each new request.

    The addition of the time stamp as additional information string implies
    that now all generate functions must be capable to process a linked
    list with additional information strings instead of a scalar.

    CC: Rafael Aquini
    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    Stephan Mueller
     
  • Find the intersection between the X.509 certificate chain contained in a PKCS#7
    message and a set of keys that we already know and trust.

    Signed-off-by: David Howells
    Acked-by: Vivek Goyal
    Reviewed-by: Kees Cook

    David Howells
     
  • Find the appropriate key in the PKCS#7 key list and verify the signature with
    it. There may be several keys in there forming a chain. Any link in that
    chain or the root of that chain may be in our keyrings.

    Signed-off-by: David Howells
    Acked-by: Vivek Goyal
    Reviewed-by: Kees Cook

    David Howells
     
  • Implement a parser for a PKCS#7 signed-data message as described in part of
    RFC 2315.

    Signed-off-by: David Howells
    Acked-by: Vivek Goyal
    Reviewed-by: Kees Cook

    David Howells
     

04 Jul, 2014

1 commit

  • The DRBG-style linked list to manage input data that is fed into the
    cipher invocations is replaced with the kernel linked list
    implementation.

    The change is transparent to users of the interfaces offered by the
    DRBG. Therefore, no changes to the testmgr code is needed.

    Reported-by: kbuild test robot
    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    Stephan Mueller
     

20 Jun, 2014

4 commits

  • Patch adds x86_64 assembly implementation of Triple DES EDE cipher algorithm.
    Two assembly implementations are provided. First is regular 'one-block at
    time' encrypt/decrypt function. Second is 'three-blocks at time' function that
    gains performance increase on out-of-order CPUs.

    tcrypt test results:

    Intel Core i5-4570:

    des3_ede-asm vs des3_ede-generic:
    size ecb-enc ecb-dec cbc-enc cbc-dec ctr-enc ctr-dec
    16B 1.21x 1.22x 1.27x 1.36x 1.25x 1.25x
    64B 1.98x 1.96x 1.23x 2.04x 2.01x 2.00x
    256B 2.34x 2.37x 1.21x 2.40x 2.38x 2.39x
    1024B 2.50x 2.47x 1.22x 2.51x 2.52x 2.51x
    8192B 2.51x 2.53x 1.21x 2.56x 2.54x 2.55x

    Signed-off-by: Jussi Kivilinna
    Signed-off-by: Herbert Xu

    Jussi Kivilinna
     
  • The header file includes the definition of:

    * DRBG data structures with
    - struct drbg_state as main structure
    - struct drbg_core referencing the backend ciphers
    - struct drbg_state_ops callbach handlers for specific code
    supporting the Hash, HMAC, CTR DRBG implementations
    - struct drbg_conc defining a linked list for input data
    - struct drbg_test_data holding the test "entropy" data for CAVS
    testing and testmgr.c
    - struct drbg_gen allowing test data, additional information
    string and personalization string data to be funneled through
    the kernel crypto API -- the DRBG requires additional
    parameters when invoking the reset and random number
    generation requests than intended by the kernel crypto API

    * wrapper function to the kernel crypto API functions using struct
    drbg_gen to pass through all data needed for DRBG

    * wrapper functions to kernel crypto API functions usable for testing
    code to inject test_data into the DRBG as needed by CAVS testing and
    testmgr.c.

    * DRBG flags required for the operation of the DRBG and for selecting
    the particular DRBG type and backend cipher

    * getter functions for data from struct drbg_core

    Signed-off-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    Stephan Mueller
     
  • Use skcipher_givcrypt_cast(crypto_dequeue_request(queue)) instead, which
    does the same thing in much cleaner way. The skcipher_givcrypt_cast()
    actually uses container_of() instead of messing around with offsetof()
    too.

    Signed-off-by: Marek Vasut
    Reported-by: Arnd Bergmann
    Cc: Pantelis Antoniou
    Signed-off-by: Herbert Xu

    Marek Vasut
     
  • It makes no sense for crypto_yield() to be defined in scatterwalk.h ,
    move it into algapi.h as it's an internal function to crypto API.

    Signed-off-by: Marek Vasut
    Signed-off-by: Herbert Xu

    Marek Vasut
     

21 May, 2014

1 commit

  • Although the existing hash walk interface has already been used
    by a number of ahash crypto drivers, it turns out that none of
    them were really asynchronous. They were all essentially polling
    for completion.

    That's why nobody has noticed until now that the walk interface
    couldn't work with a real asynchronous driver since the memory
    is mapped using kmap_atomic.

    As we now have a use-case for a real ahash implementation on x86,
    this patch creates a minimal ahash walk interface. Basically it
    just calls kmap instead of kmap_atomic and does away with the
    crypto_yield call. Real ahash crypto drivers don't need to yield
    since by definition they won't be hogging the CPU.

    Signed-off-by: Herbert Xu

    Herbert Xu
     

21 Mar, 2014

1 commit


10 Mar, 2014

2 commits


09 Dec, 2013

1 commit


28 Nov, 2013

1 commit

  • The scatterwalk_crypto_chain function invokes the scatterwalk_sg_chain
    function to chain two scatterlists, but the chain pointer indication
    bit is not set. When the resulting scatterlist is used, for example,
    by sg_nents to count the number of scatterlist entries, a segfault occurs
    because sg_nents does not follow the chain pointer to the chained scatterlist.

    Update scatterwalk_sg_chain to set the chain pointer indication bit as is
    done by the sg_chain function.

    Cc: stable@vger.kernel.org
    Signed-off-by: Tom Lendacky
    Signed-off-by: Herbert Xu

    Tom Lendacky
     

24 Nov, 2013

1 commit

  • Pull crypto update from Herbert Xu:
    - Made x86 ablk_helper generic for ARM
    - Phase out chainiv in favour of eseqiv (affects IPsec)
    - Fixed aes-cbc IV corruption on s390
    - Added constant-time crypto_memneq which replaces memcmp
    - Fixed aes-ctr in omap-aes
    - Added OMAP3 ROM RNG support
    - Add PRNG support for MSM SoC's
    - Add and use Job Ring API in caam
    - Misc fixes

    [ NOTE! This pull request was sent within the merge window, but Herbert
    has some questionable email sending setup that makes him public enemy
    #1 as far as gmail is concerned. So most of his emails seem to be
    trapped by gmail as spam, resulting in me not seeing them. - Linus ]

    * git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (49 commits)
    crypto: s390 - Fix aes-cbc IV corruption
    crypto: omap-aes - Fix CTR mode counter length
    crypto: omap-sham - Add missing modalias
    padata: make the sequence counter an atomic_t
    crypto: caam - Modify the interface layers to use JR API's
    crypto: caam - Add API's to allocate/free Job Rings
    crypto: caam - Add Platform driver for Job Ring
    hwrng: msm - Add PRNG support for MSM SoC's
    ARM: DT: msm: Add Qualcomm's PRNG driver binding document
    crypto: skcipher - Use eseqiv even on UP machines
    crypto: talitos - Simplify key parsing
    crypto: picoxcell - Simplify and harden key parsing
    crypto: ixp4xx - Simplify and harden key parsing
    crypto: authencesn - Simplify key parsing
    crypto: authenc - Export key parsing helper function
    crypto: mv_cesa: remove deprecated IRQF_DISABLED
    hwrng: OMAP3 ROM Random Number Generator support
    crypto: sha256_ssse3 - also test for BMI2
    crypto: mv_cesa - Remove redundant of_match_ptr
    crypto: sahara - Remove redundant of_match_ptr
    ...

    Linus Torvalds
     

26 Oct, 2013

2 commits


16 Oct, 2013

1 commit


07 Oct, 2013

1 commit

  • When comparing MAC hashes, AEAD authentication tags, or other hash
    values in the context of authentication or integrity checking, it
    is important not to leak timing information to a potential attacker,
    i.e. when communication happens over a network.

    Bytewise memory comparisons (such as memcmp) are usually optimized so
    that they return a nonzero value as soon as a mismatch is found. E.g,
    on x86_64/i5 for 512 bytes this can be ~50 cyc for a full mismatch
    and up to ~850 cyc for a full match (cold). This early-return behavior
    can leak timing information as a side channel, allowing an attacker to
    iteratively guess the correct result.

    This patch adds a new method crypto_memneq ("memory not equal to each
    other") to the crypto API that compares memory areas of the same length
    in roughly "constant time" (cache misses could change the timing, but
    since they don't reveal information about the content of the strings
    being compared, they are effectively benign). Iow, best and worst case
    behaviour take the same amount of time to complete (in contrast to
    memcmp).

    Note that crypto_memneq (unlike memcmp) can only be used to test for
    equality or inequality, NOT for lexicographical order. This, however,
    is not an issue for its use-cases within the crypto API.

    We tried to locate all of the places in the crypto API where memcmp was
    being used for authentication or integrity checking, and convert them
    over to crypto_memneq.

    crypto_memneq is declared noinline, placed in its own source file,
    and compiled with optimizations that might increase code size disabled
    ("Os") because a smart compiler (or LTO) might notice that the return
    value is always compared against zero/nonzero, and might then
    reintroduce the same early-return optimization that we are trying to
    avoid.

    Using #pragma or __attribute__ optimization annotations of the code
    for disabling optimization was avoided as it seems to be considered
    broken or unmaintained for long time in GCC [1]. Therefore, we work
    around that by specifying the compile flag for memneq.o directly in
    the Makefile. We found that this seems to be most appropriate.

    As we use ("Os"), this patch also provides a loop-free "fast-path" for
    frequently used 16 byte digests. Similarly to kernel library string
    functions, leave an option for future even further optimized architecture
    specific assembler implementations.

    This was a joint work of James Yonan and Daniel Borkmann. Also thanks
    for feedback from Florian Weimer on this and earlier proposals [2].

    [1] http://gcc.gnu.org/ml/gcc/2012-07/msg00211.html
    [2] https://lkml.org/lkml/2013/2/10/131

    Signed-off-by: James Yonan
    Signed-off-by: Daniel Borkmann
    Cc: Florian Weimer
    Signed-off-by: Herbert Xu

    James Yonan
     

26 Sep, 2013

2 commits


25 Sep, 2013

2 commits

  • Move the public-key algorithm pointer array from x509_public_key.c to
    public_key.c as it isn't X.509 specific.

    Note that to make this configure correctly, the public key part must be
    dependent on the RSA module rather than the other way round. This needs a
    further patch to make use of the crypto module loading stuff rather than using
    a fixed table.

    Signed-off-by: David Howells
    Reviewed-by: Kees Cook
    Reviewed-by: Josh Boyer

    David Howells
     
  • Rename the arrays of public key parameters (public key algorithm names, hash
    algorithm names and ID type names) so that the array name ends in "_name".

    Signed-off-by: David Howells
    Reviewed-by: Kees Cook
    Reviewed-by: Josh Boyer

    David Howells