2 * libcryptsvc - device unique key
4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include "SecCryptoSvc.h"
21 //#include "SecKmBase64.h"
22 //#include "CryptoSvc-debug.h"
25 #include <openssl/evp.h>
26 #include <openssl/err.h>
27 #include <openssl/rand.h>
28 #include <openssl/sha.h>
31 bool SecFrameGeneratePlatformUniqueKey(IN UINT32 uLen, IN OUT UINT8 *pCek)
35 unsigned char Key[73] = {0};
36 unsigned char hashedValue[HASH_LEN] = {0};
37 int nTempLen = SEC_DUK_SIZE;
40 unsigned char *result = NULL;
42 SLOGD("[LOG][%s:L%d] Enter \n", __func__,__LINE__);
43 #ifdef CRYPTOSVC_TARGET
44 SysSecBootGetDeviceUniqueKey(Key);
46 memset(Key, 0xFF, nTempLen);
50 SLOGD("Device Unique Key Information \n");
52 memcpy(Key+nTempLen, SEC_FRAME_OSP_KEY, 9);
57 for( i = 0 ; i < uLen ; i += HASH_LEN )
59 result = SHA1(Key, nTempLen, hashedValue);
64 SLOGE("SecCryptoHash fail \n");
71 if( remain < HASH_LEN )
73 memcpy(pCek+i, hashedValue, remain);
77 memcpy(pCek+i, hashedValue, nHashLen);
81 memset(Key, 0, sizeof(Key));
82 memcpy(Key, hashedValue, nHashLen);
84 SLOGD("[LOG][%s:L%d] End \n", __func__,__LINE__);
86 SLOGD("[LOG][%s:L%d] End with ERROR \n", __func__,__LINE__);