Migrate to openssl 1.1
[platform/core/security/drm-service-core-tizen.git] / test / drm_testutil.cpp
index c235c09..5b25fed 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2000-2019 Samsung Electronics Co., Ltd. All rights reserved
  *
  * Licensed under the Flora License, Version 1.1 (the License);
  * you may not use this file except in compliance with the License.
@@ -52,17 +52,6 @@ static unsigned char g_baAESKey[32] = {
 };
 
 
-int __initialized = _UNINITIALIZED;
-
-void __init_crypto()
-{
-       if (__initialized != _INITIALIZED) {
-               ERR_load_crypto_strings();
-               OpenSSL_add_all_algorithms();
-               __initialized = _INITIALIZED;
-       }
-}
-
 int __get_random_bytes(char *output, int random_len)
 {
        FILE *fp = fopen("/dev/urandom", "r");
@@ -201,6 +190,7 @@ int _create_dh_key(const char *dh_key_p_hex, const char *dh_key_g_hex,
 {
        int ret = DRMTEST_SUCCESS;
        DH *pDH = NULL;
+       BIGNUM *p = NULL, *g = NULL;
 
        if ((pDH = DH_new()) == NULL) {
                printf("...FAIL: DH_new() error");
@@ -208,11 +198,12 @@ int _create_dh_key(const char *dh_key_p_hex, const char *dh_key_g_hex,
                goto error;
        }
 
-       BN_hex2bn(&(pDH->p), dh_key_p_hex);
-       BN_hex2bn(&(pDH->g), dh_key_g_hex);
+       BN_hex2bn(&p, dh_key_p_hex);
+       BN_hex2bn(&g, dh_key_g_hex);
+       DH_set0_pqg(pDH, p, nullptr, g);
 
        /* 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);
 
        // Generate DH Key
        if (!DH_generate_key(pDH)) {
@@ -241,7 +232,7 @@ int _free_dh_key(DH *pkey)
 
 int _get_dh_hex_pubkey(const DH *pkey, char **dh_pubkey)
 {
-       *dh_pubkey = BN_bn2hex(pkey->pub_key);
+       *dh_pubkey = BN_bn2hex(DH_get0_pub_key(pkey));
        return DRMTEST_SUCCESS;
 }