Key-agreement Protocol Primitives (KPP)¶
Key-agreement Protocol Primitives (KPP) Cipher Algorithm Definitions¶
- structkpp_request¶
Definition:
struct kpp_request { struct crypto_async_request base; struct scatterlist *src; struct scatterlist *dst; unsigned int src_len; unsigned int dst_len; void *__ctx[] ;};Members
baseCommon attributes for async crypto requests
srcSource data
dstDestination data
src_lenSize of the input buffer
dst_lenSize of the output buffer. It needs to be at leastas big as the expected result depending on the operationAfter operation it will be updated with the actual size of theresult. In case of error where the dst sgl size was insufficient,it will be updated to the size required for the operation.
__ctxStart of private context data
- structcrypto_kpp¶
user-instantiated object which encapsulate algorithms and core processing logic
Definition:
struct crypto_kpp { unsigned int reqsize; struct crypto_tfm base;};Members
reqsizeRequest context size required by algorithmimplementation
baseCommon crypto API algorithm data structure
- structkpp_alg¶
generic key-agreement protocol primitives
Definition:
struct kpp_alg { int (*set_secret)(struct crypto_kpp *tfm, const void *buffer, unsigned int len); int (*generate_public_key)(struct kpp_request *req); int (*compute_shared_secret)(struct kpp_request *req); unsigned int (*max_size)(struct crypto_kpp *tfm); int (*init)(struct crypto_kpp *tfm); void (*exit)(struct crypto_kpp *tfm); struct crypto_alg base;};Members
set_secretFunction invokes the protocol specific function tostore the secret private key along with parameters.The implementation knows how to decode the buffer
generate_public_keyFunction generate the public key to be sent to thecounterpart. In case of error, where output is not bigenough req->dst_len will be updated to the sizerequired
compute_shared_secretFunction compute the shared secret as defined bythe algorithm. The result is given back to the user.In case of error, where output is not big enough,req->dst_len will be updated to the size required
max_sizeFunction returns the size of the output buffer
initInitialize the object. This is called only once atinstantiation time. In case the cryptographic hardwareneeds to be initialized. Software fallback should beput in place here.
exitUndo everythinginit did.
baseCommon crypto API algorithm data structure
- structkpp_secret¶
small header for packing secret buffer
Definition:
struct kpp_secret { unsigned short type; unsigned short len;};Members
typedefine type of secret. Each kpp type will define its own
lenspecify the len of the secret, include the header, thatfollows the struct
Key-agreement Protocol Primitives (KPP) Cipher API¶
The KPP API is used with the algorithm typeCRYPTO_ALG_TYPE_KPP (listed as type “kpp” in /proc/crypto)
- structcrypto_kpp*crypto_alloc_kpp(constchar*alg_name,u32type,u32mask)¶
allocate KPP tfm handle
Parameters
constchar*alg_nameis the name of the kpp algorithm (e.g. “dh”, “ecdh”)
u32typespecifies the type of the algorithm
u32maskspecifies the mask for the algorithm
Description
Allocate a handle for kpp algorithm. The returnedstructcrypto_kppis required for any following API invocation
Return
allocated handle in case of success;IS_ERR() is true in case ofan error,PTR_ERR() returns the error code.
- voidcrypto_free_kpp(structcrypto_kpp*tfm)¶
free KPP tfm handle
Parameters
structcrypto_kpp*tfmKPP tfm handle allocated with
crypto_alloc_kpp()
Description
Iftfm is a NULL or error pointer, this function does nothing.
- intcrypto_kpp_set_secret(structcrypto_kpp*tfm,constvoid*buffer,unsignedintlen)¶
Invoke kpp operation
Parameters
structcrypto_kpp*tfmtfm handle
constvoid*bufferBuffer holding the packet representation of the privatekey. The structure of the packet key depends on the particularKPP implementation. Packing and unpacking helpers are providedfor ECDH and DH (see the respective header files for thoseimplementations).
unsignedintlenLength of the packet private key buffer.
Description
Function invokes the specific kpp operation for a given alg.
Return
zero on success; error code in case of error
- intcrypto_kpp_generate_public_key(structkpp_request*req)¶
Invoke kpp operation
Parameters
structkpp_request*reqkpp key request
Description
Function invokes the specific kpp operation for generating the public partfor a given kpp algorithm.
To generate a private key, the caller should use a random number generator.The output of the requested length serves as the private key.
Return
zero on success; error code in case of error
- intcrypto_kpp_compute_shared_secret(structkpp_request*req)¶
Invoke kpp operation
Parameters
structkpp_request*reqkpp key request
Description
Function invokes the specific kpp operation for computing the shared secretfor a given kpp algorithm.
Return
zero on success; error code in case of error
- unsignedintcrypto_kpp_maxsize(structcrypto_kpp*tfm)¶
Get len for output buffer
Parameters
structcrypto_kpp*tfmKPP tfm handle allocated with
crypto_alloc_kpp()
Description
Function returns the output buffer size required for a given key.Function assumes that the key is already set in the transformation. If thisfunction is called without a setkey or with a failed setkey, you will end upin a NULL dereference.
Key-agreement Protocol Primitives (KPP) Cipher Request Handle¶
- structkpp_request*kpp_request_alloc(structcrypto_kpp*tfm,gfp_tgfp)¶
allocates kpp request
Parameters
structcrypto_kpp*tfmKPP tfm handle allocated with
crypto_alloc_kpp()gfp_tgfpallocation flags
Return
allocated handle in case of success or NULL in case of an error.
- voidkpp_request_free(structkpp_request*req)¶
zeroize and free kpp request
Parameters
structkpp_request*reqrequest to free
- voidkpp_request_set_callback(structkpp_request*req,u32flgs,crypto_completion_tcmpl,void*data)¶
Sets an asynchronous callback.
Parameters
structkpp_request*reqrequest that the callback will be set for
u32flgsspecify for instance if the operation may backlog
crypto_completion_tcmplcallback which will be called
void*dataprivate data used by the caller
Description
Callback will be called when an asynchronous operation on a givenrequest is finished.
- voidkpp_request_set_input(structkpp_request*req,structscatterlist*input,unsignedintinput_len)¶
Sets input buffer
Parameters
structkpp_request*reqkpp request
structscatterlist*inputptr to input scatter list
unsignedintinput_lensize of the input scatter list
Description
Sets parameters required by generate_public_key
- voidkpp_request_set_output(structkpp_request*req,structscatterlist*output,unsignedintoutput_len)¶
Sets output buffer
Parameters
structkpp_request*reqkpp request
structscatterlist*outputptr to output scatter list
unsignedintoutput_lensize of the output scatter list
Description
Sets parameters required by kpp operation
ECDH Helper Functions¶
To use ECDH with the KPP cipher API, the following data structure andfunctions should be used.
The ECC curves known to the ECDH implementation are specified in thisheader file.
To use ECDH with KPP, the following functions should be used to operate onan ECDH private key. The packet private key that can be set withthe KPP API function call of crypto_kpp_set_secret.
- structecdh¶
define an ECDH private key
Definition:
struct ecdh { char *key; unsigned short key_size;};Members
keyPrivate ECDH key
key_sizeSize of the private ECDH key
Parameters
conststructecdh*paramsprivate ECDH key
Description
This function returns the packet ECDH key size. A caller can use thatwith the provided ECDH private key reference to obtain the requiredmemory size to hold a packet key.
Return
size of the key in bytes
Parameters
char*bufBuffer allocated by the caller to hold the packet ECDHprivate key. The buffer should be at least crypto_ecdh_key_lenbytes in size.
unsignedintlenLength of the packet private key buffer
conststructecdh*pBuffer with the caller-specified private key
Description
The ECDH implementations operate on a packet representation of the privatekey.
Return
-EINVAL if buffer has insufficient size, 0 on success
Parameters
constchar*bufBuffer holding a packet key that should be decoded
unsignedintlenLength of the packet private key buffer
structecdh*pBuffer allocated by the caller that is filled with theunpacked ECDH private key.
Description
The unpacking obtains the private key by pointingp to the correct locationinbuf. Thus, both pointers refer to the same memory.
Return
-EINVAL if buffer has insufficient size, 0 on success
DH Helper Functions¶
To use DH with the KPP cipher API, the following data structure andfunctions should be used.
To use DH with KPP, the following functions should be used to operate ona DH private key. The packet private key that can be set withthe KPP API function call of crypto_kpp_set_secret.
- structdh¶
define a DH private key
Definition:
struct dh { const void *key; const void *p; const void *g; unsigned int key_size; unsigned int p_size; unsigned int g_size;};Members
keyPrivate DH key
pDiffie-Hellman parameter P
gDiffie-Hellman generator G
key_sizeSize of the private DH key
p_sizeSize of DH parameter P
g_sizeSize of DH generator G
Parameters
conststructdh*paramsprivate DH key
Description
This function returns the packet DH key size. A caller can use thatwith the provided DH private key reference to obtain the requiredmemory size to hold a packet key.
Return
size of the key in bytes
Parameters
char*bufBuffer allocated by the caller to hold the packet DHprivate key. The buffer should be at least crypto_dh_key_lenbytes in size.
unsignedintlenLength of the packet private key buffer
conststructdh*paramsBuffer with the caller-specified private key
Description
The DH implementations operate on a packet representation of the privatekey.
Return
-EINVAL if buffer has insufficient size, 0 on success
Parameters
constchar*bufBuffer holding a packet key that should be decoded
unsignedintlenLength of the packet private key buffer
structdh*paramsBuffer allocated by the caller that is filled with theunpacked DH private key.
Description
The unpacking obtains the private key by pointingp to the correct locationinbuf. Thus, both pointers refer to the same memory.
Return
-EINVAL if buffer has insufficient size, 0 on success