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: Norbert Loxen, Marco Eichelberg
17  *
18  *  Purpose:
19  *    classes: SiAlgorithm
20  *
21  */
22 
23 #ifndef SIALGO_H
24 #define SIALGO_H
25 
26 #include "dcmtk/config/osconfig.h"
27 
28 #ifdef WITH_OPENSSL
29 
30 #include "dcmtk/dcmsign/sitypes.h"
31 #include "dcmtk/ofstd/oftypes.h"
32 
33 /**
34  *  pure virtual base class of the public key crypto systems used for
35  *  signature creation and verification.
36  *  All public key algorithm classes should inherit from this class.
37  *  Instances of derived classes contain a single private or public key.
38  *  @remark this class is only available if DCMTK is compiled with
39  *  OpenSSL support enabled.
40  */
41 class DCMTK_DCMSIGN_EXPORT SiAlgorithm
42 {
43 public:
44 
45   /// default constructor
SiAlgorithm()46   SiAlgorithm() { }
47 
48   /// destructor
~SiAlgorithm()49   virtual ~SiAlgorithm() { }
50 
51   /** creates a signature.
52    *  @param inputHash array of hash key bytes that are to be signed
53    *  @param inputHashSize length of hash key array in bytes
54    *  @param inputHashAlgorithm MAC algorithm used for creation of hash key.
55    *    Required for creation of PKCS#1 RSA signature padding.
56    *  @param outputSignature pointer to array of at least getSize() which must be allocated by caller.
57    *  @param outputSignatureSize returns the number of bytes written to outputSignature.
58    *  @return SI_EC_Normal if successful, errorcode otherwise.
59    */
60   virtual OFCondition sign(
61     const unsigned char *inputHash,
62     unsigned long inputHashSize,
63     E_MACType inputHashAlgorithm,
64     unsigned char *outputSignature,
65     unsigned long &outputSignatureSize) = 0;
66 
67   /** verifies a signature.
68    *  @param inputHash array of bytes containing hash key to be verified against signature
69    *  @param inputHashSize length of hash key array in bytes
70    *  @param inputHashAlgorithm MAC algorithm used for creation of hash key.
71    *    Required for creation of PKCS#1 RSA signature padding.
72    *  @param inputSignature array of bytes containing signature to be verified
73    *  @param inputSignatureSize length of signature array in bytes
74    *  @param verified returns whether the signature was successfully verified
75    *  @return SI_EC_Normal if successful, errorcode otherwise.
76    */
77   virtual OFCondition verify(
78     const unsigned char *inputHash,
79     unsigned long inputHashSize,
80     E_MACType inputHashAlgorithm,
81     const unsigned char *inputSignature,
82     unsigned long inputSignatureSize,
83     OFBool &verified) = 0;
84 
85   /** returns the size of a block of encrypted/decrypted ciphertext in bytes.
86    *  The result depends on the public key algorithm, key size and padding scheme.
87    *  In general the input to decrypt() or encrypt() must be less than or equal
88    *  to this block size.  The output of decrypt() or encrypt() is always equal
89    *  to this block size.
90    *  @return block size for this public key cryptosystem and key
91    */
92   virtual unsigned long getSize() const = 0;
93 
94   /** returns the type of public key algorithm computed by this object
95    *  @return type of public key algorithm
96    */
97   virtual E_KeyType keyType() const = 0;
98 
99 };
100 
101 #endif
102 #endif
103