Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
6814 ディスカッション

HMAC SHA1 and PBKDF2 SHA1 example in SYCL

Caster
新規コントリビューター I
3,154件の閲覧回数

Is there any example on how to use HMAC SHA1 and PBKDF2 SHA1 under oneAPI in SYCL? I found just the basic HMAC description here.

AI generated for me:

Generate C++ HMAC SHA1 fucntion by using oneAPI functions: HMAC_GetSize , HMAC_Init, HMAC_Update , HMAC_GetTag , HMAC_Final.

#include <iostream>
#include <cstring>
#include <oneapi/tbb.h>
#include <oneapi/crypto.h>

int main()
{
    const char* key = "my-secret-key";
    const char* data = "data-to-hash";

    oneapi::crypto::key_256bit hmac_key;
    std::memcpy(hmac_key.data(), key, std::min(sizeof(hmac_key), strlen(key)));

    int hash_size = oneapi::crypto::HMAC_GetSize(oneapi::crypto::algorithm::sha1);
    std::vector<uint8_t> result(hash_size);

    oneapi::crypto::HMAC_Init hmac_init(oneapi::crypto::algorithm::sha1, hmac_key);
    oneapi::crypto::HMAC_Update hmac_update(hmac_init, data, strlen(data));
    oneapi::crypto::HMAC_Final hmac_final(hmac_update, result.data(), result.size());

    for (int i = 0; i < hash_size; ++i)
    {
        printf("%02x", result[i]);
    }
    std::cout << std::endl;

    return 0;
}

Generate C++ PBKDF2 SHA1 function by using oneAPI libraries.

#include <iostream>
#include <oneapi/crypto.h>
#include <oneapi/tbb.h>

int main()
{
    const char* password = "my-strong-password";
    const uint8_t* salt = (uint8_t*)"my-random-salt";
    int salt_len = strlen((const char*)salt);
    int iterations = 4096;
    int key_len = 32;

    std::vector<uint8_t> key(key_len);

    oneapi::crypto::PBKDF2_HMAC_SHA1(password, strlen(password),
                                     salt, salt_len,
                                     iterations,
                                     key.data(), key_len);

    std::cout << "Derived Key: ";
    for (int i = 0; i < key_len; i++) {
        printf("%02x", key[i]);
    }
    std::cout << std::endl;

    return 0;
}



0 件の賞賛
1 解決策
PraneethA_Intel
モデレーター
2,977件の閲覧回数

Hi Dan,


Thanks for posting in Intel communities.


SYCL based IPP cryptography isn’t implemented yet and hence we cannot provide you with an example on how to use HMAC SHA1 and PBKDF2 SHA1 in SYCL.


Please let us know if we can close this at our end.


Thanks and Regards,

Praneeth Achanta


元の投稿で解決策を見る

6 返答(返信)
ArpanB_Intel
モデレーター
3,143件の閲覧回数

Hi Dan, could you confirm the name of the Intel® tool you are using from the Toolkit? Based on that info, we will move the query to the relevant forum.


We would like to know.


Caster
新規コントリビューター I
3,133件の閲覧回数

Yes, I am using Intel® oneAPI Base Toolkit installed over VisualStudio 2022 on my W10 notebook.

ArpanB_Intel
モデレーター
3,077件の閲覧回数

Dan, thank you for the information.


We will move your thread to the relevant forum.


PraneethA_Intel
モデレーター
2,978件の閲覧回数

Hi Dan,


Thanks for posting in Intel communities.


SYCL based IPP cryptography isn’t implemented yet and hence we cannot provide you with an example on how to use HMAC SHA1 and PBKDF2 SHA1 in SYCL.


Please let us know if we can close this at our end.


Thanks and Regards,

Praneeth Achanta


Caster
新規コントリビューター I
2,965件の閲覧回数

Hi Praneeth,

Thank you for letting me know.

Dan

PraneethA_Intel
モデレーター
2,956件の閲覧回数

Hi Dan,


Thanks for accepting as a solution. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Thanks and Regards,

Praneeth Achanta


返信