diff options
| author | 1998-10-05 20:12:28 +0000 | |
|---|---|---|
| committer | 1998-10-05 20:12:28 +0000 | |
| commit | 5b37fcf34e412bf0b6ad32ddb294e900d64c5855 (patch) | |
| tree | cf5d52f4abf74eb3ee59fd705ef686e3c5b96d91 /lib/libssl/src/demos/maurice/example2.c | |
| parent | add a reference to fork(2) \ (diff) | |
| download | wireguard-openbsd-5b37fcf34e412bf0b6ad32ddb294e900d64c5855.tar.xz wireguard-openbsd-5b37fcf34e412bf0b6ad32ddb294e900d64c5855.zip | |
Import of SSLeay-0.9.0b with RSA and IDEA stubbed + OpenBSD build
functionality for shared libs.
Note that routines such as sslv2_init and friends that use RSA will
not work due to lack of RSA in this library.
Needs documentation and help from ports for easy upgrade to full
functionality where legally possible.
Diffstat (limited to 'lib/libssl/src/demos/maurice/example2.c')
| -rw-r--r-- | lib/libssl/src/demos/maurice/example2.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/libssl/src/demos/maurice/example2.c b/lib/libssl/src/demos/maurice/example2.c new file mode 100644 index 00000000000..99f7b224409 --- /dev/null +++ b/lib/libssl/src/demos/maurice/example2.c @@ -0,0 +1,77 @@ +/* NOCW */ +/* + Please read the README file for condition of use, before + using this software. + + Maurice Gittens <mgittens@gits.nl> January 1997 +*/ + +#include <stdlib.h> +#include <stdio.h> +#include <strings.h> + +#include "rsa.h" +#include "evp.h" +#include "objects.h" +#include "x509.h" +#include "err.h" +#include "pem.h" +#include "ssl.h" + +#include "loadkeys.h" + +#define PUBFILE "cert.pem" +#define PRIVFILE "privkey.pem" +#define STDIN 0 +#define STDOUT 1 + +int main() +{ + char *ct = "This the clear text"; + char *buf; + char *buf2; + EVP_PKEY *pubKey; + EVP_PKEY *privKey; + int len; + FILE *fp; + + ERR_load_crypto_strings(); + + privKey = ReadPrivateKey(PRIVFILE); + if (!privKey) + { + ERR_print_errors_fp (stderr); + exit (1); + } + + pubKey = ReadPublicKey(PUBFILE); + if(!pubKey) + { + EVP_PKEY_free(privKey); + fprintf(stderr,"Error: can't load public key"); + exit(1); + } + + /* No error checking */ + buf = malloc(EVP_PKEY_size(pubKey)); + buf2 = malloc(EVP_PKEY_size(pubKey)); + + len = RSA_public_encrypt(strlen(ct)+1, ct, buf, pubKey->pkey.rsa,RSA_PKCS1_PADDING); + + if (len != EVP_PKEY_size(pubKey)) + { + fprintf(stderr,"Error: ciphertext should match length of key\n"); + exit(1); + } + + RSA_private_decrypt(len, buf, buf2, privKey->pkey.rsa,RSA_PKCS1_PADDING); + + printf("%s\n", buf2); + + EVP_PKEY_free(privKey); + EVP_PKEY_free(pubKey); + free(buf); + free(buf2); +} + + |
