int main (int argc, char ** argv) { unsigned int hexaval, * data_send; int k, n_words_in; char word[1024]; /* check dimension */ tf_arrays_t tf; char * fileIn; FILE * hbout; if (argc != 2) { fprintf (stderr, "%s filename \n", argv[0]); return 1; } fileIn = argv[1]; printf("Opening file %s\n", fileIn); if ( (hbout = fopen(fileIn,"r")) == NULL) { fprintf(stderr, "Cannot open input file\n"); return 1; } data_send = (unsigned int *) malloc( getnumoflines(hbout)*sizeof(unsigned int)); if (data_send == NULL) { fprintf(stderr, "Malloc error\n"); return 1; } k=0; while(fscanf(hbout, "%s", word) != EOF) { hexaval = strtol(word, NULL, 16); fprintf(stdout, "%.6x\n", hexaval); data_send[k] = hexaval; k++; } // check it n_words_in = k - 1; gf_init(&tf); fprintf(stdout, "array initialized \n"); svtsim_fconread(tf); SVT_Trigger_CPU(tf, data_send, n_words_in); free (data_send); return 0; }
GrFunc* GrFunc_GcNewFlag(long flags) { GrFunc* func=GrGc_Alloc(GrFunc,&Gr_Type_Func,flags); if(func==NULL) { GrErr_MemFormat("can't Alloc Memory For Func Object"); return NULL; } gf_init(func); return func; }
GrFunc* GrFunc_GcNew() { GrFunc* func=GrGc_New(GrFunc,&Gr_Type_Func); if(func==NULL) { GrErr_MemFormat("Can't Alloc Memory For Func Object"); return NULL; } gf_init(func); return func; }
int crypto_encrypt_keypair(unsigned char * pk, unsigned char * sk) { int i; gf_t *L; poly_t g,*sqrtmod,*F; MAT R; gf_init(EXT_DEGREE); //pick the support......... L = malloc(gf_card()*sizeof(gf_t)); for(i=0;i<gf_card();i++) L[i]=i; gop_supr(gf_card(),L); do { //pick the irreducible polynomial..... g = poly_randgen_irred(NB_ERRORS, u8rnd); R = key_genmat(L,g); if (R == NULL) poly_free(g); } while (R == NULL); sqrtmod = poly_sqrtmod_init(g); F = poly_syndrome_init(g, L, LENGTH); memcpy(sk, L, LENGTH * sizeof (gf_t)); sk += LENGTH * sizeof (gf_t); free(L); memcpy(sk, g->coeff, (NB_ERRORS + 1) * sizeof (gf_t)); sk += (NB_ERRORS + 1) * sizeof (gf_t); poly_free(g); for (i = 0; i < LENGTH; ++i) { memcpy(sk, F[i]->coeff, NB_ERRORS * sizeof (gf_t)); sk += NB_ERRORS * sizeof (gf_t); poly_free(F[i]); } free(F); for (i = 0; i < NB_ERRORS; ++i) { memcpy(sk, sqrtmod[i]->coeff, NB_ERRORS * sizeof (gf_t)); sk += NB_ERRORS * sizeof (gf_t); poly_free(sqrtmod[i]); } free(sqrtmod); memcpy(pk, R->elem, R->alloc_size); mat_free(R); return 0; }
int main() { /* Test correctness of multi-byte multiplication */ printf("[%s] Testing multi-byte multiplication ... ", __FILE__); srand(0); // fixes "random" number for testing gf_init(); memset(mbuf, CANARY, TEST_SIZE); time_t ssec=0, msec=0; suseconds_t susec=0, musec=0; for (int round=0; round<NUM_ROUNDS; round++) { gf factor=(gf)rand(); for (int i=LO; i<HI; i++) { mbuf[i] = (gf)rand(); } memcpy(&sbuf[LO], &mbuf[LO], HI-LO); /* simple byte-by-byte operations */ struct timeval start, end; gettimeofday(&start, NULL); for (int i=LO; i<HI; i++) { sbuf[i] = gf_mul(sbuf[i], factor); } gettimeofday(&end, NULL); ssec += end.tv_sec - start.tv_sec; susec += end.tv_usec - start.tv_usec; /* slightly optimized multi-bytes operations */ gettimeofday(&start, NULL); gf_mul_bytes(&mbuf[LO], HI-LO, factor, &mbuf[LO]); gettimeofday(&end, NULL); msec += end.tv_sec - start.tv_sec; musec += end.tv_usec - start.tv_usec; /* check correctness */ cmp_buf(mbuf, sbuf, LO, HI, TEST_SIZE, CANARY); } printf("OK! (multi-byte: %0.2lf MiB/s; single-byte: %0.2lf MiB/s)\n", NUM_ROUNDS*TEST_SIZE / (1048576*(msec + musec/1000000.0)), NUM_ROUNDS*TEST_SIZE / (1048576*(ssec + susec/1000000.0))); return 0; }
int main(void) { gf a, b, c; gf_init(); a = 1; b = 37; c = 78; testit("1 * ( 37 + 78 ) = 1 * 37 + 1 * 78", GF_MUL(a, GF_ADD(b, c)), GF_ADD(GF_MUL(a, b), GF_MUL(a, c))); testit("(1 * 37) * 78 = 1 * (37 * 78)", GF_MUL(GF_MUL(a, b), c), GF_MUL(a, GF_MUL(b, c))); testit("(37 * 78) * 37 = (37 * 37) * 78", GF_MUL(GF_MUL(b, c), b), GF_MUL(GF_MUL(b, b), c)); testit("b * b^-1 = 1", GF_MUL(b, GF_INV(b)), 1); return 0; }