Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto/krb5: Add an API to perform requests

Add an API by which users of the krb5 crypto library can perform crypto
requests, such as encrypt, decrypt, get_mic and verify_mic. These
functions take the previously prepared crypto objects to work on.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

+162
+141
crypto/krb5/krb5_api.c
··· 292 292 return ERR_PTR(ret); 293 293 } 294 294 EXPORT_SYMBOL(crypto_krb5_prepare_checksum); 295 + 296 + /** 297 + * crypto_krb5_encrypt - Apply Kerberos encryption and integrity. 298 + * @krb5: The encoding to use. 299 + * @aead: The keyed crypto object to use. 300 + * @sg: Scatterlist defining the crypto buffer. 301 + * @nr_sg: The number of elements in @sg. 302 + * @sg_len: The size of the buffer. 303 + * @data_offset: The offset of the data in the @sg buffer. 304 + * @data_len: The length of the data. 305 + * @preconfounded: True if the confounder is already inserted. 306 + * 307 + * Using the specified Kerberos encoding, insert a confounder and padding as 308 + * needed, encrypt this and the data in place and insert an integrity checksum 309 + * into the buffer. 310 + * 311 + * The buffer must include space for the confounder, the checksum and any 312 + * padding required. The caller can preinsert the confounder into the buffer 313 + * (for testing, for example). 314 + * 315 + * The resulting secured blob may be less than the size of the buffer. 316 + * 317 + * Returns the size of the secure blob if successful, -ENOMEM on an allocation 318 + * failure, -EFAULT if there is insufficient space, -EMSGSIZE if the confounder 319 + * is too short or the data is misaligned. Other errors may also be returned 320 + * from the crypto layer. 321 + */ 322 + ssize_t crypto_krb5_encrypt(const struct krb5_enctype *krb5, 323 + struct crypto_aead *aead, 324 + struct scatterlist *sg, unsigned int nr_sg, 325 + size_t sg_len, 326 + size_t data_offset, size_t data_len, 327 + bool preconfounded) 328 + { 329 + if (WARN_ON(data_offset > sg_len || 330 + data_len > sg_len || 331 + data_offset > sg_len - data_len)) 332 + return -EMSGSIZE; 333 + return krb5->profile->encrypt(krb5, aead, sg, nr_sg, sg_len, 334 + data_offset, data_len, preconfounded); 335 + } 336 + EXPORT_SYMBOL(crypto_krb5_encrypt); 337 + 338 + /** 339 + * crypto_krb5_decrypt - Validate and remove Kerberos encryption and integrity. 340 + * @krb5: The encoding to use. 341 + * @aead: The keyed crypto object to use. 342 + * @sg: Scatterlist defining the crypto buffer. 343 + * @nr_sg: The number of elements in @sg. 344 + * @_offset: Offset of the secure blob in the buffer; updated to data offset. 345 + * @_len: The length of the secure blob; updated to data length. 346 + * 347 + * Using the specified Kerberos encoding, check and remove the integrity 348 + * checksum and decrypt the secure region, stripping off the confounder. 349 + * 350 + * If successful, @_offset and @_len are updated to outline the region in which 351 + * the data plus the trailing padding are stored. The caller is responsible 352 + * for working out how much padding there is and removing it. 353 + * 354 + * Returns the 0 if successful, -ENOMEM on an allocation failure; sets 355 + * *_error_code and returns -EPROTO if the data cannot be parsed, or -EBADMSG 356 + * if the integrity checksum doesn't match). Other errors may also be returned 357 + * from the crypto layer. 358 + */ 359 + int crypto_krb5_decrypt(const struct krb5_enctype *krb5, 360 + struct crypto_aead *aead, 361 + struct scatterlist *sg, unsigned int nr_sg, 362 + size_t *_offset, size_t *_len) 363 + { 364 + return krb5->profile->decrypt(krb5, aead, sg, nr_sg, _offset, _len); 365 + } 366 + EXPORT_SYMBOL(crypto_krb5_decrypt); 367 + 368 + /** 369 + * crypto_krb5_get_mic - Apply Kerberos integrity checksum. 370 + * @krb5: The encoding to use. 371 + * @shash: The keyed hash to use. 372 + * @metadata: Metadata to add into the hash before adding the data. 373 + * @sg: Scatterlist defining the crypto buffer. 374 + * @nr_sg: The number of elements in @sg. 375 + * @sg_len: The size of the buffer. 376 + * @data_offset: The offset of the data in the @sg buffer. 377 + * @data_len: The length of the data. 378 + * 379 + * Using the specified Kerberos encoding, calculate and insert an integrity 380 + * checksum into the buffer. 381 + * 382 + * The buffer must include space for the checksum at the front. 383 + * 384 + * Returns the size of the secure blob if successful, -ENOMEM on an allocation 385 + * failure, -EFAULT if there is insufficient space, -EMSGSIZE if the gap for 386 + * the checksum is too short. Other errors may also be returned from the 387 + * crypto layer. 388 + */ 389 + ssize_t crypto_krb5_get_mic(const struct krb5_enctype *krb5, 390 + struct crypto_shash *shash, 391 + const struct krb5_buffer *metadata, 392 + struct scatterlist *sg, unsigned int nr_sg, 393 + size_t sg_len, 394 + size_t data_offset, size_t data_len) 395 + { 396 + if (WARN_ON(data_offset > sg_len || 397 + data_len > sg_len || 398 + data_offset > sg_len - data_len)) 399 + return -EMSGSIZE; 400 + return krb5->profile->get_mic(krb5, shash, metadata, sg, nr_sg, sg_len, 401 + data_offset, data_len); 402 + } 403 + EXPORT_SYMBOL(crypto_krb5_get_mic); 404 + 405 + /** 406 + * crypto_krb5_verify_mic - Validate and remove Kerberos integrity checksum. 407 + * @krb5: The encoding to use. 408 + * @shash: The keyed hash to use. 409 + * @metadata: Metadata to add into the hash before adding the data. 410 + * @sg: Scatterlist defining the crypto buffer. 411 + * @nr_sg: The number of elements in @sg. 412 + * @_offset: Offset of the secure blob in the buffer; updated to data offset. 413 + * @_len: The length of the secure blob; updated to data length. 414 + * 415 + * Using the specified Kerberos encoding, check and remove the integrity 416 + * checksum. 417 + * 418 + * If successful, @_offset and @_len are updated to outline the region in which 419 + * the data is stored. 420 + * 421 + * Returns the 0 if successful, -ENOMEM on an allocation failure; sets 422 + * *_error_code and returns -EPROTO if the data cannot be parsed, or -EBADMSG 423 + * if the checksum doesn't match). Other errors may also be returned from the 424 + * crypto layer. 425 + */ 426 + int crypto_krb5_verify_mic(const struct krb5_enctype *krb5, 427 + struct crypto_shash *shash, 428 + const struct krb5_buffer *metadata, 429 + struct scatterlist *sg, unsigned int nr_sg, 430 + size_t *_offset, size_t *_len) 431 + { 432 + return krb5->profile->verify_mic(krb5, shash, metadata, sg, nr_sg, 433 + _offset, _len); 434 + } 435 + EXPORT_SYMBOL(crypto_krb5_verify_mic);
+21
include/crypto/krb5.h
··· 117 117 struct crypto_shash *crypto_krb5_prepare_checksum(const struct krb5_enctype *krb5, 118 118 const struct krb5_buffer *TK, 119 119 u32 usage, gfp_t gfp); 120 + ssize_t crypto_krb5_encrypt(const struct krb5_enctype *krb5, 121 + struct crypto_aead *aead, 122 + struct scatterlist *sg, unsigned int nr_sg, 123 + size_t sg_len, 124 + size_t data_offset, size_t data_len, 125 + bool preconfounded); 126 + int crypto_krb5_decrypt(const struct krb5_enctype *krb5, 127 + struct crypto_aead *aead, 128 + struct scatterlist *sg, unsigned int nr_sg, 129 + size_t *_offset, size_t *_len); 130 + ssize_t crypto_krb5_get_mic(const struct krb5_enctype *krb5, 131 + struct crypto_shash *shash, 132 + const struct krb5_buffer *metadata, 133 + struct scatterlist *sg, unsigned int nr_sg, 134 + size_t sg_len, 135 + size_t data_offset, size_t data_len); 136 + int crypto_krb5_verify_mic(const struct krb5_enctype *krb5, 137 + struct crypto_shash *shash, 138 + const struct krb5_buffer *metadata, 139 + struct scatterlist *sg, unsigned int nr_sg, 140 + size_t *_offset, size_t *_len); 120 141 121 142 #endif /* _CRYPTO_KRB5_H */