ftu/fstoken.c
2022-09-09 02:47:49 -04:00

25 lines
917 B
C

#include "fstoken.h"
void fstoken_keygen(byte* ikm, byte* sk_byte, byte* pk_byte){
blst_scalar sk;
blst_p2 pk;
blst_p2_affine pk_affine;
blst_keygen(&sk, ikm, 32, 0, 0); // generate a secret key from IKM
blst_bendian_from_scalar(sk_byte, &sk); // convert it to 32 big-endian bytes in sk_byte to return
blst_sk_to_pk_in_g2(&pk, &sk); // get a public key from the secret key
blst_p2_to_affine(&pk_affine, &pk); // convert it to an affine point, which is what most uses of the public key use
blst_p2_affine_compress(pk_byte, &pk_affine); // compress it to 96 bytes in pk_byte to return
}
void fstoken_get_pk_from_sk(byte* sk_byte, byte* pk_byte){
blst_p2 pk;
blst_p2_affine pk_affine;
blst_scalar sk;
blst_scalar_from_bendian(&sk, sk_byte);
blst_sk_to_pk_in_g2(&pk, &sk);
blst_p2_to_affine(&pk_affine, &pk);
blst_p2_affine_compress(pk_byte, &pk_affine);
}