?? computekeym16.nc
字號:
/* tab:4
*
*
* Copyright (C) 2004 by North Carolina State University.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE NORTH CAROLINA STATE UNIVERSITY BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE NORTH
* CAROLINA STATE UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE NORTH CAROLINA STATE UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE NORTH CAROLINA STATE UNIVERSITY HAS NO OBLIGATION
* TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Authors: Rongfang Li
* Date: 4/25/04
*/
includes PolyOne;
module ComputeKeyM16 { /* used to evaluate key */
provides{
interface ComputeKey;
}
}
implementation {
uint16_t f_poly16(uint16_t *b,uint16_t x){
uint16_t b2,s2=0;
uint32_t s1=0;
uint32_t s;
uint8_t i,j;
uint16_t md0,mdv;
// dbg(DBG_USR1,"c= %d\n",*b);
// dbg(DBG_USR1,"x= %d\n",x);
for(i=T+1;i>0;i--){
j=i-1;
if(s2) s=(uint32_t )x<<16;
else s=s1*x;
md0=s&0xffff;
mdv=s>>16;
if(md0>=mdv) s=md0-mdv;
else s=65536u+1+md0-mdv;
if(b[j]!=0){ /* b[j] is between 1 and 65535 */
s = s+b[j];
// dbg(DBG_USR1,"poly+= %d\n",s);
} else{ /* b[j] is 0 or 65536 */
b2=j>>4; /* j div 16 is the right shift j by 4 bits */
j=j&15; /* j mod 16, is the least 4 bits of j */
b2=b[T+1+b2]>>j; /* get the 9th bit of b[j] */
b2 = b2&1;
if(b2){ /* b[j] is 65536 */
s = s+65536u;
// dbg(DBG_USR1,"poly+= %d\n",s);
}
/* else b[i-1]=0, nothing need to do. */
}
md0=s&0xffff;
mdv=s>>16;
if(md0>=mdv) s=md0-mdv;
else s=65536u+1+md0-mdv;
s1=s&0xffff;
s2=s>>16;
}
return (uint16_t)s1;
}
command void ComputeKey.compute(uint8_t *array, uint16_t ID, uint8_t *key)
{
PolyShare *ptr;
uint16_t *key16;
key16=(uint16_t *)key;
ptr=(PolyShare *)array;
key16[0] = f_poly16(ptr->poly_ceft1, ID);
key16[1] = f_poly16(ptr->poly_ceft2, ID);
key16[2] = f_poly16(ptr->poly_ceft3, ID);
key16[3] = f_poly16(ptr->poly_ceft4, ID);
// dbg(DBG_USR1,"key=%d %d %d %d\n",key16[0],key16[1],key16[2],key16[3]);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -