3 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
23 #include <openssl/evp.h>
24 #include <openssl/rand.h>
26 #include <SecCryptoSvc.h>
30 const char *version = "1.0#";
31 char info[] = {0xca, 0xfe, 0xbe, 0xbe, 0x78, 0x07, 0x02, 0x03};
35 unsigned char *pKey = NULL;
36 unsigned char *pDuid = NULL;
38 char *pKeyVersion = NULL;
40 if (!(pKey = (unsigned char *)malloc(keyLen)))
43 if (!SecFrameGeneratePlatformUniqueKey(keyLen, pKey)) {
44 fprintf(stderr, "Failed to get duid\n");
48 if (!(pDuid = (unsigned char *)malloc(keyLen)))
51 PKCS5_PBKDF2_HMAC_SHA1(info, 8, pKey, keyLen, 1, keyLen, pDuid);
53 if (!(pId = Base64Encoding((char *)pDuid, keyLen)))
56 if (!(pKeyVersion = (char *)calloc(strlen(pId) + strlen(version) + 1, sizeof(char))))
59 strncpy(pKeyVersion, version, strlen(version));
60 strncat(pKeyVersion, pId, strlen(pId));
61 printf("%s", pKeyVersion);