One can't always believe everything that is being said. This may often present no problem but if the information is critical it's wise to verify the source. Several algorithms exist for source verification of digital messages, one of which is RSA. These code snippets deliver the power to do RSA signature validation.
rsavalidator Is a simple validator of RSA signatures with no dependencies besides a working C99 compliant C compiler. This validator is intended for small projects for which the excellent OpenSSL would be too much overhead. Be advised that no hashing algorithm is provided (which is required for useful data validation), however many exist in the public domain and most are not hard to implement from scratch.
Contents
Download
Download the source here (v.20080923):
- rsavalidator.h: The validator header
- rsavalidator.c: The validator implementation
- rsatest.c: Example validator usage
Requirements
The validator requires a working C99 compliant compiler. The only C99 dependency is the use of VLA. This can be replaced by malloc calls but that will make the source more complex. gcc -ansi will happily identify the parts that need replacement.
Usage
See the beginning of the rsatest.c file for a sample of its usage.
The rsavalidator exports one function:
int RSAverify(
const int e,
const int nlen,
const unsigned char *n,
const int slen,
const unsigned char *s,
const int mlen,
const unsigned char *m);
e | The exponent part of the public key (usually 3 or 65537) |
nlen | The length of the modulo part of the public key in bytes |
n | The modulo part of the public key |
slen | The length of the signature to validate in bytes |
s | The signature to validate |
mlen | The length of the message to validate in bytes |
m | The message to validate (usually the SHA-1 hash value) |
License
rsavalidator was written and placed in the public domain by Selwyn Kramer (selwyn at nywles.org). If you live in place that doesn't recognize the public domain i promise to look the other way when you steal this code and make it you own.