/******************************************************************************
- BIKE -- Bit Flipping Key Encapsulation
- Copyright (c) 2017 Nir Drucker, Shay Gueron, Rafael Misoczki
- ([email protected], [email protected], [email protected])
- Permission to use this code for BIKE is granted.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- The names of the contributors may not be used to endorse or promote
- products derived from this software without specific prior written
- permission.
- THIS SOFTWARE IS PROVIDED BY THE AUTHORS ""AS IS"" AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS CORPORATION OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
include "stdio.h"
include "kem.h"
include "utilities.h"
include "measurements.h"
include <time.h>
////////////////////////////////////////////////////////////////
// Main function for testing
////////////////////////////////////////////////////////////////
int main(void)
{
sk_t sk = {0}; // private-key: (h0, h1)
pk_t pk = {0}; // public-key: (g0, g1)
ct_t ct = {0}; // ciphertext: (c0, c1)
ss_t k_enc = {0}; // shared secret after encapsulate
ss_t k_dec = {0}; // shared secret after decapsulate
clock_t start,end,start_2,start_3,end_2,end_3;
double duration,duration_2,duration_3;
uint32_t mismatch_count = 0; // 初始化密钥不匹配计数为0
uint32_t total_operations = NUM_OF_ENCRYPTION_TESTS * NUM_OF_CODE_TESTS; // 总封装解封装次数
MSG("BIKE Demo Test:\n");
for (uint32_t i=1; i <= NUM_OF_CODE_TESTS; ++i)
{
status_t res = SUCCESS;
MSG("r: %d Code test: %d \n", (int) R_BITS, i);
start=clock();
//Key generation.
MEASURE(" keygen", res = static_cast<status_t>(crypto_kem_keypair(pk.raw, sk.raw)););
end = clock();
duration = (double)(end-start) / CLOCKS_PER_SEC;
MSG("%f seconds\n" , duration);
if(res != SUCCESS)
{
MSG("Keypair failed with error: %d\n", res);
continue;
}
for (uint32_t j=1; j <= NUM_OF_ENCRYPTION_TESTS; ++j)
{
// MSG("Enc/Dec test: %d\n", j);
uint32_t dec_rc = 0;
start_2 = clock();
//Encapsulate
MEASURE(" encaps", res = static_cast<status_t>(crypto_kem_enc(ct.raw, k_enc.raw, pk.raw))