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 SIECDSA_H
24 #define SIECDSA_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 ec_key_st;
35 typedef struct ec_key_st EC_KEY;
36 
37 /**
38  *  This class implements the ECDSA 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 SiECDSA : public SiAlgorithm
44 {
45 public:
46 
47   /** constructor
48    *  @param pointer to public ECDSA key
49    */
50   SiECDSA(EC_KEY *key);
51 
52   /// destructor
53   virtual ~SiECDSA();
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 ECDSA 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 ECDSA 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   SiECDSA(SiECDSA& arg);
105 
106   /// private undefined copy assignment operator
107   SiECDSA& operator=(SiECDSA& arg);
108 
109   /// ECDSA key used for signature/verification
110   EC_KEY *ecdsa;
111 
112 };
113 
114 #endif
115 #endif
116