• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #ifdef HKS_CONFIG_FILE
17 #include HKS_CONFIG_FILE
18 #else
19 #include "hks_config.h"
20 #endif
21 
22 #include "hks_mbedtls_get_main_key.h"
23 
24 #include "hks_log.h"
25 #include "hks_template.h"
26 
27 #ifndef _HARDWARE_ROOT_KEY_
28 #include "hks_rkc.h"
29 #endif
30 
HksMbedtlsGetMainKey(const struct HksBlob * message,struct HksBlob * mainKey)31 int32_t HksMbedtlsGetMainKey(const struct HksBlob *message, struct HksBlob *mainKey)
32 {
33     (void)message;
34 #ifndef _HARDWARE_ROOT_KEY_
35     return HksRkcGetMainKey(mainKey);
36 #else
37     /*
38     * Currently, root key is implemented using stubs.
39     * Product adaptation needs to be performed based on hardware capabilities.
40     */
41     uint8_t stubBuf[] = {
42         0x0c, 0xb4, 0x29, 0x39, 0xb7, 0x46, 0xa6, 0x4b,
43         0xdd, 0xf3, 0x75, 0x4c, 0xe0, 0x73, 0x91, 0x51,
44         0xc4, 0x88, 0xbe, 0xa4, 0xe1, 0x87, 0xb5, 0x42,
45         0x06, 0x27, 0x08, 0x21, 0xe2, 0x8f, 0x9b, 0xc1,
46     };
47 
48     if (memcpy_s(mainKey->data, mainKey->size, stubBuf, sizeof(stubBuf)) != EOK) {
49         HKS_LOG_E("memcpy failed, get stub main key failed");
50         return HKS_ERROR_INSUFFICIENT_MEMORY;
51     }
52     return HKS_SUCCESS;
53 #endif
54 }