following: 1
followed tags: 0
followed domains: 0
badges given: 0 of 0
hubskier for: 4268 days
Sorry about the expmod function. As you said, I have just renamed it. This decrypt function works only for data encrypted with the private key (d,n). Thus, it is useful for checking signatures not for decrypting actual data. if you try the code below you will see it will fail: HB_hex_string_to_hex_bignum( TEST_PUBLIC_KEY_EXP, &(publicKey.e) );
HB_hex_string_to_hex_bignum( TEST_PUBLIC_KEY_MOD, &(publicKey.n) );
HB_int_to_hex_bignum( 0, &privateKey.e );
HB_int_to_hex_bignum( 0, &privateKey.n );
HB_hex_string_to_hex_bignum( TEST_RESULT, &rsaOrig );
rsaEncrypt( &rsaOrig, &rsaEncrypted, &publicKey );
rsaDecrypt( &rsaEncrypted, &rsaDecrypted, &publicKey );
if ( HB_compare( &rsaOrig, &rsaDecrypted ) == 0 )
{
printf( "Passed!\n" );
}
else
{
printf( "Failed!\n" );
}
Thank you for your decrypt, but I think it is not going to work. You need something like:
where, (d * e) % ((p-1)*(q-1)) = 1, p*q = n. ////////////////////////////////////////////////////////////////////////////
//
void rsaDecrypt( hex_bignum_t *ciphertext_ptr, hex_bignum_t *plaintext_ptr, rsaSecKey_t *privkey_ptr )
{
HB_modexp( ciphertext_ptr, &(privkey_ptr->d), &(privkey_ptr->n), plaintext_ptr );
}
Thank you! I will try now to write the decrypt function...:-)
could you also share your (presumably light) rsa code?:-)