Cryptography Reference
In-Depth Information
Now come the private management functions allocate_reg_l() to set up the
register bank and destroy_reg_l() to clear it. After space for the storage of the
addresses of the registers to be allocated has been created and a pointer is then
set to the variable registers.reg_l , there follows the allocation of memory for
each individual register by a call to malloc() from the C standard library. The fact
that CLINT registers are memory units allocated by means of malloc() plays an
important role in testing the FLINT/C functions. We shall see in Section 13.2 how
this makes possible the examination of any memory errors that may occur.
static int
allocate_reg_l (void)
{
USHORT i, j;
First, memory is allocated for the vector of register addresses.
if ((registers.reg_l = (clint **) malloc (sizeof(clint *) * NoofRegs)) == NULL)
{
return E_CLINT_MAL;
}
Now comes the allocation of individual registers. If in the process a call to malloc()
ends in an error, all previously allocated registers are cleared and the error code
E_CLINT_MAL is returned.
for (i = 0; i < NoofRegs; i++)
{
if ((registers.reg_l[i] = (clint *) malloc (CLINTMAXBYTE)) == NULL)
{
for(j=0;j<i;j++)
{
free (registers.reg_l[j]);
}
return E_CLINT_MAL;
/* error: malloc */
}
}
return E_CLINT_OK;
}
The function destroy_reg_l() is essentially the inverse of the function
create_reg_l() : First, the content of the registers is cleared by overwriting them
Search WWH ::




Custom Search