• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022-2023 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 HCF_SIGNATURE_H
17 #define HCF_SIGNATURE_H
18 
19 #include <stdint.h>
20 #include <stdbool.h>
21 #include "algorithm_parameter.h"
22 #include "result.h"
23 #include "key_pair.h"
24 
25 typedef enum {
26     PSS_MD_NAME_STR = 100,
27     PSS_MGF_NAME_STR = 101,
28     PSS_MGF1_MD_STR = 102,
29     PSS_SALT_LEN_INT = 103,  // warning: PSS_SALT_LEN_NUM in JS
30     PSS_TRAILER_FIELD_INT = 104,  // warning: PSS_TRAILER_FIELD_NUM in JS
31 } SignSpecItem;
32 
33 typedef struct HcfSign HcfSign;
34 
35 struct HcfSign {
36     HcfObjectBase base;
37 
38     HcfResult (*init)(HcfSign *self, HcfParamsSpec *params, HcfPriKey *privateKey);
39 
40     HcfResult (*update)(HcfSign *self, HcfBlob *data);
41 
42     HcfResult (*sign)(HcfSign *self, HcfBlob *data, HcfBlob *returnSignatureData);
43 
44     const char *(*getAlgoName)(HcfSign *self);
45 
46     HcfResult (*setSignSpecInt)(HcfSign *self, SignSpecItem item, int32_t saltLen);
47 
48     HcfResult (*getSignSpecString)(HcfSign *self, SignSpecItem item, char **returnString);
49 
50     HcfResult (*getSignSpecInt)(HcfSign *self, SignSpecItem item, int32_t *returnInt);
51 };
52 
53 typedef struct HcfVerify HcfVerify;
54 
55 struct HcfVerify {
56     HcfObjectBase base;
57 
58     HcfResult (*init)(HcfVerify *self, HcfParamsSpec *params, HcfPubKey *publicKey);
59 
60     HcfResult (*update)(HcfVerify *self, HcfBlob *data);
61 
62     bool (*verify)(HcfVerify *self, HcfBlob *data, HcfBlob *signatureData);
63 
64     const char *(*getAlgoName)(HcfVerify *self);
65 
66     HcfResult (*setVerifySpecInt)(HcfVerify *self, SignSpecItem item, int32_t saltLen);
67 
68     HcfResult (*getVerifySpecString)(HcfVerify *self, SignSpecItem item, char **returnString);
69 
70     HcfResult (*getVerifySpecInt)(HcfVerify *self, SignSpecItem item, int32_t *returnInt);
71 };
72 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
77 HcfResult HcfSignCreate(const char *algoName, HcfSign **returnObj);
78 
79 HcfResult HcfVerifyCreate(const char *algoName, HcfVerify **returnObj);
80 
81 #ifdef __cplusplus
82 }
83 #endif
84 
85 #endif
86