PQSPP_free_memory¶
Description¶
PQSPP_free_memory frees up any memory that was allocated but will not be in used anymore.
Syntax¶
int PQSPP_free_memory(
uint8_t* mem,
);
Parameters¶
mem
A pointer to a memory address that needs to be freed.
Return value¶
Return code |
Description |
---|---|
PQSPP_OK |
The function was successful |
Anything other than OK is an error.
Code example¶
#include "pqspp.h"
#include "sha256.h"
#include <stdio.h>
#include <stdlib.h>
int main()
{
// PQSPP_keygen
/*
uint8_t *sk = NULL;
uint8_t *pk = NULL;
int pk_len = -1;
int ret = PQSPP_keygen(&sk, &pk, &pk_len);
if (ret != PQSPP_OK) {
printf("Error in keygen: %d\n", ret);
return -1;
}
printf(
"Generated a secret key and a public key (DER encoded of length %d)!\n",
pk_len);
*/
// PQSPP_sign_digest
/*
// message digest
uint8_t message[4] = {0x01, 0x02, 0x03, 0x04};
unsigned char hash[32];
SHA256_CTX ctx;
// hash the message
sha256_init(&ctx);
sha256_update(&ctx,message,sizeof(message));
sha256_final(&ctx,hash);
uint8_t *ec_sig = NULL;
int ec_sig_len = -1;
uint8_t *pip = NULL;
int pip_len = -1;
ret =
PQSPP_sign_digest(sk, hash,sizeof(hash), &ec_sig, &ec_sig_len, &pip, &pip_len);
if (ret != PQSPP_OK) {
printf("Error in sign: %d\n", ret);
PQSPP_free_memory(sk);
PQSPP_free_memory(pk);
return -2;
}
printf("Signed a message; got a pq_proof of size %d bytes\n", pip_len);
*/
// PQSPP_verify_digest
/*
ret = PQSPP_verify_digest(pk, pk_len, hash, sizeof(hash), ec_sig, ec_sig_len, pip,
pip_len);
if (ret != PQSPP_OK) {
printf("Error in verify: %d\n", ret);
PQSPP_free_memory(sk);
PQSPP_free_memory(pk);
PQSPP_free_memory(ec_sig);
PQSPP_free_memory(pip);
return -3;
}
printf("Successfully verified the signature and the preimage proof!\n");
*/
// PQSPP_free_memory
PQSPP_free_memory(sk);
PQSPP_free_memory(pk);
PQSPP_free_memory(ec_sig);
PQSPP_free_memory(pip);
return 0;
}