diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-23 00:04:48 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-23 00:04:48 -0400 |
| commit | 44d21c3f3a2ef2f58b18bda64c52c99e723f3f4a (patch) | |
| tree | 5146cf96cb0dbd7121176d484417ab942c92dcd4 /lib/mpi | |
| parent | efdfce2b7ff3205ba0fba10270b92b80bbc6187d (diff) | |
| parent | fe55dfdcdfabf160ab0c14617725c57c7a1facfc (diff) | |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto update from Herbert Xu:
"Here is the crypto update for 4.2:
API:
- Convert RNG interface to new style.
- New AEAD interface with one SG list for AD and plain/cipher text.
All external AEAD users have been converted.
- New asymmetric key interface (akcipher).
Algorithms:
- Chacha20, Poly1305 and RFC7539 support.
- New RSA implementation.
- Jitter RNG.
- DRBG is now seeded with both /dev/random and Jitter RNG. If kernel
pool isn't ready then DRBG will be reseeded when it is.
- DRBG is now the default crypto API RNG, replacing krng.
- 842 compression (previously part of powerpc nx driver).
Drivers:
- Accelerated SHA-512 for arm64.
- New Marvell CESA driver that supports DMA and more algorithms.
- Updated powerpc nx 842 support.
- Added support for SEC1 hardware to talitos"
* git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (292 commits)
crypto: marvell/cesa - remove COMPILE_TEST dependency
crypto: algif_aead - Temporarily disable all AEAD algorithms
crypto: af_alg - Forbid the use internal algorithms
crypto: echainiv - Only hold RNG during initialisation
crypto: seqiv - Add compatibility support without RNG
crypto: eseqiv - Offer normal cipher functionality without RNG
crypto: chainiv - Offer normal cipher functionality without RNG
crypto: user - Add CRYPTO_MSG_DELRNG
crypto: user - Move cryptouser.h to uapi
crypto: rng - Do not free default RNG when it becomes unused
crypto: skcipher - Allow givencrypt to be NULL
crypto: sahara - propagate the error on clk_disable_unprepare() failure
crypto: rsa - fix invalid select for AKCIPHER
crypto: picoxcell - Update to the current clk API
crypto: nx - Check for bogus firmware properties
crypto: marvell/cesa - add DT bindings documentation
crypto: marvell/cesa - add support for Kirkwood and Dove SoCs
crypto: marvell/cesa - add support for Orion SoCs
crypto: marvell/cesa - add allhwsupport module parameter
crypto: marvell/cesa - add support for all armada SoCs
...
Diffstat (limited to 'lib/mpi')
| -rw-r--r-- | lib/mpi/mpicoder.c | 87 | ||||
| -rw-r--r-- | lib/mpi/mpiutil.c | 6 |
2 files changed, 71 insertions, 22 deletions
diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c index 4cc6442733f4..bc0a1da8afba 100644 --- a/lib/mpi/mpicoder.c +++ b/lib/mpi/mpicoder.c | |||
| @@ -128,28 +128,36 @@ leave: | |||
| 128 | } | 128 | } |
| 129 | EXPORT_SYMBOL_GPL(mpi_read_from_buffer); | 129 | EXPORT_SYMBOL_GPL(mpi_read_from_buffer); |
| 130 | 130 | ||
| 131 | /**************** | 131 | /** |
| 132 | * Return an allocated buffer with the MPI (msb first). | 132 | * mpi_read_buffer() - read MPI to a bufer provided by user (msb first) |
| 133 | * NBYTES receives the length of this buffer. Caller must free the | 133 | * |
| 134 | * return string (This function does return a 0 byte buffer with NBYTES | 134 | * @a: a multi precision integer |
| 135 | * set to zero if the value of A is zero. If sign is not NULL, it will | 135 | * @buf: bufer to which the output will be written to. Needs to be at |
| 136 | * be set to the sign of the A. | 136 | * leaset mpi_get_size(a) long. |
| 137 | * @buf_len: size of the buf. | ||
| 138 | * @nbytes: receives the actual length of the data written. | ||
| 139 | * @sign: if not NULL, it will be set to the sign of a. | ||
| 140 | * | ||
| 141 | * Return: 0 on success or error code in case of error | ||
| 137 | */ | 142 | */ |
| 138 | void *mpi_get_buffer(MPI a, unsigned *nbytes, int *sign) | 143 | int mpi_read_buffer(MPI a, uint8_t *buf, unsigned buf_len, unsigned *nbytes, |
| 144 | int *sign) | ||
| 139 | { | 145 | { |
| 140 | uint8_t *p, *buffer; | 146 | uint8_t *p; |
| 141 | mpi_limb_t alimb; | 147 | mpi_limb_t alimb; |
| 148 | unsigned int n = mpi_get_size(a); | ||
| 142 | int i; | 149 | int i; |
| 143 | unsigned int n; | 150 | |
| 151 | if (buf_len < n || !buf) | ||
| 152 | return -EINVAL; | ||
| 144 | 153 | ||
| 145 | if (sign) | 154 | if (sign) |
| 146 | *sign = a->sign; | 155 | *sign = a->sign; |
| 147 | *nbytes = n = a->nlimbs * BYTES_PER_MPI_LIMB; | 156 | |
| 148 | if (!n) | 157 | if (nbytes) |
| 149 | n++; /* avoid zero length allocation */ | 158 | *nbytes = n; |
| 150 | p = buffer = kmalloc(n, GFP_KERNEL); | 159 | |
| 151 | if (!p) | 160 | p = buf; |
| 152 | return NULL; | ||
| 153 | 161 | ||
| 154 | for (i = a->nlimbs - 1; i >= 0; i--) { | 162 | for (i = a->nlimbs - 1; i >= 0; i--) { |
| 155 | alimb = a->d[i]; | 163 | alimb = a->d[i]; |
| @@ -171,15 +179,56 @@ void *mpi_get_buffer(MPI a, unsigned *nbytes, int *sign) | |||
| 171 | #error please implement for this limb size. | 179 | #error please implement for this limb size. |
| 172 | #endif | 180 | #endif |
| 173 | } | 181 | } |
| 182 | return 0; | ||
| 183 | } | ||
| 184 | EXPORT_SYMBOL_GPL(mpi_read_buffer); | ||
| 185 | |||
| 186 | /* | ||
| 187 | * mpi_get_buffer() - Returns an allocated buffer with the MPI (msb first). | ||
| 188 | * Caller must free the return string. | ||
| 189 | * This function does return a 0 byte buffer with nbytes set to zero if the | ||
| 190 | * value of A is zero. | ||
| 191 | * | ||
| 192 | * @a: a multi precision integer. | ||
| 193 | * @nbytes: receives the length of this buffer. | ||
| 194 | * @sign: if not NULL, it will be set to the sign of the a. | ||
| 195 | * | ||
| 196 | * Return: Pointer to MPI buffer or NULL on error | ||
| 197 | */ | ||
| 198 | void *mpi_get_buffer(MPI a, unsigned *nbytes, int *sign) | ||
| 199 | { | ||
| 200 | uint8_t *buf, *p; | ||
| 201 | unsigned int n; | ||
| 202 | int ret; | ||
| 203 | |||
| 204 | if (!nbytes) | ||
| 205 | return NULL; | ||
| 206 | |||
| 207 | n = mpi_get_size(a); | ||
| 208 | |||
| 209 | if (!n) | ||
| 210 | n++; | ||
| 211 | |||
| 212 | buf = kmalloc(n, GFP_KERNEL); | ||
| 213 | |||
| 214 | if (!buf) | ||
| 215 | return NULL; | ||
| 216 | |||
| 217 | ret = mpi_read_buffer(a, buf, n, nbytes, sign); | ||
| 218 | |||
| 219 | if (ret) { | ||
| 220 | kfree(buf); | ||
| 221 | return NULL; | ||
| 222 | } | ||
| 174 | 223 | ||
| 175 | /* this is sub-optimal but we need to do the shift operation | 224 | /* this is sub-optimal but we need to do the shift operation |
| 176 | * because the caller has to free the returned buffer */ | 225 | * because the caller has to free the returned buffer */ |
| 177 | for (p = buffer; !*p && *nbytes; p++, --*nbytes) | 226 | for (p = buf; !*p && *nbytes; p++, --*nbytes) |
| 178 | ; | 227 | ; |
| 179 | if (p != buffer) | 228 | if (p != buf) |
| 180 | memmove(buffer, p, *nbytes); | 229 | memmove(buf, p, *nbytes); |
| 181 | 230 | ||
| 182 | return buffer; | 231 | return buf; |
| 183 | } | 232 | } |
| 184 | EXPORT_SYMBOL_GPL(mpi_get_buffer); | 233 | EXPORT_SYMBOL_GPL(mpi_get_buffer); |
| 185 | 234 | ||
diff --git a/lib/mpi/mpiutil.c b/lib/mpi/mpiutil.c index bf076d281d40..314f4dfa603e 100644 --- a/lib/mpi/mpiutil.c +++ b/lib/mpi/mpiutil.c | |||
| @@ -69,7 +69,7 @@ void mpi_free_limb_space(mpi_ptr_t a) | |||
| 69 | if (!a) | 69 | if (!a) |
| 70 | return; | 70 | return; |
| 71 | 71 | ||
| 72 | kfree(a); | 72 | kzfree(a); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | void mpi_assign_limb_space(MPI a, mpi_ptr_t ap, unsigned nlimbs) | 75 | void mpi_assign_limb_space(MPI a, mpi_ptr_t ap, unsigned nlimbs) |
| @@ -95,7 +95,7 @@ int mpi_resize(MPI a, unsigned nlimbs) | |||
| 95 | if (!p) | 95 | if (!p) |
| 96 | return -ENOMEM; | 96 | return -ENOMEM; |
| 97 | memcpy(p, a->d, a->alloced * sizeof(mpi_limb_t)); | 97 | memcpy(p, a->d, a->alloced * sizeof(mpi_limb_t)); |
| 98 | kfree(a->d); | 98 | kzfree(a->d); |
| 99 | a->d = p; | 99 | a->d = p; |
| 100 | } else { | 100 | } else { |
| 101 | a->d = kzalloc(nlimbs * sizeof(mpi_limb_t), GFP_KERNEL); | 101 | a->d = kzalloc(nlimbs * sizeof(mpi_limb_t), GFP_KERNEL); |
| @@ -112,7 +112,7 @@ void mpi_free(MPI a) | |||
| 112 | return; | 112 | return; |
| 113 | 113 | ||
| 114 | if (a->flags & 4) | 114 | if (a->flags & 4) |
| 115 | kfree(a->d); | 115 | kzfree(a->d); |
| 116 | else | 116 | else |
| 117 | mpi_free_limb_space(a->d); | 117 | mpi_free_limb_space(a->d); |
| 118 | 118 | ||
