Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > RSA Encryption Question

RSA Encryption Question
Thread Tools
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Jun 18, 2007, 11:02 PM
 
This is a mathematics question really. I'm writing my own simple encryption procedures, and all is well except for performing digital signatures. Here's an example to illustrate my problem.

Let's say you have Alice and Bob (original) and they make the following simple choices for the public-private key encryption scheme:

Alice
mod = 3*17 = 51
phi = 2*16 = 32
public key = 7
private key = 23

Bob
mod = 5*11 = 55
phi = 4*10 = 40
public key = 13
private key = 37

Now, Bob wants to send the number 3 as a digitally signed message to Alice. So the order of steps is:
Bob encrypts with private key (37,55)
Bob encrypts with Alice's public key (7,51)
Send message
Alice decrypts with private key (23, 51)
Alice decrypts with Bob's public key (13,55)

Now here is the problem I'm running into:
When you encrypt 3 with Bob's private key, you get the number 53. When you encrypt with Alice's public key and then decrypt with Alice's private key, you will get a number that is less than 53 (as her modulus is 51). This is a problem! For the last step to work, decrypting with Bob's public key, the data that should be inputted has to be 53 or it won't work.

The issue as I see it is that the sender has a modulus that is bigger than the receiver... and I'm not sure how to work around it! Any good ideas?
     
Junior Member
Join Date: Mar 2000
Location: Salem, OR, USA
Status: Offline
Reply With Quote
Jun 19, 2007, 07:50 PM
 
If your public key is e=7, n=51, then your message M must be less than n. If your n isn't large enough then you need to go back and select larger values for your p and q.

I think your example is also leading you down a wrong path. I'm no expert in RSA, but I don't think you want to be double encrypting the message. Single encryption is fine. If you need to verify the source of a message then do it through signing.

* * *
Taken from Wikipedia
RSA - Wikipedia, the free encyclopedia
Suppose Alice wishes to send a signed message to Bob. She produces a hash value of the message, raises it to the power of d mod n (as she does when decrypting a message), and attaches it as a "signature" to the message. When Bob receives the signed message, he raises the signature to the power of e mod n (as he does when encrypting a message), and compares the resulting hash value with the message's actual hash value. If the two agree, he knows that the author of the message was in possession of Alice's secret key, and that the message has not been tampered with since.
* * *
-numero
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Jun 19, 2007, 08:57 PM
 
The problem isn't really with p and q (you could use arbitrarily large values for p and q and have the same problem). My crypto program was having issues with data as small as 3 for p's and q's that were 24 bits long! The solution I found through a friend is to deal with the special case where the sender's modulus is bigger than the receiver's modulus by breaking the number into two smaller numbers that the sender can handle properly and then combine them at the end into the original number.

So in my example, the number 53 would need to be split into two separate numbers 1 and 2 (1*51 + 2 happens to equal 53), encrypt and decrypt with Alice's keys safely (as 1 and 2 are both below 51), then make sure Alice knows to interpret 1 and 2 as 1*51+2 = 53. Viola, transmission is successful.
(Last edited by Ghoser777; Jun 19, 2007 at 10:22 PM. )
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:29 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2