Main Page | Class List | Directories | File List | Class Members | File Members

dgst.c File Reference

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "apps.h"
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/objects.h>
#include <openssl/x509.h>
#include <openssl/pem.h>

Go to the source code of this file.

Defines

#define BUFSIZE   1024*8
#define PROG   dgst_main
#define PROG_NAME_SIZE   39

Functions

int do_fp (BIO *out, unsigned char *buf, BIO *bp, int sep, int binout, EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title, const char *file)
int MAIN (int, char **)


Define Documentation

#define BUFSIZE   1024*8
 

Definition at line 71 of file dgst.c.

Referenced by do_fp(), doencryption(), main(), RAND_load_file(), RAND_write_file(), and TXT_DB_read().

#define PROG   dgst_main
 

Definition at line 74 of file dgst.c.

#define PROG_NAME_SIZE   39
 

Referenced by main().


Function Documentation

int do_fp BIO out,
unsigned char *  buf,
BIO bp,
int  sep,
int  binout,
EVP_PKEY key,
unsigned char *  sigin,
int  siglen,
const char *  title,
const char *  file
 

Definition at line 411 of file dgst.c.

References bio_err, BIO_get_md_ctx, BIO_gets(), BIO_printf(), BIO_read(), BIO_write(), ctx, ERR_print_errors(), EVP_SignFinal(), EVP_VerifyFinal(), and len.

Referenced by main().

00414         {
00415         int len;
00416         int i;
00417 
00418         for (;;)
00419                 {
00420                 i=BIO_read(bp,(char *)buf,BUFSIZE);
00421                 if(i < 0)
00422                         {
00423                         BIO_printf(bio_err, "Read Error in %s\n",file);
00424                         ERR_print_errors(bio_err);
00425                         return 1;
00426                         }
00427                 if (i == 0) break;
00428                 }
00429         if(sigin)
00430                 {
00431                 EVP_MD_CTX *ctx;
00432                 BIO_get_md_ctx(bp, &ctx);
00433                 i = EVP_VerifyFinal(ctx, sigin, (unsigned int)siglen, key); 
00434                 if(i > 0)
00435                         BIO_printf(out, "Verified OK\n");
00436                 else if(i == 0)
00437                         {
00438                         BIO_printf(out, "Verification Failure\n");
00439                         return 1;
00440                         }
00441                 else
00442                         {
00443                         BIO_printf(bio_err, "Error Verifying Data\n");
00444                         ERR_print_errors(bio_err);
00445                         return 1;
00446                         }
00447                 return 0;
00448                 }
00449         if(key)
00450                 {
00451                 EVP_MD_CTX *ctx;
00452                 BIO_get_md_ctx(bp, &ctx);
00453                 if(!EVP_SignFinal(ctx, buf, (unsigned int *)&len, key)) 
00454                         {
00455                         BIO_printf(bio_err, "Error Signing Data\n");
00456                         ERR_print_errors(bio_err);
00457                         return 1;
00458                         }
00459                 }
00460         else
00461                 len=BIO_gets(bp,(char *)buf,BUFSIZE);
00462 
00463         if(binout) BIO_write(out, buf, len);
00464         else 
00465                 {
00466                 BIO_write(out,title,strlen(title));
00467                 for (i=0; i<len; i++)
00468                         {
00469                         if (sep && (i != 0))
00470                                 BIO_printf(out, ":");
00471                         BIO_printf(out, "%02x",buf[i]);
00472                         }
00473                 BIO_printf(out, "\n");
00474                 }
00475         return 0;
00476         }

int MAIN int  ,
char ** 
 


© sourcejam.com 2005-2008