Migrate to openssl 1.1
[platform/core/security/drm-service-core-tizen.git] / tadcore / TADCInterface / TADC_IF.cpp
index 7784ca1..6dd8504 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2000-2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Flora License, Version 1.1 (the License);
  * you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
 #include <openssl/sha.h>
 #include <openssl/dh.h>
 #include <openssl/bn.h>
+#include <openssl/modes.h>
 
 //2011.03.08 to verify signature
 #include <openssl/x509.h>
@@ -93,11 +94,11 @@ int TADC_IF_GetDHKey(T_DH_INFO *t_dhinfo)
        };
        BYTE generator[1] = {DH_GENERATOR_5};
 
-       pDH->p = BN_bin2bn(prime64, 64, NULL);
-       pDH->g = BN_bin2bn(generator, 1, NULL);
+       DH_set0_pqg(pDH, BN_bin2bn(prime64, 64, NULL), nullptr,
+                       BN_bin2bn(generator, 1, NULL));
 
        /* Set a to run with normal modexp and b to use constant time */
-       pDH->flags &= ~DH_FLAG_NO_EXP_CONSTTIME;
+       DH_clear_flags(pDH, DH_FLAG_NO_EXP_CONSTTIME);
 
        // Debug
        DRM_TAPPS_LOG("After Set the Prime and Generator Value");
@@ -115,8 +116,8 @@ int TADC_IF_GetDHKey(T_DH_INFO *t_dhinfo)
        TADC_IF_MemCpy(t_dhinfo->p, prime64, 64);
        t_dhinfo->pSize = 64;
        t_dhinfo->g = DH_GENERATOR_5;
-       t_dhinfo->ASize = BN_bn2bin(pDH->pub_key, t_dhinfo->A);
-       t_dhinfo->aSize = BN_bn2bin(pDH->priv_key, t_dhinfo->a);
+       t_dhinfo->ASize = BN_bn2bin(DH_get0_pub_key(pDH), t_dhinfo->A);
+       t_dhinfo->aSize = BN_bn2bin(DH_get0_priv_key(pDH), t_dhinfo->a);
 
        //5. DH Free
        DH_free(pDH);
@@ -146,12 +147,12 @@ int TADC_IF_GetDHKey_K(T_DH_INFO *t_dhinfo)
        }
 
        //2.Set DH Info to pDH
-       pDH->p = BN_bin2bn(t_dhinfo->p, t_dhinfo->pSize, NULL);
        tempG[0] = t_dhinfo->g;
-       pDH->g = BN_bin2bn(tempG, 1, NULL);
-       pDH->flags &= ~DH_FLAG_NO_EXP_CONSTTIME;
-       pDH->pub_key = BN_bin2bn(t_dhinfo->A, t_dhinfo->ASize, NULL);
-       pDH->priv_key = BN_bin2bn(t_dhinfo->a, t_dhinfo->aSize, NULL);
+       DH_set0_pqg(pDH, BN_bin2bn(t_dhinfo->p, t_dhinfo->pSize, NULL), nullptr,
+                       BN_bin2bn(tempG, 1, NULL));
+       DH_clear_flags(pDH, DH_FLAG_NO_EXP_CONSTTIME);
+       DH_set0_key(pDH, BN_bin2bn(t_dhinfo->A, t_dhinfo->ASize, NULL),
+                       BN_bin2bn(t_dhinfo->a, t_dhinfo->aSize, NULL));
 
        //3. Set Public Key of Server
        pPubKey = BN_bin2bn(t_dhinfo->B, t_dhinfo->BSize, NULL);
@@ -190,7 +191,7 @@ int TADC_IF_AES_CTR(unsigned char *pKey, int ivLen, unsigned char *pIV,
        TADC_IF_MemSet(chain, 0, sizeof(chain));
        TADC_IF_MemCpy(chain, pIV, ivLen);
 
-       AES_ctr128_encrypt(in, out, inLen, &stKey, chain, ecount, &num);
+       CRYPTO_ctr128_encrypt(in, out, inLen, &stKey, chain, ecount, &num, (block128_f)AES_encrypt);
 
        *pOutLen = inLen;
 
@@ -396,8 +397,6 @@ error:
 int TADC_IF_VerifyCertChain(unsigned char *rica, int ricaLen,
                                                        unsigned char *cert, int certLen)
 {
-       OpenSSL_add_all_algorithms();
-
        X509_STORE *pstStore = X509_STORE_new();
 
        if (pstStore == NULL)