Setting Up pQCee SPP toolkit¶
To use SPP toolkit Windows target, you can do the following:
Have Microsoft Visual Studio 2017 installed
Open a “x64 Native Tools Command Prompt”
- Copy all files into a directory
sha256.h
sha256.c
pqspp.h
main.c
pqspp_sdk.dll.lib
Compile the code using “cl main.c sha256.c pqspp_sdk.dll.lib”. It will result in main.exe created.
Execute main.exe, and expect to see the following output:
Generated a secret key and a public key (DER encoded of length 91)!
Signed a message; got a pq_proof of size 210982 bytes
Successfully verified the signature and the preimage proof!
pQCee main.c Code Sample¶
// This is pQCee's main.c code sample
#include "pqspp.h"
#include "sha256.h"
#include <stdio.h>
#include <stdlib.h>
int main() {
uint8_t *sk = NULL;
uint8_t *pk = NULL;
int pk_len = -1;
// call PQSPP_keygen to generate a secret key, public key and the length of each key
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);
// your message digest
uint8_t message[4] = {0x01, 0x02, 0x03, 0x04};
// hash the message digest
unsigned char hash[32];
SHA256_CTX ctx;
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;
// call PQSPP_sign_digest to sign the hashed message
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);
// call PQSPP_verify_digest to verify the hashed message against its signature
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");
// call PQSPP_free_memory to free memories used during the signing process
PQSPP_free_memory(sk);
PQSPP_free_memory(pk);
PQSPP_free_memory(ec_sig);
PQSPP_free_memory(pip);
return 0;
}