//shift除法 UINT32 galois_shift_divide(UINT32 x,UINT32 y,UINT32 w)//shift除法 { UINT32 inverse;//逆元 if(y==0) return FALSE; if(x==0) return 0; inverse=galois_shift_inverse(y,w); return galois_shift_multiply(x,inverse,w); }
//整体乘法接口 UINT32 galois_single_multiply(UINT32 x,UINT32 y,UINT32 w)//整体乘法接口 { UINT32 sindex,res; if(x==0||y==0) return 0; sindex=mult_type[w]; switch(sindex) { case TABLE: //检测multable的情况 if(galois_mult_tables[w]==NULL)//如果不存在 { res=galois_multtable_create(w); if(res==FALSE)//生成失败 { show_error("galois","multiply","tablecreatefail"); return FALSE; } } return galois_multtable_multiply(x,y,w); break; case LOGS: if(galois_log_tables[w]==NULL) { res=galois_logtable_create(w); if(res==FALSE) { show_error("galois","logtables","toobig"); return FALSE; } } return galois_log_multiply(x,y,w); break; case SHIFT: return galois_shift_multiply(x,y,w); break; case SPLITW8: if(galois_split_w8[0]==NULL)//和上面的操作一样 { res=galois_create_split_w8_table(); if(res==NULL) { show_error("galois","splittables","toobig"); return FALSE; } } return galois_split_w8_multiply(x,y); break; } }
//生成w8表主要思想是将一个32位的乘法拆分成7个公式相乘然后相加P(3,2)(8,16,24)+1(0,0)表 UINT32 galois_create_split_w8_table()//创建7张split表 { UINT32 res,p1,p2,i,j,p1elt,p2elt,index,ishift,jshift,*table; if(galois_split_w8[0]!=NULL) return TRUE;//说明已经生成了 if(galois_mult_tables[8]==NULL) { res=galois_multtable_create(8); if(res==FALSE) { return FALSE;//只有失败时返回 } } for(i=0;i<7;i++)//建立张16位连接表 { galois_split_w8[i]=(UINT32 *)malloc(sizeof(UINT32)*(1<<16)); if(galois_split_w8[i]==NULL)//如果生成失败则回收 { for(i--;i>=0;i--) free(galois_split_w8[i]); return FALSE; } } for(i=0;i<4;i+=3) { ishift=i*8; for(j=((i==0)?0:1);j<4;j++) { jshift=j*8; table=galois_split_w8[i+j];//将table指针位置进行定位 index=0; for(p1=0;p1<256;p1++) { p1elt=(p1<<ishift); for(p2=0;p2<256;p2++) { p2elt=(p2<<jshift); table[index]=galois_shift_multiply(p1elt,p2elt,32); index++; } } } } return TRUE; }
/* * Class: eu_vandertil_jerasure_jni_Galois * Method: galois_shift_multiply * Signature: (III)I */ JNIEXPORT jint JNICALL Java_eu_vandertil_jerasure_jni_Galois_galois_1shift_1multiply (JNIEnv *env, jclass clazz, jint x, jint y, jint w) { return galois_shift_multiply(x, y, w); }