/*************************************************
* IF Scheme Header File                          *
* (C) 1999-2003 The Botan Project                *
*************************************************/

#ifndef BOTAN_IF_ALGO_H__
#define BOTAN_IF_ALGO_H__

#include <botan/mod_exp.h>
#include <botan/x509_key.h>
#include <botan/pkcs8.h>
#include <botan/blinding.h>

namespace Botan {

/*************************************************
* IF Public Key                                  *
*************************************************/
class IF_Scheme_PublicKey : public virtual X509_PublicKey
   {
   public:
      const BigInt& get_n() const { return n; }
      const BigInt& get_e() const { return e; }
      virtual ~IF_Scheme_PublicKey() {}
   protected:
      void if_initialize(const BigInt&, const BigInt&, bool);
      BigInt n, e;
      FixedExponent_Exp powermod_e_n;
   private:
      SecureVector<byte> DER_encode_pub() const;
      void BER_decode_pub(DataSource&);
      bool odd_exponent;
   };

/*************************************************
* IF Private Key                                 *
*************************************************/
class IF_Scheme_PrivateKey : public virtual IF_Scheme_PublicKey,
                             public virtual PKCS8_PrivateKey
   {
   public:
      bool check_params() const;
      const BigInt& get_p() const { return p; }
      const BigInt& get_q() const { return q; }
      const BigInt& get_d() const { return d; }
   protected:
      BigInt if_private_op(const BigInt&) const;
      void precompute();
      BigInt d, p, q, d1, d2, c;
      FixedExponent_Exp powermod_d1_p, powermod_d2_q;
   private:
      Blinder blinder;
      SecureVector<byte> DER_encode_priv() const;
      void BER_decode_priv(DataSource&);
   };

}

#endif
