aead.h (552c69b36ebd966186573b9c7a286b390935cce1) | aead.h (cac5818c25d0423bda73e2b6997404ed0a7ed9e3) |
---|---|
1/* 2 * AEAD: Authenticated Encryption with Associated Data 3 * 4 * Copyright (c) 2007-2015 Herbert Xu <herbert@gondor.apana.org.au> 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License as published by the Free 8 * Software Foundation; either version 2 of the License, or (at your option) --- 292 unchanged lines hidden (view full) --- 301 */ 302int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize); 303 304static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req) 305{ 306 return __crypto_aead_cast(req->base.tfm); 307} 308 | 1/* 2 * AEAD: Authenticated Encryption with Associated Data 3 * 4 * Copyright (c) 2007-2015 Herbert Xu <herbert@gondor.apana.org.au> 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License as published by the Free 8 * Software Foundation; either version 2 of the License, or (at your option) --- 292 unchanged lines hidden (view full) --- 301 */ 302int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize); 303 304static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req) 305{ 306 return __crypto_aead_cast(req->base.tfm); 307} 308 |
309static inline void crypto_stat_aead_encrypt(struct aead_request *req, int ret) 310{ 311#ifdef CONFIG_CRYPTO_STATS 312 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 313 314 if (ret && ret != -EINPROGRESS && ret != -EBUSY) { 315 atomic_inc(&tfm->base.__crt_alg->aead_err_cnt); 316 } else { 317 atomic_inc(&tfm->base.__crt_alg->encrypt_cnt); 318 atomic64_add(req->cryptlen, &tfm->base.__crt_alg->encrypt_tlen); 319 } 320#endif 321} 322 323static inline void crypto_stat_aead_decrypt(struct aead_request *req, int ret) 324{ 325#ifdef CONFIG_CRYPTO_STATS 326 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 327 328 if (ret && ret != -EINPROGRESS && ret != -EBUSY) { 329 atomic_inc(&tfm->base.__crt_alg->aead_err_cnt); 330 } else { 331 atomic_inc(&tfm->base.__crt_alg->decrypt_cnt); 332 atomic64_add(req->cryptlen, &tfm->base.__crt_alg->decrypt_tlen); 333 } 334#endif 335} 336 |
|
309/** 310 * crypto_aead_encrypt() - encrypt plaintext 311 * @req: reference to the aead_request handle that holds all information 312 * needed to perform the cipher operation 313 * 314 * Encrypt plaintext data using the aead_request handle. That data structure 315 * and how it is filled with data is discussed with the aead_request_* 316 * functions. --- 6 unchanged lines hidden (view full) --- 323 * that sufficient memory is available for the ciphertext and 324 * the authentication tag. 325 * 326 * Return: 0 if the cipher operation was successful; < 0 if an error occurred 327 */ 328static inline int crypto_aead_encrypt(struct aead_request *req) 329{ 330 struct crypto_aead *aead = crypto_aead_reqtfm(req); | 337/** 338 * crypto_aead_encrypt() - encrypt plaintext 339 * @req: reference to the aead_request handle that holds all information 340 * needed to perform the cipher operation 341 * 342 * Encrypt plaintext data using the aead_request handle. That data structure 343 * and how it is filled with data is discussed with the aead_request_* 344 * functions. --- 6 unchanged lines hidden (view full) --- 351 * that sufficient memory is available for the ciphertext and 352 * the authentication tag. 353 * 354 * Return: 0 if the cipher operation was successful; < 0 if an error occurred 355 */ 356static inline int crypto_aead_encrypt(struct aead_request *req) 357{ 358 struct crypto_aead *aead = crypto_aead_reqtfm(req); |
359 int ret; |
|
331 332 if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY) | 360 361 if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY) |
333 return -ENOKEY; 334 335 return crypto_aead_alg(aead)->encrypt(req); | 362 ret = -ENOKEY; 363 else 364 ret = crypto_aead_alg(aead)->encrypt(req); 365 crypto_stat_aead_encrypt(req, ret); 366 return ret; |
336} 337 338/** 339 * crypto_aead_decrypt() - decrypt ciphertext 340 * @req: reference to the ablkcipher_request handle that holds all information 341 * needed to perform the cipher operation 342 * 343 * Decrypt ciphertext data using the aead_request handle. That data structure --- 11 unchanged lines hidden (view full) --- 355 * decryption operation. Therefore, the function returns this error if 356 * the authentication of the ciphertext was unsuccessful (i.e. the 357 * integrity of the ciphertext or the associated data was violated); 358 * < 0 if an error occurred. 359 */ 360static inline int crypto_aead_decrypt(struct aead_request *req) 361{ 362 struct crypto_aead *aead = crypto_aead_reqtfm(req); | 367} 368 369/** 370 * crypto_aead_decrypt() - decrypt ciphertext 371 * @req: reference to the ablkcipher_request handle that holds all information 372 * needed to perform the cipher operation 373 * 374 * Decrypt ciphertext data using the aead_request handle. That data structure --- 11 unchanged lines hidden (view full) --- 386 * decryption operation. Therefore, the function returns this error if 387 * the authentication of the ciphertext was unsuccessful (i.e. the 388 * integrity of the ciphertext or the associated data was violated); 389 * < 0 if an error occurred. 390 */ 391static inline int crypto_aead_decrypt(struct aead_request *req) 392{ 393 struct crypto_aead *aead = crypto_aead_reqtfm(req); |
394 int ret; |
|
363 364 if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY) | 395 396 if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY) |
365 return -ENOKEY; 366 367 if (req->cryptlen < crypto_aead_authsize(aead)) 368 return -EINVAL; 369 370 return crypto_aead_alg(aead)->decrypt(req); | 397 ret = -ENOKEY; 398 else if (req->cryptlen < crypto_aead_authsize(aead)) 399 ret = -EINVAL; 400 else 401 ret = crypto_aead_alg(aead)->decrypt(req); 402 crypto_stat_aead_decrypt(req, ret); 403 return ret; |
371} 372 373/** 374 * DOC: Asynchronous AEAD Request Handle 375 * 376 * The aead_request data structure contains all pointers to data required for 377 * the AEAD cipher operation. This includes the cipher handle (which can be 378 * used by multiple aead_request instances), pointer to plaintext and --- 154 unchanged lines hidden --- | 404} 405 406/** 407 * DOC: Asynchronous AEAD Request Handle 408 * 409 * The aead_request data structure contains all pointers to data required for 410 * the AEAD cipher operation. This includes the cipher handle (which can be 411 * used by multiple aead_request instances), pointer to plaintext and --- 154 unchanged lines hidden --- |