AKE32位的源代码
// ake32.c #include "ake32.h" // performs n ^ 2 mod p operation word32 squaremod( word32 n, word32 p ) { word32 k, sum, result = 0; word32 partial; int carry = 0; // copy 'n' into 'sum' and into 'bits' and set 'n' to zero k = sum = n; // extract the bits from the right part of 'bits' // for each bit to 1 we add 'sum' to 'n' // 'sum' is shifted to the left in each step while ( k > 0 ) { if ( k & 1 ) { // if bit0 == 1 // then we add 'sum' to 'result' partial = result + sum; if ( (partial < result) || (partial p) || carry ) {// if result>p then result-p */ result -= p; carry = 0; } } // Multiply sum by 2 if ( sum & 0x80000000 ) carry = 1; sum < p) || carry ) { // if sum>p then sum-p sum -= p; carry = 0; } k >>= 1; } return result; } // performs the leftwise rotation operation on a 128-bit word void rotl128( word32 * a, int b ) { word32 temp1, temp2; register int i; if ( b 0; i-- ) { a[i] (32-b); } a[0] (32-b); } else if ( b 1; i-- ) { a[i] = 0; a[i] = a[i-1] (64-b); } a[1] = 0; a[1] = a[0] (64-b); a[0] = 0; a[0] = temp1 (64-b); } else if ( b < 96 ) { temp1 = a[0]; temp2 = a[1]; b = 128-b; for ( i = 0; i > (b-32); a[i] |= a[i+2] (b-32); a[2] |= temp1 (b-32); a[3] |= temp2
暂无评论