X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=demos%2Fsign%2Fsign.c;h=0fdf0de387d47a129a9f6753e4e32422ce2109f1;hp=280cc633aced75fda439a3f8af6375fb5b3e9db2;hb=29159a42d2708cb962b3fa6358f3a02ec5cf46b2;hpb=d02b48c63a58ea4367a0e905979f140b7d090f86 diff --git a/demos/sign/sign.c b/demos/sign/sign.c index 280cc633ac..0fdf0de387 100644 --- a/demos/sign/sign.c +++ b/demos/sign/sign.c @@ -1,5 +1,5 @@ /* demos/sign/sign.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -61,16 +61,20 @@ /* converted to C - eay :-) */ +/* reformated a bit and converted to use the more common functions: this was + * initially written at the dawn of time :-) - Steve. + */ + #include -#include "rsa.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" -#include "err.h" -#include "pem.h" -#include "ssl.h" +#include +#include +#include +#include +#include +#include +#include -void main () +int main () { int err; int sig_len; @@ -90,48 +94,60 @@ void main () /* Read private key */ - fp = fopen (keyfile, "r"); if (fp == NULL) exit (1); - pkey = (EVP_PKEY*)PEM_ASN1_read ((char *(*)())d2i_PrivateKey, - PEM_STRING_EVP_PKEY, - fp, - NULL, NULL); - if (pkey == NULL) { ERR_print_errors_fp (stderr); exit (1); } + fp = fopen (keyfile, "r"); + if (fp == NULL) exit (1); + pkey = PEM_read_PrivateKey(fp, NULL, NULL); fclose (fp); + + if (pkey == NULL) { + ERR_print_errors_fp (stderr); + exit (1); + } /* Do the signature */ - EVP_SignInit (&md_ctx, EVP_md5()); + EVP_SignInit (&md_ctx, EVP_sha1()); EVP_SignUpdate (&md_ctx, data, strlen(data)); sig_len = sizeof(sig_buf); - err = EVP_SignFinal (&md_ctx, - sig_buf, - &sig_len, - pkey); - if (err != 1) { ERR_print_errors_fp (stderr); exit (1); } + err = EVP_SignFinal (&md_ctx, sig_buf, &sig_len, pkey); + + if (err != 1) { + ERR_print_errors_fp(stderr); + exit (1); + } + EVP_PKEY_free (pkey); /* Read public key */ - fp = fopen (certfile, "r"); if (fp == NULL) exit (1); - x509 = (X509 *)PEM_ASN1_read ((char *(*)())d2i_X509, - PEM_STRING_X509, - fp, NULL, NULL); - if (x509 == NULL) { ERR_print_errors_fp (stderr); exit (1); } + fp = fopen (certfile, "r"); + if (fp == NULL) exit (1); + x509 = PEM_read_X509(fp, NULL, NULL); fclose (fp); + + if (x509 == NULL) { + ERR_print_errors_fp (stderr); + exit (1); + } /* Get public key - eay */ - pkey=X509_extract_key(x509); - if (pkey == NULL) { ERR_print_errors_fp (stderr); exit (1); } + pkey=X509_get_pubkey(x509); + if (pkey == NULL) { + ERR_print_errors_fp (stderr); + exit (1); + } /* Verify the signature */ - EVP_VerifyInit (&md_ctx, EVP_md5()); + EVP_VerifyInit (&md_ctx, EVP_sha1()); EVP_VerifyUpdate (&md_ctx, data, strlen((char*)data)); - err = EVP_VerifyFinal (&md_ctx, - sig_buf, - sig_len, - pkey); - if (err != 1) { ERR_print_errors_fp (stderr); exit (1); } + err = EVP_VerifyFinal (&md_ctx, sig_buf, sig_len, pkey); EVP_PKEY_free (pkey); + + if (err != 1) { + ERR_print_errors_fp (stderr); + exit (1); + } printf ("Signature Verified Ok.\n"); + return(0); }