aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mpi/mpicoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mpi/mpicoder.c')
-rw-r--r--lib/mpi/mpicoder.c24
1 files changed, 3 insertions, 21 deletions
diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c
index f4f9e3396f3e..823cf5f5196b 100644
--- a/lib/mpi/mpicoder.c
+++ b/lib/mpi/mpicoder.c
@@ -80,10 +80,8 @@ EXPORT_SYMBOL_GPL(mpi_read_raw_data);
80MPI mpi_read_from_buffer(const void *xbuffer, unsigned *ret_nread) 80MPI mpi_read_from_buffer(const void *xbuffer, unsigned *ret_nread)
81{ 81{
82 const uint8_t *buffer = xbuffer; 82 const uint8_t *buffer = xbuffer;
83 int i, j; 83 unsigned int nbits, nbytes;
84 unsigned nbits, nbytes, nlimbs; 84 MPI val;
85 mpi_limb_t a;
86 MPI val = NULL;
87 85
88 if (*ret_nread < 2) 86 if (*ret_nread < 2)
89 return ERR_PTR(-EINVAL); 87 return ERR_PTR(-EINVAL);
@@ -93,7 +91,6 @@ MPI mpi_read_from_buffer(const void *xbuffer, unsigned *ret_nread)
93 pr_info("MPI: mpi too large (%u bits)\n", nbits); 91 pr_info("MPI: mpi too large (%u bits)\n", nbits);
94 return ERR_PTR(-EINVAL); 92 return ERR_PTR(-EINVAL);
95 } 93 }
96 buffer += 2;
97 94
98 nbytes = DIV_ROUND_UP(nbits, 8); 95 nbytes = DIV_ROUND_UP(nbits, 8);
99 if (nbytes + 2 > *ret_nread) { 96 if (nbytes + 2 > *ret_nread) {
@@ -102,24 +99,9 @@ MPI mpi_read_from_buffer(const void *xbuffer, unsigned *ret_nread)
102 return ERR_PTR(-EINVAL); 99 return ERR_PTR(-EINVAL);
103 } 100 }
104 101
105 nlimbs = DIV_ROUND_UP(nbytes, BYTES_PER_MPI_LIMB); 102 val = mpi_read_raw_data(buffer + 2, nbytes);
106 val = mpi_alloc(nlimbs);
107 if (!val) 103 if (!val)
108 return ERR_PTR(-ENOMEM); 104 return ERR_PTR(-ENOMEM);
109 i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB;
110 i %= BYTES_PER_MPI_LIMB;
111 val->nbits = nbits;
112 j = val->nlimbs = nlimbs;
113 val->sign = 0;
114 for (; j > 0; j--) {
115 a = 0;
116 for (; i < BYTES_PER_MPI_LIMB; i++) {
117 a <<= 8;
118 a |= *buffer++;
119 }
120 i = 0;
121 val->d[j - 1] = a;
122 }
123 105
124 *ret_nread = nbytes + 2; 106 *ret_nread = nbytes + 2;
125 return val; 107 return val;