1 /* 2 * 3 * Copyright (C) 2016-2018, 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: Marco Eichelberg 17 * 18 * Purpose: 19 * classes: SiSHA256 20 * 21 */ 22 23 #ifndef SISHA256_H 24 #define SISHA256_H 25 26 #include "dcmtk/config/osconfig.h" 27 #include "dcmtk/dcmsign/simac.h" 28 #include "dcmtk/dcmsign/sitypes.h" 29 30 #ifdef WITH_OPENSSL 31 32 struct SHA256state_st; 33 typedef struct SHA256state_st SHA256_CTX; 34 35 /** 36 * a class implementing the hash function SHA256 37 * @remark this class is only available if DCMTK is compiled with 38 * OpenSSL support enabled. 39 */ 40 class DCMTK_DCMSIGN_EXPORT SiSHA256 : public SiMAC 41 { 42 public: 43 /// default constructor 44 SiSHA256(); 45 46 /// destructor 47 virtual ~SiSHA256(); 48 49 /** initializes the MAC algorithm. 50 * @return status code 51 */ 52 virtual OFCondition initialize(); 53 54 /** feeds data into the MAC algorithm 55 * @param data pointer to raw data to be fed into the MAC, must not be NULL 56 * @param length number of bytes in raw data array 57 * @return status code 58 */ 59 virtual OFCondition digest(const unsigned char *data, unsigned long length); 60 61 /** finalizes the MAC and writes it to the given output array, 62 * which must be at least getSize() bytes large. 63 * After a call to finalize, the MAC algorithm must be initialized 64 * again, see initialize(). 65 * @param result pointer to array of getSize() bytes into which the MAC is written 66 * @return status code 67 */ 68 virtual OFCondition finalize(unsigned char *result); 69 70 /** returns the size of a MAC in bytes. 71 * @return block size for this MAC algorithm 72 */ 73 virtual unsigned long getSize() const; 74 75 /** returns the type of MAC algorithm computed by this object 76 * @return type of MAC algorithm 77 */ 78 virtual E_MACType macType() const; 79 80 /** returns the DICOM identifier for this MAC algorithm 81 * @return DICOM defined term for algorithm 82 */ 83 virtual const char *getDefinedTerm() const; 84 85 private: 86 87 /// private undefined copy constructor 88 SiSHA256(SiSHA256& arg); 89 90 /// private undefined copy assignment operator 91 SiSHA256& operator=(SiSHA256& arg); 92 93 /// OpenSSL SHA256 context 94 SHA256_CTX *ctx; 95 }; 96 97 #endif 98 #endif 99