@@ -89,17 +89,35 @@ static int skcipher_done_slow(struct skcipher_walk *walk, unsigned int bsize)
8989 return 0 ;
9090}
9191
92- int skcipher_walk_done (struct skcipher_walk * walk , int err )
92+ /**
93+ * skcipher_walk_done() - finish one step of a skcipher_walk
94+ * @walk: the skcipher_walk
95+ * @res: number of bytes *not* processed (>= 0) from walk->nbytes,
96+ * or a -errno value to terminate the walk due to an error
97+ *
98+ * This function cleans up after one step of walking through the source and
99+ * destination scatterlists, and advances to the next step if applicable.
100+ * walk->nbytes is set to the number of bytes available in the next step,
101+ * walk->total is set to the new total number of bytes remaining, and
102+ * walk->{src,dst}.virt.addr is set to the next pair of data pointers. If there
103+ * is no more data, or if an error occurred (i.e. -errno return), then
104+ * walk->nbytes and walk->total are set to 0 and all resources owned by the
105+ * skcipher_walk are freed.
106+ *
107+ * Return: 0 or a -errno value. If @res was a -errno value then it will be
108+ * returned, but other errors may occur too.
109+ */
110+ int skcipher_walk_done (struct skcipher_walk * walk , int res )
93111{
94- unsigned int n = walk -> nbytes ;
95- unsigned int nbytes = 0 ;
112+ unsigned int n = walk -> nbytes ; /* num bytes processed this step */
113+ unsigned int total = 0 ; /* new total remaining */
96114
97115 if (!n )
98116 goto finish ;
99117
100- if (likely (err >= 0 )) {
101- n -= err ;
102- nbytes = walk -> total - n ;
118+ if (likely (res >= 0 )) {
119+ n -= res ; /* subtract num bytes *not* processed */
120+ total = walk -> total - n ;
103121 }
104122
105123 if (likely (!(walk -> flags & (SKCIPHER_WALK_SLOW |
@@ -115,31 +133,31 @@ int skcipher_walk_done(struct skcipher_walk *walk, int err)
115133 memcpy (walk -> dst .virt .addr , walk -> page , n );
116134 skcipher_unmap_dst (walk );
117135 } else if (unlikely (walk -> flags & SKCIPHER_WALK_SLOW )) {
118- if (err > 0 ) {
136+ if (res > 0 ) {
119137 /*
120138 * Didn't process all bytes. Either the algorithm is
121139 * broken, or this was the last step and it turned out
122140 * the message wasn't evenly divisible into blocks but
123141 * the algorithm requires it.
124142 */
125- err = - EINVAL ;
126- nbytes = 0 ;
143+ res = - EINVAL ;
144+ total = 0 ;
127145 } else
128146 n = skcipher_done_slow (walk , n );
129147 }
130148
131- if (err > 0 )
132- err = 0 ;
149+ if (res > 0 )
150+ res = 0 ;
133151
134- walk -> total = nbytes ;
152+ walk -> total = total ;
135153 walk -> nbytes = 0 ;
136154
137155 scatterwalk_advance (& walk -> in , n );
138156 scatterwalk_advance (& walk -> out , n );
139- scatterwalk_done (& walk -> in , 0 , nbytes );
140- scatterwalk_done (& walk -> out , 1 , nbytes );
157+ scatterwalk_done (& walk -> in , 0 , total );
158+ scatterwalk_done (& walk -> out , 1 , total );
141159
142- if (nbytes ) {
160+ if (total ) {
143161 crypto_yield (walk -> flags & SKCIPHER_WALK_SLEEP ?
144162 CRYPTO_TFM_REQ_MAY_SLEEP : 0 );
145163 return skcipher_walk_next (walk );
@@ -158,7 +176,7 @@ int skcipher_walk_done(struct skcipher_walk *walk, int err)
158176 free_page ((unsigned long )walk -> page );
159177
160178out :
161- return err ;
179+ return res ;
162180}
163181EXPORT_SYMBOL_GPL (skcipher_walk_done );
164182
0 commit comments