1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright(c) 2007-2022 Intel Corporation */ 3 #ifndef QAT_UTILS_H 4 #define QAT_UTILS_H 5 6 7 #include <sys/param.h> 8 #include <sys/ctype.h> 9 #include <sys/endian.h> 10 #include <sys/lock.h> 11 #include <sys/mutex.h> 12 #include <sys/systm.h> 13 #include <sys/types.h> 14 #include <sys/sema.h> 15 #include <sys/time.h> 16 #include <sys/malloc.h> 17 #include <sys/kernel.h> 18 #include <sys/sysctl.h> 19 #include <sys/limits.h> 20 #include <sys/unistd.h> 21 #include <sys/libkern.h> 22 #ifdef __x86_64__ 23 #include <asm/atomic64.h> 24 #else 25 #include <asm/atomic.h> 26 #endif 27 #include <vm/vm.h> 28 #include <vm/pmap.h> 29 30 #include <sys/md5.h> 31 #include <crypto/sha1.h> 32 #include <crypto/sha2/sha256.h> 33 #include <crypto/sha2/sha224.h> 34 #include <crypto/sha2/sha384.h> 35 #include <crypto/sha2/sha512.h> 36 #include <crypto/rijndael/rijndael-api-fst.h> 37 38 #include <opencrypto/cryptodev.h> 39 40 #include "cpa.h" 41 42 #define QAT_UTILS_LOG(...) printf("QAT: "__VA_ARGS__) 43 44 #define QAT_UTILS_WAIT_FOREVER (-1) 45 #define QAT_UTILS_WAIT_NONE 0 46 47 #define QAT_UTILS_HOST_TO_NW_16(uData) QAT_UTILS_OS_HOST_TO_NW_16(uData) 48 #define QAT_UTILS_HOST_TO_NW_32(uData) QAT_UTILS_OS_HOST_TO_NW_32(uData) 49 #define QAT_UTILS_HOST_TO_NW_64(uData) QAT_UTILS_OS_HOST_TO_NW_64(uData) 50 51 #define QAT_UTILS_NW_TO_HOST_16(uData) QAT_UTILS_OS_NW_TO_HOST_16(uData) 52 #define QAT_UTILS_NW_TO_HOST_32(uData) QAT_UTILS_OS_NW_TO_HOST_32(uData) 53 #define QAT_UTILS_NW_TO_HOST_64(uData) QAT_UTILS_OS_NW_TO_HOST_64(uData) 54 55 #define QAT_UTILS_UDIV64_32(dividend, divisor) \ 56 QAT_UTILS_OS_UDIV64_32(dividend, divisor) 57 58 #define QAT_UTILS_UMOD64_32(dividend, divisor) \ 59 QAT_UTILS_OS_UMOD64_32(dividend, divisor) 60 61 #define ICP_CHECK_FOR_NULL_PARAM(param) \ 62 do { \ 63 if (NULL == param) { \ 64 QAT_UTILS_LOG("%s(): invalid param: %s\n", \ 65 __FUNCTION__, \ 66 #param); \ 67 return CPA_STATUS_INVALID_PARAM; \ 68 } \ 69 } while (0) 70 71 #define ICP_CHECK_FOR_NULL_PARAM_VOID(param) \ 72 do { \ 73 if (NULL == param) { \ 74 QAT_UTILS_LOG("%s(): invalid param: %s\n", \ 75 __FUNCTION__, \ 76 #param); \ 77 return; \ 78 } \ 79 } while (0) 80 81 /*Macro for adding an element to the tail of a doubly linked list*/ 82 /*The currentptr tracks the tail, and the headptr tracks the head.*/ 83 #define ICP_ADD_ELEMENT_TO_END_OF_LIST(elementtoadd, currentptr, headptr) \ 84 do { \ 85 if (NULL == currentptr) { \ 86 currentptr = elementtoadd; \ 87 elementtoadd->pNext = NULL; \ 88 elementtoadd->pPrev = NULL; \ 89 headptr = currentptr; \ 90 } else { \ 91 elementtoadd->pPrev = currentptr; \ 92 currentptr->pNext = elementtoadd; \ 93 elementtoadd->pNext = NULL; \ 94 currentptr = elementtoadd; \ 95 } \ 96 } while (0) 97 98 /*currentptr is not used in this case since we don't track the tail. */ 99 #define ICP_ADD_ELEMENT_TO_HEAD_OF_LIST(elementtoadd, currentptr, headptr) \ 100 do { \ 101 if (NULL == headptr) { \ 102 elementtoadd->pNext = NULL; \ 103 elementtoadd->pPrev = NULL; \ 104 headptr = elementtoadd; \ 105 } else { \ 106 elementtoadd->pPrev = NULL; \ 107 elementtoadd->pNext = headptr; \ 108 headptr->pPrev = elementtoadd; \ 109 headptr = elementtoadd; \ 110 } \ 111 } while (0) 112 113 #define ICP_REMOVE_ELEMENT_FROM_LIST(elementtoremove, currentptr, headptr) \ 114 do { \ 115 /*If the previous pointer is not NULL*/ \ 116 if (NULL != elementtoremove->pPrev) { \ 117 elementtoremove->pPrev->pNext = \ 118 elementtoremove->pNext; \ 119 if (elementtoremove->pNext) { \ 120 elementtoremove->pNext->pPrev = \ 121 elementtoremove->pPrev; \ 122 } else { \ 123 /* Move the tail pointer backwards */ \ 124 currentptr = elementtoremove->pPrev; \ 125 } \ 126 } else if (NULL != elementtoremove->pNext) { \ 127 /*Remove the head pointer.*/ \ 128 elementtoremove->pNext->pPrev = NULL; \ 129 /*Hence move the head forward.*/ \ 130 headptr = elementtoremove->pNext; \ 131 } else { \ 132 /*Remove the final entry in the list. */ \ 133 currentptr = NULL; \ 134 headptr = NULL; \ 135 } \ 136 } while (0) 137 138 MALLOC_DECLARE(M_QAT); 139 140 #ifdef __x86_64__ 141 typedef atomic64_t QatUtilsAtomic; 142 #else 143 typedef atomic_t QatUtilsAtomic; 144 #endif 145 146 #define QAT_UTILS_OS_NW_TO_HOST_16(uData) be16toh(uData) 147 #define QAT_UTILS_OS_NW_TO_HOST_32(uData) be32toh(uData) 148 #define QAT_UTILS_OS_NW_TO_HOST_64(uData) be64toh(uData) 149 150 #define QAT_UTILS_OS_HOST_TO_NW_16(uData) htobe16(uData) 151 #define QAT_UTILS_OS_HOST_TO_NW_32(uData) htobe32(uData) 152 #define QAT_UTILS_OS_HOST_TO_NW_64(uData) htobe64(uData) 153 154 /** 155 * @ingroup QatUtils 156 * 157 * @brief Atomically read the value of atomic variable 158 * 159 * @param pAtomicVar IN - atomic variable 160 * 161 * Atomically reads the value of pAtomicVar to the outValue 162 * 163 * @li Reentrant: yes 164 * @li IRQ safe: yes 165 * 166 * @return pAtomicVar value 167 */ 168 int64_t qatUtilsAtomicGet(QatUtilsAtomic *pAtomicVar); 169 170 /** 171 * @ingroup QatUtils 172 * 173 * @brief Atomically set the value of atomic variable 174 * 175 * @param inValue IN - atomic variable to be set equal to inValue 176 * 177 * @param pAtomicVar OUT - atomic variable 178 * 179 * Atomically sets the value of pAtomicVar to the value given 180 * 181 * @li Reentrant: yes 182 * @li IRQ safe: yes 183 * 184 * @return none 185 */ 186 void qatUtilsAtomicSet(int64_t inValue, QatUtilsAtomic *pAtomicVar); 187 188 /** 189 * @ingroup QatUtils 190 * 191 * @brief add the value to atomic variable 192 * 193 * @param inValue (in) - value to be added to the atomic variable 194 * 195 * @param pAtomicVar (in & out) - atomic variable 196 * 197 * Atomically adds the value of inValue to the pAtomicVar 198 * 199 * @li Reentrant: yes 200 * @li IRQ safe: yes 201 * 202 * @return pAtomicVar value after the addition 203 */ 204 int64_t qatUtilsAtomicAdd(int64_t inValue, QatUtilsAtomic *pAtomicVar); 205 206 /** 207 * @ingroup QatUtils 208 * 209 * @brief subtract the value from atomic variable 210 * 211 * @param inValue IN - atomic variable value to be subtracted by value 212 * 213 * @param pAtomicVar IN/OUT - atomic variable 214 * 215 * Atomically subtracts the value of pAtomicVar by inValue 216 * 217 * @li Reentrant: yes 218 * @li IRQ safe: yes 219 * 220 * @return pAtomicVar value after the subtraction 221 */ 222 int64_t qatUtilsAtomicSub(int64_t inValue, QatUtilsAtomic *pAtomicVar); 223 224 /** 225 * @ingroup QatUtils 226 * 227 * @brief increment value of atomic variable by 1 228 * 229 * @param pAtomicVar IN/OUT - atomic variable 230 * 231 * Atomically increments the value of pAtomicVar by 1. 232 * 233 * @li Reentrant: yes 234 * @li IRQ safe: yes 235 * 236 * @return pAtomicVar value after the increment 237 */ 238 int64_t qatUtilsAtomicInc(QatUtilsAtomic *pAtomicVar); 239 240 /** 241 * @ingroup QatUtils 242 * 243 * @brief decrement value of atomic variable by 1 244 * 245 * @param pAtomicVar IN/OUT - atomic variable 246 * 247 * Atomically decrements the value of pAtomicVar by 1. 248 * 249 * @li Reentrant: yes 250 * @li IRQ safe: yes 251 * 252 * @return pAtomic value after the decrement 253 */ 254 int64_t qatUtilsAtomicDec(QatUtilsAtomic *pAtomicVar); 255 256 /** 257 * @ingroup QatUtils 258 * 259 * @brief NUMA aware memory allocation; available on Linux OS only. 260 * 261 * @param size - memory size to allocate, in bytes 262 * @param node - node 263 * @param alignment - memory boundary alignment (alignment can not be 0) 264 * 265 * Allocates a memory zone of a given size on the specified node 266 * The returned memory is guaraunteed to be physically contiguous if the 267 * given size is less than 128KB and belonging to the node specified 268 * 269 * @li Reentrant: yes 270 * @li IRQ safe: no 271 * 272 * @return Pointer to the allocated zone or NULL if the allocation failed 273 */ 274 void *qatUtilsMemAllocContiguousNUMA(uint32_t size, 275 uint32_t node, 276 uint32_t alignment); 277 278 /** 279 * @ingroup QatUtils 280 * 281 * @brief Frees memory allocated by qatUtilsMemAllocContigousNUMA. 282 * 283 * @param ptr - pointer to the memory zone 284 * @param size - size of the pointer previously allocated 285 * 286 * Frees a previously allocated memory zone 287 * 288 * @li Reentrant: yes 289 * @li IRQ safe: no 290 * 291 * @return - none 292 */ 293 void qatUtilsMemFreeNUMA(void *ptr); 294 295 /** 296 * @ingroup QatUtils 297 * 298 * @brief virtual to physical address translation 299 * 300 * @param virtAddr - virtual address 301 * 302 * Converts a virtual address into its equivalent MMU-mapped physical address 303 * 304 * @li Reentrant: yes 305 * @li IRQ safe: yes 306 * 307 * @return Corresponding physical address 308 */ 309 #define QAT_UTILS_MMU_VIRT_TO_PHYS(virtAddr) \ 310 ((uint64_t)((virtAddr) ? vtophys(virtAddr) : 0)) 311 312 /** 313 * @ingroup QatUtils 314 * 315 * @brief Initializes the SpinLock object 316 * 317 * @param pLock - Spinlock handle 318 * 319 * Initializes the SpinLock object. 320 * 321 * @li Reentrant: yes 322 * @li IRQ safe: yes 323 * 324 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 325 */ 326 CpaStatus qatUtilsLockInit(struct mtx *pLock); 327 328 /** 329 * @ingroup QatUtils 330 * 331 * @brief Acquires a spin lock 332 * 333 * @param pLock - Spinlock handle 334 * 335 * This routine acquires a spin lock so the 336 * caller can synchronize access to shared data in a 337 * multiprocessor-safe way by raising IRQL. 338 * 339 * @li Reentrant: yes 340 * @li IRQ safe: yes 341 * 342 * @return - Returns CPA_STATUS_SUCCESS if the spinlock is acquired. Returns 343 * CPA_STATUS_FAIL 344 * if 345 * spinlock handle is NULL. If spinlock is already acquired by any 346 * other thread of execution then it tries in busy loop/spins till it 347 * gets spinlock. 348 */ 349 CpaStatus qatUtilsLock(struct mtx *pLock); 350 351 /** 352 * @ingroup QatUtils 353 * 354 * @brief Releases the spin lock 355 * 356 * @param pLock - Spinlock handle 357 * 358 * This routine releases the spin lock which the thread had acquired 359 * 360 * @li Reentrant: yes 361 * @li IRQ safe: yes 362 * 363 * @return - return CPA_STATUS_SUCCESS if the spinlock is released. Returns 364 * CPA_STATUS_FAIL 365 * if 366 * spinlockhandle passed is NULL. 367 */ 368 CpaStatus qatUtilsUnlock(struct mtx *pLock); 369 370 /** 371 * @ingroup QatUtils 372 * 373 * @brief Destroy the spin lock object 374 * 375 * @param pLock - Spinlock handle 376 * 377 * @li Reentrant: yes 378 * @li IRQ safe: yes 379 * 380 * @return - returns CPA_STATUS_SUCCESS if plock is destroyed. 381 * returns CPA_STATUS_FAIL if plock is NULL. 382 */ 383 CpaStatus qatUtilsLockDestroy(struct mtx *pLock); 384 385 /** 386 * @ingroup QatUtils 387 * 388 * @brief Initializes a semaphore 389 * 390 * @param pSid - semaphore handle 391 * @param start_value - initial semaphore value 392 * 393 * Initializes a semaphore object 394 * Note: Semaphore initialization qatUtilsSemaphoreInit API must be called 395 * first before using any QAT Utils Semaphore APIs 396 * 397 * @li Reentrant: yes 398 * @li IRQ safe: no 399 * 400 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 401 */ 402 CpaStatus qatUtilsSemaphoreInit(struct sema **pSid, uint32_t start_value); 403 404 /** 405 * @ingroup QatUtils 406 * 407 * @brief Destroys a semaphore object 408 * 409 * @param pSid - semaphore handle 410 * 411 * Destroys a semaphore object; the caller should ensure that no thread is 412 * blocked on this semaphore. If call made when thread blocked on semaphore the 413 * behaviour is unpredictable 414 * 415 * @li Reentrant: yes 416 ] * @li IRQ safe: no 417 * 418 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 419 */ 420 CpaStatus qatUtilsSemaphoreDestroy(struct sema **pSid); 421 422 /** 423 * @ingroup QatUtils 424 * 425 * @brief Waits on (decrements) a semaphore 426 * 427 * @param pSid - semaphore handle 428 * @param timeout - timeout, in ms; QAT_UTILS_WAIT_FOREVER (-1) if the thread 429 * is to block indefinitely or QAT_UTILS_WAIT_NONE (0) if the thread is to 430 * return immediately even if the call fails 431 * 432 * Decrements a semaphore, blocking if the semaphore is 433 * unavailable (value is 0). 434 * 435 * @li Reentrant: yes 436 * @li IRQ safe: no 437 * 438 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 439 */ 440 CpaStatus qatUtilsSemaphoreWait(struct sema **pSid, int32_t timeout); 441 442 /** 443 * @ingroup QatUtils 444 * 445 * @brief Non-blocking wait on semaphore 446 * 447 * @param semaphore - semaphore handle 448 * 449 * Decrements a semaphore, not blocking the calling thread if the semaphore 450 * is unavailable 451 * 452 * @li Reentrant: yes 453 * @li IRQ safe: no 454 * 455 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 456 */ 457 CpaStatus qatUtilsSemaphoreTryWait(struct sema **semaphore); 458 459 /** 460 * @ingroup QatUtils 461 * 462 * @brief Posts to (increments) a semaphore 463 * 464 * @param pSid - semaphore handle 465 * 466 * Increments a semaphore object 467 * 468 * @li Reentrant: yes 469 * @li IRQ safe: no 470 * 471 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 472 */ 473 CpaStatus qatUtilsSemaphorePost(struct sema **pSid); 474 475 /** 476 * @ingroup QatUtils 477 * 478 * @brief initializes a pMutex 479 * 480 * @param pMutex - pMutex handle 481 * 482 * Initializes a pMutex object 483 * @note Mutex initialization qatUtilsMutexInit API must be called 484 * first before using any QAT Utils Mutex APIs 485 * 486 * @li Reentrant: yes 487 * @li IRQ safe: no 488 * 489 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 490 */ 491 CpaStatus qatUtilsMutexInit(struct mtx **pMutex); 492 493 /** 494 * @ingroup QatUtils 495 * 496 * @brief locks a pMutex 497 * 498 * @param pMutex - pMutex handle 499 * @param timeout - timeout in ms; QAT_UTILS_WAIT_FOREVER (-1) to wait forever 500 * or QAT_UTILS_WAIT_NONE to return immediately 501 * 502 * Locks a pMutex object 503 * 504 * @li Reentrant: yes 505 * @li IRQ safe: no 506 * 507 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 508 */ 509 CpaStatus qatUtilsMutexLock(struct mtx **pMutex, int32_t timeout); 510 511 /** 512 * @ingroup QatUtils 513 * 514 * @brief Unlocks a pMutex 515 * 516 * @param pMutex - pMutex handle 517 * 518 * Unlocks a pMutex object 519 * 520 * @li Reentrant: yes 521 * @li IRQ safe: no 522 * 523 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 524 */ 525 CpaStatus qatUtilsMutexUnlock(struct mtx **pMutex); 526 527 /** 528 * @ingroup QatUtils 529 * 530 * @brief Destroys a pMutex object 531 * 532 * @param pMutex - pMutex handle 533 * 534 * Destroys a pMutex object; the caller should ensure that no thread is 535 * blocked on this pMutex. If call made when thread blocked on pMutex the 536 * behaviour is unpredictable 537 * 538 * @li Reentrant: yes 539 * @li IRQ safe: no 540 * 541 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 542 */ 543 CpaStatus qatUtilsMutexDestroy(struct mtx **pMutex); 544 545 /** 546 * @ingroup QatUtils 547 * 548 * @brief Non-blocking attempt to lock a pMutex 549 * 550 * @param pMutex - pMutex handle 551 * 552 * Attempts to lock a pMutex object, returning immediately with 553 * CPA_STATUS_SUCCESS if 554 * the lock was successful or CPA_STATUS_FAIL if the lock failed 555 * 556 * @li Reentrant: yes 557 * @li IRQ safe: no 558 * 559 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 560 */ 561 CpaStatus qatUtilsMutexTryLock(struct mtx **pMutex); 562 563 /** 564 * @ingroup QatUtils 565 * 566 * @brief Yielding sleep for a number of milliseconds 567 * 568 * @param milliseconds - number of milliseconds to sleep 569 * 570 * The calling thread will sleep for the specified number of milliseconds. 571 * This sleep is yielding, hence other tasks will be scheduled by the 572 * operating system during the sleep period. Calling this function with an 573 * argument of 0 will place the thread at the end of the current scheduling 574 * loop. 575 * 576 * @li Reentrant: yes 577 * @li IRQ safe: no 578 * 579 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 580 */ 581 CpaStatus qatUtilsSleep(uint32_t milliseconds); 582 583 /** 584 * @ingroup QatUtils 585 * 586 * @brief Yields execution of current thread 587 * 588 * Yields the execution of the current thread 589 * 590 * @li Reentrant: yes 591 * @li IRQ safe: no 592 * 593 * @return - none 594 */ 595 void qatUtilsYield(void); 596 597 /** 598 * @ingroup QatUtils 599 * 600 * @brief Calculate MD5 transform operation 601 * 602 * @param in - pointer to data to be processed. 603 * The buffer needs to be at least md5 block size long as defined in 604 * rfc1321 (64 bytes) 605 * out - output pointer for state data after single md5 transform 606 * operation. 607 * The buffer needs to be at least md5 state size long as defined in 608 * rfc1321 (16 bytes) 609 * 610 * @li Reentrant: yes 611 * @li IRQ safe: yes 612 * 613 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 614 * 615 */ 616 CpaStatus qatUtilsHashMD5(uint8_t *in, uint8_t *out); 617 618 /** 619 * @ingroup QatUtils 620 * 621 * @brief Calculate MD5 transform operation 622 * 623 * @param in - pointer to data to be processed. 624 * The buffer needs to be at least md5 block size long as defined in 625 * rfc1321 (64 bytes) 626 * out - output pointer for state data after single md5 transform 627 * operation. 628 * The buffer needs to be at least md5 state size long as defined in 629 * rfc1321 (16 bytes) 630 * len - Length on the input to be processed. 631 * 632 * @li Reentrant: yes 633 * @li IRQ safe: yes 634 * 635 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 636 * 637 */ 638 CpaStatus qatUtilsHashMD5Full(uint8_t *in, uint8_t *out, uint32_t len); 639 640 /** 641 * @ingroup QatUtils 642 * 643 * @brief Calculate SHA1 transform operation 644 * 645 * @param in - pointer to data to be processed. 646 * The buffer needs to be at least sha1 block size long as defined in 647 * rfc3174 (64 bytes) 648 * out - output pointer for state data after single sha1 transform 649 * operation. 650 * The buffer needs to be at least sha1 state size long as defined in 651 * rfc3174 (20 bytes) 652 * 653 * @li Reentrant: yes 654 * @li IRQ safe: yes 655 * 656 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 657 * 658 */ 659 CpaStatus qatUtilsHashSHA1(uint8_t *in, uint8_t *out); 660 661 /** 662 * @ingroup QatUtils 663 * 664 * @brief Calculate SHA1 transform operation 665 * 666 * @param in - pointer to data to be processed. 667 * The buffer needs to be at least sha1 block size long as defined in 668 * rfc3174 (64 bytes) 669 * out - output pointer for state data after single sha1 transform 670 * operation. 671 * The buffer needs to be at least sha1 state size long as defined in 672 * rfc3174 (20 bytes) 673 * len - Length on the input to be processed. 674 * 675 * @li Reentrant: yes 676 * @li IRQ safe: yes 677 * 678 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 679 * 680 */ 681 CpaStatus qatUtilsHashSHA1Full(uint8_t *in, uint8_t *out, uint32_t len); 682 683 /** 684 * @ingroup QatUtils 685 * 686 * @brief Calculate SHA224 transform operation 687 * 688 * @param in - pointer to data to be processed. 689 * The buffer needs to be at least sha224 block size long as defined in 690 * rfc3874 and rfc4868 (64 bytes) 691 * out - output pointer for state data after single sha224 transform 692 * operation. 693 * The buffer needs to be at least sha224 state size long as defined in 694 * rfc3874 and rfc4868 (32 bytes) 695 * @li Reentrant: yes 696 * @li IRQ safe: yes 697 * 698 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 699 * 700 */ 701 CpaStatus qatUtilsHashSHA224(uint8_t *in, uint8_t *out); 702 703 /** 704 * @ingroup QatUtils 705 * 706 * @brief Calculate SHA256 transform operation 707 * 708 * 709 * @param in - pointer to data to be processed. 710 * The buffer needs to be at least sha256 block size long as defined in 711 * rfc4868 (64 bytes) 712 * out - output pointer for state data after single sha256 transform 713 * operation. 714 * The buffer needs to be at least sha256 state size long as defined in 715 * rfc4868 (32 bytes) 716 * @li Reentrant: yes 717 * @li IRQ safe: yes 718 * 719 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 720 * 721 */ 722 CpaStatus qatUtilsHashSHA256(uint8_t *in, uint8_t *out); 723 724 /** 725 * @ingroup QatUtils 726 * 727 * @brief Calculate SHA256 transform operation 728 * 729 * 730 * @param in - pointer to data to be processed. 731 * The buffer needs to be at least sha256 block size long as defined in 732 * rfc4868 (64 bytes) 733 * out - output pointer for state data after single sha256 transform 734 * operation. 735 * The buffer needs to be at least sha256 state size long as defined in 736 * rfc4868 (32 bytes) 737 * len - Length on the input to be processed. 738 * @li Reentrant: yes 739 * @li IRQ safe: yes 740 * 741 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 742 * 743 */ 744 CpaStatus qatUtilsHashSHA256Full(uint8_t *in, uint8_t *out, uint32_t len); 745 746 /** 747 * @ingroup QatUtils 748 * 749 * @brief Calculate SHA384 transform operation 750 * 751 * @param in - pointer to data to be processed. 752 * The buffer needs to be at least sha384 block size long as defined in 753 * rfc4868 (128 bytes) 754 * out - output pointer for state data after single sha384 transform 755 * operation. 756 * The buffer needs to be at least sha384 state size long as defined in 757 * rfc4868 (64 bytes) 758 * @li Reentrant: yes 759 * @li IRQ safe: yes 760 * 761 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 762 * 763 */ 764 CpaStatus qatUtilsHashSHA384(uint8_t *in, uint8_t *out); 765 766 /** 767 * @ingroup QatUtils 768 * 769 * @brief Calculate SHA384 transform operation 770 * 771 * @param in - pointer to data to be processed. 772 * The buffer needs to be at least sha384 block size long as defined in 773 * rfc4868 (128 bytes) 774 * out - output pointer for state data after single sha384 transform 775 * operation. 776 * The buffer needs to be at least sha384 state size long as defined in 777 * rfc4868 (64 bytes) 778 * len - Length on the input to be processed. 779 * @li Reentrant: yes 780 * @li IRQ safe: yes 781 * 782 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 783 * 784 */ 785 CpaStatus qatUtilsHashSHA384Full(uint8_t *in, uint8_t *out, uint32_t len); 786 787 /** 788 * @ingroup QatUtils 789 * 790 * @brief Calculate SHA512 transform operation 791 * 792 * @param in - pointer to data to be processed. 793 * The buffer needs to be at least sha512 block size long as defined in 794 * rfc4868 (128 bytes) 795 * out - output pointer for state data after single sha512 transform 796 * operation. 797 * The buffer needs to be at least sha512 state size long as defined in 798 * rfc4868 (64 bytes) 799 * @li Reentrant: yes 800 * @li IRQ safe: yes 801 * 802 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 803 * 804 */ 805 CpaStatus qatUtilsHashSHA512(uint8_t *in, uint8_t *out); 806 807 /** 808 * @ingroup QatUtils 809 * 810 * @brief Calculate SHA512 transform operation 811 * 812 * @param in - pointer to data to be processed. 813 * The buffer needs to be at least sha512 block size long as defined in 814 * rfc4868 (128 bytes) 815 * out - output pointer for state data after single sha512 transform 816 * operation. 817 * The buffer needs to be at least sha512 state size long as defined in 818 * rfc4868 (64 bytes) 819 * len - Length on the input to be processed. 820 * @li Reentrant: yes 821 * @li IRQ safe: yes 822 * 823 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 824 * 825 */ 826 CpaStatus qatUtilsHashSHA512Full(uint8_t *in, uint8_t *out, uint32_t len); 827 828 /** 829 * @ingroup QatUtils 830 * 831 * @brief Single block AES encrypt 832 * 833 * @param key - pointer to symetric key. 834 * keyLenInBytes - key length 835 * in - pointer to data to encrypt 836 * out - pointer to output buffer for encrypted text 837 * The in and out buffers need to be at least AES block size long 838 * as defined in rfc3686 (16 bytes) 839 * 840 * @li Reentrant: yes 841 * @li IRQ safe: yes 842 * 843 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 844 * 845 */ 846 CpaStatus qatUtilsAESEncrypt(uint8_t *key, 847 uint32_t keyLenInBytes, 848 uint8_t *in, 849 uint8_t *out); 850 851 /** 852 * @ingroup QatUtils 853 * 854 * @brief Converts AES forward key to reverse key 855 * 856 * @param key - pointer to symetric key. 857 * keyLenInBytes - key length 858 * out - pointer to output buffer for reversed key 859 * The in and out buffers need to be at least AES block size long 860 * as defined in rfc3686 (16 bytes) 861 * 862 * @li Reentrant: yes 863 * @li IRQ safe: yes 864 * 865 * @return - CPA_STATUS_SUCCESS/CPA_STATUS_FAIL 866 * 867 */ 868 CpaStatus qatUtilsAESKeyExpansionForward(uint8_t *key, 869 uint32_t keyLenInBytes, 870 uint32_t *out); 871 #endif 872