RSA_sign and RSA_verify varied behavior
<p>I have a sample signature generator in C which will create a hash message <code>&lt;count:mac-addr&gt;</code> and generate a signature.</p>

<p>When I use <code>char *message = "120:08:00:27:7c:b6:18";</code> 
and sign, the signature is verified successfully.</p>

<p>But when I use </p>

<pre><code>char * generate_hash()
{
    xmlDoc         *document;
    xmlNode        *root, *first_child, *node;
    char           *filename;
    char            *ap_count;
    char            *ap_mac_address;
    char            *message;

    filename = "/license.xml";

    document = xmlReadFile(filename, NULL, 0);
    root = xmlDocGetRootElement(document);
    first_child = root-&gt;children;
    for (node = first_child; node; node = node-&gt;next) {
        if ( strcmp((char*)node-&gt;name, "ap_count") == 0 ) {
            ap_count = (char*)xmlNodeGetContent(node);
        }
        if ( strcmp((char*)node-&gt;name, "ap_mac_address") == 0 ){
            ap_mac_address = (char*)xmlNodeGetContent(node);
        }
    }
    message = (char *) malloc(strlen(ap_count)+ strlen(ap_mac_address) +1 );
    memset(message,0x0,(1 + strlen(ap_count)+ strlen(ap_mac_address)));
    strcpy(message,ap_count);
    strcat(message,":");
    strcat(message,ap_mac_address);
    printf(" %d \n", (1 + strlen(ap_count)+ strlen(ap_mac_address)));
    return message;
}
</code></pre>

<p>--- while verifying,</p>

<pre><code>char* message;
message = generate_hash();
</code></pre>

<p>I am using the below function call to generate the signature in both the cases.</p>

<pre><code>if(RSA_sign(NID_sha256, (unsigned char*) message, strlen(message),
signature, &amp;slen, private_key) != 1) {
    ERR_print_errors_fp(stdout);
    return 1;
}
</code></pre>

<p>The signature verification fails with this above procedure. Not sure what I am doing wrong here.</p>

<p>Below is the call I am using to verify the same.</p>

<pre><code>verified = RSA_verify(NID_sha256, (unsigned char*) message,
        strlen(message), sign, file_len, public_key);
</code></pre>