==
becomes
typedef uint32_t* bignum;
uint8 bigNumCmp(bignum a,int lenA,bignum b,int lenB){
int lenLongest = max(lenA,lenB);
int iA,iB;
uint32_t op1,op2;
for(int i=0;i<lenLongest;i++){
iA = lenA - (lenLongest-i);
iB = lenB - (lenLongest-i);
op1 = (iA<0)?0:a[iA];
op2 = (iB<0)?0:b[iB];
if(op1<op2) return LESS_THAN;
else if(op1>op2) return GREATER_THAN;
}
return EQUAL;
}
Algorithms can scale with variables such as the number of bits. However, they must take the same amount of time when two numbers are the same size. If your secret is 1 and the computer takes a lot less time than when it manipulates a secret of \(2^256 -1\), then the attacker has gained information on your secret and, depending on how non-constant it is, may be able to determine your secret; not ideal. This is a real issue for stuff such as exponentiation where the common algorithm is square and multiply Too long for this margin Wikipedia where the naive implementation will do \(b\) extra multiplications where \(b\) is the number of 1 bits in the number. To rectify this vulnerability, you perform square and always multiply. Where at each bit of the exponent, you perform a square and a multiply, regardless of if you need the multiplication or not.
In some elliptic curve groups, the order of the group is non-prime and so by Lagrange's theorem, there could exist a subgroup which has an order of a smaller factor of the original group's order. On Curve25519, the group used has an order of \(8p\) where \(p\) is a very large prime. During a key exchange, an interceptor (Eve of course) could perform point multiplication on the first step of the key share (\(G^a\)) to bring it into a subgroup of order 8 (i.e. \({G^a}^p\)). When the recipient uses their secret to produce the shared secret, they can only produce 8 possible private keys and Eve can brute force this. To combat this, the recipient can 'clamp' their private key (the \(b\) in \({G^a}^b\)) by zeroing out the lowest 3 bits. As \(b\) is a multiple of 8, if \(G^a\) was in a subgroup of order 8, then \({G^a}^b\) is now the identity of the group. This can be spotted and the result discarded.
See below