Cryptography Reference
In-Depth Information
processed, that is, until the closing semicolon has been reached. Due to the
declaration of the function value as const such nonsensical constructs as (a*b)
=c; will not get past the compiler. The goal is to treat LINT objects in exactly the
same way as the built-in integer types.
We can extend the operator functions by the following detail: If the factors to
be multiplied are equal, then the multiplication can be replaced by squaring, so
that the advantage in efficiency associated with this changeover can be utilized
automatically (cf. Section 4.2.2). However, since in general it costs an elementwise
comparison of the arguments to determine whether they are equal, which is
too expensive for us, we shall be satisfied with a compromise: Squaring will be
brought into play only if both factors refer to one and the same object. Thus
we test whether ln and lm point to the same object and in this case execute the
squaring function instead of multiplication. Here is the relevant code:
if (&lm == &ln)
{
error = sqr_l (lm.n_l, prd.n_l);
}
else
{
error = mul_l (lm.n_l, ln.n_l, prd.n_l);
}
This falling back on the functions implemented in C from Part I is a model
for all of the remaining functions of the class LINT , which is formed like a shell
around the kernel of C functions and protects it from the user of the class.
Before we turn our attention to the more complex assignment operator “ *= ”,
it seems a good idea to take a closer look at the simple assignment operator “ = ”.
Already in Part I we established that assignment of objects requires particular
attention (cf. Chapter 8). Therefore, just as in the C implementation we had to
pay heed that in assigning one CLINT object to another the content and not the
address of the object was assigned, we must likewise for our LINT class define a
special version of the assignment operator “ = ” that does more than simply copy
elements of the class: For the same reasons as were introduced in Chapter 8 we
must therefore take care that it is not the address of the numerical vector n_l that
is copied, but the digits of the numerical representation pointed to by n_l .
Once one has understood the fundamental necessity for proceeding thus,
the implementation is no longer particularly complicated. The operator “ = ”is
implemented as a member function, which returns as a result of the assignment
a reference to the implicit left argument. Of course, we use internally the C
function cpy_l() to move digits from one object into the other. For executing
the assignment a=b the compiler calls the operator function “ = ” in the context
of a ,where a takes over the role of an implicit argument that is not given in the
Search WWH ::




Custom Search