aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/security
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-11-01 18:23:59 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-11-01 18:23:59 -0400
commitbaa888d25ea64d0c59344d474284ca99cfdd449a (patch)
tree06b85d1c3b70a12ad5c8a49394d57c14d5a69993 /Documentation/security
parent7260935d71b6d582376543844185add72848dde8 (diff)
parent64ae16dfeefec670276607fa789ce096c7ebd7c4 (diff)
Merge branch 'next-keys2' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull keys updates from James Morris: "Provide five new operations in the key_type struct that can be used to provide access to asymmetric key operations. These will be implemented for the asymmetric key type in a later patch and may refer to a key retained in RAM by the kernel or a key retained in crypto hardware. int (*asym_query)(const struct kernel_pkey_params *params, struct kernel_pkey_query *info); int (*asym_eds_op)(struct kernel_pkey_params *params, const void *in, void *out); int (*asym_verify_signature)(struct kernel_pkey_params *params, const void *in, const void *in2); Since encrypt, decrypt and sign are identical in their interfaces, they're rolled together in the asym_eds_op() operation and there's an operation ID in the params argument to distinguish them. Verify is different in that we supply the data and the signature instead and get an error value (or 0) as the only result on the expectation that this may well be how a hardware crypto device may work" * 'next-keys2' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (22 commits) KEYS: asym_tpm: Add support for the sign operation [ver #2] KEYS: asym_tpm: Implement tpm_sign [ver #2] KEYS: asym_tpm: Implement signature verification [ver #2] KEYS: asym_tpm: Implement the decrypt operation [ver #2] KEYS: asym_tpm: Implement tpm_unbind [ver #2] KEYS: asym_tpm: Add loadkey2 and flushspecific [ver #2] KEYS: Move trusted.h to include/keys [ver #2] KEYS: trusted: Expose common functionality [ver #2] KEYS: asym_tpm: Implement encryption operation [ver #2] KEYS: asym_tpm: Implement pkey_query [ver #2] KEYS: Add parser for TPM-based keys [ver #2] KEYS: asym_tpm: extract key size & public key [ver #2] KEYS: asym_tpm: add skeleton for asym_tpm [ver #2] crypto: rsa-pkcs1pad: Allow hash to be optional [ver #2] KEYS: Implement PKCS#8 RSA Private Key parser [ver #2] KEYS: Implement encrypt, decrypt and sign for software asymmetric key [ver #2] KEYS: Allow the public_key struct to hold a private key [ver #2] KEYS: Provide software public key query function [ver #2] KEYS: Make the X.509 and PKCS7 parsers supply the sig encoding type [ver #2] KEYS: Provide missing asymmetric key subops for new key type ops [ver #2] ...
Diffstat (limited to 'Documentation/security')
-rw-r--r--Documentation/security/keys/core.rst217
1 files changed, 217 insertions, 0 deletions
diff --git a/Documentation/security/keys/core.rst b/Documentation/security/keys/core.rst
index 9ce7256c6edb..9521c4207f01 100644
--- a/Documentation/security/keys/core.rst
+++ b/Documentation/security/keys/core.rst
@@ -859,6 +859,7 @@ The keyctl syscall functions are:
859 and either the buffer length or the OtherInfo length exceeds the 859 and either the buffer length or the OtherInfo length exceeds the
860 allowed length. 860 allowed length.
861 861
862
862 * Restrict keyring linkage:: 863 * Restrict keyring linkage::
863 864
864 long keyctl(KEYCTL_RESTRICT_KEYRING, key_serial_t keyring, 865 long keyctl(KEYCTL_RESTRICT_KEYRING, key_serial_t keyring,
@@ -890,6 +891,116 @@ The keyctl syscall functions are:
890 applicable to the asymmetric key type. 891 applicable to the asymmetric key type.
891 892
892 893
894 * Query an asymmetric key::
895
896 long keyctl(KEYCTL_PKEY_QUERY,
897 key_serial_t key_id, unsigned long reserved,
898 struct keyctl_pkey_query *info);
899
900 Get information about an asymmetric key. The information is returned in
901 the keyctl_pkey_query struct::
902
903 __u32 supported_ops;
904 __u32 key_size;
905 __u16 max_data_size;
906 __u16 max_sig_size;
907 __u16 max_enc_size;
908 __u16 max_dec_size;
909 __u32 __spare[10];
910
911 ``supported_ops`` contains a bit mask of flags indicating which ops are
912 supported. This is constructed from a bitwise-OR of::
913
914 KEYCTL_SUPPORTS_{ENCRYPT,DECRYPT,SIGN,VERIFY}
915
916 ``key_size`` indicated the size of the key in bits.
917
918 ``max_*_size`` indicate the maximum sizes in bytes of a blob of data to be
919 signed, a signature blob, a blob to be encrypted and a blob to be
920 decrypted.
921
922 ``__spare[]`` must be set to 0. This is intended for future use to hand
923 over one or more passphrases needed unlock a key.
924
925 If successful, 0 is returned. If the key is not an asymmetric key,
926 EOPNOTSUPP is returned.
927
928
929 * Encrypt, decrypt, sign or verify a blob using an asymmetric key::
930
931 long keyctl(KEYCTL_PKEY_ENCRYPT,
932 const struct keyctl_pkey_params *params,
933 const char *info,
934 const void *in,
935 void *out);
936
937 long keyctl(KEYCTL_PKEY_DECRYPT,
938 const struct keyctl_pkey_params *params,
939 const char *info,
940 const void *in,
941 void *out);
942
943 long keyctl(KEYCTL_PKEY_SIGN,
944 const struct keyctl_pkey_params *params,
945 const char *info,
946 const void *in,
947 void *out);
948
949 long keyctl(KEYCTL_PKEY_VERIFY,
950 const struct keyctl_pkey_params *params,
951 const char *info,
952 const void *in,
953 const void *in2);
954
955 Use an asymmetric key to perform a public-key cryptographic operation a
956 blob of data. For encryption and verification, the asymmetric key may
957 only need the public parts to be available, but for decryption and signing
958 the private parts are required also.
959
960 The parameter block pointed to by params contains a number of integer
961 values::
962
963 __s32 key_id;
964 __u32 in_len;
965 __u32 out_len;
966 __u32 in2_len;
967
968 ``key_id`` is the ID of the asymmetric key to be used. ``in_len`` and
969 ``in2_len`` indicate the amount of data in the in and in2 buffers and
970 ``out_len`` indicates the size of the out buffer as appropriate for the
971 above operations.
972
973 For a given operation, the in and out buffers are used as follows::
974
975 Operation ID in,in_len out,out_len in2,in2_len
976 ======================= =============== =============== ===============
977 KEYCTL_PKEY_ENCRYPT Raw data Encrypted data -
978 KEYCTL_PKEY_DECRYPT Encrypted data Raw data -
979 KEYCTL_PKEY_SIGN Raw data Signature -
980 KEYCTL_PKEY_VERIFY Raw data - Signature
981
982 ``info`` is a string of key=value pairs that supply supplementary
983 information. These include:
984
985 ``enc=<encoding>`` The encoding of the encrypted/signature blob. This
986 can be "pkcs1" for RSASSA-PKCS1-v1.5 or
987 RSAES-PKCS1-v1.5; "pss" for "RSASSA-PSS"; "oaep" for
988 "RSAES-OAEP". If omitted or is "raw", the raw output
989 of the encryption function is specified.
990
991 ``hash=<algo>`` If the data buffer contains the output of a hash
992 function and the encoding includes some indication of
993 which hash function was used, the hash function can be
994 specified with this, eg. "hash=sha256".
995
996 The ``__spare[]`` space in the parameter block must be set to 0. This is
997 intended, amongst other things, to allow the passing of passphrases
998 required to unlock a key.
999
1000 If successful, encrypt, decrypt and sign all return the amount of data
1001 written into the output buffer. Verification returns 0 on success.
1002
1003
893Kernel Services 1004Kernel Services
894=============== 1005===============
895 1006
@@ -1483,6 +1594,112 @@ The structure has a number of fields, some of which are mandatory:
1483 attempted key link operation. If there is no match, -EINVAL is returned. 1594 attempted key link operation. If there is no match, -EINVAL is returned.
1484 1595
1485 1596
1597 * ``int (*asym_eds_op)(struct kernel_pkey_params *params,
1598 const void *in, void *out);``
1599 ``int (*asym_verify_signature)(struct kernel_pkey_params *params,
1600 const void *in, const void *in2);``
1601
1602 These methods are optional. If provided the first allows a key to be
1603 used to encrypt, decrypt or sign a blob of data, and the second allows a
1604 key to verify a signature.
1605
1606 In all cases, the following information is provided in the params block::
1607
1608 struct kernel_pkey_params {
1609 struct key *key;
1610 const char *encoding;
1611 const char *hash_algo;
1612 char *info;
1613 __u32 in_len;
1614 union {
1615 __u32 out_len;
1616 __u32 in2_len;
1617 };
1618 enum kernel_pkey_operation op : 8;
1619 };
1620
1621 This includes the key to be used; a string indicating the encoding to use
1622 (for instance, "pkcs1" may be used with an RSA key to indicate
1623 RSASSA-PKCS1-v1.5 or RSAES-PKCS1-v1.5 encoding or "raw" if no encoding);
1624 the name of the hash algorithm used to generate the data for a signature
1625 (if appropriate); the sizes of the input and output (or second input)
1626 buffers; and the ID of the operation to be performed.
1627
1628 For a given operation ID, the input and output buffers are used as
1629 follows::
1630
1631 Operation ID in,in_len out,out_len in2,in2_len
1632 ======================= =============== =============== ===============
1633 kernel_pkey_encrypt Raw data Encrypted data -
1634 kernel_pkey_decrypt Encrypted data Raw data -
1635 kernel_pkey_sign Raw data Signature -
1636 kernel_pkey_verify Raw data - Signature
1637
1638 asym_eds_op() deals with encryption, decryption and signature creation as
1639 specified by params->op. Note that params->op is also set for
1640 asym_verify_signature().
1641
1642 Encrypting and signature creation both take raw data in the input buffer
1643 and return the encrypted result in the output buffer. Padding may have
1644 been added if an encoding was set. In the case of signature creation,
1645 depending on the encoding, the padding created may need to indicate the
1646 digest algorithm - the name of which should be supplied in hash_algo.
1647
1648 Decryption takes encrypted data in the input buffer and returns the raw
1649 data in the output buffer. Padding will get checked and stripped off if
1650 an encoding was set.
1651
1652 Verification takes raw data in the input buffer and the signature in the
1653 second input buffer and checks that the one matches the other. Padding
1654 will be validated. Depending on the encoding, the digest algorithm used
1655 to generate the raw data may need to be indicated in hash_algo.
1656
1657 If successful, asym_eds_op() should return the number of bytes written
1658 into the output buffer. asym_verify_signature() should return 0.
1659
1660 A variety of errors may be returned, including EOPNOTSUPP if the operation
1661 is not supported; EKEYREJECTED if verification fails; ENOPKG if the
1662 required crypto isn't available.
1663
1664
1665 * ``int (*asym_query)(const struct kernel_pkey_params *params,
1666 struct kernel_pkey_query *info);``
1667
1668 This method is optional. If provided it allows information about the
1669 public or asymmetric key held in the key to be determined.
1670
1671 The parameter block is as for asym_eds_op() and co. but in_len and out_len
1672 are unused. The encoding and hash_algo fields should be used to reduce
1673 the returned buffer/data sizes as appropriate.
1674
1675 If successful, the following information is filled in::
1676
1677 struct kernel_pkey_query {
1678 __u32 supported_ops;
1679 __u32 key_size;
1680 __u16 max_data_size;
1681 __u16 max_sig_size;
1682 __u16 max_enc_size;
1683 __u16 max_dec_size;
1684 };
1685
1686 The supported_ops field will contain a bitmask indicating what operations
1687 are supported by the key, including encryption of a blob, decryption of a
1688 blob, signing a blob and verifying the signature on a blob. The following
1689 constants are defined for this::
1690
1691 KEYCTL_SUPPORTS_{ENCRYPT,DECRYPT,SIGN,VERIFY}
1692
1693 The key_size field is the size of the key in bits. max_data_size and
1694 max_sig_size are the maximum raw data and signature sizes for creation and
1695 verification of a signature; max_enc_size and max_dec_size are the maximum
1696 raw data and signature sizes for encryption and decryption. The
1697 max_*_size fields are measured in bytes.
1698
1699 If successful, 0 will be returned. If the key doesn't support this,
1700 EOPNOTSUPP will be returned.
1701
1702
1486Request-Key Callback Service 1703Request-Key Callback Service
1487============================ 1704============================
1488 1705