GenToken has three steps: Initialize the HVE, Populate the HVE, and run QED_GenToken.
An example is presented at the end.
- Initialize HVE:
To initialize an HVE for the token function, simply call HVE_Init_Token with the Private Key. This can be done only after the Setup has been ran, and a Private Key has been generated;int HVE_Init_Token( HVE_t *HVE, QEDPrivateKey_t *PrivKey);
- Populate HVE:
Please refer to the subsection on Populating the HVE. - Run QED_GenToken:
QED_GenToken will take in the Private Key, the HVE and the context, and populate a QED_Token_t.int QED_GenToken( QEDToken_t *Token, QEDPrivateKey_t *PrivKey, HVE_t *HVE, QED_CTX *c);
Example
This example builds on top of the example started in the setup section.
First, declare a context, a token, a private key and an HVE variable.
QED_CTX c; QEDToken_t Token; QEDPrivateKey_t PrivKey; HVE_t HVE;
Second, initialize the context variable to use TYPE1 algorithm.
QED_Init(&c, TYPE1);
Third, obtain the private key.
- A file containing a serialized private
key should have been created at setup time. Read the contents of this
file into an unsigned char buffer, and use
Import/Export functions to deserialize the variable PrivKey.
Fourth, initialize the HVE with the Private Key.
HVE_Init_Token(&HVE, &PrivKey);
Fifth, populate the HVE with appropriate data.
- From setup know the HVE is expecting:
- an integer for a comparison query on the first sector
- a string for an equality query on the second sector
- three strings for a subset query on the third sector
- an integer for a raw query
- Populate the first sector of the HVE
HVE_COMPARISON_t comp = {2, 0}; HVE_Insert_Comparison(&HVE, &comp);
- Populate the second sector of the HVE
HVE_EQUALITY_t equal = {"foo", 3, 1}; HVE_Insert_Equality(&HVE, &equal);
- Populate the third sector of the HVE
HVE_SUBSET_DATA_t data[4] = { {"hello", 5}, {"world", 5}, {"beautiful", 9}, {END, END} }; HVE_SUBSET subset = {data, 4, 2}; HVE_Insert_Subset(&HVE, &subset);
- Populate the fourth sector of the HVE
HVE_RAW_t raw = {18, 3}; HVE_Insert_Raw(&HVE, &raw);
Finally, generate the token for the above HVE.
QED_GenToken(&Token, &PrivKey, &HVE, &c);