1 /* 2 * 3 * Copyright (C) 1998-2019, 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: SiDSA 20 * 21 */ 22 23 #ifndef SIDSA_H 24 #define SIDSA_H 25 26 #include "dcmtk/config/osconfig.h" 27 28 #ifdef WITH_OPENSSL 29 30 #include "dcmtk/dcmsign/sialgo.h" 31 #include "dcmtk/ofstd/oftypes.h" 32 33 class SiPrivateKey; 34 struct dsa_st; 35 typedef struct dsa_st DSA; 36 37 /** 38 * This class implements the DSA public key crypto algorithms. 39 * @remark This class is only available if DCMTK is compiled with 40 * OpenSSL support enabled. 41 */ 42 43 class DCMTK_DCMSIGN_EXPORT SiDSA : public SiAlgorithm 44 { 45 public: 46 47 /** constructor 48 * @param pointer to public DSA key 49 */ 50 SiDSA(DSA *key); 51 52 /// destructor 53 virtual ~SiDSA(); 54 55 /** creates a signature. 56 * @param inputHash array of hash key bytes that are to be signed 57 * @param inputHashSize length of hash key array in bytes 58 * @param inputHashAlgorithm MAC algorithm used for creation of hash key. Ignored for DSA signatures. 59 * @param outputSignature pointer to array of at least getSize() which must be allocated by caller. 60 * @param outputSignatureSize returns the number of bytes written to outputSignature. 61 * @return SI_EC_Normal if successful, errorcode otherwise. 62 */ 63 virtual OFCondition sign( 64 const unsigned char *inputHash, 65 unsigned long inputHashSize, 66 E_MACType inputHashAlgorithm, 67 unsigned char *outputSignature, 68 unsigned long &outputSignatureSize); 69 70 /** verifies a signature. 71 * @param inputHash array of bytes containing hash key to be verified against signature 72 * @param inputHashSize length of hash key array in bytes 73 * @param inputHashAlgorithm MAC algorithm used for creation of hash key. Ignored for DSA signatures. 74 * @param inputSignature array of bytes containing signature to be verified 75 * @param inputSignatureSize length of signature array in bytes 76 * @param verified returns whether the signature was successfully verified 77 * @return SI_EC_Normal if successful, errorcode otherwise. 78 */ 79 virtual OFCondition verify( 80 const unsigned char *inputHash, 81 unsigned long inputHashSize, 82 E_MACType inputHashAlgorithm, 83 const unsigned char *inputSignature, 84 unsigned long inputSignatureSize, 85 OFBool &verified); 86 87 /** returns the size of a block of encrypted/decrypted ciphertext in bytes. 88 * The result depends on the public key algorithm, key size and padding scheme. 89 * In general the input to decrypt() or encrypt() must be less than or equal 90 * to this block size. The output of decrypt() or encrypt() is always equal 91 * to this block size. 92 * @return block size for this public key cryptosystem and key 93 */ 94 virtual unsigned long getSize() const; 95 96 /** returns the type of public key algorithm computed by this object 97 * @return type of public key algorithm 98 */ 99 virtual E_KeyType keyType() const; 100 101 private: 102 103 /// private undefined copy constructor 104 SiDSA(SiDSA& arg); 105 106 /// private undefined copy assignment operator 107 SiDSA& operator=(SiDSA& arg); 108 109 /// DSA key used for signature/verification 110 DSA *dsa; 111 112 }; 113 114 #endif 115 #endif 116