Michael Richardson <[EMAIL PROTECTED]>:

>>   My suggestion:
>> 
>> change the typedef, (or probably, add a new one):
>> 
>>   struct des_ks_struct
>>      {
>>      union   {
>>              des_cblock _;
>>              /* make sure things are correct size on machines with
>>               * 8 byte longs */
>>              DES_LONG pad[2];
>>              } ks[16];
>>      };
>>
>>   typedef struct des_ks_struct * des_key_schedule;

>   I see the error of my ways.
> 
>   des_key_schedule gets to be a nice chameleon.
>   If declared as an auto/static, its gets storage like a structure.
>   If declared in a parameter list, it gets treated like a pointer. This is
> the nature of arrays in C. (And before structure passing, this was the case
> for structures as well)
> 
>   The above breaks lots of programs.
>   The problem is that one can't cast a pointer to a "des_key_schedule"
> (as it was defined before) because that is an array type, not a pointer to an
> array. So, one needs at a minimum:
> 
> struct des_eks {
>   des_key_schedule ks;
> };
> 
>   so that one can do ((struct des_eks *)foo)->ks to get the right type to
> satisfy the prototype.

Actually a change similar to what you proposed above was done in the
development version of OpenSSL (0.9.7-dev, snapshots available at
<URL: ftp://ftp.openssl.org/snapshot;type=d>), except that
des_key_schedule is now the actual struct and not a pointer to the
struct.


OpenSSL 0.9.6 definition:

typedef struct des_ks_struct
        {
        union   {
                des_cblock cblock;
                /* make sure things are correct size on machines with
                 * 8 byte longs */
                DES_LONG deslong[2];
                } ks;
        int weak_key;
        } des_key_schedule[16];

(des_key_schedule is an array of structs containing just a union.)


Current definition (0.9.7-dev):

typedef struct des_ks
    {
    union
        {
        des_cblock cblock;
        /* make sure things are correct size on machines with
         * 8 byte longs */
        DES_LONG deslong[2];
        } ks[16];
    } des_key_schedule;


No doubt this will break many programs (binary compatibility will be
maintained at least) because if you have

    des_key_schedule ks;

(which is still valid for variable definitions) then 'ks' will not
automatically replaced by an appropriate pointer and you have to use
'&ks' in function calls.  If I remember correctly, I was the only one
worried about this though.  (Apart from transition difficulties, the
new scheme surely is less confusing.)



-- 
Bodo M�ller <[EMAIL PROTECTED]>
PGP http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/moeller/0x36d2c658.html
* TU Darmstadt, Theoretische Informatik, Alexanderstr. 10, D-64283 Darmstadt
* Tel. +49-6151-16-6628, Fax +49-6151-16-6036
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to