| 1 | /************************************************************************* |
| 2 | * Copyright (C) 2025 Intel Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | *************************************************************************/ |
| 16 | |
| 17 | #include "owndefs.h" |
| 18 | #include "owncp.h" |
| 19 | #include "hash/pcphash.h" |
| 20 | #include "hash/pcphash_rmf.h" |
| 21 | #include "pcptool.h" |
| 22 | #include "hash/sha3/shake256/pcpshake256_stuff.h" |
| 23 | |
| 24 | /* |
| 25 | // Name: ippsHashMethod_SHAKE256 |
| 26 | // |
| 27 | // Purpose: Return SHAKE256 method. |
| 28 | // |
| 29 | // Returns: Reason: |
| 30 | // NULL digestBitsize is not positive multiple of 8 integer |
| 31 | // Pointer to SHAKE256 hash-method no errors |
| 32 | // |
| 33 | */ |
| 34 | |
| 35 | IPPFUN(const IppsHashMethod*, ippsHashMethod_SHAKE256, (int digestBitsize)) |
| 36 | { |
| 37 | /* Prevents re-initialization for better multi-threaded/repeated call performance */ |
| 38 | static volatile int isInitialized = 0; |
| 39 | |
| 40 | IPP_BADARG_RET(digestBitsize <= 0, NULL); |
| 41 | /* test if digestBitsize is not byte aligned */ |
| 42 | IPP_BADARG_RET(digestBitsize % 8, NULL); |
| 43 | |
| 44 | /* clang-format off */ |
| 45 | static IppsHashMethod method = { ippHashAlg_SHAKE256, |
| 46 | 0, |
| 47 | MBS_SHAKE256, |
| 48 | 0, |
| 49 | IPP_SHA3_STATE_BYTESIZE, |
| 50 | NULL, |
| 51 | NULL, |
| 52 | NULL, |
| 53 | NULL }; |
| 54 | /* clang-format on */ |
| 55 | method.hashLen = digestBitsize / 8; |
| 56 | |
| 57 | if (isInitialized) { |
| 58 | CP_PREVENT_REORDER(); |
| 59 | return &method; |
| 60 | } |
| 61 | |
| 62 | // don't merge `method` initialization with function pointers assignment |
| 63 | // to prevent relocations (indirect calls) to be generated in the binary |
| 64 | method.hashInit = cp_sha3_hashInit; |
| 65 | method.hashUpdate = cp_shake256_hashUpdate; |
| 66 | method.hashOctStr = cp_sha3_hashOctString; |
| 67 | method.msgLenRep = NULL; |
| 68 | |
| 69 | CP_PREVENT_REORDER(); |
| 70 | isInitialized = 1; |
| 71 | |
| 72 | return &method; |
| 73 | } |