Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

HMAC SHA1 and PBKDF2 SHA1 example in SYCL

Caster
New Contributor I
1,633 Views

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 Kudos
1 Solution
PraneethA_Intel
Moderator
1,456 Views

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


View solution in original post

0 Kudos
6 Replies
ArpanB_Intel
Moderator
1,622 Views

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.


0 Kudos
Caster
New Contributor I
1,612 Views

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

0 Kudos
ArpanB_Intel
Moderator
1,556 Views

Dan, thank you for the information.


We will move your thread to the relevant forum.


0 Kudos
PraneethA_Intel
Moderator
1,457 Views

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


0 Kudos
Caster
New Contributor I
1,444 Views

Hi Praneeth,

Thank you for letting me know.

Dan

0 Kudos
PraneethA_Intel
Moderator
1,435 Views

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


0 Kudos
Reply