* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
/**
* @file DTapps2HMAC.cpp
* @brief This file includes functions relating to HMAC.
* @author Harsha Shekar (h.shekar@samsung.com)
*/
-#include <dukgen.h>
+#include "DTapps2HMAC.h"
+
#include <openssl/evp.h>
#include <openssl/hmac.h>
-#include "DTapps2HMAC.h"
+#include <SecCryptoSvc.h>
void DTappsCalHMACSHA1(unsigned char* key,int key_len,unsigned char* msg,size_t msglen,unsigned char *md,unsigned int *md_len)
{
HMAC(EVP_sha1(),(void*)key,key_len,msg,msglen,md,md_len);
}
-int DTappsGetDeviceKey(unsigned char **pDevKey,unsigned int *DevKeyLen)
+int DTappsGetDeviceKey(unsigned char **pDevKey, unsigned int *pDevKeyLen)
{
- int ret = 0;
- char passwd[30] = {0,};
- unsigned int LocalKeyLen = 16;
-
- char* pDuk = GetDeviceUniqueKey(passwd, strlen(passwd), 16);
-
- if (!pDuk || !pDevKey || !DevKeyLen)
- {
- DRM_TAPPS_EXCEPTION("pDevKey = %p, DevKeyLen = %p",pDevKey,DevKeyLen);
- goto DTApps_ERR;
+ if (pDevKey == NULL || pDevKeyLen == NULL) {
+ DRM_TAPPS_EXCEPTION("Invalid parameters on DTappsGetDeviceKey.");
+ return 0;
}
- DRM_TAPPS_LOG("LocalKeyLen = %u", LocalKeyLen);
-
- *pDevKey = (unsigned char*)DTAPPS_MALLOC(LocalKeyLen + 1);
-
- if(NULL == *pDevKey)
- {
- DRM_TAPPS_EXCEPTION("Malloc Failed");
-
- goto DTApps_ERR;
+ constexpr int KeyLen = 16;
+ char passwd[30] = {0,};
+ unsigned char *key = NULL;
+ int ret = cs_derive_key_with_pass(passwd, strlen(passwd), KeyLen, &key);
+ if (ret != CS_ERROR_NONE || key == NULL) {
+ DRM_TAPPS_EXCEPTION("cs_derive_key_with_pass ret[%d]", ret);
+ free(key);
+ return 0;
}
- DTAPPS_MEMSET(*pDevKey, 0x0, LocalKeyLen + 1);
- DTAPPS_MEMCPY(*pDevKey, pDuk, LocalKeyLen);
-
- *DevKeyLen = LocalKeyLen;
- ret = 1;
-
-DTApps_ERR:
+ *pDevKey = key;
+ *pDevKeyLen = static_cast<unsigned int>(KeyLen);
- if (ret == 1)
- DRM_TAPPS_LOG("SUCCESS:ret=%d", ret);
- else
- DRM_TAPPS_EXCEPTION("FAILED:ret=%d", ret);
-
- free(pDuk);
-
- return ret;
+ return 1;
}
void DTappsFreeDeviceKey(unsigned char **pDevKey)
{
- if(pDevKey == NULL)
- {
- DRM_TAPPS_EXCEPTION("pDevKey = %p", pDevKey);
-
+ if (pDevKey == NULL)
return;
- }
DTAPPS_FREE(*pDevKey);
*pDevKey = NULL;