On September 13, 2004 10:04 am, Steve Hay wrote:
> The above seems to work OK after a quick test, but why does one need
>
>     EVP_CIPHER cipher = *EVP_bf_cbc();
>     cipher.key_len = ...
>
> rather than
>
>     EVP_CIPHER *cipher = (EVP_CIPHER *)EVP_bf_cbc();
>     cipher->key_len = ...
>
> ?

Because with the latter you are trying to alter the original structure, 
which is probably compiled "const" in the library and your binary loader 
is probably putting it in read-only-mapped memory.

> typedef struct fred_st FRED;
> struct fred_st { int foo; };
>
> const FRED *new_fred(void) {
>     static FRED fred;
>     fred.foo = 16;
>     return &fred;
> }
>
> void main(void) {
>     FRED *fred = (FRED *)new_fred();
>     EVP_CIPHER *cipher = (EVP_CIPHER *)EVP_bf_cbc();
>
>     printf("FRED foo = %d\n", fred->foo);
>     fred->foo = 24;
>     printf("FRED foo = %d\n", fred->foo);
>
>     printf("BF-CBC key len = %d\n", EVP_CIPHER_key_length(cipher));
>     // The next line causes an Access Violation:
>     cipher->key_len = 24;
>     printf("BF-CBC key len = %d\n", EVP_CIPHER_key_length(cipher));
> }

Try defining your FRED structure as const and see if that doesn't help it 
crash. Anyway, the fact remains that you are better to copy the original 
implementation and then manipulate your copy.

Cheers,
Geoff
-- 
Geoff Thorpe
[EMAIL PROTECTED]
http://www.geoffthorpe.net/

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to