BigNum Math: Implementing Cryptographic Multiple Precision Arithmetic

5.3: Squaring

5.3 Squaring

Squaring is a special case of multiplication where both multiplicands are equal. At first, it may seem like there is no significant optimization available, but in fact there is. Consider the multiplication of 576 against 241. In total there will be nine single precision multiplications performed-1 6, 1 7, 1 5, 4 6, 4 7, 4 5, 2 6, 2 7, and 2 5. Now consider the multiplication of 123 against 123. The nine products are 3 3, 3 2, 3 1, 2 3, 2 2, 2 1, 1 3, 1 2, and 1 1. On closer inspection some of the products are equivalent; for example, 3 2 = 2 3 and 3 1 = 1 3.

For any n-digit input, there are possible unique single precision multiplications required compared to the n 2 required for multiplication. Figure 5.11 gives an example of the operations required.


Figure 5.11: Squaring Optimization Diagram

Starting from zero and numbering the columns from right to left, you will see a very simple pattern become obvious. For the purposes of this discussion, let x represent the number being squared. The first observation is that in row k, the 2 k'th column of the product has a ( x k) 2 term in it.

The second observation is that every column j in row k where j ? 2k is part of a double product. Every non-square term of a column will appear twice, hence the name "double product." Every odd column is made up entirely of double products. In fact, every column is made up...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Sheeters
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.