forked from blue/squawk
41 lines
1.0 KiB
C++
41 lines
1.0 KiB
C++
|
/*
|
||
|
* Created by victoria on 2021-05-13.
|
||
|
*/
|
||
|
|
||
|
#include "crypto.h"
|
||
|
|
||
|
extern "C" {
|
||
|
#include <openssl/rand.h>
|
||
|
}
|
||
|
|
||
|
#include "aes_openssl.h"
|
||
|
#include "hmac_sha256_openssl.h"
|
||
|
#include "sha512_digest_openssl.h"
|
||
|
|
||
|
int random_func(uint8_t *data, size_t len, void *) {
|
||
|
if (RAND_bytes(data, len)) {
|
||
|
return 0;
|
||
|
} else {
|
||
|
return SG_ERR_UNKNOWN;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
signal_crypto_provider Signal::Crypto::createProvider() {
|
||
|
signal_crypto_provider result{};
|
||
|
|
||
|
result.random_func = random_func;
|
||
|
result.hmac_sha256_init_func = HmacSha256::init;
|
||
|
result.hmac_sha256_update_func = HmacSha256::update;
|
||
|
result.hmac_sha256_final_func = HmacSha256::final;
|
||
|
result.hmac_sha256_cleanup_func = HmacSha256::cleanup;
|
||
|
result.sha512_digest_init_func = Sha512::init;
|
||
|
result.sha512_digest_update_func = Sha512::update;
|
||
|
result.sha512_digest_final_func = Sha512::final;
|
||
|
result.sha512_digest_cleanup_func = Sha512::cleanup;
|
||
|
result.encrypt_func = Aes::encrypt;
|
||
|
result.decrypt_func = Aes::decrypt;
|
||
|
result.user_data = nullptr;
|
||
|
|
||
|
return result;
|
||
|
}
|