1 /********************************************************************** 2 Copyright(c) 2024 Intel Corporation All rights reserved. 3 4 Redistribution and use in source and binary forms, with or without 5 modification, are permitted provided that the following conditions 6 are met: 7 * Redistributions of source code must retain the above copyright 8 notice, this list of conditions and the following disclaimer. 9 * Redistributions in binary form must reproduce the above copyright 10 notice, this list of conditions and the following disclaimer in 11 the documentation and/or other materials provided with the 12 distribution. 13 * Neither the name of Intel Corporation nor the names of its 14 contributors may be used to endorse or promote products derived 15 from this software without specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 **********************************************************************/ 29 30 #include "sm3_mb.h" 31 #include "isal_crypto_api.h" 32 33 int 34 isal_sm3_ctx_mgr_init(SM3_HASH_CTX_MGR *mgr) 35 { 36 #ifdef SAFE_PARAM 37 if (mgr == NULL) 38 return ISAL_CRYPTO_ERR_NULL_MGR; 39 #endif 40 sm3_ctx_mgr_init(mgr); 41 42 return 0; 43 } 44 45 int 46 isal_sm3_ctx_mgr_submit(SM3_HASH_CTX_MGR *mgr, SM3_HASH_CTX *ctx_in, SM3_HASH_CTX **ctx_out, 47 const void *buffer, const uint32_t len, const HASH_CTX_FLAG flags) 48 { 49 #ifdef SAFE_PARAM 50 if (mgr == NULL) 51 return ISAL_CRYPTO_ERR_NULL_MGR; 52 if (ctx_in == NULL || ctx_out == NULL) 53 return ISAL_CRYPTO_ERR_NULL_CTX; 54 if (buffer == NULL) 55 return ISAL_CRYPTO_ERR_NULL_SRC; 56 #endif 57 58 *ctx_out = sm3_ctx_mgr_submit(mgr, ctx_in, buffer, len, flags); 59 60 #ifdef SAFE_PARAM 61 if (*ctx_out != NULL && (SM3_HASH_CTX *) (*ctx_out)->error != HASH_CTX_ERROR_NONE) { 62 SM3_HASH_CTX *cp = (SM3_HASH_CTX *) (*ctx_out); 63 64 if (cp->error == HASH_CTX_ERROR_INVALID_FLAGS) 65 return ISAL_CRYPTO_ERR_INVALID_FLAGS; 66 if (cp->error == HASH_CTX_ERROR_ALREADY_PROCESSING) 67 return ISAL_CRYPTO_ERR_ALREADY_PROCESSING; 68 if (cp->error == HASH_CTX_ERROR_ALREADY_COMPLETED) 69 return ISAL_CRYPTO_ERR_ALREADY_COMPLETED; 70 } 71 #endif 72 return 0; 73 } 74 75 int 76 isal_sm3_ctx_mgr_flush(SM3_HASH_CTX_MGR *mgr, SM3_HASH_CTX **ctx_out) 77 { 78 #ifdef SAFE_PARAM 79 if (mgr == NULL) 80 return ISAL_CRYPTO_ERR_NULL_MGR; 81 if (ctx_out == NULL) 82 return ISAL_CRYPTO_ERR_NULL_CTX; 83 #endif 84 *ctx_out = sm3_ctx_mgr_flush(mgr); 85 86 return 0; 87 } 88