• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef __HVB_SM3_H__
17 #define __HVB_SM3_H__
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include "hvb_sm3.h"
23 
hvb_sm3_init(struct sm3_ctx_t * hash_ctx)24 int hvb_sm3_init(struct sm3_ctx_t *hash_ctx)
25 {
26     char *hashValue = getenv("HASH_VALUE");
27 
28     printf("[Replace]:hvb_sm3_init in\n");
29 
30     if ((hashValue == NULL) || (strcmp(hashValue, "InitFail") == 0)) {
31         return -1;
32     }
33 
34     return SM3_OK;
35 }
36 
hvb_sm3_update(struct sm3_ctx_t * hash_ctx,const void * msg,uint32_t msg_len)37 int hvb_sm3_update(struct sm3_ctx_t *hash_ctx, const void *msg, uint32_t msg_len)
38 {
39     char *hashValue = getenv("HASH_VALUE");
40 
41     printf("[Replace]:hvb_sm3_update in\n");
42 
43     if ((hashValue == NULL) || (strcmp(hashValue, "UpdateFail") == 0)) {
44         return -1;
45     }
46 
47     return SM3_OK;
48 }
49 
hvb_sm3_final(struct sm3_ctx_t * hash_ctx,uint8_t * out,uint32_t * out_len)50 int hvb_sm3_final(struct sm3_ctx_t *hash_ctx, uint8_t *out, uint32_t *out_len)
51 {
52     char *hashValue = getenv("HASH_VALUE");
53 
54     printf("[Replace]:hvb_sm3_final in\n");
55 
56     if ((hashValue == NULL) || (strcmp(hashValue, "FinalFail") == 0)) {
57         return -1;
58     }
59 
60     out[0] = 1;
61     return SM3_OK;
62 }
63 
64 #endif
65