Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:RES = BASE ^ EXP mod MOD

Proto:int mpi_powm(MPI res, MPI base, MPI exp, MPI mod)

Type:int

Parameter:

TypeParameterName
MPIres
MPIbase
MPIexp
MPImod
26  mpi_ptr_t mp_marker = NULL, bp_marker = NULL, ep_marker = NULL
27  struct karatsuba_ctx karactx = {}
28  mpi_ptr_t xp_marker = NULL
29  mpi_ptr_t tspace = NULL
36  assign_rp = 0
37  tsize = 0
39  rc = -ENOMEM
41  esize = number of valid limbs
42  msize = number of valid limbs
43  size = 2 * msize
44  msign = indicates a negative number
46  rp = array with the limbs
47  ep = array with the limbs
49  If Not msize Then Return -EINVAL
52  If Not esize Then
55  number of valid limbs = If msize == 1 && array with the limbs [0] == 1 Then 0 Else 1
60  rp[0] = 1
62  indicates a negative number = 0
63  Go to leave
70  mp = mp_marker = -- mpiutil.c --
71  If Not mp Then Go to enomem
73  mod_shift_cnt = _leading_zeros - Count the number of zeros from the MSB back*@x: The value* Count the number of leading zeros from the MSB going towards the LSB in @x.* If the MSB of @x is set, the result is 0.
74  If mod_shift_cnt Then Shift U (pointed to by UP and USIZE digits long) CNT bits to the left* and store the USIZE least significant digits of the result at WP.* Return the bits shifted out from the most significant digit.* Argument constraints:* 1. 0 < CNT < BITS_PER_MP_LIMB* 2
76  Else Copy N limbs from S to D. (mp, array with the limbs , msize)
79  bsize = number of valid limbs
80  bsign = indicates a negative number
81  If bsize > msize Then
84  bp = bp_marker = -- mpiutil.c --
85  If Not bp Then Go to enomem
87  Copy N limbs from S to D. (bp, array with the limbs , bsize)
90  Divide num (NP/NSIZE) by den (DP/DSIZE) and write* the NSIZE-DSIZE least significant quotient limbs at QP* and the DSIZE long remainder at NP. If QEXTRA_LIMBS is* non-zero, generate that many fraction bits and append them after the* other quotient limbs.
91  bsize = msize
94  MPN_NORMALIZE(bp, bsize)
95  Else bp = array with the limbs
98  If Not bsize Then
99  number of valid limbs = 0
100  indicates a negative number = 0
101  Go to leave
104  If array size (# of allocated limbs) < size Then
108  If rp == ep || rp == mp || rp == bp Then
110  If Not rp Then Go to enomem
112  assign_rp = 1
113  Else
118  Else
119  If rp == bp Then
121  BUG_ON(bp_marker)
123  If Not bp Then Go to enomem
127  If rp == ep Then
130  If Not ep Then Go to enomem
134  If rp == mp Then
136  BUG_ON(mp_marker)
138  If Not mp Then Go to enomem
144  Copy N limbs from S to D. (rp, bp, bsize)
145  rsize = bsize
146  rsign = bsign
155  xp = xp_marker = -- mpiutil.c --
156  If Not xp Then Go to enomem
159  negative_result = ep[0] & 1 && indicates a negative number
161  i = esize - 1
162  e = ep[i]
163  c = _leading_zeros - Count the number of zeros from the MSB back*@x: The value* Count the number of leading zeros from the MSB going towards the LSB in @x.* If the MSB of @x is set, the result is 0.
164  e = e << c << 1
165  c = BITS_PER_MPI_LIMB - 1 - c
177  cycle
178  When c cycle
185  Else
186  If Not tspace Then
187  tsize = 2 * rsize
190  If Not tspace Then Go to enomem
192  Else if tsize < 2 * rsize Then
194  tsize = 2 * rsize
197  If Not tspace Then Go to enomem
203  xsize = 2 * rsize
204  If xsize > msize Then
210  tp = rp
211  rp = xp
212  xp = tp
213  rsize = xsize
215  If e < 0 Then
243  e <<= 1
244  c--
245  cond_resched()
248  i--
249  If i < 0 Then Break
251  e = ep[i]
261  If mod_shift_cnt Then
265  If carry_limb Then
266  rp[rsize] = carry_limb
267  rsize++
269  Else
274  If rsize >= msize Then
276  rsize = msize
280  If mod_shift_cnt Then Shift U (pointed to by UP and USIZE limbs long) CNT bits to the right* and store the USIZE least significant limbs of the result at WP.* The bits shifted out to the right are returned.* Argument constraints:* 1. 0 < CNT < BITS_PER_MP_LIMB* 2
282  MPN_NORMALIZE(rp, rsize)
285  If negative_result && rsize Then
286  If mod_shift_cnt Then Shift U (pointed to by UP and USIZE limbs long) CNT bits to the right* and store the USIZE least significant limbs of the result at WP.* The bits shifted out to the right are returned.* Argument constraints:* 1. 0 < CNT < BITS_PER_MP_LIMB* 2
288  mpihelp_sub(rp, mp, msize, rp, rsize)
289  rsize = msize
290  rsign = msign
291  MPN_NORMALIZE(rp, rsize)
293  number of valid limbs = rsize
294  indicates a negative number = rsign
296  leave :
297  rc = 0
298  enomem :
299  mpihelp_release_karatsuba_ctx( & karactx)
300  If assign_rp Then mpi_assign_limb_space(res, rp, size)
302  If mp_marker Then mpi_free_limb_space(mp_marker)
304  If bp_marker Then mpi_free_limb_space(bp_marker)
306  If ep_marker Then mpi_free_limb_space(ep_marker)
308  If xp_marker Then mpi_free_limb_space(xp_marker)
310  If tspace Then mpi_free_limb_space(tspace)
312  Return rc
Caller
NameDescribe
digsig_verify_rsaRSA Signature verification with public key