/*************************************************
* Discrete Logarithm Group Header File           *
* (C) 1999-2003 The Botan Project                *
*************************************************/

#ifndef BOTAN_DL_PARM_H__
#define BOTAN_DL_PARM_H__

#include <botan/bigint.h>
#include <botan/data_src.h>

namespace Botan {

/*************************************************
* Discrete Logarithm Group                       *
*************************************************/
class DL_Group
   {
   public:
      const BigInt& get_p() const;
      const BigInt& get_q() const;
      const BigInt& get_g() const;

      enum EncodingFormat { ANSI_X9_42, ANSI_X9_57, PKCS_3 };
      enum PrimeType { Strong, Prime_Subgroup, DSA_Kosherizer };

      PrimeType group_type() const;
      bool verify_group() const;

      std::string PEM_encode(EncodingFormat) const;
      SecureVector<byte> DER_encode(EncodingFormat) const;
      void BER_decode(DataSource&, EncodingFormat);
      void PEM_decode(DataSource&);

      DL_Group();
      DL_Group(u32bit, PrimeType = Strong);
      DL_Group(const SecureVector<byte>&, u32bit = 1024, u32bit = 0);
      DL_Group(const BigInt&, const BigInt&);
      DL_Group(const BigInt&, const BigInt&, const BigInt&);
   private:
      void init_check() const;
      void initialize(const BigInt&, const BigInt&, const BigInt&);
      bool initialized;
      BigInt p, q, g;
   };

/*************************************************
* Retrieve a DL group by name                    *
*************************************************/
const DL_Group& get_dl_group(const std::string&);

/*************************************************
* Register a named DL group                      *
*************************************************/
void add_dl_group(const std::string&, const DL_Group&);

/*************************************************
* Destroy all the DL groups                      *
*************************************************/
void destroy_dl_groups();

}

#endif
