1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include "hvb_crypto.h"
20 
hash_ctx_init(struct hash_ctx_t *hash_ctx, enum hash_alg_type alg_type)21 int hash_ctx_init(struct hash_ctx_t *hash_ctx, enum hash_alg_type alg_type)
22 {
23     char *hashValue = getenv("HASH_VALUE");
24 
25     printf("[Replace]:hash_ctx_init in\n");
26 
27     if ((hashValue == NULL) || (strcmp(hashValue, "InitFail") == 0)) {
28         return -1;
29     }
30 
31     return 0;
32 }
33 
hash_calc_update(struct hash_ctx_t *hash_ctx, const void *msg, uint32_t msg_len)34 int hash_calc_update(struct hash_ctx_t *hash_ctx, const void *msg, uint32_t msg_len)
35 {
36     char *hashValue = getenv("HASH_VALUE");
37 
38     printf("[Replace]:hash_calc_update in\n");
39 
40     if ((hashValue == NULL) || (strcmp(hashValue, "UpdateFail") == 0)) {
41         return -1;
42     }
43 
44     return 0;
45 }
46 
hash_calc_do_final(struct hash_ctx_t *hash_ctx, const void *msg, uint32_t msg_len, uint8_t *out, uint32_t out_len)47 int hash_calc_do_final(struct hash_ctx_t *hash_ctx, const void *msg, uint32_t msg_len, uint8_t *out, uint32_t out_len)
48 {
49     char *hashValue = getenv("HASH_VALUE");
50 
51     printf("[Replace]:hash_calc_do_final in\n");
52 
53     if ((hashValue == NULL) || (strcmp(hashValue, "FinalFail") == 0)) {
54         return -1;
55     }
56 
57     return 0;
58 }
59