Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:security\keys\dh.c Create Date:2022-07-28 18:27:23
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:__keyctl_dh_compute

Proto:long __keyctl_dh_compute(struct keyctl_dh_params __user *params, char __user *buffer, size_t buflen, struct keyctl_kdf_params *kdfcopy)

Type:long

Parameter:

TypeParameterName
struct keyctl_dh_params __user *params
char __user *buffer
size_tbuflen
struct keyctl_kdf_params *kdfcopy
243  struct kdf_sdesc * sdesc = NULL
245  If Not params || Not buffer && buflen Then
246  ret = -EINVAL
247  Go to out1
249  If copy_from_user( & pcopy, params, size of pcopy ) != 0 Then
250  ret = -EFAULT
251  Go to out1
254  If kdfcopy Then
258  ret = -EINVAL
259  Go to out1
264  ret = -EMSGSIZE
265  Go to out1
269  hashname = strndup_user - duplicate an existing string from user space*@s: The string to duplicate*@n: Maximum number of bytes to copy, including the trailing NUL.* Return: newly allocated copy of @s or an ERR_PTR() in case of error
270  If IS_ERR(hashname) Then
271  ret = PTR_ERR(hashname)
272  Go to out1
276  ret = kdf_alloc( & sdesc, hashname)
277  kfree(hashname)
278  If ret Then Go to out1
282  memset( & dh_inputs, 0, size of dh_inputs )
284  dlen = dh_data_from_key(prime, & p)
285  If dlen < 0 Then
286  ret = dlen
287  Go to out1
289  p_size = dlen
291  dlen = dh_data_from_key(base, & g)
292  If dlen < 0 Then
293  ret = dlen
294  Go to out2
296  g_size = dlen
298  dlen = dh_data_from_key(private, & key)
299  If dlen < 0 Then
300  ret = dlen
301  Go to out2
303  key_size = dlen
305  secretlen = rypto_dh_key_len() - Obtain the size of the private DH key*@params: private DH key* This function returns the packet DH key size
306  secret = Allocation memory
307  If Not secret Then
308  ret = -ENOMEM
309  Go to out2
311  ret = rypto_dh_encode_key() - encode the private key*@buf: Buffer allocated by the caller to hold the packet DH* private key
312  If ret Then Go to out3
315  tfm = rypto_alloc_kpp() - allocate KPP tfm handle*@alg_name: is the name of the kpp algorithm (e.g. "dh", "ecdh")*@type: specifies the type of the algorithm*@mask: specifies the mask for the algorithm* Allocate a handle for kpp algorithm
316  If IS_ERR(tfm) Then
317  ret = PTR_ERR(tfm)
318  Go to out3
321  ret = rypto_kpp_set_secret() - Invoke kpp operation* Function invokes the specific kpp operation for a given alg.*@tfm: tfm handle*@buffer: Buffer holding the packet representation of the private* key. The structure of the packet key depends on the particular
322  If ret Then Go to out4
325  outlen = rypto_kpp_maxsize() - Get len for output buffer* Function returns the output buffer size required for a given key
327  If Not kdfcopy Then
332  If buflen == 0 Then
333  ret = outlen
334  Go to out4
335  Else if outlen > buflen Then
336  ret = -EOVERFLOW
337  Go to out4
341  outbuf = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc).
343  If Not outbuf Then
344  ret = -ENOMEM
345  Go to out4
348  sg_init_one - Initialize a single entry sg list*@sg: SG entry*@buf: Virtual address for IO*@buflen: IO length
350  req = kpp_request_alloc() - allocates kpp request*@tfm: KPP tfm handle allocated with crypto_alloc_kpp()*@gfp: allocation flags* Return: allocated handle in case of success or NULL in case of an error.
351  If Not req Then
352  ret = -ENOMEM
353  Go to out5
356  kpp_request_set_input() - Sets input buffer* Sets parameters required by generate_public_key*@req: kpp request*@input: ptr to input scatter list*@input_len: size of the input scatter list
357  kpp_request_set_output() - Sets output buffer* Sets parameters required by kpp operation*@req: kpp request*@output: ptr to output scatter list*@output_len: size of the output scatter list
358  init_completion( & completion)
359  kpp_request_set_callback() - Sets an asynchronous callback
367  ret = rypto_kpp_generate_public_key() - Invoke kpp operation* Function invokes the specific kpp operation for generating the public part* for a given kpp algorithm.* To generate a private key, the caller should use a random number generator.
368  If ret == -EINPROGRESS Then
369  wait_for_completion: - waits for completion of a task*@x: holds the state of this particular completion* This waits to be signaled for completion of a specific task. It is NOT* interruptible and there is no timeout.* See also similar routines (i
370  ret = err
371  If ret Then Go to out6
375  If kdfcopy Then
382  ret = -EFAULT
383  Go to out6
386  ret = keyctl_dh_compute_kdf(sdesc, buffer, buflen, outbuf, dst_len + otherinfolen, outlen - dst_len)
389  Else if copy_to_user(buffer, outbuf, dst_len) == 0 Then
390  ret = dst_len
391  Else
392  ret = -EFAULT
395  out6 :
396  kpp_request_free() - zeroize and free kpp request*@req: request to free
397  out5 :
398  kzfree - like kfree but zero memory*@p: object to free memory of* The memory of the object @p points to is zeroed before freed.* If @p is %NULL, kzfree() does nothing.* Note: this function zeroes the whole allocated buffer which can be a good
399  out4 :
400  rypto_free_kpp() - free KPP tfm handle*@tfm: KPP tfm handle allocated with crypto_alloc_kpp()
401  out3 :
402  kzfree - like kfree but zero memory*@p: object to free memory of* The memory of the object @p points to is zeroed before freed.* If @p is %NULL, kzfree() does nothing.* Note: this function zeroes the whole allocated buffer which can be a good
403  out2 :
404  dh_free_data( & dh_inputs)
405  out1 :
406  kdf_dealloc(sdesc)
407  Return ret
Caller
NameDescribe
compat_keyctl_dh_computePerform the DH computation or DH based key derivation.* If successful, 0 will be returned.
keyctl_dh_compute