1 /* 2 * 3 * Copyright (C) 1998-2010, OFFIS e.V. 4 * All rights reserved. See COPYRIGHT file for details. 5 * 6 * This software and supporting documentation were developed by 7 * 8 * OFFIS e.V. 9 * R&D Division Health 10 * Escherweg 2 11 * D-26121 Oldenburg, Germany 12 * 13 * 14 * Module: dcmsign 15 * 16 * Author: Norbert Loxen, Marco Eichelberg 17 * 18 * Purpose: 19 * classes: SiSHA1 20 * 21 */ 22 23 #include "dcmtk/config/osconfig.h" 24 25 #ifdef WITH_OPENSSL 26 27 #include "dcmtk/dcmsign/sisha1.h" 28 #include "dcmtk/dcmdata/dcerror.h" 29 30 #define INCLUDE_CSTDLIB 31 #include "dcmtk/ofstd/ofstdinc.h" 32 33 BEGIN_EXTERN_C 34 #include <openssl/sha.h> 35 END_EXTERN_C 36 37 SiSHA1()38SiSHA1::SiSHA1() 39 : ctx(new SHA_CTX()) 40 { 41 initialize(); 42 } 43 ~SiSHA1()44SiSHA1::~SiSHA1() 45 { 46 delete ctx; 47 } 48 getSize() const49unsigned long SiSHA1::getSize() const 50 { 51 return SHA_DIGEST_LENGTH; 52 } 53 initialize()54OFCondition SiSHA1::initialize() 55 { 56 SHA1_Init(ctx); 57 return EC_Normal; 58 } 59 digest(const unsigned char * data,unsigned long length)60OFCondition SiSHA1::digest(const unsigned char *data, unsigned long length) 61 { 62 if (length == 0) return EC_Normal; 63 if ((data == NULL)||(ctx == NULL)) return EC_IllegalCall; 64 SHA1_Update(ctx, data, length); 65 return EC_Normal; 66 } 67 finalize(unsigned char * result)68OFCondition SiSHA1::finalize(unsigned char *result) 69 { 70 if ((result == NULL)||(ctx == NULL)) return EC_IllegalCall; 71 SHA1_Final(result, ctx); 72 return EC_Normal; 73 } 74 macType() const75E_MACType SiSHA1::macType() const 76 { 77 return EMT_SHA1; 78 } 79 getDefinedTerm() const80const char *SiSHA1::getDefinedTerm() const 81 { 82 return SI_DEFTERMS_SHA1; 83 } 84 85 #else /* WITH_OPENSSL */ 86 87 int sisha1_cc_dummy_to_keep_linker_from_moaning = 0; 88 89 #endif 90