• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 USERIAM_USER_SIGN_CENTRE_H
17 #define USERIAM_USER_SIGN_CENTRE_H
18 
19 #include <stdint.h>
20 
21 #include "buffer.h"
22 #include "defines.h"
23 #include "context_manager.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define SHA256_SIGN_LEN 32
30 #define AUTH_TOKEN_LEN sizeof(UserAuthTokenHal)
31 #define AUTH_TOKEN_DATA_LEN (AUTH_TOKEN_LEN - SHA256_SIGN_LEN)
32 #define SHA256_KEY_LEN 32
33 #define TOKEN_VERSION 0
34 
35 typedef struct {
36     uint32_t version;
37     uint8_t challenge[CHALLENGE_LEN];
38     uint64_t secureUid;
39     uint64_t enrolledId;
40     uint64_t credentialId;
41     uint64_t time;
42     uint32_t authTrustLevel;
43     uint32_t authType;
44     uint32_t authMode;
45     uint32_t securityLevel;
46     uint8_t sign[SHA256_SIGN_LEN];
47 } __attribute__((__packed__)) UserAuthTokenHal;
48 
49 ResultCode GetTokenDataAndSign(const UserAuthContext *context,
50     uint64_t credentialId, uint32_t authMode, UserAuthTokenHal *authToken);
51 ResultCode UserAuthTokenSign(UserAuthTokenHal *userAuthToken);
52 ResultCode UserAuthTokenVerify(const UserAuthTokenHal *userAuthToken);
53 
54 #ifdef __cplusplus
55 }
56 #endif
57 
58 #endif // USERIAM_USER_SIGN_CENTRE_H