Coverage Report

Created: 2021-05-04 09:02

/src/botan/build/include/botan/elgamal.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* ElGamal
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_ELGAMAL_H_
9
#define BOTAN_ELGAMAL_H_
10
11
#include <botan/dl_algo.h>
12
13
namespace Botan {
14
15
/**
16
* ElGamal Public Key
17
*/
18
class BOTAN_PUBLIC_API(2,0) ElGamal_PublicKey : public virtual DL_Scheme_PublicKey
19
   {
20
   public:
21
0
      std::string algo_name() const override { return "ElGamal"; }
22
0
      DL_Group_Format group_format() const override { return DL_Group_Format::ANSI_X9_42; }
23
24
      /**
25
      * Load a public key.
26
      * @param alg_id the X.509 algorithm identifier
27
      * @param key_bits DER encoded public key bits
28
      */
29
      ElGamal_PublicKey(const AlgorithmIdentifier& alg_id,
30
                        const std::vector<uint8_t>& key_bits) :
31
         DL_Scheme_PublicKey(alg_id, key_bits, DL_Group_Format::ANSI_X9_42)
32
0
         {}
Unexecuted instantiation: Botan::ElGamal_PublicKey::ElGamal_PublicKey(Botan::AlgorithmIdentifier const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&)
Unexecuted instantiation: Botan::ElGamal_PublicKey::ElGamal_PublicKey(Botan::AlgorithmIdentifier const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&)
33
34
      /**
35
      * Create a public key.
36
      * @param group the underlying DL group
37
      * @param y the public value y = g^x mod p
38
      */
39
      ElGamal_PublicKey(const DL_Group& group, const BigInt& y);
40
41
      std::unique_ptr<PK_Ops::Encryption>
42
         create_encryption_op(RandomNumberGenerator& rng,
43
                              const std::string& params,
44
                              const std::string& provider) const override;
45
46
   protected:
47
0
      ElGamal_PublicKey() = default;
48
   };
49
50
/**
51
* ElGamal Private Key
52
*/
53
class BOTAN_PUBLIC_API(2,0) ElGamal_PrivateKey final : public ElGamal_PublicKey,
54
                                     public virtual DL_Scheme_PrivateKey
55
   {
56
   public:
57
      bool check_key(RandomNumberGenerator& rng, bool) const override;
58
59
      /**
60
      * Load a private key.
61
      * @param alg_id the X.509 algorithm identifier
62
      * @param key_bits DER encoded key bits in ANSI X9.42 format
63
      */
64
      ElGamal_PrivateKey(const AlgorithmIdentifier& alg_id,
65
                         const secure_vector<uint8_t>& key_bits);
66
67
      /**
68
      * Create a private key.
69
      * @param rng random number generator to use
70
      * @param group the group to be used in the key
71
      * @param priv_key the key's secret value (or if zero, generate a new key)
72
      */
73
      ElGamal_PrivateKey(RandomNumberGenerator& rng,
74
                         const DL_Group& group,
75
                         const BigInt& priv_key = BigInt::zero());
76
77
      std::unique_ptr<Public_Key> public_key() const override;
78
79
      std::unique_ptr<PK_Ops::Decryption>
80
         create_decryption_op(RandomNumberGenerator& rng,
81
                              const std::string& params,
82
                              const std::string& provider) const override;
83
   };
84
85
}
86
87
#endif