-
Notifications
You must be signed in to change notification settings - Fork 1
/
hash.cpp
31 lines (24 loc) · 935 Bytes
/
hash.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "photon_beetle.hpp"
#include <iostream>
// Compile it with
//
// g++ -std=c++20 -Wall -O3 -march=native -I ./include example/hash.cpp
int
main()
{
constexpr size_t mlen = 64; // message length in bytes
constexpr size_t dlen = photon_beetle::DIGEST_LEN; // digest length in bytes
// allocate memory on heap
uint8_t* msg = static_cast<uint8_t*>(std::malloc(mlen));
uint8_t* dig = static_cast<uint8_t*>(std::malloc(dlen));
photon_utils::random_data(msg, mlen); // generate random message bytes
std::memset(dig, 0, dlen); // set digest to zero bytes
// compute Photon-Beetle hash
photon_beetle::hash(msg, mlen, dig);
std::cout << "Input : " << photon_utils::to_hex(msg, mlen) << std::endl;
std::cout << "Output : " << photon_utils::to_hex(dig, dlen) << std::endl;
// release acquired memory resources
std::free(msg);
std::free(dig);
return EXIT_SUCCESS;
}