On Tue October 5 2010, krishnamurthy santhanam wrote:
> Hi,
>
> memcpy is not working for the RAND_bytes. could anyone help me to resolve
> the issue.
>
> blf.c
>
> #include<stdio.h>
> #include"scatype.h"
> #include<stdlib.h>
> #define BF_DEFAULT_KEY_SIZE 128
> typedef struct {
> unsigned long length;
> unsigned char dsc_type;
> unsigned char dsc_class;
> char *str;
> } STR_DESCRIPTOR;
> /* functions have to be external */
> extern blfGenKey();
> int main() {
> printf("in main\n");
> /* call function from shared library */
> STR_DESCRIPTOR key;
> key.str = malloc(1024);
> blfGenKey(&key);
> printf("digest - |%s|\n",key.str);
> free (key.str);
> return 0;
> }
>
>
> blowfish.c
>
> int blfGenKey(STR_DESCRIPTOR *key)
> {
> unsigned char keyData[BF_DEFAULT_KEY_SIZE];
> int status = FAILURE;
> printf("\n entered\n");
> printf("%d\n",BF_DEFAULT_KEY_SIZE);
> int i;
> printf("\n entered loop\n");
> if(!RAND_bytes(keyData,BF_DEFAULT_KEY_SIZE))
> memcpy(key->str,keyData,BF_DEFAULT_KEY_SIZE);
> key->length = BF_DEFAULT_KEY_SIZE;
>
> printf("key=\n%s\n",key->str);
>
And you know that key->str does not contain a zero byte?
> status = SUCCESS;
> printf("\n%d\n",key->length);
>
> output:
> in main
>
> entered
> 128
> entered loop
> key= <--------------null value
>
Comment probably says it all - a null (\000) byte in the string.
Use your debugger to check or print it as if it where data (which it is).
Mike
> 128
> status=0
> digest - || <------key is not printing
>
> Any help would be greatly appreciable.
>
> kris
>
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]