~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to modules/eng_ossl/bn_powm.cpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*************************************************
2
 
* OpenSSL Modular Exponentiation Source File     *
3
 
* (C) 1999-2007 The Botan Project                *
4
 
*************************************************/
5
 
 
6
 
#include <botan/eng_ossl.h>
7
 
#include <botan/bn_wrap.h>
8
 
 
9
 
namespace Botan {
10
 
 
11
 
namespace {
12
 
 
13
 
/*************************************************
14
 
* OpenSSL Modular Exponentiator                  *
15
 
*************************************************/
16
 
class OpenSSL_Modular_Exponentiator : public Modular_Exponentiator
17
 
   {
18
 
   public:
19
 
      void set_base(const BigInt& b) { base = b; }
20
 
      void set_exponent(const BigInt& e) { exp = e; }
21
 
      BigInt execute() const;
22
 
      Modular_Exponentiator* copy() const
23
 
         { return new OpenSSL_Modular_Exponentiator(*this); }
24
 
 
25
 
      OpenSSL_Modular_Exponentiator(const BigInt& n) : mod(n) {}
26
 
   private:
27
 
      OSSL_BN base, exp, mod;
28
 
      OSSL_BN_CTX ctx;
29
 
   };
30
 
 
31
 
/*************************************************
32
 
* Compute the result                             *
33
 
*************************************************/
34
 
BigInt OpenSSL_Modular_Exponentiator::execute() const
35
 
   {
36
 
   OSSL_BN r;
37
 
   BN_mod_exp(r.value, base.value, exp.value, mod.value, ctx.value);
38
 
   return r.to_bigint();
39
 
   }
40
 
 
41
 
}
42
 
 
43
 
/*************************************************
44
 
* Return the OpenSSL-based modular exponentiator *
45
 
*************************************************/
46
 
Modular_Exponentiator* OpenSSL_Engine::mod_exp(const BigInt& n,
47
 
                                           Power_Mod::Usage_Hints) const
48
 
   {
49
 
   return new OpenSSL_Modular_Exponentiator(n);
50
 
   }
51
 
 
52
 
}