KEYS: add kpp keyctl operations
Subsystems (5)
cover KEYS: add kpp keyctl operations
This series provides keyctl access for kpp operations, including a query function, a function to generate the public key that is associated with the private key and a function to compute the shared secret.
I've added a KPP ecdh parser so that you can load an ECDH private key into the kernel. The ECDH private keys are expected to be encoded with the ecdh helpers from kernel. If the private key is valid, the parser will allocate a tfm and set the private key. There is a one-to-one binding between the private key and the tfm. The tfm will be associated with the key for the entire life of the key. The tfm is allocated once and used as many times as needed.
The kernel patches can be found here also:
https://github.com/ambarus/linux/commits/keys-kpp
The keyutils changes can be found here:
https://github.com/ambarus/keyutils/commits/keys-kpp
These patches are similar to what David Howells proposed for akcipher:
https://www.mail-archive.com/[email protected]/msg19915.html
I've ported David's patches on top of keys-next and then I've added my patches on top of them.
Both proposals, David's and mine, lack support for accessing TPM. Before getting familiar with TPM, please let me know how you feel about this series.
Tudor Ambarus (5):
KEYS: Provide key type operations for kpp ops
KEYS: Provide keyctls to drive the new key type ops for kpp
KEYS: Provide missing asym kpp subops for new key type ops
KEYS: add asymmetric kpp subtype
KEYS: add KPP ecdh parser
Documentation/security/keys/core.rst | 113 +++++++++++++++++ crypto/asymmetric_keys/Kconfig | 15 +++ crypto/asymmetric_keys/Makefile | 6 + crypto/asymmetric_keys/asym_kpp.c | 142 +++++++++++++++++++++ crypto/asymmetric_keys/asymmetric_type.c | 77 ++++++++++++ crypto/asymmetric_keys/kpp_parser.c | 124 +++++++++++++++++++ include/crypto/asym_kpp_subtype.h | 14 +++ include/keys/asymmetric-subtype.h | 12 ++ include/linux/key-type.h | 7 ++ include/linux/keyctl.h | 11 ++ include/uapi/linux/keyctl.h | 19 +++ security/keys/Makefile | 1 + security/keys/compat.c | 10 ++ security/keys/internal.h | 28 +++++ security/keys/keyctl.c | 13 ++ security/keys/keyctl_kpp.c | 205 +++++++++++++++++++++++++++++++ 16 files changed, 797 insertions(+) create mode 100644 crypto/asymmetric_keys/asym_kpp.c create mode 100644 crypto/asymmetric_keys/kpp_parser.c create mode 100644 include/crypto/asym_kpp_subtype.h create mode 100644 security/keys/keyctl_kpp.c
Signature · 1 line
2.9.4
RFC PATCH 1/5 KEYS: Provide key type operations for kpp ops
Provide three new operations in the key_type struct that can be used to provide access to kpp 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_kpp_query)(const struct kernel_kpp_params *params,
struct kernel_kpp_query *res);
int (*asym_kpp_gen_pubkey)(struct kernel_kpp_params *params,
void *out);
int (*asym_kpp_compute_ss)(struct kernel_kpp_params *params,
const void *in, void *out);
--- Documentation/security/keys/core.rst | 54 ++++++++++++++++++++++++++++++++++++ include/linux/key-type.h | 7 +++++ include/linux/keyctl.h | 11 ++++++++ include/uapi/linux/keyctl.h | 3 ++ 4 files changed, 75 insertions(+)
Documentation/security/keys/core.rst +54 -0
@@ -1688,6 +1688,60 @@ The structure has a number of fields, some of which are mandatory: If successful, 0 will be returned. If the key doesn't support this, EOPNOTSUPP will be returned. + * ``int (*asym_kpp_gen_pubkey)(struct kernel_kpp_params *params, void *out);`` + * ``int (*asym_kpp_compute_ss)(struct kernel_kpp_params *params, const void *in, void *out);`` + + These methods are optional. If provided the first allows to generate the + public key pair corresponding to the private key. The second method allows + to generate a shared secret by combining the private key and the other + party's public key. + + In all cases, the following information is provided in the params block:: + + struct kernel_kpp_query { + struct key *key; + __u32 in_len; /* Input data size */ + __u32 out_len; /* Output buffer size */ + } + + This includes the key to be used and the sizes in bytes of the input and + output buffers. + + For a given operation, the in and out buffers are used as follows:: + + Operation ID in,in_len out,out_len + ============ ========== ============ + KEYCTL_KPP_GEN_PUBKEY - Corresponding public key + KEYCTL_KPP_COMPUTE_SS Pair's public key Shared Secret + + If successful, the public key generation and the shared secret computation + will return the amount of data written into the output buffer. + + * ``int (*asym_kpp_query)(const struct kernel_kpp_params *params, struct kernel_kpp_query *res);`` + + This method is optional. If provided it allows information about the + asymmetric KPP (Key Protocol Primitives) key held in the key to be + determined. + + The ``params`` block will contain the key to be queried. ``in_len`` and + ``out_len`` are unused. + + If successful, the following information is filled in:: + + struct kernel_kpp_query { + __u32 supported_ops; /* Which ops are supported */ + __u32 max_size; /* Maximum size of the output buffer */ + }; + + The supported_ops field will contain a bitmask indicating what operations + are supported by the key, including public key generation and shared + secret computation. The following constants are defined for this:: + + KEYCTL_SUPPORTS_{GEN_PUBKEY, COMPUTE_SS}; + + If successful, 0 is returned. If the key is not an asymmetric kpp key, + EOPNOTSUPP is returned. + Request-Key Callback Service ==============
include/linux/key-type.h +7 -0
@@ -19,6 +19,8 @@struct kernel_pkey_query ;struct kernel_pkey_params ; +struct kernel_kpp_query ; +struct kernel_kpp_params ;/* * key under-construction record
@@ -165,6 +167,11 @@ struct key_type { const void *in, void *out);int (*asym_verify_signature)(struct kernel_pkey_params *params,const void *in,const void *in2); +int (*asym_kpp_query)(const struct kernel_kpp_params *params, +struct kernel_kpp_query *res); +int (*asym_kpp_gen_pubkey)(struct kernel_kpp_params *params,void *out); +int (*asym_kpp_compute_ss)(struct kernel_kpp_params *params, +const void *in,void *out);/* internal fields */ struct list_head link;/* link in types list */
include/linux/keyctl.h +11 -0
@@ -43,4 +43,15 @@ struct kernel_pkey_params { enum kernel_pkey_operation op : 8; }; +struct kernel_kpp_query { +__u32 supported_ops;/* Which ops are supported */ +__u32 max_size;/* Maximum size of the output buffer */ +}; + +struct kernel_kpp_params { +struct key *key; +__u32 in_len;/* Input data size */ +__u32 out_len;/* Output buffer size */ +}; +#endif /* __LINUX_KEYCTL_H */
include/uapi/linux/keyctl.h +3 -0
@@ -107,4 +107,7 @@ struct keyctl_pkey_params { __u32 __spare[7]; }; +#define KEYCTL_SUPPORTS_GEN_PUBKEY 0x0f +#define KEYCTL_SUPPORTS_COMPUTE_SS 0x10 +#endif /* _LINUX_KEYCTL_H */
Signature · 1 line
2.9.4
Re: [RFC PATCH 1/5] KEYS: Provide key type operations for kpp ops
Hi Tudor,
Quoted 34 lines · Tudor Ambarus
Provide three new operations in the
key_typestruct that can be used to provide access to kpp 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_kpp_query)(const struct
kernel_kpp_params*params,
structkernel_kpp_query*res);
int (*asym_kpp_gen_pubkey)(structkernel_kpp_params*params,
void *out);
int (*asym_kpp_compute_ss)(structkernel_kpp_params*params,
const void *in, void *out);Signed-off-by Tudor Ambarus <[email protected]>--- Documentation/security/keys/core.rst | 54 ++++++++++++++++++++++++++++++++++++ include/linux/key-type.h | 7 +++++ include/linux/keyctl.h | 11 ++++++++ include/uapi/linux/keyctl.h | 3 ++ 4 files changed, 75 insertions(+)Documentation/security/keys/core.rst +6
-0@@ -1688,6 +1688,60 @@ The structure has a number of fields, some of which are mandatory: If successful, 0 will be returned. If the key doesn't support this, EOPNOTSUPP will be returned. + * ``int (*asym_kpp_gen_pubkey)(struct kernel_kpp_params *params, void *out);`` + * ``int (*asym_kpp_compute_ss)(struct kernel_kpp_params *params, const void *in, void *out);`` + + These methods are optional. If provided the first allows to generate the + public key pair corresponding to the private key. The second method allows + to generate a shared secret by combining the private key and the other
Documentation/security/keys/core.rst The structure has a number of fields, some of which are mandatory: · line 1706
Quoted 10 lines
Documentation/security/keys/core.rst +10
-0+ party's public key. + + In all cases, the following information is provided in the params block:: + + struct kernel_kpp_query { + struct key *key; + __u32 in_len; /* Input data size */ + __u32 out_len; /* Output buffer size */ + } +
Probably not a huge deal as most common key sizes are already supported, but... is there a way to query supported key sizes? I think for DH_COMPUTE we didn't have this problem as everything was done in software. However, if the intent is to use TPM / other hardware engines we might need a way to query supported key sizes.
Quoted 91 lines
Documentation/security/keys/core.rst +38
-0+ This includes the key to be used and the sizes in bytes of the input and + output buffers. + + For a given operation, the in and out buffers are used as follows:: + + Operation ID in,in_len out,out_len + ============ ========== ============ + KEYCTL_KPP_GEN_PUBKEY - Corresponding public key + KEYCTL_KPP_COMPUTE_SS Pair's public key Shared Secret + + If successful, the public key generation and the shared secret computation + will return the amount of data written into the output buffer. + + * ``int (*asym_kpp_query)(const struct kernel_kpp_params *params, struct kernel_kpp_query *res);`` + + This method is optional. If provided it allows information about the + asymmetric KPP (Key Protocol Primitives) key held in the key to be + determined. + + The ``params`` block will contain the key to be queried. ``in_len`` and + ``out_len`` are unused. + + If successful, the following information is filled in:: + + struct kernel_kpp_query { + __u32 supported_ops; /* Which ops are supported */ + __u32 max_size; /* Maximum size of the output buffer */ + }; + + The supported_ops field will contain a bitmask indicating what operations + are supported by the key, including public key generation and shared + secret computation. The following constants are defined for this:: + + KEYCTL_SUPPORTS_{GEN_PUBKEY, COMPUTE_SS}; + + If successful, 0 is returned. If the key is not an asymmetric kpp key, + EOPNOTSUPP is returned. + Request-Key Callback Service ==============include/linux/key-type.h +7
-0@@ -19,6 +19,8 @@struct kernel_pkey_query ;struct kernel_pkey_params ; +struct kernel_kpp_query ; +struct kernel_kpp_params ;/* * key under-construction record @@ -165,6 +167,11 @@ struct key_type { const void *in, void *out);int (*asym_verify_signature)(struct kernel_pkey_params *params,const void *in,const void *in2); +int (*asym_kpp_query)(const struct kernel_kpp_params *params, +struct kernel_kpp_query *res); +int (*asym_kpp_gen_pubkey)(struct kernel_kpp_params *params,void *out); +int (*asym_kpp_compute_ss)(struct kernel_kpp_params *params, +const void *in,void *out);/* internal fields */ struct list_head link;/* link in types list */ include/linux/keyctl.h +11
-0@@ -43,4 +43,15 @@ struct kernel_pkey_params { enum kernel_pkey_operation op : 8; }; +struct kernel_kpp_query { +__u32 supported_ops;/* Which ops are supported */ +__u32 max_size;/* Maximum size of the output buffer */ +}; + +struct kernel_kpp_params { +struct key *key; +__u32 in_len;/* Input data size */ +__u32 out_len;/* Output buffer size */ +}; +#endif /* __LINUX_KEYCTL_H */ include/uapi/linux/keyctl.h +0
-0
include/uapi/linux/keyctl.h struct keyctl_pkey_params { · line 110
Quoted 4 lines
include/uapi/linux/keyctl.h +1
-0@@ -107,4 +107,7 @@ struct keyctl_pkey_params {__u32 __spare[7 ]; }; +#define KEYCTL_SUPPORTS_GEN_PUBKEY 0x0f
This looks fishy, the other KEYCTL_SUPPORTS_ block ends at 0x08. This would imply that KPP supports encryption, decryption, sign, verify. Do you mean 0x10 here?
include/uapi/linux/keyctl.h struct keyctl_pkey_params { · line 112
Quoted 2 lines
include/uapi/linux/keyctl.h +2
-0+#define KEYCTL_SUPPORTS_COMPUTE_SS 0x10 +
And 0x20 here?
include/uapi/linux/keyctl.h struct keyctl_pkey_params { · line 113
Quoted 2 lines
include/uapi/linux/keyctl.h +0
-0#endif /* _LINUX_KEYCTL_H */
Otherwise this looks good to me. Feel free to add:
Regards,
-Denis
Re: [RFC PATCH 1/5] KEYS: Provide key type operations for kpp ops
In reply to Tudor AmbarusHi, Denis,
Thanks for the review! Please see inline.
Quoted 54 lines · Denis Kenzior
Hi Tudor,
Quoted 51 lines · Tudor Ambarus
Provide three new operations in the
key_typestruct that can be used to provide access to kpp 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_kpp_query)(const struct
kernel_kpp_params*params,
structkernel_kpp_query*res);
int (*asym_kpp_gen_pubkey)(structkernel_kpp_params*params,
void *out);
int (*asym_kpp_compute_ss)(structkernel_kpp_params*params,
const void *in, void *out);Signed-off-by Tudor Ambarus <[email protected]>--- Documentation/security/keys/core.rst | 54 ++++++++++++++++++++++++++++++++++++ include/linux/key-type.h | 7 +++++ include/linux/keyctl.h | 11 ++++++++ include/uapi/linux/keyctl.h | 3 ++ 4 files changed, 75 insertions(+)Documentation/security/keys/core.rst +0
-0@@ -1688,6 +1688,60 @@ The structure has a number of fields, some ofwhich are mandatory:
If successful, 0 will be returned. If the key doesn't support
this,
EOPNOTSUPP will be returned.
+ * ``int (*asym_kpp_gen_pubkey)(structkernel_kpp_params*params, void *out);``
+ * ``int (*asym_kpp_compute_ss)(structkernel_kpp_params*params, const void *in, void *out);``Documentation/security/keys/core.rst +2
-0+ + These methods are optional. If provided the first allows togenerate the
+ public key pair corresponding to the private key. The second
method allows
+ to generate a shared secret by combining the private key and
the otherDocumentation/security/keys/core.rst +3
-0+ party's public key. + + In all cases, the following information is provided in theparams block::
Documentation/security/keys/core.rst +5
-0+ + struct kernel_kpp_query { + struct key *key; + __u32 in_len; /* Input data size */ + __u32 out_len; /* Output buffer size */
Quoted 8 lines
Documentation/security/keys/core.rst
Quoted 2 lines
Documentation/security/keys/core.rst +2
-0+ } +Probably not a huge deal as most common key sizes are already supported, but... is there a way to query supported key sizes? I think for
DH_COMPUTEwe didn't have this problem as everything was done in software. However, if the intent is to use TPM / other hardware engines we might need a way to query supported key sizes.
Oh, there's a typo here, this structure should have been named 'kernel_kpp_params' and not 'kernel_kpp_query'. 'kernel_kpp_query' is defined below, it provides a way for determining the maximum supported key size.
Quoted 99 lines
Quoted 99 lines
+ This includes the key to be used and the sizes in bytes of the
input andDocumentation/security/keys/core.rst +6
-0+ output buffers. + + For a given operation, the in and out buffers are used as follows:: + + Operation ID in,in_len out,out_len + ============ ======================
+KEYCTL_KPP_GEN_PUBKEY- Corresponding
public keyDocumentation/security/keys/core.rst +3
-0+ KEYCTL_KPP_COMPUTE_SS Pair's public key Shared Secret + + If successful, the public key generation and the shared secretcomputation
Documentation/security/keys/core.rst +3
-0+ will return the amount of data written into the output buffer. + + * ``int (*asym_kpp_query)(const struct kernel_kpp_params *params,struct
kernel_kpp_query*res);``Documentation/security/keys/core.rst +2
-0+ + This method is optional. If provided it allows information aboutthe
Documentation/security/keys/core.rst +4
-0+ asymmetric KPP (Key Protocol Primitives) key held in the key to be + determined. + + The ``params`` block will contain the key to be queried.``in_len`` and
Documentation/security/keys/core.rst +6
-0+ ``out_len`` are unused. + + If successful, the following information is filled in:: + + struct kernel_kpp_query { + __u32 supported_ops; /* Which ops aresupported */
+__u32max_size; /* Maximum size of the
output buffer */Documentation/security/keys/core.rst +3
-0+ }; + + The supported_ops field will contain a bitmask indicating whatoperations
+ are supported by the key, including public key generation and
sharedDocumentation/security/keys/core.rst +5
-0+ secret computation. The following constants are defined for this:: + + KEYCTL_SUPPORTS_{GEN_PUBKEY, COMPUTE_SS}; + + If successful, 0 is returned. If the key is not an asymmetrickpp key,
Documentation/security/keys/core.rst +2
-0+ EOPNOTSUPP is returned. + Request-Key Callback Service ==============include/linux/key-type.h +7
-0@@ -19,6 +19,8 @@struct kernel_pkey_query ;struct kernel_pkey_params ; +struct kernel_kpp_query ; +struct kernel_kpp_params ;/* * key under-construction record @@ -165,6 +167,11 @@ struct key_type { const void *in, void *out);int (*asym_verify_signature)(struct kernel_pkey_params *params,const void *in,const void *in2); +int (*asym_kpp_query)(const struct kernel_kpp_params *params, +struct kernel_kpp_query *res); +int (*asym_kpp_gen_pubkey)(struct kernel_kpp_params *params,void *out); +int (*asym_kpp_compute_ss)(struct kernel_kpp_params *params, +const void *in,void *out);/* internal fields */ struct list_head link;/* link in types list */ include/linux/keyctl.h +11
-0@@ -43,4 +43,15 @@ struct kernel_pkey_params { enum kernel_pkey_operation op : 8; }; +struct kernel_kpp_query { +__u32 supported_ops;/* Which ops are supported */ +__u32 max_size;/* Maximum size of the output buffer */ +}; + +struct kernel_kpp_params { +struct key *key; +__u32 in_len;/* Input data size */ +__u32 out_len;/* Output buffer size */ +}; +#endif /* __LINUX_KEYCTL_H */ include/uapi/linux/keyctl.h +0
-0
Quoted 9 lines
include/uapi/linux/keyctl.h struct keyctl_pkey_params { · line 109
Quoted 4 lines
include/uapi/linux/keyctl.h +1
-0@@ -107,4 +107,7 @@ struct keyctl_pkey_params {__u32 __spare[7 ]; }; +#define KEYCTL_SUPPORTS_GEN_PUBKEY 0x0fThis looks fishy, the other
KEYCTL_SUPPORTS_block ends at0x08. This would imply that KPP supports encryption, decryption, sign, verify. Do you mean0x10here?
of course, thanks!
Quoted 4 lines
include/uapi/linux/keyctl.h struct keyctl_pkey_params { · line 112
Quoted 2 lines
include/uapi/linux/keyctl.h +2
-0+#define KEYCTL_SUPPORTS_COMPUTE_SS 0x10 +And
0x20here?
you're right, thanks!
Best,
ta
RFC PATCH 2/5 KEYS: Provide keyctls to drive the new key type ops for kpp
In reply to Tudor AmbarusProvide three keyctl functions that permit userspace to make use of the new key type ops for accessing and driving asymmetric kpp keys.
(*) Query an asymmetric kpp key.
long keyctl(KEYCTL_KPP_QUERY,
key_serial_t key, struct keyctl_kpp_query *res);
Get information about an asymmetric kpp key. The information is returned in the keyctl_kpp_query struct:
__u32 supported_ops;
A bit mask of flags indicating which ops are supported. This is constructed from a bitwise-OR of:
KEYCTL_SUPPORTS_{GEN_PUBKEY, COMPUTE_SS}
__u32 max_size;
The maximum size in bytes of the key.
__spare must be set to 0. This is intended for future use to hand over one or more passphrases needed to unlock a key.
If successful, 0 is returned. If the key is not an asymmetric kpp key, EOPNOTSUPP is returned.
(*) Generate the public key or compute the shared secret using an
asymmetric kpp key.
long keyctl(KEYCTL_KPP_GEN_PUBKEY,
const struct keyctl_kpp_params *params, void *out);
long keyctl(KEYCTL_KPP_GEN_PUBKEY,
const struct keyctl_kpp_params *params, const void *in, void *out);
The parameter block pointed by params contains a number of integer values:
__s32 key_id;
__u32 in_len;
__u32 out_len;
For a given operation, the in and out buffers are used as follows:
Operation ID in,in_len out,out_len
============ ========== ============
KEYCTL_KPP_GEN_PUBKEY - Corresponding public key
KEYCTL_KPP_COMPUTE_SS Pair's public key Shared Secret
The __spare space in the parameter block must be set to 0. This is intended, amongst other things, to allow the passing of passphrases required to unlock a key.
If successful, the public key generation and the shared secret computation will return the amount of data written into the output buffer.
--- Documentation/security/keys/core.rst | 59 ++++++++++ include/uapi/linux/keyctl.h | 16 +++ security/keys/Makefile | 1 + security/keys/compat.c | 10 ++ security/keys/internal.h | 28 +++++ security/keys/keyctl.c | 13 +++ security/keys/keyctl_kpp.c | 205 +++++++++++++++++++++++++++++++++++ 7 files changed, 332 insertions(+) create mode 100644 security/keys/keyctl_kpp.c
Documentation/security/keys/core.rst +59 -0
@@ -994,6 +994,65 @@ The keyctl syscall functions are: If successful, encrypt, decrypt and sign all return the amount of data written into the output buffer. Verification returns 0 on success. + * Query an asymmetric kpp key:: + + long keyctl(KEYCTL_KPP_QUERY, + key_serial_t key, struct keyctl_kpp_query *res); + + Get information about an asymmetric kpp key. The information is + returned in the keyctl_kpp_query struct:: + + struct keyctl_kpp_query { + __u32 supported_ops; /* Which ops are supported */ + __u32 max_size; /* Maximum size of the output buffer in bytes */ + __u32 __spare[10]; + }; + + ``__u32 supported_ops;`` is a bit mask of flags indicating which ops are + supported. This is constructed from a bitwise-OR of:: + + KEYCTL_SUPPORTS_{GEN_PUBKEY, COMPUTE_SS} + + ``__spare`` must be set to 0. This is intended for future use to hand + over one or more passphrases needed to unlock a key. + + If successful, 0 is returned. If the key is not an asymmetric kpp key, + EOPNOTSUPP is returned. + + * Generate the public key or compute the shared secret using an asymmetric + kpp key:: + + long keyctl(KEYCTL_KPP_GEN_PUBKEY, + const struct keyctl_kpp_params *params, + void *out); + + long keyctl(KEYCTL_KPP_GEN_PUBKEY, + const struct keyctl_kpp_params *params, + const void *in, void *out); + + The parameter block pointed by params contains a number of integer + values:: + __s32 key_id; + __u32 in_len; + __u32 out_len; + + ``key_id`` is the key tp be used and ``in_len`` and ``out_len`` are the + lengths in bytes of the input and output buffers. + + For a given operation, the in and out buffers are used as follows:: + + Operation ID in,in_len out,out_len + ============ ========== ============ + KEYCTL_KPP_GEN_PUBKEY - Corresponding public key + KEYCTL_KPP_COMPUTE_SS Pair's public key Shared Secret + + The __spare space in the parameter block must be set to 0. This is + intended, amongst other things, to allow the passing of passphrases + required to unlock a key. + + If successful, the public key generation and the shared secret computation + will return the amount of data written into the output buffer. + Kernel Services =======diff --git a/include/uapi/linux/keyctl.h b/include/uapi/linux/keyctl.h
index 98b79f8..dcee74c 100644
include/uapi/linux/keyctl.h +16 -0
@@ -67,6 +67,9 @@#define KEYCTL_PKEY_DECRYPT 26/* Decrypt a blob using a public key */ #define KEYCTL_PKEY_SIGN 27/* Create a public key signature */ #define KEYCTL_PKEY_VERIFY 28/* Verify a public key signature */ +#define KEYCTL_KPP_QUERY 30/* Query KPP parameters */ +#define KEYCTL_KPP_GEN_PUBKEY 31/* Generate public key */ +#define KEYCTL_KPP_COMPUTE_SS 32/* Compute shared secret */ /* keyctl structures */ struct keyctl_dh_params {
@@ -110,4 +113,17 @@ struct keyctl_pkey_params {#define KEYCTL_SUPPORTS_GEN_PUBKEY 0x0f#define KEYCTL_SUPPORTS_COMPUTE_SS 0x10 +struct keyctl_kpp_query { +__u32 supported_ops;/* Which ops are supported */ +__u32 max_size;/* Maximum size of the output buffer in bytes */ +__u32 __spare[10 ]; +}; + +struct keyctl_kpp_params { +__s32 key_id;/* Serial no. of private key to use */ +__u32 in_len;/* Input data size */ +__u32 out_len;/* Output buffer size */ +__u32 __spare[7 ]; +}; +#endif /* _LINUX_KEYCTL_H */
security/keys/Makefile +1 -0
@@ -23,6 +23,7 @@ obj-$(CONFIG_SYSCTL) += sysctl.o obj-$(CONFIG_PERSISTENT_KEYRINGS) += persistent.o obj-$(CONFIG_KEY_DH_OPERATIONS) += dh.o obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += keyctl_pkey.o +obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += keyctl_kpp.o # # Key types
security/keys/compat.c +10 -0
@@ -159,6 +159,16 @@ COMPAT_SYSCALL_DEFINE5(keyctl, u32, option,return keyctl_pkey_verify (compat_ptr (arg2),compat_ptr (arg3),compat_ptr (arg4),compat_ptr (arg5)); +case KEYCTL_KPP_QUERY : +return keyctl_kpp_query (arg2,compat_ptr (arg5)); + +case KEYCTL_KPP_GEN_PUBKEY : + return keyctl_kpp_gen_pubkey(compat_ptr(arg2), compat_ptr(arg5); + +case KEYCTL_KPP_COMPUTE_SS : +return keyctl_kpp_compute_ss (compat_ptr (arg2),compat_ptr (arg4), +compat_ptr (arg5)); +default :return -EOPNOTSUPP ; }
security/keys/internal.h +28 -0
@@ -311,6 +311,14 @@ extern long keyctl_pkey_e_d_s(int, const struct keyctl_pkey_params __user *, const char __user *, const void __user *, void __user *); + +extern long keyctl_kpp_query (key_serial_t ,struct keyctl_kpp_query __user *); + +extern long keyctl_kpp_gen_pubkey (const struct keyctl_kpp_params __user *, +void __user *); + +extern long keyctl_kpp_compute_ss (const struct keyctl_kpp_params __user *, +const void __user *,void __user *);#else static inline long keyctl_pkey_query(key_serial_t id, const char __user *_info,
@@ -335,6 +343,26 @@ static inline long keyctl_pkey_e_d_s(int op, {return -EOPNOTSUPP ; } + +static inline long keyctl_kpp_query (key_serial_t id, +struct keyctl_kpp_query __user *_res); +{ +return -EOPNOTSUPP ; +} + +static inline long keyctl_kpp_gen_pubkey ( +const struct keyctl_kpp_params __user *params, +void __user *_out); +{ +return -EOPNOTSUPP ; +} + +static inline long keyctl_kpp_compute_ss ( +const struct keyctl_kpp_params __user *params, +const void __user *in,void __user *_out); +{ +return -EOPNOTSUPP ; +}#endif /*
security/keys/keyctl.c +13 -0
@@ -1775,6 +1775,19 @@ SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3, (const void __user *)arg4, (const void __user *)arg5); +case KEYCTL_KPP_QUERY : +return keyctl_kpp_query ((key_serial_t )arg2, + (struct keyctl_kpp_query *)arg5); +case KEYCTL_KPP_GEN_PUBKEY : +return keyctl_kpp_gen_pubkey ( + (const struct keyctl_kpp_params __user *)arg2, + (void __user *)arg5); +case KEYCTL_KPP_COMPUTE_SS : +return keyctl_kpp_compute_ss ( + (const struct keyctl_kpp_params __user *)arg2, + (const void __user *)arg4, + (void __user *)arg5); +default :return -EOPNOTSUPP ; }
security/keys/keyctl_kpp.c new file +205 -0
205 lines not on this page · raw message
Signature · 1 line
2.9.4
RFC PATCH 3/5 KEYS: Provide missing asym kpp subops for new key type ops
In reply to Tudor AmbarusIncludes kpp_query, kpp_gen_pubkey and kpp_compute_ss.
--- crypto/asymmetric_keys/asymmetric_type.c | 77 ++++++++++++++++++++++++++++++++ include/keys/asymmetric-subtype.h | 12 +++++ 2 files changed, 89 insertions(+)
crypto/asymmetric_keys/asymmetric_type.c +77 -0
@@ -578,6 +578,80 @@ static int asymmetric_key_verify_signature(struct kernel_pkey_params *params,return verify_signature (params->key, &sig); } +int query_asym_kpp_key (const struct kernel_kpp_params *params, +struct kernel_kpp_query *res) +{ +const struct asymmetric_key_subtype *subtype; +struct key *key = params->key; +int ret; + +pr_devel ("=>%s()\n" , __func__); + +if (key->type != &key_type_asymmetric) +return -EINVAL ; + + subtype =asymmetric_key_subtype (key); +if (!subtype || !key->payload.data[0 ]) +return -EINVAL ; + +if (!subtype->kpp_query) +return -ENOTSUPP ; + + ret = subtype->kpp_query (params, res); + +pr_devel ("<=%s() = %d\n" , __func__, ret); +return ret; +} + +int asymmetric_key_kpp_gen_pubkey (struct kernel_kpp_params *params,void *out) +{ +const struct asymmetric_key_subtype *subtype; +struct key *key = params->key; +int ret; + +pr_devel ("=>%s()\n" , __func__); + +if (key->type != &key_type_asymmetric) +return -EINVAL ; + + subtype =asymmetric_key_subtype (key); +if (!subtype || !key->payload.data[0 ]) +return -EINVAL ; + +if (!subtype->kpp_gen_pubkey) +return -ENOTSUPP ; + + ret = subtype->kpp_gen_pubkey (params, out); + +pr_devel ("<=%s() = %d\n" , __func__, ret); +return ret; +} + +int asymmetric_key_kpp_compute_ss (struct kernel_kpp_params *params, +const void *in,void *out) +{ +const struct asymmetric_key_subtype *subtype; +struct key *key = params->key; +int ret; + +pr_devel ("=>%s()\n" , __func__); + +if (key->type != &key_type_asymmetric) +return -EINVAL ; + + subtype =asymmetric_key_subtype (key); +if (!subtype || !key->payload.data[0 ]) +return -EINVAL ; + +if (!subtype->kpp_compute_ss) +return -ENOTSUPP ; + + ret = subtype->kpp_compute_ss (params, in, out); + +pr_devel ("<=%s() = %d\n" , __func__, ret); +return ret; +} +struct key_type key_type_asymmetric = { .name ="asymmetric" , .preparse = asymmetric_key_preparse,
@@ -591,6 +665,9 @@ struct key_type key_type_asymmetric = { .asym_query = query_asymmetric_key, .asym_eds_op = asymmetric_key_eds_op, .asym_verify_signature = asymmetric_key_verify_signature, + .asym_kpp_query = query_asym_kpp_key, + .asym_kpp_gen_pubkey = asymmetric_key_kpp_gen_pubkey, + .asym_kpp_compute_ss = asymmetric_key_kpp_compute_ss, };EXPORT_SYMBOL_GPL (key_type_asymmetric);
include/keys/asymmetric-subtype.h +12 -0
@@ -20,6 +20,8 @@struct kernel_pkey_query ;struct kernel_pkey_params ;struct public_key_signature ; +struct kernel_kpp_query ; +struct kernel_kpp_params ;/* * Keys of this type declare a subtype that indicates the handlers and
@@ -46,6 +48,16 @@ struct asymmetric_key_subtype {/* Verify the signature on a key of this subtype (optional) */ int (*verify_signature)(const struct key *key,const struct public_key_signature *sig); + +int (*kpp_query)(const struct kernel_kpp_params *params, +struct kernel_kpp_query *res); + +/* Generate public key */ +int (*kpp_gen_pubkey)(struct kernel_kpp_params *params,void *out); + +/* Compute shared secret */ +int (*kpp_compute_ss)(struct kernel_kpp_params *params, +const void *in,void *out); };/**
Signature · 1 line
2.9.4
RFC PATCH 4/5 KEYS: add asymmetric kpp subtype
In reply to Tudor AmbarusIncludes generation of public key and computation of shared secret. This mostly involves offloading the calls to the crypto layer.
The crypto tfm was allocated and the private key was set when parsing the private key. This permits us to use a single tfm whatever the number of operation calls.
The private key, the corresponding public key, the pair's public key and the shared secret are the same as those in crypto/testmgr.h:
# echo -n 020028000200200024d121ebe5cf2d83f6621b6e43843aa38be086c32019da92505303e1c0eab882 \
| xxd -r -p | keyctl padd asymmetric private @s
# keyctl kpp_query 266205365
max_sized
kpp_gen_pubkey=y
kpp_compute_ss=y
# keyctl kpp_gen_pubkey 266205365 | xxd -p
1a7feb5200bd3c317db670c186a6c7c43bc55f6c6f583cf5b66382773324
a15f6aca436ff77eff023708cc405e7afd6a6a026e4187683877faa94443
2def09df
# echo -n ccb4da74b1473fea6c709e382dc7aab729b2470319abdd34bda82c93e1a474d96463f770202fa4e69f4a38ccc02c492fb132bbaf2261dacb6fdba9aafc7781f3 | xxd -r -p > /tmp/bpub
# keyctl kpp_compute_ss 266205365 0 /tmp/bpub | xxd -p
ea176f7e6e5726388bfb41ebbac86da5a872d1ffc9473daa58439f340f8c
f3c9--- crypto/asymmetric_keys/Kconfig | 7 ++ crypto/asymmetric_keys/Makefile | 1 + crypto/asymmetric_keys/asym_kpp.c | 142 ++++++++++++++++++++++++++++++++++++++ include/crypto/asym_kpp_subtype.h | 12 ++++ 4 files changed, 162 insertions(+) create mode 100644 crypto/asymmetric_keys/asym_kpp.c create mode 100644 include/crypto/asym_kpp_subtype.h
crypto/asymmetric_keys/Kconfig +7 -0
@@ -21,6 +21,13 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE appropriate hash algorithms (such as SHA-1) must be available. ENOPKG will be reported if the requisite algorithm is unavailable. +config ASYMMETRIC_KPP_SUBTYPE + tristate "Asymmetric Key Protocol Primitives (KPP) subtype" + select CRYPTO_ECDH + help + This option provides support for KPP handling. + ENOPKG will be reported if the requisite algorithm is unavailable. + config X509_CERTIFICATE_PARSER tristate "X.509 certificate parser" depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE
crypto/asymmetric_keys/Makefile +1 -0
@@ -11,6 +11,7 @@ asymmetric_keys-y := \ signature.o obj-$(CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key.o +obj-$(CONFIG_ASYMMETRIC_KPP_SUBTYPE) += asym_kpp.o # # X.509 Certificate handling
crypto/asymmetric_keys/asym_kpp.c new file +142 -0
142 lines not on this page · raw message
include/crypto/asym_kpp_subtype.h new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef _LINUX_ASYM_KPP_SUBTYPE_H +#define _LINUX_ASYM_KPP_SUBTYPE_H + +#include <linux/keyctl.h> + +struct asym_kpp_ctx { +struct crypto_kpp *tfm; +const char *alg_name; +}; + +#endif /* _LINUX_ASYM_KPP_SUBTYPE_H */
Signature · 1 line
2.9.4
RFC PATCH 5/5 KEYS: add KPP ecdh parser
In reply to Tudor AmbarusThe ECDH private keys are expected to be encoded with the ecdh helpers from kernel.
Use the ecdh helpers to check if the key is valid. If valid, allocate a tfm and set the private key. There is a one-to-one binding between the private key and the tfm. The tfm is allocated once and used as many times as needed.
ECDH keys can be loaded like this:
# echo -n 020028000200200024d121ebe5cf2d83f6621b6e43843aa38be086c32019da92505303e1c0eab882 \
| xxd -r -p | keyctl padd asymmetric private @s--- crypto/asymmetric_keys/Kconfig | 8 +++ crypto/asymmetric_keys/Makefile | 5 ++ crypto/asymmetric_keys/kpp_parser.c | 124 ++++++++++++++++++++++++++++++++++++ include/crypto/asym_kpp_subtype.h | 2 + 4 files changed, 139 insertions(+) create mode 100644 crypto/asymmetric_keys/kpp_parser.c
crypto/asymmetric_keys/Kconfig +8 -0
@@ -57,6 +57,14 @@ config PKCS7_MESSAGE_PARSER This option provides support for parsing PKCS#7 format messages for signature data and provides the ability to verify the signature. +config KPP_KEY_PARSER + tristate "KPP private key parser" + depends on ASYMMETRIC_KPP_SUBTYPE + help + This option provides support for parsing KPP format blobs for + private key data and provides the ability to instantiate a crypto key + from that data. + config PKCS7_TEST_KEY tristate "PKCS#7 testing key type" depends on SYSTEM_DATA_VERIFICATION
crypto/asymmetric_keys/Makefile +5 -0
@@ -62,6 +62,11 @@ $(obj)/pkcs7-asn1.o: $(obj)/pkcs7-asn1.c $(obj)/pkcs7-asn1.h clean-files += pkcs7-asn1.c pkcs7-asn1.h # +# KPP private key handling +# +obj-$(CONFIG_KPP_KEY_PARSER) += kpp_parser.o + +# # PKCS#7 parser testing key # obj-$(CONFIG_PKCS7_TEST_KEY) += pkcs7_test_key.o
crypto/asymmetric_keys/kpp_parser.c new file +124 -0
124 lines not on this page · raw message
include/crypto/asym_kpp_subtype.h +2 -0
@@ -9,4 +9,6 @@ struct asym_kpp_ctx { const char *alg_name; }; +extern struct asymmetric_key_subtype asym_kpp_subtype; +#endif /* _LINUX_ASYM_KPP_SUBTYPE_H */
Signature · 1 line
2.9.4
Re: [RFC PATCH 5/5] KEYS: add KPP ecdh parser
Hi Tudor,
Quoted 10 lines · Tudor Ambarus
The ECDH private keys are expected to be encoded with the ecdh helpers from kernel.
Use the ecdh helpers to check if the key is valid. If valid, allocate a tfm and set the private key. There is a one-to-one binding between the private key and the tfm. The tfm is allocated once and used as many times as needed.
ECDH keys can be loaded like this:
# echo -n 020028000200200024d121ebe5cf2d83f6621b6e43843aa38be086c32019da92505303e1c0eab882 \
This part looks a bit scary. Isn't this translating directly to kpp_secret data structure (in looks like little-endian order) followed curve_id, etc.
If the intent is to extend KPP with regular DH, DH + KDF, etc, then we might want to invent a proper format here? I don't think that a Diffie Hellman or ECDH Private Key format was ever invented, similar to how PKCS8 is used for RSA.
Inventing an ASN.1 syntax would be logical but somewhat painful as D-H is frequently used with plain old random numbers and certificates are not stored on disk...
Quoted 10 lines
| xxd -r -p | keyctl padd asymmetric private @s
Signed-off-by Tudor Ambarus <[email protected]>--- crypto/asymmetric_keys/Kconfig | 8 +++ crypto/asymmetric_keys/Makefile | 5 ++ crypto/asymmetric_keys/kpp_parser.c | 124 ++++++++++++++++++++++++++++++++++++ include/crypto/asym_kpp_subtype.h | 2 + 4 files changed, 139 insertions(+)create mode 100644
crypto/asymmetric_keys/kpp_parser.c
Regards,
-Denis
Re: [RFC PATCH 5/5] KEYS: add KPP ecdh parser
In reply to Tudor AmbarusHi, Denis,
Quoted 11 lines · Denis Kenzior
Hi Tudor,
Quoted 8 lines · Tudor Ambarus
The ECDH private keys are expected to be encoded with the ecdh helpers from kernel.
Use the ecdh helpers to check if the key is valid. If valid, allocate a tfm and set the private key. There is a one-to-one binding between the private key and the tfm. The tfm is allocated once and used as many times as needed.
Quoted 8 lines
Quoted 4 lines
ECDH keys can be loaded like this:
# echo -n 020028000200200024d121ebe5cf2d83f6621b6e43843aa38be086c32019da92505303e1c0eab882 \This part looks a bit scary. Isn't this translating directly to
kpp_secretdata structure (in looks like little-endian order) followedcurve_id, etc. >
yes, this is how it works.
Quoted 5 lines
If the intent is to extend KPP with regular DH, DH + KDF, etc, then we might want to invent a proper format here? I don't think that a Diffie Hellman or ECDH Private Key format was ever invented, similar to how PKCS8 is used for RSA.
This can be resolved by falling through kpp decoding types until one recognizes the format.
Quoted 3 lines
Inventing an ASN.1 syntax would be logical but somewhat painful as D-H is frequently used with plain old random numbers and certificates are not stored on disk...
There was this kind of discussion when kpp was introduced, see:
https://www.mail-archive.com/[email protected]/msg19599.html
Best,
ta
Quoted 16 lines
Quoted 4 lines
| xxd -r -p | keyctl padd asymmetric private @s
Signed-off-by Tudor Ambarus <[email protected]>Quoted 8 lines
--- crypto/asymmetric_keys/Kconfig | 8 +++ crypto/asymmetric_keys/Makefile | 5 ++ crypto/asymmetric_keys/kpp_parser.c | 124 ++++++++++++++++++++++++++++++++++++ include/crypto/asym_kpp_subtype.h | 2 + 4 files changed, 139 insertions(+)create mode 100644
crypto/asymmetric_keys/kpp_parser.cRegards,
-Denis
Hi,
There was a long discussion about which interface to chose to export akcipher and kpp to user-space. This series came as an alternative to what Stephan proposed for af_alg[1]. I would like some feedback before diving into tpm.
Best,
ta
[1] https://www.mail-archive.com/[email protected]/msg27255.html
Quoted 61 lines · Tudor Ambarus
This series provides keyctl access for kpp operations, including a query function, a function to generate the public key that is associated with the private key and a function to compute the shared secret.
I've added a KPP ecdh parser so that you can load an ECDH private key into the kernel. The ECDH private keys are expected to be encoded with the ecdh helpers from kernel. If the private key is valid, the parser will allocate a tfm and set the private key. There is a one-to-one binding between the private key and the tfm. The tfm will be associated with the key for the entire life of the key. The tfm is allocated once and used as many times as needed.
The kernel patches can be found here also:
https://github.com/ambarus/linux/commits/keys-kpp
The keyutils changes can be found here:
https://github.com/ambarus/keyutils/commits/keys-kpp
These patches are similar to what David Howells proposed for akcipher:
https://www.mail-archive.com/[email protected]/msg19915.html
I've ported David's patches on top of keys-next and then I've added my patches on top of them.
Both proposals, David's and mine, lack support for accessing TPM. Before getting familiar with TPM, please let me know how you feel about this series.
Tudor Ambarus (5):
KEYS: Provide key type operations for kpp ops
KEYS: Provide keyctls to drive the new key type ops for kpp
KEYS: Provide missing asym kpp subops for new key type ops
KEYS: add asymmetric kpp subtype
KEYS: add KPP ecdh parserDocumentation/security/keys/core.rst | 113 +++++++++++++++++ crypto/asymmetric_keys/Kconfig | 15 +++ crypto/asymmetric_keys/Makefile | 6 + crypto/asymmetric_keys/asym_kpp.c | 142 +++++++++++++++++++++ crypto/asymmetric_keys/asymmetric_type.c | 77 ++++++++++++ crypto/asymmetric_keys/kpp_parser.c | 124 +++++++++++++++++++ include/crypto/asym_kpp_subtype.h | 14 +++ include/keys/asymmetric-subtype.h | 12 ++ include/linux/key-type.h | 7 ++ include/linux/keyctl.h | 11 ++ include/uapi/linux/keyctl.h | 19 +++ security/keys/Makefile | 1 + security/keys/compat.c | 10 ++ security/keys/internal.h | 28 +++++ security/keys/keyctl.c | 13 ++ security/keys/keyctl_kpp.c | 205 +++++++++++++++++++++++++++++++ 16 files changed, 797 insertions(+)create mode 100644
crypto/asymmetric_keys/asym_kpp.ccreate mode 100644crypto/asymmetric_keys/kpp_parser.ccreate mode 100644include/crypto/asym_kpp_subtype.hcreate mode 100644security/keys/keyctl_kpp.c
Am Mittwoch, 11. April 2018, 13:08:11 CEST schrieb Tudor Ambarus:
Hi Tudor,
Quoted 6 lines
Hi,
There was a long discussion about which interface to chose to export akcipher and kpp to user-space. This series came as an alternative to what Stephan proposed for af_alg[1]. I would like some feedback before diving into tpm.
I am having that on my todo list. Sorry for being not so fast, but I try to have some review shortly.
Ciao
Stephan
ping again.
Quoted 80 lines · Tudor Ambarus
Hi,
There was a long discussion about which interface to chose to export akcipher and kpp to user-space. This series came as an alternative to what Stephan proposed for af_alg[1]. I would like some feedback before diving into tpm.
Best,
ta[1] https://www.mail-archive.com/[email protected]/msg27255.html
Quoted 62 lines · Tudor Ambarus
This series provides keyctl access for kpp operations, including a query function, a function to generate the public key that is associated with the private key and a function to compute the shared secret.
I've added a KPP ecdh parser so that you can load an ECDH private key into the kernel. The ECDH private keys are expected to be encoded with the ecdh helpers from kernel. If the private key is valid, the parser will allocate a tfm and set the private key. There is a one-to-one binding between the private key and the tfm. The tfm will be associated with the key for the entire life of the key. The tfm is allocated once and used as many times as needed.
The kernel patches can be found here also:
https://github.com/ambarus/linux/commits/keys-kpp
The keyutils changes can be found here:
https://github.com/ambarus/keyutils/commits/keys-kpp
These patches are similar to what David Howells proposed for akcipher:
https://www.mail-archive.com/[email protected]/msg19915.html
I've ported David's patches on top of keys-next and then I've added my patches on top of them.
Both proposals, David's and mine, lack support for accessing TPM. Before getting familiar with TPM, please let me know how you feel about this series.
Tudor Ambarus (5):
KEYS: Provide key type operations for kpp ops
KEYS: Provide keyctls to drive the new key type ops for kpp
KEYS: Provide missing asym kpp subops for new key type ops
KEYS: add asymmetric kpp subtype
KEYS: add KPP ecdh parserDocumentation/security/keys/core.rst | 113 +++++++++++++++++ crypto/asymmetric_keys/Kconfig | 15 +++ crypto/asymmetric_keys/Makefile | 6 + crypto/asymmetric_keys/asym_kpp.c | 142 +++++++++++++++++++++ crypto/asymmetric_keys/asymmetric_type.c | 77 ++++++++++++ crypto/asymmetric_keys/kpp_parser.c | 124 +++++++++++++++++++ include/crypto/asym_kpp_subtype.h | 14 +++ include/keys/asymmetric-subtype.h | 12 ++ include/linux/key-type.h | 7 ++ include/linux/keyctl.h | 11 ++ include/uapi/linux/keyctl.h | 19 +++ security/keys/Makefile | 1 + security/keys/compat.c | 10 ++ security/keys/internal.h | 28 +++++ security/keys/keyctl.c | 13 ++ security/keys/keyctl_kpp.c | 205 +++++++++++++++++++++++++++++++ 16 files changed, 797 insertions(+)create mode 100644
crypto/asymmetric_keys/asym_kpp.ccreate mode 100644crypto/asymmetric_keys/kpp_parser.ccreate mode 100644include/crypto/asym_kpp_subtype.hcreate mode 100644security/keys/keyctl_kpp.cSignature · 3 lines
To unsubscribe from this list: send the line "unsubscribe keyrings" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html