Hello Kaleb,
There is no protocol, I am just using wolfSSL in a proof of concept where the DSA algorithm is used to sign messages.
The steps I am making are:
0. a public/private key pair is generated, the client has the private key while the server has the public counterpart
I performed this step using openssl, then exported both keys to DER encoded files
openssl dsaparam -out dsaparam.pem 1024
openssl gendsa -out dsa.pem dsaparam.pem
openssl dsa -in dsa.pem -outform DER -pubout -out dsa_public.der
openssl dsa -in dsa.pem -outform DER -out dsa_private.der
1. a message (= octect string) is generated at the client side and signed with the private key:
// this code is based on section 10.5.4 of the wolfSSL manual, error handling is not shown for brevity
DsaKey privKey;
RNG rng;
uint8_t signature[40] = { 0x00 };
uint8_t shaDigest[SHA256_DIGEST_SIZE] = { 0x00 };
uint32_t idx = 0;
// initialize random number generator and DSA private key structure
wc_InitDsaKey(&privKey);
wc_InitRng(&rng);
// load the key, assumed to be in ASN.1 DER encoding
// pKey is a uint8_t buffer with the contents of the file dsa_private.der
// keySize is the length of the pKey buffer
wc_DsaPrivateKeyDecode(pKey, &idx, &privKey, keySize);
// hash the message (also done using wolfCrypt functions, but not show for brevity)
// message is an uint8_t buffer, with size messageSize
// I verified the hash and it is correct
compute_sha256(shaDigest,message, messageSize);
// compute the signature
wc_DsaSign(shaDigest,signature,&privKey, &rng);
// free used resources
wc_FreeDsaKey(&privKey);
wc_FreeRng(&rng);
2. append the signature to the end of the message, message = message || signature
This is done by simply writing both to a file.
3. send it to the server and verify its signature
In this proof of concept, it is just a Python program that reads the public key and the file with: message || signature
I am using the Python library cryptography https://cryptography.io/en/latest/
The signature verification fails (step 3), because the Python library expects the signature to be encoded per RFC 3279 (https://cryptography.io/en/latest/hazma … a/#signing), instead of being the concatenation of R and S.
It is very much possible that I am not correctly using the wolfCrypt library or that I am using the DSA algorithm in the wrong manner. But I cannot understand what it is.