Original Message:
Sent: Fri March 22, 2024 05:50 PM
From: Mark Vollmer
Subject: I'm running into problems creating a RSA digital signature and then verifying that same signature.
Eric,
Thanks very much for your help. We are making progress.
I had no idea that I needed to wrap the HASH in a DER block. I'll work on that for my next test. But if the DER wrapping was the problem, then the second signature should have validated.
I have the private key in the PKDS file under a 64 character label.
A while back, I created a 256 byte RSA private-public key pair. I extracted the public key for use later. It is these two pieces of information that I use to generate the signatures and to validate them too.
I'll get this test done on Monday and let you know how I'm progressing.
Sincerely,
------------------------------
Mark Vollmer
Developer, but does everything.
CV Systems, LLC
Original Message:
Sent: Fri March 22, 2024 05:37 PM
From: Eric Rossman
Subject: I'm running into problems creating a RSA digital signature and then verifying that same signature.
"Since I do not have a private part of the key, I will leave the private exponent length value as zero." How did you call DSG without the private key?
steps 1 and 2 COULD give the same results as step 3 if you format the data a certain way. If you say "HASH" you are saying that the data is already in the correct format. If you ask for "MESSAGE" you are asking for ICSF to hash and format the message. I think you are missing the DER encoding of the hash.
For example, if the hash is '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'X, the input for "HASH" rule should really be
'3031300D060960864801650304020105000420'X||
'0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'X
Which is:
SEQUENCE (2 elem)
SEQUENCE (2 elem)
OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 sha-256
OCTET STRING (32 byte) 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
Thank you for pointing out my error regarding the repeatability of PKCS #1 signatures. Technically, PKCS-1.1 signatures can be repeatable, which is what it appears is happening here.
A terminology clarification: an RSA public key is both the modulus (256 bytes) AND the exponent (3 bytes for '010001'X).
I need to take a break but I will take another look at this later.
------------------------------
Eric Rossman
Original Message:
Sent: Fri March 22, 2024 11:52 AM
From: Mark Vollmer
Subject: I'm running into problems creating a RSA digital signature and then verifying that same signature.
Eric,
Thanks for trying to help me out. I appreciate it.
Regarding PKCS-1.1 --> I've noted that it seems (by eyeball) that the signature results are repeatable in my tests. This suggests the me that the padding might consistent with the data sizes. What am I missing about the steps 1 & 2 vs 3. It would seem to me that step 3 is equivalent to steps 1 & 2. What is happening different that I'm missing? Perhaps it is when and where the padding is applied during the process? Or something else.
Yes, I was looking at the RSA-CRT structure rather than the RSA-PUBL structure. And now I have a question. Since I do not have a private part of the key, I will leave the private exponent length value as zero. My structure now looks like yours, albeit, in COBOL.
The RSA public key I have to work with is just the 256 byte public RSA key. I get to assume the exponent is x'010001'. If it had to specify the exponent when I created the RSA pair (in ICSF), then I did indeed use x'010001'. It is a standard I will not stray from until I know a better, more appropriate, value to use.
I will make the structure changes and try my tests again to see if I get new results.
Thank you.
Sincerely,
------------------------------
Mark Vollmer
Developer, but does everything.
CV Systems, LLC
Original Message:
Sent: Fri March 22, 2024 11:14 AM
From: Eric Rossman
Subject: I'm running into problems creating a RSA digital signature and then verifying that same signature.
Hello Mark. I hope I can help!
Rule PKCS-1.1 implements the "RSA PKCS #1 v2.0 standard for the RSASSA-PKCS1-v1_5 signature scheme" which contains a pseudorandom padding string. This is why FIRSTSIG and SECONDSIG will never match.
I'm not quite sure of the exact parameters of your public key such that it is exactly 256 bytes long. Perhaps you can provide an example (just the public information, no private key information)? Given that you are getting 4/11000 (signature doesn't match), my first guess is that the public key you are building contains the wrong information. Is the PUBKEY you are providing just the modulus and you are assuming that the exponent is X'010001'?
You said:
Use PKB to create a RSA-PUBL external token (RSAPUBTKN) on the PUBKEY (256 byte RSA public key). I use 256 bytes, 2048 bits, with exponent of 3 bytes X'010001'. The structure contains all fixed fields up to and including the 2 byte reserved field. Then the block has 256 byte area for the public key and a 3 byte area for the exponent value. I did not include any of the PPP, QQQ, UUU etc fields in the structure. I'd have no clue what to put in them anyway.
This makes me wonder if you looked at the RSA-CRT section of key_value_structure, since there are no PPP, etc fields for RSA-PUBL rule.
Can you verify that the key_value_structure you provided looks like:
'0800'X || /* Modulus length in bits. */
'0100'X || /* Modulus field length in bytes, "XXX". */
'0003'X || /* Public exponent field length in bytes, "YYY". */
'0000'X || /* Private exponent field length in bytes, "ZZZ". */
PUBKEY || /* Modulus, n. (I'm assuming that PUBKEY is the modulus) */
'010001'X /* RSA public exponent, e. */
/* RSA secret exponent d (none for public key) */
------------------------------
Eric Rossman
Original Message:
Sent: Thu March 21, 2024 12:53 PM
From: Mark Vollmer
Subject: I'm running into problems creating a RSA digital signature and then verifying that same signature.
My goal is to be able to sign a 256byte public RSA key with it's own private key. (Self signed key as it were.) I can't get the target system to accept the signature I create. So I've set out to see if I can validate my own signature.
I start with a RSA key pair in the PKDS (call is RSAPRIM). I also have a 256 binary message (BINMSG) that I need to sign. I have the 256 byte public key (PUBKEY) in program storage that is a match to RSAPRIM. I will use SHA-256 and PKCS-1.1 attributes in my efforts.
(For what it's worth, BINMSG and PUBKEY are identical)
Step 1. Use OWH to apply a SHA-256 hash to the BINMSG to generate a 32 byte hash result.
Step 2. Use DSG to sign that 32 byte hash result using PKCS-1.1 and the RSAPRIM. I get my first signature (FIRSTSIG).
Step 3. Use DSG to sign the BINMSG using MESSAGE, SHA-256, PKCS-1.1 and the RSAPRIM generating my second signature (SECONDSIG).
FIRSTSIG and SECONDSIG do not match.
Use PKB to create a RSA-PUBL external token (RSAPUBTKN) on the PUBKEY (256 byte RSA public key). I use 256 bytes, 2048 bits, with exponent of 3 bytes X'010001'. The structure contains all fixed fields up to and including the 2 byte reserved field. Then the block has 256 byte area for the public key and a 3 byte area for the exponent value. I did not include any of the PPP, QQQ, UUU etc fields in the structure. I'd have no clue what to put in them anyway.
All of the above calls return zeros.
Step 4. Use DSV with MESSAGE, PKCS-1.1 & SHA-256 rules, RSAPUBTKN, source data of BINMSG to try and validate FIRSTSIG. That fails 4/100011. (Good return but failed sig validation).
Step 5. Use DSV with MESSAGE, PKCS-1.1 & SHA-256 rules, RSAPUBTKN, source data of BINMSG to try and validate SECONDTSIG. That fails 4/100011. (Good return but failed sig validation).
I have to be doing something wrong somewhere. I've checked all the parameters (down to the bytes) going into and coming out of each ICSF call. I've very sure they are all correct.
I can't explain why I get two different signature results. I expected them to the the same.
And I can't explain why I can't validate either of the signatures that I've created. Perhaps it has something to do with the RSAPUBTKN I created.
I have visually inspected the RSAPRIM token and confirmed that I do in fact have the corresponding 256 public RSA key in my storage (PUBKEY). I have every reason to believe they match.
I could use a second pair of eyes. Thanks very much for your help.
Sincerely,
------------------------------
Mark Vollmer
Developer, but does everything.
CV Systems, LLC
------------------------------